]> granicus.if.org Git - ejabberd/commitdiff
Merge branch 'master' into xml-ng
authorEvgeniy Khramtsov <ekhramtsov@process-one.net>
Sat, 12 Nov 2016 10:27:15 +0000 (13:27 +0300)
committerEvgeniy Khramtsov <ekhramtsov@process-one.net>
Sat, 12 Nov 2016 10:27:15 +0000 (13:27 +0300)
Conflicts:
src/adhoc.erl
src/cyrsasl_oauth.erl
src/ejabberd_c2s.erl
src/ejabberd_config.erl
src/ejabberd_service.erl
src/gen_mod.erl
src/mod_admin_extra.erl
src/mod_announce.erl
src/mod_carboncopy.erl
src/mod_client_state.erl
src/mod_configure.erl
src/mod_echo.erl
src/mod_mam.erl
src/mod_muc.erl
src/mod_muc_room.erl
src/mod_offline.erl
src/mod_pubsub.erl
src/mod_stats.erl
src/node_flat_sql.erl
src/randoms.erl

53 files changed:
1  2 
Makefile.in
include/mod_muc_room.hrl
include/ns.hrl
include/xmpp_codec.hrl
specs/xmpp_codec.spec
src/acl.erl
src/cyrsasl_oauth.erl
src/cyrsasl_scram.erl
src/ejabberd_app.erl
src/ejabberd_c2s.erl
src/ejabberd_http.erl
src/ejabberd_http_bind.erl
src/ejabberd_http_ws.erl
src/ejabberd_local.erl
src/ejabberd_oauth.erl
src/ejabberd_s2s.erl
src/ejabberd_s2s_out.erl
src/ejabberd_service.erl
src/ejabberd_sm.erl
src/ejabberd_sm_redis.erl
src/ejabberd_sql.erl
src/ejabberd_web_admin.erl
src/ejabberd_xmlrpc.erl
src/jid.erl
src/jlib.erl
src/mod_admin_extra.erl
src/mod_announce.erl
src/mod_carboncopy.erl
src/mod_client_state.erl
src/mod_configure.erl
src/mod_delegation.erl
src/mod_echo.erl
src/mod_http_api.erl
src/mod_http_upload_quota.erl
src/mod_irc.erl
src/mod_mam.erl
src/mod_mix.erl
src/mod_muc.erl
src/mod_muc_admin.erl
src/mod_muc_log.erl
src/mod_muc_room.erl
src/mod_offline.erl
src/mod_offline_sql.erl
src/mod_privacy_sql.erl
src/mod_privilege.erl
src/mod_pubsub.erl
src/mod_roster.erl
src/mod_stats.erl
src/node_flat_sql.erl
src/node_mb.erl
src/nodetree_tree_sql.erl
src/xmpp_codec.erl
src/xmpp_util.erl

diff --cc Makefile.in
Simple merge
Simple merge
diff --cc include/ns.hrl
Simple merge
index 443769bb78917eb6f7b7d5751fc9c6640a13d02f,0000000000000000000000000000000000000000..981f7f4c2bb091ee66a958e082fc2b7ee26e200a
mode 100644,000000..100644
--- /dev/null
@@@ -1,1067 -1,0 +1,1092 @@@
- -record(forwarded, {delay :: #delay{},
-                     sub_els = [] :: [xmpp_element() | fxml:xmlel()]}).
- -type forwarded() :: #forwarded{}.
 +%% Created automatically by XML generator (fxml_gen.erl)
 +%% Source: xmpp_codec.spec
 +
 +-record(vcard_xupdate, {us = {<<>>, <<>>} :: {binary(), binary()},
 +                      hash :: binary()}).
 +-type vcard_xupdate() :: #vcard_xupdate{}.
 +
 +-record(ps_affiliation, {xmlns = <<>> :: binary(),
 +                       node = <<>> :: binary(),
 +                       type :: member | none | outcast |
 +                               owner | publisher | publish_only,
 +                       jid :: jid:jid()}).
 +-type ps_affiliation() :: #ps_affiliation{}.
 +
 +-type ps_error_type() :: 'closed-node' | 'configuration-required' |
 +                       'invalid-jid' | 'invalid-options' |
 +                       'invalid-payload' | 'invalid-subid' |
 +                       'item-forbidden' | 'item-required' | 'jid-required' |
 +                       'max-items-exceeded' | 'max-nodes-exceeded' |
 +                       'nodeid-required' | 'not-in-roster-group' |
 +                       'not-subscribed' | 'payload-too-big' |
 +                       'payload-required' | 'pending-subscription' |
 +                       'presence-subscription-required' | 'subid-required' |
 +                       'too-many-subscriptions' | 'unsupported' |
 +                       'unsupported-access-model'.
 +-type ps_feature() :: 'access-authorize' | 'access-open' |
 +                    'access-presence' | 'access-roster' |
 +                    'access-whitelist' | 'auto-create' |
 +                    'auto-subscribe' | 'collections' | 'config-node' |
 +                    'create-and-configure' | 'create-nodes' |
 +                    'delete-items' | 'delete-nodes' |
 +                    'filtered-notifications' | 'get-pending' |
 +                    'instant-nodes' | 'item-ids' | 'last-published' |
 +                    'leased-subscription' | 'manage-subscriptions' |
 +                    'member-affiliation' | 'meta-data' |
 +                    'modify-affiliations' | 'multi-collection' |
 +                    'multi-subscribe' | 'outcast-affiliation' |
 +                    'persistent-items' | 'presence-notifications' |
 +                    'presence-subscribe' | 'publish' |
 +                    'publish-options' | 'publish-only-affiliation' |
 +                    'publisher-affiliation' | 'purge-nodes' |
 +                    'retract-items' | 'retrieve-affiliations' |
 +                    'retrieve-default' | 'retrieve-items' |
 +                    'retrieve-subscriptions' | 'subscribe' |
 +                    'subscription-options' | 'subscription-notifications'.
 +-record(ps_error, {type :: ps_error_type(), feature :: ps_feature()}).
 +-type ps_error() :: #ps_error{}.
 +
 +-record(chatstate, {type :: active | composing | gone | inactive | paused}).
 +-type chatstate() :: #chatstate{}.
 +
 +-record(csi, {type :: active | inactive}).
 +-type csi() :: #csi{}.
 +
 +-record(hint, {type :: 'no-copy' | 'no-store' | 'no-storage' | 'store' |
 +                     'no-permanent-store' | 'no-permanent-storage'}).
 +-type hint() :: #hint{}.
 +
 +-record(iq, {id = <<>> :: binary(),
 +             type :: 'error' | 'get' | 'result' | 'set',
 +             lang = <<>> :: binary(),
 +             from :: jid:jid(),
 +             to :: jid:jid(),
 +             sub_els = [] :: [xmpp_element() | fxml:xmlel()]}).
 +-type iq() :: #iq{}.
 +
 +-record(feature_register, {}).
 +-type feature_register() :: #feature_register{}.
 +
 +-record(adhoc_note, {type = info :: 'error' | 'info' | 'warn',
 +                     data = <<>> :: binary()}).
 +-type adhoc_note() :: #adhoc_note{}.
 +
 +-record(address, {type :: 'bcc' | 'cc' | 'noreply' | 'ofrom' | 'replyroom' | 'replyto' | 'to',
 +                  jid :: jid:jid(),
 +                  desc = <<>> :: binary(),
 +                  node = <<>> :: binary(),
 +                  delivered :: boolean()}).
 +-type address() :: #address{}.
 +
 +-record(sasl_success, {text = <<>> :: binary()}).
 +-type sasl_success() :: #sasl_success{}.
 +
 +-record(mam_result, {xmlns = <<>> :: binary(),
 +                     queryid = <<>> :: binary(),
 +                     id = <<>> :: binary(),
 +                     sub_els = [] :: [xmpp_element() | fxml:xmlel()]}).
 +-type mam_result() :: #mam_result{}.
 +
 +-record(rsm_first, {index :: non_neg_integer(),
 +                    data = <<>> :: binary()}).
 +-type rsm_first() :: #rsm_first{}.
 +
 +-record(text, {lang = <<>> :: binary(),
 +               data = <<>> :: binary()}).
 +-type text() :: #text{}.
 +
 +-record(streamhost, {jid :: jid:jid(),
 +                     host = <<>> :: binary(),
 +                     port = 1080 :: non_neg_integer()}).
 +-type streamhost() :: #streamhost{}.
 +
 +-record(sm_resume, {h :: non_neg_integer(),
 +                    previd = <<>> :: binary(),
 +                    xmlns = <<>> :: binary()}).
 +-type sm_resume() :: #sm_resume{}.
 +
 +-record(carbons_enable, {}).
 +-type carbons_enable() :: #carbons_enable{}.
 +
 +-record(carbons_private, {}).
 +-type carbons_private() :: #carbons_private{}.
 +
 +-record(expire, {seconds :: non_neg_integer(),
 +                 stored :: non_neg_integer()}).
 +-type expire() :: #expire{}.
 +
 +-record(muc_unsubscribe, {}).
 +-type muc_unsubscribe() :: #muc_unsubscribe{}.
 +
 +-record(ps_unsubscribe, {node = <<>> :: binary(),
 +                         jid :: jid:jid(),
 +                         subid = <<>> :: binary()}).
 +-type ps_unsubscribe() :: #ps_unsubscribe{}.
 +
 +-record(mix_leave, {}).
 +-type mix_leave() :: #mix_leave{}.
 +
 +-record(ping, {}).
 +-type ping() :: #ping{}.
 +
 +-record(delay, {stamp :: erlang:timestamp(),
 +                from :: jid:jid(),
 +                desc = <<>> :: binary()}).
 +-type delay() :: #delay{}.
 +
 +-record(muc_history, {maxchars :: non_neg_integer(),
 +                      maxstanzas :: non_neg_integer(),
 +                      seconds :: non_neg_integer(),
 +                      since :: erlang:timestamp()}).
 +-type muc_history() :: #muc_history{}.
 +
 +-record(thumbnail, {uri = <<>> :: binary(),
 +                    'media-type' = <<>> :: binary(),
 +                    width :: non_neg_integer(),
 +                    height :: non_neg_integer()}).
 +-type thumbnail() :: #thumbnail{}.
 +
++-record(privilege_perm, {access :: 'message' | 'presence' | 'roster',
++                         type :: 'both' | 'get' | 'managed_entity' | 'none' | 'outgoing' | 'roster' | 'set'}).
++-type privilege_perm() :: #privilege_perm{}.
++
 +-record(muc_decline, {reason = <<>> :: binary(),
 +                      from :: jid:jid(),
 +                      to :: jid:jid()}).
 +-type muc_decline() :: #muc_decline{}.
 +
 +-record(sm_a, {h :: non_neg_integer(),
 +               xmlns = <<>> :: binary()}).
 +-type sm_a() :: #sm_a{}.
 +
 +-record(stream_start, {from :: jid:jid(),
 +                       to :: jid:jid(),
 +                       id = <<>> :: binary(),
 +                       version :: {non_neg_integer(),non_neg_integer()},
 +                       xmlns = <<>> :: binary(),
 +                       stream_xmlns = <<>> :: binary(),
 +                       db_xmlns = <<>> :: binary(),
 +                       lang = <<>> :: binary()}).
 +-type stream_start() :: #stream_start{}.
 +
 +-record(muc_subscribe, {nick = <<>> :: binary(),
 +                        events = [] :: [binary()]}).
 +-type muc_subscribe() :: #muc_subscribe{}.
 +
 +-record(stanza_id, {by :: jid:jid(),
 +                    id = <<>> :: binary()}).
 +-type stanza_id() :: #stanza_id{}.
 +
 +-record(starttls_proceed, {}).
 +-type starttls_proceed() :: #starttls_proceed{}.
 +
++-record(forwarded, {delay :: #delay{},
++                    sub_els = [] :: [xmpp_element() | fxml:xmlel()]}).
++-type forwarded() :: #forwarded{}.
++
++-record(privilege, {perms = [] :: [#privilege_perm{}],
++                    forwarded :: #forwarded{}}).
++-type privilege() :: #privilege{}.
++
 +-record(client_id, {id = <<>> :: binary()}).
 +-type client_id() :: #client_id{}.
 +
 +-record(sm_resumed, {h :: non_neg_integer(),
 +                     previd = <<>> :: binary(),
 +                     xmlns = <<>> :: binary()}).
 +-type sm_resumed() :: #sm_resumed{}.
 +
- -type xmpp_element() :: muc_admin() |
-                         compression() |
 +-record(sm_enable, {max :: non_neg_integer(),
 +                    resume = false :: boolean(),
 +                    xmlns = <<>> :: binary()}).
 +-type sm_enable() :: #sm_enable{}.
 +
 +-record(starttls_failure, {}).
 +-type starttls_failure() :: #starttls_failure{}.
 +
 +-record(sasl_challenge, {text = <<>> :: binary()}).
 +-type sasl_challenge() :: #sasl_challenge{}.
 +
 +-record(handshake, {data = <<>> :: binary()}).
 +-type handshake() :: #handshake{}.
 +
 +-record(gone, {uri = <<>> :: binary()}).
 +-type gone() :: #gone{}.
 +
 +-record(x_conference, {jid :: jid:jid(),
 +                       password = <<>> :: binary(),
 +                       reason = <<>> :: binary(),
 +                       continue :: boolean(),
 +                       thread = <<>> :: binary()}).
 +-type x_conference() :: #x_conference{}.
 +
 +-record(private, {xml_els = [] :: [fxml:xmlel()]}).
 +-type private() :: #private{}.
 +
++-record(delegation_query, {to :: jid:jid(),
++                           delegate = [] :: [binary()]}).
++-type delegation_query() :: #delegation_query{}.
++
 +-record(db_verify, {from = <<>> :: binary(),
 +                    to = <<>> :: binary(),
 +                    id = <<>> :: binary(),
 +                    type :: 'error' | 'invalid' | 'valid',
 +                    key = <<>> :: binary(),
 +                    sub_els = [] :: [xmpp_element() | fxml:xmlel()]}).
 +-type db_verify() :: #db_verify{}.
 +
 +-record(nick, {name = <<>> :: binary()}).
 +-type nick() :: #nick{}.
 +
 +-record(p1_ack, {}).
 +-type p1_ack() :: #p1_ack{}.
 +
 +-record(feature_sm, {xmlns = <<>> :: binary()}).
 +-type feature_sm() :: #feature_sm{}.
 +
 +-record(ps_item, {xmlns = <<>> :: binary(),
 +                  id = <<>> :: binary(),
 +                  xml_els = [] :: [fxml:xmlel()],
 +                  node = <<>> :: binary(),
 +                  publisher = <<>> :: binary()}).
 +-type ps_item() :: #ps_item{}.
 +
 +-record(ps_publish, {node = <<>> :: binary(),
 +                     items = [] :: [#ps_item{}]}).
 +-type ps_publish() :: #ps_publish{}.
 +
 +-record(roster_item, {jid :: jid:jid(),
 +                      name = <<>> :: binary(),
 +                      groups = [] :: [binary()],
 +                      subscription = none :: 'both' | 'from' | 'none' | 'remove' | 'to',
 +                      ask :: 'subscribe'}).
 +-type roster_item() :: #roster_item{}.
 +
 +-record(roster_query, {items = [] :: [#roster_item{}],
 +                       ver :: binary()}).
 +-type roster_query() :: #roster_query{}.
 +
 +-record(sm_r, {xmlns = <<>> :: binary()}).
 +-type sm_r() :: #sm_r{}.
 +
 +-record(muc_actor, {jid :: jid:jid(),
 +                    nick = <<>> :: binary()}).
 +-type muc_actor() :: #muc_actor{}.
 +
 +-record(stat_error, {code :: integer(),
 +                     reason = <<>> :: binary()}).
 +-type stat_error() :: #stat_error{}.
 +
 +-record(stat, {name = <<>> :: binary(),
 +               units = <<>> :: binary(),
 +               value = <<>> :: binary(),
 +               error :: #stat_error{}}).
 +-type stat() :: #stat{}.
 +
 +-record(addresses, {list = [] :: [#address{}]}).
 +-type addresses() :: #addresses{}.
 +
 +-record('see-other-host', {host :: binary() | inet:ip_address() | {binary() | inet:ip_address(),non_neg_integer()}}).
 +-type 'see-other-host'() :: #'see-other-host'{}.
 +
 +-record(compress, {methods = [] :: [binary()]}).
 +-type compress() :: #compress{}.
 +
 +-record(starttls, {required = false :: boolean()}).
 +-type starttls() :: #starttls{}.
 +
 +-record(last, {seconds :: non_neg_integer(),
 +               status = <<>> :: binary()}).
 +-type last() :: #last{}.
 +
 +-record(redirect, {uri = <<>> :: binary()}).
 +-type redirect() :: #redirect{}.
 +
 +-record(sm_enabled, {id = <<>> :: binary(),
 +                     location = <<>> :: binary(),
 +                     max :: non_neg_integer(),
 +                     resume = false :: boolean(),
 +                     xmlns = <<>> :: binary()}).
 +-type sm_enabled() :: #sm_enabled{}.
 +
 +-record(muc_unique, {name = <<>> :: binary()}).
 +-type muc_unique() :: #muc_unique{}.
 +
 +-record(sasl_response, {text = <<>> :: binary()}).
 +-type sasl_response() :: #sasl_response{}.
 +
 +-record(legacy_auth, {username :: binary(),
 +                      password :: binary(),
 +                      digest :: binary(),
 +                      resource :: binary()}).
 +-type legacy_auth() :: #legacy_auth{}.
 +
 +-record(ps_subscribe, {node = <<>> :: binary(),
 +                       jid :: jid:jid()}).
 +-type ps_subscribe() :: #ps_subscribe{}.
 +
 +-record(message, {id = <<>> :: binary(),
 +                  type = normal :: 'chat' | 'error' | 'groupchat' | 'headline' | 'normal',
 +                  lang = <<>> :: binary(),
 +                  from :: jid:jid(),
 +                  to :: jid:jid(),
 +                  subject = [] :: [#text{}],
 +                  body = [] :: [#text{}],
 +                  thread :: binary(),
 +                  sub_els = [] :: [xmpp_element() | fxml:xmlel()]}).
 +-type message() :: #message{}.
 +
 +-record(sasl_auth, {mechanism = <<>> :: binary(),
 +                    text = <<>> :: binary()}).
 +-type sasl_auth() :: #sasl_auth{}.
 +
 +-record(p1_push, {}).
 +-type p1_push() :: #p1_push{}.
 +
 +-record(feature_csi, {xmlns = <<>> :: binary()}).
 +-type feature_csi() :: #feature_csi{}.
 +
 +-record(disco_item, {jid :: jid:jid(),
 +                     name = <<>> :: binary(),
 +                     node = <<>> :: binary()}).
 +-type disco_item() :: #disco_item{}.
 +
 +-record(unblock, {items = [] :: [jid:jid()]}).
 +-type unblock() :: #unblock{}.
 +
 +-record(block, {items = [] :: [jid:jid()]}).
 +-type block() :: #block{}.
 +
 +-record(compression, {methods = [] :: [binary()]}).
 +-type compression() :: #compression{}.
 +
 +-record(muc_subscriptions, {list = [] :: [jid:jid()]}).
 +-type muc_subscriptions() :: #muc_subscriptions{}.
 +
 +-record(ps_subscription, {xmlns = <<>> :: binary(),
 +                          jid :: jid:jid(),
 +                          type :: 'none' | 'pending' | 'subscribed' | 'unconfigured',
 +                          node = <<>> :: binary(),
 +                          subid = <<>> :: binary(),
 +                          expiry :: erlang:timestamp()}).
 +-type ps_subscription() :: #ps_subscription{}.
 +
 +-record(bob_data, {cid = <<>> :: binary(),
 +                   'max-age' :: non_neg_integer(),
 +                   type = <<>> :: binary(),
 +                   data = <<>> :: binary()}).
 +-type bob_data() :: #bob_data{}.
 +
 +-record(muc_item, {actor :: #muc_actor{},
 +                   continue :: binary(),
 +                   reason = <<>> :: binary(),
 +                   affiliation :: 'admin' | 'member' | 'none' | 'outcast' | 'owner',
 +                   role :: 'moderator' | 'none' | 'participant' | 'visitor',
 +                   jid :: jid:jid(),
 +                   nick = <<>> :: binary()}).
 +-type muc_item() :: #muc_item{}.
 +
 +-record(muc_admin, {items = [] :: [#muc_item{}]}).
 +-type muc_admin() :: #muc_admin{}.
 +
 +-record(shim, {headers = [] :: [{binary(),binary()}]}).
 +-type shim() :: #shim{}.
 +
 +-record(mam_prefs, {xmlns = <<>> :: binary(),
 +                    default :: 'always' | 'never' | 'roster',
 +                    always :: [jid:jid()],
 +                    never :: [jid:jid()]}).
 +-type mam_prefs() :: #mam_prefs{}.
 +
 +-record(caps, {node = <<>> :: binary(),
 +               version = <<>> :: binary(),
 +               hash = <<>> :: binary(),
 +               exts = [] :: [binary()]}).
 +-type caps() :: #caps{}.
 +
 +-record(muc, {history :: #muc_history{},
 +              password :: binary()}).
 +-type muc() :: #muc{}.
 +
 +-record(stream_features, {sub_els = [] :: [xmpp_element() | fxml:xmlel()]}).
 +-type stream_features() :: #stream_features{}.
 +
 +-record(stats, {list = [] :: [#stat{}],
 +                node = <<>> :: binary()}).
 +-type stats() :: #stats{}.
 +
 +-record(ps_items, {xmlns = <<>> :: binary(),
 +                   node = <<>> :: binary(),
 +                   items = [] :: [#ps_item{}],
 +                   max_items :: non_neg_integer(),
 +                   subid = <<>> :: binary(),
 +                   retract :: binary()}).
 +-type ps_items() :: #ps_items{}.
 +
 +-record(presence, {id = <<>> :: binary(),
 +                   type = available :: 'available' | 'error' | 'probe' | 'subscribe' | 'subscribed' | 'unavailable' | 'unsubscribe' | 'unsubscribed',
 +                   lang = <<>> :: binary(),
 +                   from :: jid:jid(),
 +                   to :: jid:jid(),
 +                   show :: 'away' | 'chat' | 'dnd' | 'xa',
 +                   status = [] :: [#text{}],
 +                   priority :: integer(),
 +                   sub_els = [] :: [xmpp_element() | fxml:xmlel()]}).
 +-type presence() :: #presence{}.
 +
 +-record(sic, {ip :: inet:ip_address(),
 +              port :: non_neg_integer(),
 +              xmlns = <<>> :: binary()}).
 +-type sic() :: #sic{}.
 +
 +-record(carbons_sent, {forwarded :: #forwarded{}}).
 +-type carbons_sent() :: #carbons_sent{}.
 +
 +-record(mam_archived, {by :: jid:jid(),
 +                       id = <<>> :: binary()}).
 +-type mam_archived() :: #mam_archived{}.
 +
 +-record(p1_rebind, {}).
 +-type p1_rebind() :: #p1_rebind{}.
 +
 +-record(compress_failure, {reason :: 'processing-failed' | 'setup-failed' | 'unsupported-method'}).
 +-type compress_failure() :: #compress_failure{}.
 +
 +-record(sasl_abort, {}).
 +-type sasl_abort() :: #sasl_abort{}.
 +
 +-record(xevent, {offline = false :: boolean(),
 +                 delivered = false :: boolean(),
 +                 displayed = false :: boolean(),
 +                 composing = false :: boolean(),
 +                 id :: binary()}).
 +-type xevent() :: #xevent{}.
 +
 +-record(vcard_email, {home = false :: boolean(),
 +                      work = false :: boolean(),
 +                      internet = false :: boolean(),
 +                      pref = false :: boolean(),
 +                      x400 = false :: boolean(),
 +                      userid :: binary()}).
 +-type vcard_email() :: #vcard_email{}.
 +
 +-record(db_result, {from = <<>> :: binary(),
 +                    to = <<>> :: binary(),
 +                    type :: 'error' | 'invalid' | 'valid',
 +                    key = <<>> :: binary(),
 +                    sub_els = [] :: [xmpp_element() | fxml:xmlel()]}).
 +-type db_result() :: #db_result{}.
 +
 +-record(carbons_received, {forwarded :: #forwarded{}}).
 +-type carbons_received() :: #carbons_received{}.
 +
 +-record(ps_retract, {node = <<>> :: binary(),
 +                     notify = false :: boolean(),
 +                     items = [] :: [#ps_item{}]}).
 +-type ps_retract() :: #ps_retract{}.
 +
 +-record(upload_slot, {get :: binary(),
 +                      put :: binary(),
 +                      xmlns = <<>> :: binary()}).
 +-type upload_slot() :: #upload_slot{}.
 +
 +-record(mix_participant, {jid :: jid:jid(),
 +                          nick = <<>> :: binary()}).
 +-type mix_participant() :: #mix_participant{}.
 +
 +-record(vcard_geo, {lat :: binary(),
 +                    lon :: binary()}).
 +-type vcard_geo() :: #vcard_geo{}.
 +
 +-record(compressed, {}).
 +-type compressed() :: #compressed{}.
 +
 +-record(sasl_failure, {reason :: 'aborted' | 'account-disabled' | 'bad-protocol' | 'credentials-expired' | 'encryption-required' | 'incorrect-encoding' | 'invalid-authzid' | 'invalid-mechanism' | 'malformed-request' | 'mechanism-too-weak' | 'not-authorized' | 'temporary-auth-failure',
 +                       text = [] :: [#text{}]}).
 +-type sasl_failure() :: #sasl_failure{}.
 +
 +-record(block_list, {items = [] :: [jid:jid()]}).
 +-type block_list() :: #block_list{}.
 +
 +-record(upload_request, {filename :: binary(),
 +                         size :: non_neg_integer(),
 +                         'content-type' = <<>> :: binary(),
 +                         xmlns = <<>> :: binary()}).
 +-type upload_request() :: #upload_request{}.
 +
 +-record(xdata_option, {label = <<>> :: binary(),
 +                       value :: binary()}).
 +-type xdata_option() :: #xdata_option{}.
 +
 +-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(),
 +                      required = false :: boolean(),
 +                      desc = <<>> :: binary(),
 +                      values = [] :: [binary()],
 +                      options = [] :: [#xdata_option{}],
 +                      sub_els = [] :: [xmpp_element() | fxml:xmlel()]}).
 +-type xdata_field() :: #xdata_field{}.
 +
 +-record(version, {name :: binary(),
 +                  ver :: binary(),
 +                  os :: binary()}).
 +-type version() :: #version{}.
 +
 +-record(bind, {jid :: jid:jid(),
 +               resource = <<>> :: binary()}).
 +-type bind() :: #bind{}.
 +
 +-record(rosterver_feature, {}).
 +-type rosterver_feature() :: #rosterver_feature{}.
 +
 +-record(muc_invite, {reason = <<>> :: binary(),
 +                     from :: jid:jid(),
 +                     to :: jid:jid(),
 +                     continue :: binary()}).
 +-type muc_invite() :: #muc_invite{}.
 +
++-record(delegated, {ns = <<>> :: binary(),
++                    attrs = [] :: [binary()]}).
++-type delegated() :: #delegated{}.
++
 +-record(carbons_disable, {}).
 +-type carbons_disable() :: #carbons_disable{}.
 +
 +-record(bytestreams, {hosts = [] :: [#streamhost{}],
 +                      used :: jid:jid(),
 +                      activate :: jid:jid(),
 +                      dstaddr = <<>> :: binary(),
 +                      mode = tcp :: 'tcp' | 'udp',
 +                      sid = <<>> :: binary()}).
 +-type bytestreams() :: #bytestreams{}.
 +
 +-record(adhoc_actions, {execute :: 'complete' | 'next' | 'prev',
 +                        prev = false :: boolean(),
 +                        next = false :: boolean(),
 +                        complete = false :: boolean()}).
 +-type adhoc_actions() :: #adhoc_actions{}.
 +
 +-record(vcard_org, {name :: binary(),
 +                    units = [] :: [binary()]}).
 +-type vcard_org() :: #vcard_org{}.
 +
 +-record(rsm_set, {'after' :: binary(),
 +                  before :: binary(),
 +                  count :: non_neg_integer(),
 +                  first :: #rsm_first{},
 +                  index :: non_neg_integer(),
 +                  last :: binary(),
 +                  max :: non_neg_integer()}).
 +-type rsm_set() :: #rsm_set{}.
 +
 +-record(mam_fin, {xmlns = <<>> :: binary(),
 +                  id = <<>> :: binary(),
 +                  rsm :: #rsm_set{},
 +                  stable :: boolean(),
 +                  complete :: boolean()}).
 +-type mam_fin() :: #mam_fin{}.
 +
 +-record(disco_items, {node = <<>> :: binary(),
 +                      items = [] :: [#disco_item{}],
 +                      rsm :: #rsm_set{}}).
 +-type disco_items() :: #disco_items{}.
 +
 +-record(vcard_tel, {home = false :: boolean(),
 +                    work = false :: boolean(),
 +                    voice = false :: boolean(),
 +                    fax = false :: boolean(),
 +                    pager = false :: boolean(),
 +                    msg = false :: boolean(),
 +                    cell = false :: boolean(),
 +                    video = false :: boolean(),
 +                    bbs = false :: boolean(),
 +                    modem = false :: boolean(),
 +                    isdn = false :: boolean(),
 +                    pcs = false :: boolean(),
 +                    pref = false :: boolean(),
 +                    number :: binary()}).
 +-type vcard_tel() :: #vcard_tel{}.
 +
 +-record(media_uri, {type = <<>> :: binary(),
 +                    uri = <<>> :: binary()}).
 +-type media_uri() :: #media_uri{}.
 +
 +-record(media, {height :: non_neg_integer(),
 +                width :: non_neg_integer(),
 +                uri = [] :: [#media_uri{}]}).
 +-type media() :: #media{}.
 +
 +-record(muc_destroy, {xmlns = <<>> :: binary(),
 +                      jid :: jid:jid(),
 +                      reason = <<>> :: binary(),
 +                      password :: binary()}).
 +-type muc_destroy() :: #muc_destroy{}.
 +
 +-record(muc_user, {decline :: #muc_decline{},
 +                   destroy :: #muc_destroy{},
 +                   invites = [] :: [#muc_invite{}],
 +                   items = [] :: [#muc_item{}],
 +                   status_codes = [] :: [pos_integer()],
 +                   password :: binary()}).
 +-type muc_user() :: #muc_user{}.
 +
 +-record(vcard_key, {type :: binary(),
 +                    cred :: binary()}).
 +-type vcard_key() :: #vcard_key{}.
 +
 +-record(vcard_name, {family :: binary(),
 +                     given :: binary(),
 +                     middle :: binary(),
 +                     prefix :: binary(),
 +                     suffix :: binary()}).
 +-type vcard_name() :: #vcard_name{}.
 +
 +-record(identity, {category = <<>> :: binary(),
 +                   type = <<>> :: binary(),
 +                   lang = <<>> :: binary(),
 +                   name = <<>> :: binary()}).
 +-type identity() :: #identity{}.
 +
 +-record(bookmark_conference, {name = <<>> :: binary(),
 +                              jid :: jid:jid(),
 +                              autojoin = false :: boolean(),
 +                              nick :: binary(),
 +                              password :: binary()}).
 +-type bookmark_conference() :: #bookmark_conference{}.
 +
 +-record(xmpp_session, {optional = false :: boolean()}).
 +-type xmpp_session() :: #xmpp_session{}.
 +
 +-record(bookmark_url, {name = <<>> :: binary(),
 +                       url = <<>> :: binary()}).
 +-type bookmark_url() :: #bookmark_url{}.
 +
 +-record(bookmark_storage, {conference = [] :: [#bookmark_conference{}],
 +                           url = [] :: [#bookmark_url{}]}).
 +-type bookmark_storage() :: #bookmark_storage{}.
 +
 +-record(oob_x, {url :: binary(),
 +                desc = <<>> :: binary(),
 +                sid = <<>> :: binary()}).
 +-type oob_x() :: #oob_x{}.
 +
 +-record(vcard_sound, {phonetic :: binary(),
 +                      binval :: binary(),
 +                      extval :: binary()}).
 +-type vcard_sound() :: #vcard_sound{}.
 +
 +-record(vcard_photo, {type :: binary(),
 +                      binval :: binary(),
 +                      extval :: binary()}).
 +-type vcard_photo() :: #vcard_photo{}.
 +
 +-record(vcard_label, {home = false :: boolean(),
 +                      work = false :: boolean(),
 +                      postal = false :: boolean(),
 +                      parcel = false :: boolean(),
 +                      dom = false :: boolean(),
 +                      intl = false :: boolean(),
 +                      pref = false :: boolean(),
 +                      line = [] :: [binary()]}).
 +-type vcard_label() :: #vcard_label{}.
 +
 +-record(vcard_adr, {home = false :: boolean(),
 +                    work = false :: boolean(),
 +                    postal = false :: boolean(),
 +                    parcel = false :: boolean(),
 +                    dom = false :: boolean(),
 +                    intl = false :: boolean(),
 +                    pref = false :: boolean(),
 +                    pobox :: binary(),
 +                    extadd :: binary(),
 +                    street :: binary(),
 +                    locality :: binary(),
 +                    region :: binary(),
 +                    pcode :: binary(),
 +                    ctry :: binary()}).
 +-type vcard_adr() :: #vcard_adr{}.
 +
 +-record(search_item, {jid :: jid:jid(),
 +                      first :: binary(),
 +                      last :: binary(),
 +                      nick :: binary(),
 +                      email :: binary()}).
 +-type search_item() :: #search_item{}.
 +
 +-record(xdata, {type :: 'cancel' | 'form' | 'result' | 'submit',
 +                instructions = [] :: [binary()],
 +                title :: binary(),
 +                reported :: [#xdata_field{}],
 +                items = [] :: [[#xdata_field{}]],
 +                fields = [] :: [#xdata_field{}]}).
 +-type xdata() :: #xdata{}.
 +
 +-record(xcaptcha, {xdata :: #xdata{}}).
 +-type xcaptcha() :: #xcaptcha{}.
 +
 +-record(adhoc_command, {node = <<>> :: binary(),
 +                        action = execute :: 'cancel' | 'complete' | 'execute' | 'next' | 'prev',
 +                        sid = <<>> :: binary(),
 +                        status :: 'canceled' | 'completed' | 'executing',
 +                        lang = <<>> :: binary(),
 +                        actions :: #adhoc_actions{},
 +                        notes = [] :: [#adhoc_note{}],
 +                        xdata :: #xdata{}}).
 +-type adhoc_command() :: #adhoc_command{}.
 +
 +-record(search, {instructions :: binary(),
 +                 first :: binary(),
 +                 last :: binary(),
 +                 nick :: binary(),
 +                 email :: binary(),
 +                 items = [] :: [#search_item{}],
 +                 xdata :: #xdata{}}).
 +-type search() :: #search{}.
 +
 +-record(mam_query, {xmlns = <<>> :: binary(),
 +                    id = <<>> :: binary(),
 +                    start :: erlang:timestamp(),
 +                    'end' :: erlang:timestamp(),
 +                    with :: jid:jid(),
 +                    withtext :: binary(),
 +                    rsm :: #rsm_set{},
 +                    xdata :: #xdata{}}).
 +-type mam_query() :: #mam_query{}.
 +
 +-record(pubsub_owner, {affiliations :: {binary(),[#ps_affiliation{}]},
 +                       configure :: {binary(),'undefined' | #xdata{}},
 +                       default :: {binary(),'undefined' | #xdata{}},
 +                       delete :: {binary(),binary()},
 +                       purge :: binary(),
 +                       subscriptions :: {binary(),[#ps_subscription{}]}}).
 +-type pubsub_owner() :: #pubsub_owner{}.
 +
 +-record(ps_options, {node = <<>> :: binary(),
 +                     jid :: jid:jid(),
 +                     subid = <<>> :: binary(),
 +                     xdata :: #xdata{}}).
 +-type ps_options() :: #ps_options{}.
 +
 +-record(pubsub, {subscriptions :: {binary(),[#ps_subscription{}]},
 +                 subscription :: #ps_subscription{},
 +                 affiliations :: {binary(),[#ps_affiliation{}]},
 +                 publish :: #ps_publish{},
 +                 publish_options :: #xdata{},
 +                 subscribe :: #ps_subscribe{},
 +                 unsubscribe :: #ps_unsubscribe{},
 +                 options :: #ps_options{},
 +                 items :: #ps_items{},
 +                 retract :: #ps_retract{},
 +                 create :: binary(),
 +                 configure :: {binary(),'undefined' | #xdata{}},
 +                 default :: {binary(),'undefined' | #xdata{}},
 +                 delete :: {binary(),binary()},
 +                 purge :: binary(),
 +                 rsm :: #rsm_set{}}).
 +-type pubsub() :: #pubsub{}.
 +
 +-record(ps_event, {items :: #ps_items{},
 +                   purge :: binary(),
 +                   subscription :: #ps_subscription{},
 +                   delete :: {binary(),binary()},
 +                   create :: binary(),
 +                   configuration :: {binary(),'undefined' | #xdata{}}}).
 +-type ps_event() :: #ps_event{}.
 +
 +-record(register, {registered = false :: boolean(),
 +                   remove = false :: boolean(),
 +                   instructions :: binary(),
 +                   username :: binary(),
 +                   nick :: binary(),
 +                   password :: binary(),
 +                   name :: binary(),
 +                   first :: binary(),
 +                   last :: binary(),
 +                   email :: binary(),
 +                   address :: binary(),
 +                   city :: binary(),
 +                   state :: binary(),
 +                   zip :: binary(),
 +                   phone :: binary(),
 +                   url :: binary(),
 +                   date :: binary(),
 +                   misc :: binary(),
 +                   text :: binary(),
 +                   key :: binary(),
 +                   xdata :: #xdata{},
 +                   sub_els = [] :: [xmpp_element() | fxml:xmlel()]}).
 +-type register() :: #register{}.
 +
 +-record(disco_info, {node = <<>> :: binary(),
 +                     identities = [] :: [#identity{}],
 +                     features = [] :: [binary()],
 +                     xdata = [] :: [#xdata{}]}).
 +-type disco_info() :: #disco_info{}.
 +
 +-record(offline_item, {node = <<>> :: binary(),
 +                       action :: 'remove' | 'view'}).
 +-type offline_item() :: #offline_item{}.
 +
 +-record(offline, {items = [] :: [#offline_item{}],
 +                  purge = false :: boolean(),
 +                  fetch = false :: boolean()}).
 +-type offline() :: #offline{}.
 +
 +-record(muc_owner, {destroy :: #muc_destroy{},
 +                    config :: #xdata{},
 +                    items = [] :: [#muc_item{}]}).
 +-type muc_owner() :: #muc_owner{}.
 +
 +-record(sasl_mechanisms, {list = [] :: [binary()]}).
 +-type sasl_mechanisms() :: #sasl_mechanisms{}.
 +
 +-record(sm_failed, {reason :: atom() | #gone{} | #redirect{},
 +                    h :: non_neg_integer(),
 +                    xmlns = <<>> :: binary()}).
 +-type sm_failed() :: #sm_failed{}.
 +
 +-record(stanza_error, {type :: 'auth' | 'cancel' | 'continue' | 'modify' | 'wait',
 +                       code :: non_neg_integer(),
 +                       by = <<>> :: binary(),
 +                       reason :: atom() | #gone{} | #redirect{},
 +                       text :: #text{},
 +                       sub_els = [] :: [xmpp_element() | fxml:xmlel()]}).
 +-type stanza_error() :: #stanza_error{}.
 +
++-record(delegation, {delegated = [] :: [#delegated{}],
++                     forwarded :: #forwarded{}}).
++-type delegation() :: #delegation{}.
++
 +-record(mix_join, {jid :: jid:jid(),
 +                   subscribe = [] :: [binary()]}).
 +-type mix_join() :: #mix_join{}.
 +
 +-record(privacy_item, {order :: non_neg_integer(),
 +                       action :: 'allow' | 'deny',
 +                       type :: 'group' | 'jid' | 'subscription',
 +                       value = <<>> :: binary(),
 +                       message = false :: boolean(),
 +                       iq = false :: boolean(),
 +                       presence_in = false :: boolean(),
 +                       presence_out = false :: boolean()}).
 +-type privacy_item() :: #privacy_item{}.
 +
 +-record(privacy_list, {name = <<>> :: binary(),
 +                       items = [] :: [#privacy_item{}]}).
 +-type privacy_list() :: #privacy_list{}.
 +
 +-record(privacy_query, {lists = [] :: [#privacy_list{}],
 +                        default :: 'none' | binary(),
 +                        active :: 'none' | binary()}).
 +-type privacy_query() :: #privacy_query{}.
 +
 +-record(stream_error, {reason :: atom() | #'see-other-host'{},
 +                       text :: #text{}}).
 +-type stream_error() :: #stream_error{}.
 +
 +-record(vcard_logo, {type :: binary(),
 +                     binval :: binary(),
 +                     extval :: binary()}).
 +-type vcard_logo() :: #vcard_logo{}.
 +
 +-record(vcard_temp, {version :: binary(),
 +                     fn :: binary(),
 +                     n :: #vcard_name{},
 +                     nickname :: binary(),
 +                     photo :: #vcard_photo{},
 +                     bday :: binary(),
 +                     adr = [] :: [#vcard_adr{}],
 +                     label = [] :: [#vcard_label{}],
 +                     tel = [] :: [#vcard_tel{}],
 +                     email = [] :: [#vcard_email{}],
 +                     jabberid :: binary(),
 +                     mailer :: binary(),
 +                     tz :: binary(),
 +                     geo :: #vcard_geo{},
 +                     title :: binary(),
 +                     role :: binary(),
 +                     logo :: #vcard_logo{},
 +                     org :: #vcard_org{},
 +                     categories = [] :: [binary()],
 +                     note :: binary(),
 +                     prodid :: binary(),
 +                     rev :: binary(),
 +                     sort_string :: binary(),
 +                     sound :: #vcard_sound{},
 +                     uid :: binary(),
 +                     url :: binary(),
 +                     class :: 'confidential' | 'private' | 'public',
 +                     key :: #vcard_key{},
 +                     desc :: binary()}).
 +-type vcard_temp() :: #vcard_temp{}.
 +
 +-record(time, {tzo :: {integer(),integer()},
 +               utc :: erlang:timestamp()}).
 +-type time() :: #time{}.
 +
-                         ps_affiliation() |
-                         mam_fin() |
++-type xmpp_element() :: compression() |
 +                        ps_subscription() |
 +                        xdata_option() |
 +                        version() |
-                         forwarded() |
 +                        sm_a() |
 +                        bob_data() |
 +                        media() |
 +                        stanza_id() |
 +                        starttls_proceed() |
++                        forwarded() |
 +                        client_id() |
 +                        sm_resumed() |
-                         privacy_query() |
 +                        xevent() |
 +                        privacy_list() |
 +                        carbons_sent() |
 +                        mam_archived() |
 +                        p1_rebind() |
 +                        sasl_abort() |
 +                        db_result() |
 +                        carbons_received() |
 +                        upload_slot() |
 +                        mix_participant() |
 +                        compressed() |
 +                        block_list() |
++                        delegated() |
 +                        rsm_set() |
 +                        'see-other-host'() |
 +                        hint() |
 +                        stream_start() |
 +                        text() |
 +                        vcard_org() |
 +                        shim() |
 +                        search_item() |
 +                        offline_item() |
 +                        feature_sm() |
 +                        roster_item() |
 +                        muc_item() |
 +                        vcard_temp() |
 +                        address() |
 +                        sasl_success() |
 +                        addresses() |
 +                        muc_subscriptions() |
 +                        disco_items() |
 +                        compress() |
 +                        bytestreams() |
 +                        adhoc_actions() |
++                        privacy_query() |
 +                        muc_history() |
 +                        identity() |
 +                        feature_csi() |
-                         db_verify() |
-                         roster_query() |
 +                        delay() |
 +                        thumbnail() |
 +                        vcard_tel() |
 +                        vcard_geo() |
 +                        vcard_photo() |
 +                        pubsub_owner() |
 +                        pubsub() |
 +                        muc_owner() |
 +                        muc_actor() |
 +                        ps_error() |
 +                        starttls_failure() |
 +                        sasl_challenge() |
 +                        x_conference() |
 +                        private() |
 +                        sasl_failure() |
 +                        vcard_name() |
 +                        adhoc_note() |
 +                        rosterver_feature() |
 +                        muc_invite() |
 +                        vcard_xupdate() |
 +                        carbons_disable() |
 +                        bookmark_conference() |
 +                        offline() |
 +                        time() |
 +                        ps_subscribe() |
 +                        sm_enable() |
 +                        handshake() |
 +                        compress_failure() |
 +                        bookmark_storage() |
 +                        muc_decline() |
 +                        legacy_auth() |
 +                        search() |
 +                        ps_publish() |
 +                        nick() |
 +                        p1_ack() |
 +                        block() |
++                        delegation() |
 +                        mix_join() |
 +                        xmpp_session() |
 +                        xdata() |
 +                        iq() |
 +                        xcaptcha() |
 +                        streamhost() |
 +                        bind() |
 +                        ps_retract() |
 +                        last() |
 +                        redirect() |
 +                        sm_enabled() |
 +                        vcard_sound() |
 +                        ps_event() |
 +                        mam_result() |
 +                        rsm_first() |
 +                        stat() |
 +                        upload_request() |
 +                        xdata_field() |
 +                        adhoc_command() |
 +                        sm_failed() |
 +                        ping() |
++                        privilege_perm() |
 +                        privacy_item() |
 +                        disco_item() |
 +                        ps_item() |
 +                        mam_prefs() |
 +                        sasl_mechanisms() |
 +                        caps() |
 +                        muc() |
 +                        stream_features() |
 +                        stats() |
 +                        ps_items() |
 +                        sic() |
 +                        ps_options() |
 +                        starttls() |
++                        db_verify() |
++                        roster_query() |
 +                        media_uri() |
 +                        muc_destroy() |
 +                        vcard_key() |
 +                        csi() |
-                         unblock().
++                        delegation_query() |
 +                        mam_query() |
 +                        bookmark_url() |
 +                        vcard_email() |
 +                        vcard_label() |
 +                        vcard_logo() |
 +                        disco_info() |
 +                        feature_register() |
 +                        register() |
 +                        sm_r() |
 +                        stat_error() |
 +                        stanza_error() |
 +                        stream_error() |
 +                        muc_user() |
 +                        vcard_adr() |
 +                        gone() |
 +                        carbons_private() |
 +                        mix_leave() |
 +                        muc_subscribe() |
++                        privilege() |
 +                        muc_unique() |
 +                        sasl_response() |
 +                        message() |
 +                        presence() |
 +                        sm_resume() |
 +                        carbons_enable() |
 +                        expire() |
 +                        muc_unsubscribe() |
 +                        ps_unsubscribe() |
 +                        chatstate() |
 +                        sasl_auth() |
 +                        p1_push() |
 +                        oob_x() |
++                        unblock() |
++                        muc_admin() |
++                        ps_affiliation() |
++                        mam_fin().
index 608e1fe2de6f1e1573e2da210051d6fc4a5129b8,acf9c3bb7e874f1a94f91f55482af1c3bee4e601..12bc4b6a944cabacd0304515922f99ce3b634d92
  
  -xml(mix_participant,
       #elem{name = <<"participant">>,
 -           xmlns = <<"urn:xmpp:mix:0">>,
 -           result = {mix_participant, '$jid', '$nick'},
 -           attrs = [#attr{name = <<"jid">>,
 -                          required = true,
 -                          label = '$jid',
 -                          dec = {dec_jid, []},
 +         xmlns = <<"urn:xmpp:mix:0">>,
 +         result = {mix_participant, '$jid', '$nick'},
 +         attrs = [#attr{name = <<"jid">>,
 +                        required = true,
 +                        label = '$jid',
 +                        dec = {dec_jid, []},
                            enc = {enc_jid, []}},
 -                    #attr{name = <<"nick">>,
 -                          label = '$nick'}]}).
 +                  #attr{name = <<"nick">>,
 +                        label = '$nick'}]}).
 +
 +-record(hint, {type :: 'no-copy' | 'no-store' | 'no-storage' | 'store' |
 +                     'no-permanent-store' | 'no-permanent-storage'}).
 +-type hint() :: #hint{}.
 +
 +-xml(hint_no_copy,
 +     #elem{name = <<"no-copy">>,
 +         xmlns = <<"urn:xmpp:hints">>,
 +         result = {hint, 'no-copy'}}).
 +
 +-xml(hint_no_store,
 +     #elem{name = <<"no-store">>,
 +         xmlns = <<"urn:xmpp:hints">>,
 +         result = {hint, 'no-store'}}).
 +
 +-xml(hint_no_storage,
 +     #elem{name = <<"no-storage">>,
 +         xmlns = <<"urn:xmpp:hints">>,
 +         result = {hint, 'no-storage'}}).
 +
 +-xml(hint_store,
 +     #elem{name = <<"store">>,
 +         xmlns = <<"urn:xmpp:hints">>,
 +         result = {hint, 'store'}}).
 +
 +-xml(hint_no_permanent_store,
 +     #elem{name = <<"no-permanent-store">>,
 +         xmlns = <<"urn:xmpp:hints">>,
 +         result = {hint, 'no-permanent-store'}}).
 +
 +-xml(hint_no_permanent_storage,
 +     #elem{name = <<"no-permanent-storage">>,
 +         xmlns = <<"urn:xmpp:hints">>,
 +         result = {hint, 'no-permanent-storage'}}).
 +
 +-xml(search_instructions,
 +     #elem{name = <<"instructions">>,
 +           xmlns = <<"jabber:iq:search">>,
 +           result = '$cdata'}).
 +
 +-xml(search_first,
 +     #elem{name = <<"first">>,
 +         xmlns = <<"jabber:iq:search">>,
 +         cdata = #cdata{default = <<"">>},
 +           result = '$cdata'}).
 +-xml(search_last,
 +     #elem{name = <<"last">>,
 +           xmlns = <<"jabber:iq:search">>,
 +           cdata = #cdata{default = <<"">>},
 +           result = '$cdata'}).
 +-xml(search_nick,
 +     #elem{name = <<"nick">>,
 +           xmlns = <<"jabber:iq:search">>,
 +           cdata = #cdata{default = <<"">>},
 +           result = '$cdata'}).
 +-xml(search_email,
 +     #elem{name = <<"email">>,
 +           xmlns = <<"jabber:iq:search">>,
 +           cdata = #cdata{default = <<"">>},
 +           result = '$cdata'}).
 +
 +-xml(search_item,
 +     #elem{name = <<"item">>,
 +         xmlns = <<"jabber:iq:search">>,
 +         result = {search_item, '$jid', '$first', '$last', '$nick', '$email'},
 +         attrs = [#attr{name = <<"jid">>,
 +                        required = true,
 +                        enc = {enc_jid, []},
 +                        dec = {dec_jid, []}}],
 +         refs = [#ref{name = search_first, min = 0, max = 1,
 +                      label = '$first'},
 +                 #ref{name = search_last, min = 0, max = 1,
 +                      label = '$last'},
 +                 #ref{name = search_nick, min = 0, max = 1,
 +                      label = '$nick'},
 +                 #ref{name = search_email, min = 0, max = 1,
 +                      label = '$email'}]}).
 +
 +-xml(search,
 +     #elem{name = <<"query">>,
 +         xmlns = <<"jabber:iq:search">>,
 +         result = {search, '$instructions', '$first', '$last',
 +                   '$nick', '$email', '$items', '$xdata'},
 +         refs = [#ref{name = search_instructions, min = 0, max = 1,
 +                        label = '$instructions'},
 +                 #ref{name = search_first, min = 0, max = 1,
 +                      label = '$first'},
 +                 #ref{name = search_last, min = 0, max = 1,
 +                      label = '$last'},
 +                 #ref{name = search_nick, min = 0, max = 1,
 +                      label = '$nick'},
 +                 #ref{name = search_email, min = 0, max = 1,
 +                      label = '$email'},
 +                 #ref{name = search_item, label = '$items'},
 +                 #ref{name = xdata, min = 0, max = 1,
 +                      label = '$xdata'}]}).
 +
 +-xml(xevent_offline,
 +     #elem{name = <<"offline">>,
 +         xmlns = <<"jabber:x:event">>,
 +         result = true}).
 +-xml(xevent_delivered,
 +     #elem{name = <<"delivered">>,
 +         xmlns = <<"jabber:x:event">>,
 +         result = true}).
 +-xml(xevent_displayed,
 +     #elem{name = <<"displayed">>,
 +         xmlns = <<"jabber:x:event">>,
 +         result = true}).
 +-xml(xevent_composing,
 +     #elem{name = <<"composing">>,
 +         xmlns = <<"jabber:x:event">>,
 +         result = true}).
 +-xml(xevent_id,
 +     #elem{name = <<"id">>,
 +         xmlns = <<"jabber:x:event">>,
 +         cdata = #cdata{},
 +           result = '$cdata'}).
 +
 +-xml(xevent,
 +     #elem{name = <<"x">>,
 +         xmlns = <<"jabber:x:event">>,
 +         result = {xevent, '$offline', '$delivered', '$displayed',
 +                   '$composing', '$id'},
 +         refs = [#ref{name = xevent_offline, min = 0, max = 1,
 +                      label = '$offline', default = false},
 +                 #ref{name = xevent_delivered, min = 0, max = 1,
 +                      label = '$delivered', default = false},
 +                 #ref{name = xevent_displayed, min = 0, max = 1,
 +                      label = '$displayed', default = false},
 +                 #ref{name = xevent_composing, min = 0, max = 1,
 +                      label = '$composing', default = false},
 +                 #ref{name = xevent_id, min = 0, max = 1,
 +                      label = '$id'}]}).
 +
 +-xml(expire,
 +     #elem{name = <<"x">>,
 +         xmlns = <<"jabber:x:expire">>,
 +         result = {expire, '$seconds', '$stored'},
 +         attrs = [#attr{name = <<"seconds">>,
 +                        required = true,
 +                        dec = {dec_int, [0, infinity]},
 +                          enc = {enc_int, []}},
 +                  #attr{name = <<"stored">>,
 +                        dec = {dec_int, [0, infinity]},
 +                          enc = {enc_int, []}}]}).
 +
 +-xml(nick,
 +     #elem{name = <<"nick">>,
 +         xmlns = <<"http://jabber.org/protocol/nick">>,
 +         result = {nick, '$name'},
 +         cdata = #cdata{label = '$name',
 +                        required = true}}).
 +
 +-xml(address,
 +     #elem{name = <<"address">>,
 +         xmlns = <<"http://jabber.org/protocol/address">>,
 +         result = {address, '$type', '$jid', '$desc', '$node', '$delivered'},
 +         attrs = [#attr{name = <<"type">>,
 +                        required = true,
 +                        dec = {dec_enum, [[bcc, cc, noreply, ofrom,
 +                                           replyroom, replyto, to]]},
 +                        enc = {enc_enum, []}},
 +                  #attr{name = <<"jid">>,
 +                        enc = {enc_jid, []},
 +                        dec = {dec_jid, []}},
 +                  #attr{name = <<"desc">>},
 +                  #attr{name = <<"node">>},
 +                  #attr{name = <<"delivered">>,
 +                        enc = {enc_bool, []},
 +                        dec = {dec_bool, []}}]}).
 +
 +-xml(addresses,
 +     #elem{name = <<"addresses">>,
 +         xmlns = <<"http://jabber.org/protocol/address">>,
 +         result = {addresses, '$list'},
 +         %% TODO: 'min' should be '1', but this is not implemented
 +         refs = [#ref{name = address, label = '$list'}]}).
 +
 +-xml(stanza_id,
 +     #elem{name = <<"stanza-id">>,
 +         xmlns = <<"urn:xmpp:sid:0">>,
 +         result = {stanza_id, '$by', '$id'},
 +         attrs = [#attr{name = <<"id">>, required = true},
 +                  #attr{name = <<"by">>, required = true,
 +                        enc = {enc_jid, []},
 +                        dec = {dec_jid, []}}]}).
 +
 +-xml(client_id,
 +     #elem{name = <<"client-id">>,
 +         xmlns = <<"urn:xmpp:sid:0">>,
 +         result = {client_id, '$id'},
 +         attrs = [#attr{name = <<"id">>, required = true}]}).
 +
 +-xml(adhoc_command_prev,
 +     #elem{name = <<"prev">>,
 +         xmlns = <<"http://jabber.org/protocol/commands">>,
 +         result = true}).
 +-xml(adhoc_command_next,
 +     #elem{name = <<"next">>,
 +         xmlns = <<"http://jabber.org/protocol/commands">>,
 +         result = true}).
 +-xml(adhoc_command_complete,
 +     #elem{name = <<"complete">>,
 +         xmlns = <<"http://jabber.org/protocol/commands">>,
 +         result = true}).
 +
 +-xml(adhoc_command_actions,
 +     #elem{name = <<"actions">>,
 +         xmlns = <<"http://jabber.org/protocol/commands">>,
 +         result = {adhoc_actions, '$execute', '$prev', '$next', '$complete'},
 +         attrs = [#attr{name = <<"execute">>,
 +                        dec = {dec_enum, [[complete, next, prev]]},
 +                        enc = {enc_enum, []}}],
 +         refs = [#ref{name = adhoc_command_prev, min = 0, max = 1,
 +                      default = false, label = '$prev'},
 +                 #ref{name = adhoc_command_next, min = 0, max = 1,
 +                      default = false, label = '$next'},
 +                 #ref{name = adhoc_command_complete, min = 0, max = 1,
 +                      default = false, label = '$complete'}]}).
 +
 +-xml(adhoc_command_notes,
 +     #elem{name = <<"note">>,
 +         xmlns = <<"http://jabber.org/protocol/commands">>,
 +         result = {adhoc_note, '$type', '$data'},
 +         attrs = [#attr{name = <<"type">>, default = info,
 +                        dec = {dec_enum, [[info, warn, error]]},
 +                        enc = {enc_enum, []}}],
 +         cdata = #cdata{default = <<"">>, label = '$data'}}).
 +
 +-xml(adhoc_command,
 +     #elem{name = <<"command">>,
 +         xmlns = <<"http://jabber.org/protocol/commands">>,
 +         result = {adhoc_command, '$node', '$action', '$sid',
 +                   '$status', '$lang', '$actions', '$notes', '$xdata'},
 +         attrs = [#attr{name = <<"node">>, required = true},
 +                  #attr{name = <<"xml:lang">>, label = '$lang'},
 +                  #attr{name = <<"sessionid">>, label = '$sid'},
 +                  #attr{name = <<"status">>,
 +                        dec = {dec_enum, [[canceled, completed, executing]]},
 +                        enc = {enc_enum, []}},
 +                  #attr{name = <<"action">>, default = execute,
 +                        dec = {dec_enum, [[cancel, complete,
 +                                           execute, next, prev]]},
 +                        enc = {enc_enum, []}}],
 +         refs = [#ref{name = adhoc_command_actions, min = 0, max = 1,
 +                      label = '$actions'},
 +                 #ref{name = xdata, min = 0, max = 1},
 +                 #ref{name = adhoc_command_notes, label = '$notes'}]}).
 +
 +-xml(db_result,
 +     #elem{name = <<"db:result">>,
 +         xmlns = <<"jabber:server">>,
 +         result = {db_result, '$from', '$to', '$type', '$key', '$_els'},
 +         cdata = #cdata{default = <<"">>, label = '$key'},
 +         attrs = [#attr{name = <<"from">>, required = true,
 +                        dec = {nameprep, []}, enc = {nameprep, []}},
 +                  #attr{name = <<"to">>, required = true,
 +                        dec = {nameprep, []}, enc = {nameprep, []}},
 +                  #attr{name = <<"type">>,
 +                        dec = {dec_enum, [[valid, invalid, error]]},
 +                        enc = {enc_enum, []}}]}).
 +
 +-xml(db_verify,
 +     #elem{name = <<"db:verify">>,
 +         xmlns = <<"jabber:server">>,
 +         result = {db_verify, '$from', '$to', '$id', '$type', '$key', '$_els'},
 +         cdata = #cdata{default = <<"">>, label = '$key'},
 +         attrs = [#attr{name = <<"from">>, required = true,
 +                        dec = {nameprep, []}, enc = {nameprep, []}},
 +                  #attr{name = <<"to">>, required = true,
 +                        dec = {nameprep, []}, enc = {nameprep, []}},
 +                  #attr{name = <<"id">>, required = true},
 +                  #attr{name = <<"type">>,
 +                        dec = {dec_enum, [[valid, invalid, error]]},
 +                        enc = {enc_enum, []}}]}).
 +
 +-xml(handshake,
 +     #elem{name = <<"handshake">>,
 +         xmlns = <<"jabber:component:accept">>,
 +         result = {handshake, '$data'},
 +         cdata = #cdata{default = <<"">>, label = '$data'}}).
 +
 +-xml(stream_start,
 +     #elem{name = <<"stream:stream">>,
 +         xmlns = [<<"jabber:client">>, <<"jabber:server">>,
 +                  <<"jabber:component:accept">>],
 +         result = {stream_start, '$from', '$to', '$id',
 +                   '$version', '$xmlns', '$stream_xmlns',
 +                   '$db_xmlns', '$lang'},
 +         attrs = [#attr{name = <<"from">>,
 +                        dec = {dec_jid, []},
 +                        enc = {enc_jid, []}},
 +                  #attr{name = <<"to">>,
 +                        dec = {dec_jid, []},
 +                        enc = {enc_jid, []}},
 +                  #attr{name = <<"xmlns">>},
 +                  #attr{name = <<"xmlns:stream">>,
 +                        label = '$stream_xmlns',
 +                        default = <<"">>},
 +                  #attr{name = <<"xmlns:db">>,
 +                        label = '$db_xmlns',
 +                        default = <<"">>},
 +                  #attr{name = <<"xml:lang">>, label = '$lang',
 +                        default = <<"">>},
 +                  #attr{name = <<"version">>,
 +                        dec = {dec_version, []},
 +                        enc = {enc_version, []}},
 +                  #attr{name = <<"id">>, default = <<"">>}]}).
 +
 +-xml(bob_data,
 +     #elem{name = <<"data">>,
 +         xmlns = <<"urn:xmpp:bob">>,
 +         result = {bob_data, '$cid', '$max-age', '$type', '$data'},
 +         attrs = [#attr{name = <<"cid">>, required = true},
 +                  #attr{name = <<"max-age">>,
 +                        dec = {dec_int, [0, infinity]},
 +                        enc = {enc_int, []}},
 +                  #attr{name = <<"type">>}],
 +         cdata = #cdata{label = '$data', default = <<"">>,
 +                        dec = {base64, decode, []},
 +                        enc = {base64, encode, []}}}).
 +
 +-xml(captcha,
 +     #elem{name = <<"captcha">>,
 +         xmlns = <<"urn:xmpp:captcha">>,
 +         result = {xcaptcha, '$xdata'},
 +         refs = [#ref{name = xdata, min = 1, max = 1}]}).
 +
 +-xml(media_uri,
 +     #elem{name = <<"uri">>,
 +         xmlns = <<"urn:xmpp:media-element">>,
 +         result = {media_uri, '$type', '$uri'},
 +         attrs = [#attr{name = <<"type">>, required = true}],
 +         cdata = #cdata{label = '$uri', default = <<"">>}}).
 +
 +-xml(media,
 +     #elem{name = <<"media">>,
 +         xmlns = <<"urn:xmpp:media-element">>,
 +         result = {media, '$height', '$width', '$uri'},
 +         attrs = [#attr{name = <<"height">>,
 +                        dec = {dec_int, [0, infinity]},
 +                        enc = {enc_int, []}},
 +                  #attr{name = <<"width">>,
 +                        dec = {dec_int, [0, inifinity]},
 +                        enc = {enc_int, []}}],
 +         refs = [#ref{name = media_uri, label = '$uri'}]}).
 +
 +-xml(oob_url,
 +     #elem{name = <<"url">>,
 +         xmlns = <<"jabber:x:oob">>,
 +         result = '$cdata',
 +         cdata = #cdata{required = true}}).
 +
 +-xml(oob_desc,
 +     #elem{name = <<"desc">>,
 +         xmlns = <<"jabber:x:oob">>,
 +         result = '$cdata',
 +         cdata = #cdata{default = <<"">>}}).
  
 +-xml(oob_x,
 +     #elem{name = <<"x">>,
 +         xmlns = <<"jabber:x:oob">>,
 +         result = {oob_x, '$url', '$desc', '$sid'},
 +         attrs = [#attr{name = <<"sid">>, default = <<"">>}],
 +         refs = [#ref{name = oob_url, min = 1, max = 1,
 +                      label = '$url'},
 +                 #ref{name = oob_desc, default = <<"">>,
 +                      min = 0, max = 1, label = '$desc'}]}).
 +
 +-xml(sic_ip,
 +     #elem{name = <<"ip">>,
 +         xmlns = [<<"urn:xmpp:sic:0">>, <<"urn:xmpp:sic:1">>],
 +         result = '$cdata',
 +         cdata = #cdata{required = true,
 +                        dec = {dec_ip, []},
 +                        enc = {enc_ip, []}}}).
 +
 +-xml(sip_port,
 +     #elem{name = <<"port">>,
 +         xmlns = <<"urn:xmpp:sic:1">>,
 +         result = '$cdata',
 +         cdata = #cdata{required = true,
 +                        dec = {dec_int, [0, 65535]},
 +                        enc = {enc_int, []}}}).
 +
 +-xml(sic,
 +     #elem{name = <<"address">>,
 +         xmlns = [<<"urn:xmpp:sic:0">>, <<"urn:xmpp:sic:1">>],
 +         result = {sic, '$ip', '$port', '$xmlns'},
 +         attrs = [#attr{name = <<"xmlns">>}],
 +         refs = [#ref{name = sic_ip, min = 0, max = 1, label = '$ip'},
 +                 #ref{name = sip_port, min = 0, max = 1, label = '$port'}]}).
 +
 +-xml(upload_filename,
 +     #elem{name = <<"filename">>,
 +         xmlns = [<<"urn:xmpp:http:upload">>,
 +                  <<"eu:siacs:conversations:http:upload">>],
 +         result = '$cdata',
 +         cdata = #cdata{required = true}}).
 +
 +-xml(upload_size,
 +     #elem{name = <<"size">>,
 +         xmlns = [<<"urn:xmpp:http:upload">>,
 +                  <<"eu:siacs:conversations:http:upload">>],
 +         result = '$cdata',
 +         cdata = #cdata{required = true,
 +                        dec = {dec_int, [0, infinity]},
 +                        enc = {enc_int, []}}}).
 +
 +-xml(upload_content_type,
 +     #elem{name = <<"content-type">>,
 +         xmlns = [<<"urn:xmpp:http:upload">>,
 +                  <<"eu:siacs:conversations:http:upload">>],
 +         result = '$cdata',
 +         cdata = #cdata{default = <<"">>}}).
 +
 +-xml(upload_request,
 +     #elem{name = <<"request">>,
 +         xmlns = [<<"urn:xmpp:http:upload">>,
 +                  <<"eu:siacs:conversations:http:upload">>],
 +         result = {upload_request, '$filename', '$size',
 +                   '$content-type', '$xmlns'},
 +         attrs = [#attr{name = <<"xmlns">>}],
 +         refs = [#ref{name = upload_filename, label = '$filename',
 +                      min = 1, max = 1},
 +                 #ref{name = upload_size, label = '$size', min = 1, max = 1},
 +                 #ref{name = upload_content_type, label = '$content-type',
 +                      min = 0, max = 1, default = <<"">>}]}).
 +
 +-xml(upload_get,
 +     #elem{name = <<"get">>,
 +         xmlns = [<<"urn:xmpp:http:upload">>,
 +                  <<"eu:siacs:conversations:http:upload">>],
 +         result = '$cdata',
 +         cdata = #cdata{required = true}}).
 +
 +-xml(upload_put,
 +     #elem{name = <<"put">>,
 +         xmlns = [<<"urn:xmpp:http:upload">>,
 +                  <<"eu:siacs:conversations:http:upload">>],
 +         result = '$cdata',
 +         cdata = #cdata{required = true}}).
 +
 +-xml(upload_slot,
 +     #elem{name = <<"slot">>,
 +         xmlns = [<<"urn:xmpp:http:upload">>,
 +                  <<"eu:siacs:conversations:http:upload">>],
 +         result = {upload_slot, '$get', '$put', '$xmlns'},
 +         attrs = [#attr{name = <<"xmlns">>}],
 +         refs = [#ref{name = upload_get, min = 0, max = 1, label = '$get'},
 +                 #ref{name = upload_put, min = 0, max = 1, label = '$put'}]}).
 +
 +-xml(thumbnail,
 +     #elem{name = <<"thumbnail">>,
 +         xmlns = <<"urn:xmpp:thumbs:1">>,
 +         result = {thumbnail, '$uri', '$media-type', '$width', '$height'},
 +         attrs = [#attr{name = <<"uri">>, required = true},
 +                  #attr{name = <<"media-type">>, default = <<"">>},
 +                  #attr{name = <<"width">>,
 +                        dec = {dec_int, [0, infinity]},
 +                        enc = {enc_int, []}},
 +                  #attr{name = <<"height">>,
 +                        dec = {dec_int, [0, infinity]},
 +                        enc = {enc_int, []}}]}).
 +
++-xml(privilege_perm,
++     #elem{name = <<"perm">>,
++         xmlns = <<"urn:xmpp:privilege:1">>,
++         result = {privilege_perm, '$access', '$type'},
++         attrs = [#attr{name = <<"access">>,
++                        required = true,
++                        dec = {dec_enum, [[roster, message, presence]]},
++                        enc = {enc_enum, []}},
++                  #attr{name = <<"type">>,
++                        required = true,
++                        dec = {dec_enum, [[none, get, set, both,
++                                           outgoing, roster,
++                                           managed_entity]]},
++                        enc = {enc_enum, []}}]}).
++
++-xml(privilege,
++     #elem{name = <<"privilege">>,
++         xmlns = <<"urn:xmpp:privilege:1">>,
++         result = {privilege, '$perms', '$forwarded'},
++         refs = [#ref{name = privilege_perm, label = '$perms'},
++                 #ref{name = forwarded, min = 0,
++                        max = 1, label = '$forwarded'}]}).
++
++-xml(delegated_attribute,
++     #elem{name = <<"attribute">>,
++         xmlns = <<"urn:xmpp:delegation:1">>,
++         result = '$name',
++         attrs = [#attr{name = <<"name">>,
++                        required = true}]}).
++
++-xml(delegated,
++     #elem{name = <<"delegated">>,
++         xmlns = <<"urn:xmpp:delegation:1">>,
++         result = {delegated, '$ns', '$attrs'},
++         attrs = [#attr{name = <<"namespace">>,
++                        label = '$ns',
++                        required = true}],
++         refs = [#ref{name = delegated_attribute,
++                      label = '$attrs'}]}).
++
++-xml(delegation,
++     #elem{name = <<"delegation">>,
++         xmlns = <<"urn:xmpp:delegation:1">>,
++         result = {delegation, '$delegated', '$forwarded'},
++         refs = [#ref{name = delegated, label = '$delegated'},
++                 #ref{name = forwarded, min = 0,
++                      max = 1, label = '$forwarded'}]}).
++
++-xml(delegate,
++     #elem{name = <<"delegate">>,
++         xmlns = <<"urn:xmpp:delegation:1">>,
++         result = '$namespace',
++         attrs = [#attr{name = <<"namespace">>,
++                        required = true}]}).
++
++-xml(delegation_query,
++     #elem{name = <<"query">>,
++         xmlns = <<"urn:xmpp:delegation:1">>,
++         result = {delegation_query, '$to', '$delegate'},
++         attrs = [#attr{name = <<"to">>,
++                        required = true,
++                        dec = {dec_jid, []},
++                        enc = {enc_jid, []}}],
++         refs = [#ref{name = delegate, label = '$delegate'}]}).
++
 +-spec dec_tzo(_) -> {integer(), integer()}.
  dec_tzo(Val) ->
      [H1, M1] = str:tokens(Val, <<":">>),
 -    H = jlib:binary_to_integer(H1),
 -    M = jlib:binary_to_integer(M1),
 +    H = binary_to_integer(H1),
 +    M = binary_to_integer(M1),
      if H >= -12, H =< 12, M >= 0, M < 60  ->
              {H, M}
      end.
diff --cc src/acl.erl
index 7519e12e207459cbbd873dcec8c591fc7915950d,1476081dd8f841dbc28322b3f83f6019f84d8e69..e3fdfcae1c0fcee9882c534e9e0839f9e80fd88e
@@@ -432,30 -438,35 +438,35 @@@ acl_rule_matches({node_glob, {UR, SR}}
  acl_rule_matches(_ACL, _Data, _Host) ->
      false.
  
- -spec access_matches(atom()|list(), any(), global|binary()) -> any().
- access_matches(all, _Data, _Host) ->
-     allow;
- access_matches(none, _Data, _Host) ->
-     deny;
- access_matches(Name, Data, Host) when is_atom(Name) ->
-     GAccess = ets:lookup(access, {Name, global}),
+ resolve_access(all, _Host) ->
+     all;
+ resolve_access(none, _Host) ->
+     none;
+ resolve_access(Name, Host) when is_atom(Name) ->
+     GAccess = mnesia:dirty_read(access, {Name, global}),
      LAccess =
-       if Host /= global -> ets:lookup(access, {Name, Host});
+     if Host /= global -> mnesia:dirty_read(access, {Name, Host});
 -      true -> []
 -    end,
 +          true -> []
 +      end,
      case GAccess ++ LAccess of
        [] ->
-           deny;
+           [];
        AccessList ->
-           Rules = lists:flatmap(
+           lists:flatmap(
                fun(#access{rules = Rs}) ->
                    Rs
-               end, AccessList),
-           access_rules_matches(Rules, Data, Host)
+               end, AccessList)
      end;
- access_matches(Rules, Data, Host) when is_list(Rules) ->
-     access_rules_matches(Rules, Data, Host).
+ resolve_access(Rules, _Host) when is_list(Rules) ->
+     Rules.
+ -spec access_matches(atom()|list(), any(), global|binary()) -> allow|deny.
+ access_matches(Rules, Data, Host) ->
+     case resolve_access(Rules, Host) of
+       all -> allow;
+       none -> deny;
+       RRules -> access_rules_matches(RRules, Data, Host)
+     end.
  
  -spec access_rules_matches(list(), any(), global|binary()) -> any().
  
index 09d143ef56892621b394f2485ea206d8e26f919b,80ba315ed5879ad4fd5c063ca4819d2644bd73aa..21dedc6db1e040e198ff5bb1eab032e146f1869b
@@@ -51,10 -51,10 +51,10 @@@ mech_step(State, ClientIn) -
                      {ok,
                       [{username, User}, {authzid, AuthzId},
                        {auth_module, ejabberd_oauth}]};
-                 false ->
+                 _ ->
 -                    {error, <<"not-authorized">>, User}
 +                    {error, 'not-authorized', User}
              end;
 -        _ -> {error, <<"bad-protocol">>}
 +        _ -> {error, 'bad-protocol'}
      end.
  
  prepare(ClientIn) ->
Simple merge
index 703614f63bb7fe479b0edb5bb95dd76812114f01,e4087142b095c61bf5a5ba19f5f981fdcdd132ab..e88f24e1e1a7689229b6b0ea4f661a2a90caa83c
@@@ -74,6 -77,8 +77,7 @@@ start(normal, _Args) -
      ejabberd_oauth:start(),
      gen_mod:start_modules(),
      ejabberd_listener:start_listeners(),
 -    ejabberd_service:start(),
+     register_elixir_config_hooks(),
      ?INFO_MSG("ejabberd ~s is started in the node ~p", [?VERSION, node()]),
      Sup;
  start(_, _) ->
index 986310546d659225069771e98d72aa478f54a6b2,6068c85ef73e166094e4ae52d4d7dbf8bfdb8202..7ef708d314088e32b6b67395c452ca56ed1da285
@@@ -182,15 -222,16 +192,18 @@@ socket_type() -> xml_stream
  get_presence(FsmRef) ->
      (?GEN_FSM):sync_send_all_state_event(FsmRef,
                                         {get_presence}, 1000).
+ get_last_presence(FsmRef) ->
+     (?GEN_FSM):sync_send_all_state_event(FsmRef,
+                                        {get_last_presence}, 1000).
  
 +-spec get_aux_field(any(), state()) -> {ok, any()} | error.
  get_aux_field(Key, #state{aux_fields = Opts}) ->
 -    case lists:keysearch(Key, 1, Opts) of
 -      {value, {_, Val}} -> {ok, Val};
 -      _ -> error
 +    case lists:keyfind(Key, 1, Opts) of
 +      {_, Val} -> {ok, Val};
 +      false -> error
      end.
  
 +-spec set_aux_field(any(), any(), state()) -> state().
  set_aux_field(Key, Val,
              #state{aux_fields = Opts} = State) ->
      Opts1 = lists:keydelete(Key, 1, Opts),
@@@ -218,7 -257,27 +231,28 @@@ get_subscription(LFrom, StateData) -
         true -> none
      end.
  
+ get_queued_stanzas(#state{mgmt_queue = Queue} = StateData) ->
+     lists:map(fun({_N, Time, El}) ->
+                     add_resent_delay_info(StateData, El, Time)
+             end, queue:to_list(Queue)).
+ get_csi_state(#state{csi_state = CsiState}) ->
+     CsiState.
+ set_csi_state(#state{} = StateData, CsiState) ->
+     StateData#state{csi_state = CsiState};
+ set_csi_state(FsmRef, CsiState) ->
+     FsmRef ! {set_csi_state, CsiState}.
+ get_resume_timeout(#state{mgmt_timeout = Timeout}) ->
+     Timeout.
+ set_resume_timeout(#state{} = StateData, Timeout) ->
+     StateData#state{mgmt_timeout = Timeout};
+ set_resume_timeout(FsmRef, Timeout) ->
+     FsmRef ! {set_resume_timeout, Timeout}.
 +-spec send_filtered(pid(), binary(), jid(), jid(), stanza()) -> any().
  send_filtered(FsmRef, Feature, From, To, Packet) ->
      FsmRef ! {send_filtered, Feature, From, To, Packet}.
  
@@@ -1225,141 -1442,272 +1274,146 @@@ handle_info({route, _From, _To, {broadc
              fsm_next_state(StateName, StateData)
      end;
  %% Process Packets that are to be send to the user
 -handle_info({route, From, To,
 -             #xmlel{name = Name, attrs = Attrs, children = Els} = Packet},
 -            StateName, StateData) ->
 -    {Pass, NewAttrs, NewState} = case Name of
 -                                 <<"presence">> ->
 -                                     State =
 -                                         ejabberd_hooks:run_fold(c2s_presence_in,
 -                                                                 StateData#state.server,
 -                                                                 StateData,
 -                                                                 [{From, To,
 -                                                                   Packet}]),
 -                                     case fxml:get_attr_s(<<"type">>, Attrs) of
 -                                       <<"probe">> ->
 -                                           LFrom = jid:tolower(From),
 -                                           LBFrom =
 -                                               jid:remove_resource(LFrom),
 -                                           NewStateData = case
 -                                                            (?SETS):is_element(LFrom,
 -                                                                               State#state.pres_a)
 -                                                              orelse
 -                                                              (?SETS):is_element(LBFrom,
 -                                                                                 State#state.pres_a)
 -                                                              of
 -                                                            true -> State;
 -                                                            false ->
 -                                                                case
 -                                                                  (?SETS):is_element(LFrom,
 -                                                                                     State#state.pres_f)
 -                                                                    of
 -                                                                  true ->
 -                                                                      A =
 -                                                                          (?SETS):add_element(LFrom,
 -                                                                                              State#state.pres_a),
 -                                                                      State#state{pres_a
 -                                                                                      =
 -                                                                                      A};
 -                                                                  false ->
 -                                                                      case
 -                                                                        (?SETS):is_element(LBFrom,
 -                                                                                           State#state.pres_f)
 -                                                                          of
 -                                                                        true ->
 -                                                                            A =
 -                                                                                (?SETS):add_element(LBFrom,
 -                                                                                                    State#state.pres_a),
 -                                                                            State#state{pres_a
 -                                                                                            =
 -                                                                                            A};
 -                                                                        false ->
 -                                                                            State
 -                                                                      end
 -                                                                end
 -                                                          end,
 -                                           process_presence_probe(From, To,
 -                                                                  NewStateData),
 -                                           {false, Attrs, NewStateData};
 -                                       <<"error">> ->
 -                                           NewA =
 -                                               remove_element(jid:tolower(From),
 -                                                              State#state.pres_a),
 -                                           {true, Attrs,
 -                                            State#state{pres_a = NewA}};
 -                                       <<"subscribe">> ->
 -                                           SRes = is_privacy_allow(State,
 -                                                                   From, To,
 -                                                                   Packet,
 -                                                                   in),
 -                                           {SRes, Attrs, State};
 -                                       <<"subscribed">> ->
 -                                           SRes = is_privacy_allow(State,
 -                                                                   From, To,
 -                                                                   Packet,
 -                                                                   in),
 -                                           {SRes, Attrs, State};
 -                                       <<"unsubscribe">> ->
 -                                           SRes = is_privacy_allow(State,
 -                                                                   From, To,
 -                                                                   Packet,
 -                                                                   in),
 -                                           {SRes, Attrs, State};
 -                                       <<"unsubscribed">> ->
 -                                           SRes = is_privacy_allow(State,
 -                                                                   From, To,
 -                                                                   Packet,
 -                                                                   in),
 -                                           {SRes, Attrs, State};
 -                                       _ ->
 -                                           case privacy_check_packet(State,
 -                                                                     From, To,
 -                                                                     Packet,
 -                                                                     in)
 -                                               of
 -                                             allow ->
 -                                                 LFrom =
 -                                                     jid:tolower(From),
 -                                                 LBFrom =
 -                                                     jid:remove_resource(LFrom),
 -                                                 case
 -                                                   (?SETS):is_element(LFrom,
 -                                                                      State#state.pres_a)
 -                                                     orelse
 -                                                     (?SETS):is_element(LBFrom,
 -                                                                        State#state.pres_a)
 -                                                     of
 -                                                   true ->
 -                                                       {true, Attrs, State};
 -                                                   false ->
 -                                                       case
 -                                                         (?SETS):is_element(LFrom,
 -                                                                            State#state.pres_f)
 -                                                           of
 -                                                         true ->
 -                                                             A =
 -                                                                 (?SETS):add_element(LFrom,
 -                                                                                     State#state.pres_a),
 -                                                             {true, Attrs,
 -                                                              State#state{pres_a
 -                                                                              =
 -                                                                              A}};
 -                                                         false ->
 -                                                             case
 -                                                               (?SETS):is_element(LBFrom,
 -                                                                                  State#state.pres_f)
 -                                                                 of
 -                                                               true ->
 -                                                                   A =
 -                                                                       (?SETS):add_element(LBFrom,
 -                                                                                           State#state.pres_a),
 -                                                                   {true,
 -                                                                    Attrs,
 -                                                                    State#state{pres_a
 -                                                                                    =
 -                                                                                    A}};
 -                                                               false ->
 -                                                                   {true,
 -                                                                    Attrs,
 -                                                                    State}
 -                                                             end
 -                                                       end
 -                                                 end;
 -                                             deny -> {false, Attrs, State}
 -                                           end
 -                                     end;
 -                                 <<"iq">> ->
 -                                     IQ = jlib:iq_query_info(Packet),
 -                                     case IQ of
 -                                       #iq{xmlns = ?NS_LAST} ->
 -                                           LFrom = jid:tolower(From),
 -                                           LBFrom =
 -                                               jid:remove_resource(LFrom),
 -                                           HasFromSub =
 -                                               ((?SETS):is_element(LFrom,
 -                                                                   StateData#state.pres_f)
 -                                                  orelse
 -                                                  (?SETS):is_element(LBFrom,
 -                                                                     StateData#state.pres_f))
 -                                                 andalso
 -                                                 is_privacy_allow(StateData,
 -                                                                  To, From,
 -                                                                  #xmlel{name
 -                                                                             =
 -                                                                             <<"presence">>,
 -                                                                         attrs
 -                                                                             =
 -                                                                             [],
 -                                                                         children
 -                                                                             =
 -                                                                             []},
 -                                                                  out),
 -                                           case HasFromSub of
 -                                             true ->
 -                                                 case
 -                                                   privacy_check_packet(StateData,
 -                                                                        From,
 -                                                                        To,
 -                                                                        Packet,
 -                                                                        in)
 -                                                     of
 -                                                   allow ->
 -                                                       {true, Attrs,
 -                                                        StateData};
 -                                                   deny ->
 -                                                       Err =
 -                                                           jlib:make_error_reply(Packet,
 -                                                                                 ?ERR_SERVICE_UNAVAILABLE),
 -                                                       ejabberd_router:route(To,
 -                                                                             From,
 -                                                                             Err),
 -                                                       {false, Attrs,
 -                                                        StateData}
 -                                                 end;
 -                                             _ ->
 -                                                 Err =
 -                                                     jlib:make_error_reply(Packet,
 -                                                                           ?ERR_FORBIDDEN),
 -                                                 ejabberd_router:route(To,
 -                                                                       From,
 -                                                                       Err),
 -                                                 {false, Attrs, StateData}
 -                                           end;
 -                                       IQ
 -                                           when is_record(IQ, iq) or
 -                                                  (IQ == reply) ->
 -                                           case
 -                                             privacy_check_packet(StateData,
 -                                                                  From, To,
 -                                                                  Packet, in)
 -                                               of
 -                                             allow ->
 -                                                 {true, Attrs, StateData};
 -                                             deny when is_record(IQ, iq) ->
 -                                                 Err =
 -                                                     jlib:make_error_reply(Packet,
 -                                                                           ?ERR_SERVICE_UNAVAILABLE),
 -                                                 ejabberd_router:route(To,
 -                                                                       From,
 -                                                                       Err),
 -                                                 {false, Attrs, StateData};
 -                                             deny when IQ == reply ->
 -                                                 {false, Attrs, StateData}
 -                                           end;
 -                                       IQ
 -                                           when (IQ == invalid) or
 -                                                  (IQ == not_iq) ->
 -                                           {false, Attrs, StateData}
 -                                     end;
 -                                 <<"message">> ->
 -                                     case privacy_check_packet(StateData,
 -                                                               From, To,
 -                                                               Packet, in)
 -                                         of
 -                                       allow ->
 -                                           {true, Attrs, StateData};
 -                                       deny ->
 -                                               case fxml:get_attr_s(<<"type">>, Attrs) of
 -                                                   <<"error">> -> ok;
 -                                                   <<"groupchat">> -> ok;
 -                                                   <<"headline">> -> ok;
 -                                                   _ ->
 -                                                     case fxml:get_subtag_with_xmlns(Packet,
 -                                                                                     <<"x">>,
 -                                                                                     ?NS_MUC_USER)
 -                                                         of
 -                                                       false ->
 -                                                           Err =
 -                                                               jlib:make_error_reply(Packet,
 -                                                                                     ?ERR_SERVICE_UNAVAILABLE),
 -                                                           ejabberd_router:route(To, From,
 -                                                                                 Err);
 -                                                       _ -> ok
 -                                                     end
 -                                               end,
 -                                               {false, Attrs, StateData}
 -                                     end;
 -                                 _ -> {true, Attrs, StateData}
 -                               end,
 +handle_info({route, From, To, Packet}, StateName, StateData) when ?is_stanza(Packet) ->
 +    {Pass, NewState} =
 +      case Packet of
 +          #presence{type = T} ->
 +              State = ejabberd_hooks:run_fold(c2s_presence_in,
 +                                              StateData#state.server,
 +                                              StateData,
 +                                              [{From, To, Packet}]),
 +              case T of
 +                  probe ->
 +                      LFrom = jid:tolower(From),
 +                      LBFrom = jid:remove_resource(LFrom),
 +                      NewStateData =
 +                          case (?SETS):is_element(LFrom, State#state.pres_a)
 +                              orelse (?SETS):is_element(LBFrom, State#state.pres_a) of
 +                              true -> State;
 +                              false ->
 +                                  case (?SETS):is_element(LFrom, State#state.pres_f) of
 +                                      true ->
 +                                          A = (?SETS):add_element(LFrom, State#state.pres_a),
 +                                          State#state{pres_a = A};
 +                                      false ->
 +                                          case (?SETS):is_element(LBFrom, State#state.pres_f) of
 +                                              true ->
 +                                                  A = (?SETS):add_element(LBFrom, State#state.pres_a),
 +                                                  State#state{pres_a = A};
 +                                              false ->
 +                                                  State
 +                                          end
 +                                  end
 +                          end,
 +                      process_presence_probe(From, To, NewStateData),
 +                      {false, NewStateData};
 +                  error ->
 +                      NewA = ?SETS:del_element(jid:tolower(From), State#state.pres_a),
 +                      {true, State#state{pres_a = NewA}};
 +                  subscribe ->
 +                      SRes = is_privacy_allow(State, From, To, Packet, in),
 +                      {SRes, State};
 +                  subscribed ->
 +                      SRes = is_privacy_allow(State, From, To, Packet, in),
 +                      {SRes, State};
 +                  unsubscribe ->
 +                      SRes = is_privacy_allow(State, From, To, Packet, in),
 +                      {SRes, State};
 +                  unsubscribed ->
 +                      SRes = is_privacy_allow(State, From, To, Packet, in),
 +                      {SRes, State};
 +                  _ ->
 +                      case privacy_check_packet(State, From, To, Packet, in) of
 +                          allow ->
 +                              LFrom = jid:tolower(From),
 +                              LBFrom = jid:remove_resource(LFrom),
 +                              case (?SETS):is_element(LFrom, State#state.pres_a)
 +                                  orelse (?SETS):is_element(LBFrom, State#state.pres_a) of
 +                                  true ->
 +                                      {true, State};
 +                                  false ->
 +                                      case (?SETS):is_element(LFrom, State#state.pres_f) of
 +                                          true ->
 +                                              A = (?SETS):add_element(LFrom, State#state.pres_a),
 +                                              {true, State#state{pres_a = A}};
 +                                          false ->
 +                                              case (?SETS):is_element(LBFrom,
 +                                                                      State#state.pres_f) of
 +                                                  true ->
 +                                                      A = (?SETS):add_element(
 +                                                            LBFrom,
 +                                                            State#state.pres_a),
 +                                                      {true, State#state{pres_a = A}};
 +                                                  false ->
 +                                                      {true, State}
 +                                              end
 +                                      end
 +                              end;
 +                          deny -> {false, State}
 +                      end
 +              end;
 +          #iq{type = T} ->
 +              case xmpp:has_subtag(Packet, #last{}) of
 +                  true when T == get; T == set ->
 +                      LFrom = jid:tolower(From),
 +                      LBFrom = jid:remove_resource(LFrom),
 +                      HasFromSub = ((?SETS):is_element(LFrom, StateData#state.pres_f)
 +                                    orelse (?SETS):is_element(LBFrom, StateData#state.pres_f))
 +                          andalso is_privacy_allow(StateData, To, From, #presence{}, out),
 +                      case HasFromSub of
 +                          true ->
 +                              case privacy_check_packet(
 +                                     StateData, From, To, Packet, in) of
 +                                  allow ->
 +                                      {true, StateData};
 +                                  deny ->
 +                                      ejabberd_router:route_error(
 +                                        To, From, Packet,
 +                                        xmpp:err_service_unavailable()),
 +                                      {false, StateData}
 +                              end;
 +                          _ ->
 +                              ejabberd_router:route_error(
 +                                To, From, Packet, xmpp:err_forbidden()),
 +                              {false, StateData}
 +                      end;
 +                  _ ->
 +                      case privacy_check_packet(StateData, From, To, Packet, in) of
 +                          allow ->
 +                              {true, StateData};
 +                          deny ->
 +                              ejabberd_router:route_error(
 +                                To, From, Packet, xmpp:err_service_unavailable()),
 +                              {false, StateData}
 +                      end
 +              end;
 +          #message{type = T} ->
 +              case privacy_check_packet(StateData, From, To, Packet, in) of
 +                  allow ->
 +                      {true, StateData};
 +                  deny ->
 +                      case T of
 +                          groupchat -> ok;
 +                          headline -> ok;
 +                          _ ->
-                               ejabberd_router:route_error(
-                                 To, From, Packet, xmpp:err_service_unavailable())
++                              case xmpp:has_subtag(Packet, #muc_user{}) of
++                                  true ->
++                                      ok;
++                                  false ->
++                                      ejabberd_router:route_error(
++                                        To, From, Packet, xmpp:err_service_unavailable())
++                              end
 +                      end,
 +                      {false, StateData}
 +              end
 +      end,
      if Pass ->
 -          Attrs2 =
 -              jlib:replace_from_to_attrs(jid:to_string(From),
 -                  jid:to_string(To), NewAttrs),
 -          FixedPacket0 = #xmlel{name = Name, attrs = Attrs2, children = Els},
 +          FixedPacket0 = xmpp:set_from_to(Packet, From, To),
            FixedPacket = ejabberd_hooks:run_fold(
 -                  user_receive_packet,
 -                  NewState#state.server,
 -                  FixedPacket0,
 -                  [NewState, NewState#state.jid, From, To]),
 +                          user_receive_packet,
 +                          NewState#state.server,
 +                          FixedPacket0,
 +                          [NewState, NewState#state.jid, From, To]),
            SentStateData = send_packet(NewState, FixedPacket),
            ejabberd_hooks:run(c2s_loop_debug, [{route, From, To, Packet}]),
            fsm_next_state(StateName, SentStateData);
@@@ -1558,28 -1924,15 +1628,29 @@@ send_text(StateData, Text) -
      ?DEBUG("Send XML on stream = ~p", [Text]),
      (StateData#state.sockmod):send(StateData#state.socket, Text).
  
 +-spec send_element(state(), xmlel() | xmpp_element()) -> ok | {error, any()}.
  send_element(StateData, El) when StateData#state.mgmt_state == pending ->
      ?DEBUG("Cannot send element while waiting for resumption: ~p", [El]);
 -send_element(StateData, El) when StateData#state.xml_socket ->
 +send_element(StateData, #xmlel{} = El) when StateData#state.xml_socket ->
+     ?DEBUG("Send XML on stream = ~p", [fxml:element_to_binary(El)]),
      (StateData#state.sockmod):send_xml(StateData#state.socket,
                                       {xmlstreamelement, El});
 -send_element(StateData, El) ->
 -    send_text(StateData, fxml:element_to_binary(El)).
 +send_element(StateData, #xmlel{} = El) ->
 +    send_text(StateData, fxml:element_to_binary(El));
 +send_element(StateData, Pkt) ->
 +    send_element(StateData, xmpp:encode(Pkt, ?NS_CLIENT)).
 +
 +-spec send_error(state(), xmlel() | stanza(), stanza_error()) -> state().
 +send_error(StateData, Stanza, Error) ->
 +    Type = xmpp:get_type(Stanza),
 +    if Type == error; Type == result;
 +       Type == <<"error">>; Type == <<"result">> ->
 +          StateData;
 +       true ->
 +          send_stanza(StateData, xmpp:make_error(Stanza, Error))
 +    end.
  
 +-spec send_stanza(state(), xmpp_element()) -> state().
  send_stanza(StateData, Stanza) when StateData#state.csi_state == inactive ->
      csi_filter_stanza(StateData, Stanza);
  send_stanza(StateData, Stanza) when StateData#state.mgmt_state == pending ->
@@@ -2336,31 -2810,48 +2419,32 @@@ handle_r(StateData) -
      send_element(StateData, Res),
      StateData.
  
 -handle_a(StateData, Attrs) ->
 -    case catch jlib:binary_to_integer(fxml:get_attr_s(<<"h">>, Attrs)) of
 -      H when is_integer(H), H >= 0 ->
 -        NewStateData = check_h_attribute(StateData, H),
 -        maybe_renew_ack_request(NewStateData);
 -      _ ->
 -        ?DEBUG("Ignoring invalid ACK element from ~s",
 -               [jid:to_string(StateData#state.jid)]),
 -        StateData
 -    end.
 +-spec handle_a(state(), sm_a()) -> state().
 +handle_a(StateData, #sm_a{h = H}) ->
-     check_h_attribute(StateData, H).
++    NewStateData = check_h_attribute(StateData, H),
++    maybe_renew_ack_request(NewStateData).
  
 -handle_resume(StateData, Attrs) ->
 -    R = case fxml:get_attr_s(<<"xmlns">>, Attrs) of
 -        Xmlns when ?IS_SUPPORTED_MGMT_XMLNS(Xmlns) ->
 -            case stream_mgmt_enabled(StateData) of
 -              true ->
 -                  case {fxml:get_attr(<<"previd">>, Attrs),
 -                        catch jlib:binary_to_integer(fxml:get_attr_s(<<"h">>, Attrs))}
 -                      of
 -                    {{value, PrevID}, H} when is_integer(H), H >= 0 ->
 -                        case inherit_session_state(StateData, PrevID) of
 +-spec handle_resume(state(), sm_resume()) -> {ok, state()} | error.
 +handle_resume(StateData, #sm_resume{h = H, previd = PrevID, xmlns = Xmlns}) ->
 +    R = case stream_mgmt_enabled(StateData) of
 +          true ->
 +              case inherit_session_state(StateData, PrevID) of
-                   {ok, InheritedState} ->
-                       {ok, InheritedState, H};
+                           {ok, InheritedState, Info} ->
+                               {ok, InheritedState, Info, H};
 -                          {error, Err, InH} ->
 -                              {error, ?MGMT_ITEM_NOT_FOUND_H(Xmlns, InH), Err};
 -                          {error, Err} ->
 -                              {error, ?MGMT_ITEM_NOT_FOUND(Xmlns), Err}
 -                        end;
 -                    _ ->
 -                        {error, ?MGMT_BAD_REQUEST(Xmlns),
 -                         <<"Invalid request">>}
 -                  end;
 -              false ->
 -                  {error, ?MGMT_SERVICE_UNAVAILABLE(Xmlns),
 -                   <<"XEP-0198 disabled">>}
 -            end;
 -        _ ->
 -            {error, ?MGMT_UNSUPPORTED_VERSION(?NS_STREAM_MGMT_3),
 -             <<"Invalid XMLNS">>}
 +                  {error, Err, InH} ->
 +                      {error, #sm_failed{reason = 'item-not-found',
 +                                         h = InH, xmlns = Xmlns}, Err};
 +                  {error, Err} ->
 +                      {error, #sm_failed{reason = 'item-not-found',
 +                                         xmlns = Xmlns}, Err}
 +              end;
 +          false ->
 +              {error, #sm_failed{reason = 'service-unavailable',
 +                                 xmlns = Xmlns},
 +               <<"XEP-0198 disabled">>}
        end,
      case R of
-       {ok, ResumedState, NumHandled} ->
+       {ok, ResumedState, ResumedInfo, NumHandled} ->
          NewState = check_h_attribute(ResumedState, NumHandled),
          AttrXmlns = NewState#state.mgmt_xmlns,
          AttrId = make_resume_id(NewState),
                            send_element(NewState, NewEl)
                    end,
          handle_unacked_stanzas(NewState, SendFun),
 -        send_element(NewState,
 -                     #xmlel{name = <<"r">>,
 -                            attrs = [{<<"xmlns">>, AttrXmlns}],
 -                            children = []}),
 +        send_element(NewState, #sm_r{xmlns = AttrXmlns}),
-         FlushedState = csi_flush_queue(NewState),
-         NewStateData = FlushedState#state{csi_state = active},
+         NewState1 = csi_flush_queue(NewState),
+         NewState2 = ejabberd_hooks:run_fold(c2s_session_resumed,
+                                             StateData#state.server,
+                                             NewState1,
+                                             [NewState1#state.sid,
+                                              NewState1#state.jid,
+                                              ResumedInfo]),
          ?INFO_MSG("Resumed session for ~s",
-                   [jid:to_string(NewStateData#state.jid)]),
-         {ok, NewStateData};
+                   [jid:to_string(NewState2#state.jid)]),
+         {ok, NewState2};
        {error, El, Msg} ->
          send_element(StateData, El),
          ?INFO_MSG("Cannot resume session for ~s@~s: ~s",
@@@ -2413,18 -2913,47 +2502,48 @@@ update_num_stanzas_in(#state{mgmt_stat
  update_num_stanzas_in(StateData, _El) ->
      StateData.
  
- -spec send_stanza_and_ack_req(state(), stanza()) -> state().
- send_stanza_and_ack_req(StateData, Stanza) ->
-     AckReq = #sm_r{xmlns = StateData#state.mgmt_xmlns},
-     case send_element(StateData, Stanza) == ok andalso
-        send_element(StateData, AckReq) == ok of
+ mgmt_send_stanza(StateData, Stanza) ->
+     case send_element(StateData, Stanza) of
+       ok ->
+         maybe_request_ack(StateData);
+       _ ->
+         StateData#state{mgmt_state = pending}
+     end.
+ maybe_request_ack(#state{mgmt_ack_timer = undefined} = StateData) ->
+     request_ack(StateData);
+ maybe_request_ack(StateData) ->
+     StateData.
+ request_ack(#state{mgmt_xmlns = Xmlns,
+                  mgmt_ack_timeout = AckTimeout} = StateData) ->
 -    AckReq = #xmlel{name = <<"r">>, attrs = [{<<"xmlns">>, Xmlns}]},
++    AckReq = #sm_r{xmlns = Xmlns},
+     case {send_element(StateData, AckReq), AckTimeout} of
+       {ok, undefined} ->
+         ok;
+       {ok, Timeout} ->
+         Timer = erlang:send_after(Timeout, self(), close),
+         StateData#state{mgmt_ack_timer = Timer,
+                         mgmt_stanzas_req = StateData#state.mgmt_stanzas_out};
+       _ ->
+         StateData#state{mgmt_state = pending}
+     end.
+ maybe_renew_ack_request(#state{mgmt_ack_timer = undefined} = StateData) ->
+     StateData;
+ maybe_renew_ack_request(#state{mgmt_ack_timer = Timer,
+                              mgmt_queue = Queue,
+                              mgmt_stanzas_out = NumStanzasOut,
+                              mgmt_stanzas_req = NumStanzasReq} = StateData) ->
+     erlang:cancel_timer(Timer),
+     case NumStanzasReq < NumStanzasOut andalso not queue:is_empty(Queue) of
        true ->
-         StateData;
+         request_ack(StateData#state{mgmt_ack_timer = undefined});
        false ->
-         StateData#state{mgmt_state = pending}
+         StateData#state{mgmt_ack_timer = undefined}
      end.
  
 +-spec mgmt_queue_add(state(), xmpp_element()) -> state().
  mgmt_queue_add(StateData, El) ->
      NewNum = case StateData#state.mgmt_stanzas_out of
               4294967295 ->
@@@ -2470,10 -2996,15 +2589,15 @@@ handle_unacked_stanzas(#state{mgmt_stat
          ?DEBUG("~B stanza(s) were not acknowledged by ~s",
                 [N, jid:to_string(StateData#state.jid)]),
          lists:foreach(
 -          fun({_, Time, #xmlel{attrs = Attrs} = El}) ->
 -                  From_s = fxml:get_attr_s(<<"from">>, Attrs),
 -                  To_s = fxml:get_attr_s(<<"to">>, Attrs),
 -                  case {jid:from_string(From_s), jid:from_string(To_s)} of
 -                    {#jid{} = From, #jid{} = To} ->
 -                        F(From, To, El, Time);
 -                    {_, _} ->
 -                        ?DEBUG("Dropping stanza due to invalid JID(s)", [])
 +          fun({_, Time, Pkt}) ->
 +                  From = xmpp:get_from(Pkt),
 +                  To = xmpp:get_to(Pkt),
-                   F(From, To, Pkt, Time)
++                  case {From, To} of
++                      {#jid{}, #jid{}} ->
++                          F(From, To, Pkt, Time);
++                      {_, _} ->
++                          ?DEBUG("Dropping stanza due to invalid JID(s)", [])
+                   end
            end, queue:to_list(Queue))
      end;
  handle_unacked_stanzas(_StateData, _F) ->
@@@ -2540,7 -3074,10 +2664,8 @@@ handle_unacked_stanzas(#state{mgmt_stat
                                                   [StateData, From,
                                                    StateData#state.jid, El]) of
                        true ->
 -                          ?DEBUG("Dropping archived message stanza from ~s",
 -                                 [fxml:get_attr_s(<<"from">>,
 -                                                  El#xmlel.attrs)]),
--                          ok;
++                          ?DEBUG("Dropping archived message stanza from ~p",
++                                 [jid:to_string(xmpp:get_from(El))]);
                        false ->
                            ReRoute(From, To, El, Time)
                      end
@@@ -2621,11 -3173,9 +2746,11 @@@ inherit_session_state(#state{user = U, 
          {error, <<"Invalid 'previd' value">>}
      end.
  
 +-spec resume_session({integer(), pid()}) -> any().
  resume_session({Time, PID}) ->
-     (?GEN_FSM):sync_send_all_state_event(PID, {resume_session, Time}, 5000).
+     (?GEN_FSM):sync_send_all_state_event(PID, {resume_session, Time}, 15000).
  
 +-spec make_resume_id(state()) -> binary().
  make_resume_id(StateData) ->
      {Time, _} = StateData#state.sid,
      jlib:term_to_base64({StateData#state.resource, Time}).
@@@ -2639,22 -3188,23 +2764,24 @@@ add_resent_delay_info(#state{server = F
  %%%----------------------------------------------------------------------
  %%% XEP-0352
  %%%----------------------------------------------------------------------
 -
 +-spec csi_filter_stanza(state(), stanza()) -> state().
- csi_filter_stanza(#state{csi_state = CsiState, server = Server} = StateData,
-                 Stanza) ->
+ csi_filter_stanza(#state{csi_state = CsiState, jid = JID, server = Server} =
+                 StateData, Stanza) ->
      {StateData1, Stanzas} = ejabberd_hooks:run_fold(csi_filter_stanza, Server,
                                                    {StateData, [Stanza]},
-                                                   [Server, Stanza]),
+                                                   [Server, JID, Stanza]),
      StateData2 = lists:foldl(fun(CurStanza, AccState) ->
                                     send_stanza(AccState, CurStanza)
                             end, StateData1#state{csi_state = active},
                             Stanzas),
      StateData2#state{csi_state = CsiState}.
  
- csi_flush_queue(#state{csi_state = CsiState, server = Server} = StateData) ->
 +-spec csi_flush_queue(state()) -> state().
+ csi_flush_queue(#state{csi_state = CsiState, jid = JID, server = Server} =
+               StateData) ->
      {StateData1, Stanzas} = ejabberd_hooks:run_fold(csi_flush_queue, Server,
-                                                   {StateData, []}, [Server]),
+                                                   {StateData, []},
+                                                   [Server, JID]),
      StateData2 = lists:foldl(fun(CurStanza, AccState) ->
                                     send_stanza(AccState, CurStanza)
                             end, StateData1#state{csi_state = active},
index 35679ccd398600eb63f86655ce825456df7646ed,e6e49d9b2380ff6dd3d33e1dadd05b6cbbddd202..c6c31a971931ee72ee8f32f4868396af49f2ba18
@@@ -391,18 -396,21 +396,21 @@@ extract_path_query(#state{request_metho
                          socket = _Socket} = State)
      when (Method =:= 'POST' orelse Method =:= 'PUT') andalso
           is_integer(Len) ->
-     {NewState, Data} = recv_data(State, Len),
+     case recv_data(State, Len) of
+       error -> {State, false};
+       {NewState, Data} ->
 -          ?DEBUG("client data: ~p~n", [Data]),
 -          case catch url_decode_q_split(Path) of
 -              {'EXIT', _} -> {NewState, false};
 -              {NPath, _Query} ->
 -                  LPath = normalize_path([NPE
 -                                          || NPE <- str:tokens(path_decode(NPath), <<"/">>)]),
 -                  LQuery = case catch parse_urlencoded(Data) of
 -                               {'EXIT', _Reason} -> [];
 -                               LQ -> LQ
 -                           end,
 -                  {NewState, {LPath, LQuery, Data}}
 +    ?DEBUG("client data: ~p~n", [Data]),
 +    case catch url_decode_q_split(Path) of
 +        {'EXIT', _} -> {NewState, false};
 +        {NPath, _Query} ->
 +            LPath = normalize_path([NPE
 +                                    || NPE <- str:tokens(path_decode(NPath), <<"/">>)]),
 +            LQuery = case catch parse_urlencoded(Data) of
 +                         {'EXIT', _Reason} -> [];
 +                         LQ -> LQ
 +                     end,
 +            {NewState, {LPath, LQuery, Data}}
+           end
      end;
  extract_path_query(State) ->
      {State, false}.
Simple merge
Simple merge
index c2bf453a546bcedab3f1d37ac5faab6764e53201,2ba94369363f211485a9be8b2cbf2d9ca6092732..210575e5e6654cd6bfca1c3464fc55e2b05ad558
@@@ -183,13 -167,13 +183,15 @@@ unregister_iq_handler(Host, XMLNS) -
  refresh_iq_handlers() ->
      ejabberd_local ! refresh_iq_handlers.
  
 +-spec bounce_resource_packet(jid(), jid(), stanza()) -> ok.
++bounce_resource_packet(_From, _To, #presence{}) ->
++    ok;
  bounce_resource_packet(From, To, Packet) ->
 -    Lang = fxml:get_tag_attr_s(<<"xml:lang">>, Packet),
 +    Lang = xmpp:get_lang(Packet),
      Txt = <<"No available resource found">>,
 -    Err = jlib:make_error_reply(Packet,
 -                              ?ERRT_ITEM_NOT_FOUND(Lang, Txt)),
 -    ejabberd_router:route(To, From, Err),
 -    stop.
 +    Err = xmpp:make_error(Packet,
 +                        xmpp:err_item_not_found(Txt, Lang)),
 +    ejabberd_router:route(To, From, Err).
  
  %%====================================================================
  %% gen_server callbacks
@@@ -282,28 -265,36 +284,19 @@@ do_route(From, To, Packet) -
      ?DEBUG("local route~n\tfrom ~p~n\tto ~p~n\tpacket "
           "~P~n",
           [From, To, Packet, 8]),
++    Type = xmpp:get_type(Packet),
      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">> ->
 -               #xmlel{attrs = Attrs} = Packet,
 -               case fxml:get_attr_s(<<"type">>, Attrs) of
 -                 <<"headline">> -> ok;
 -                 <<"error">> -> ok;
 -                 _ ->
 -                     Err = jlib:make_error_reply(Packet,
 -                                                 ?ERR_SERVICE_UNAVAILABLE),
 -                     ejabberd_router:route(To, From, Err)
 -               end;
 -           <<"presence">> -> ok;
 -           _ -> ok
 -         end;
 +          ejabberd_sm:route(From, To, Packet);
-        To#jid.lresource == <<"">> ->
-           case Packet of
-               #iq{} ->
-                   process_iq(From, To, Packet);
-               #message{type = T} when T /= headline, T /= error ->
-                   Err = xmpp:make_error(Packet, xmpp:err_service_unavailable()),
-                   ejabberd_router:route(To, From, Err);
-               _ -> ok
-           end;
++       is_record(Packet, iq), To#jid.lresource == <<"">> ->
++          process_iq(From, To, Packet);
++       Type == result; Type == error; Type == headline ->
++          ok;
         true ->
-           case xmpp:get_type(Packet) of
-               error -> ok;
-               result -> ok;
-               _ ->
-                   ejabberd_hooks:run(local_send_to_resource_hook,
-                                      To#jid.lserver, [From, To, Packet])
-           end
 -         #xmlel{attrs = Attrs} = Packet,
 -         case fxml: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
++          ejabberd_hooks:run(local_send_to_resource_hook,
++                             To#jid.lserver, [From, To, Packet])
      end.
  
 +-spec update_table() -> ok.
  update_table() ->
      case catch mnesia:table_info(iq_response, attributes) of
        [id, module, function] ->
index 4e9dc8d081aa63ca8a09a34b8581735f5b9b5685,d11548c22eca88ca92fc7bb44550e59fabeff714..318feb3f8b3cb1f5e34a0beb0bef844c5f7360c0
@@@ -48,9 -49,9 +49,9 @@@
           process/2,
           opt_type/1]).
  
- -export([oauth_issue_token/1, oauth_list_tokens/0, oauth_revoke_token/1, oauth_list_scopes/0]).
+ -export([oauth_issue_token/3, oauth_list_tokens/0, oauth_revoke_token/1, oauth_list_scopes/0]).
  
 --include("jlib.hrl").
 +-include("xmpp.hrl").
  
  -include("ejabberd.hrl").
  -include("logger.hrl").
@@@ -122,17 -133,21 +133,21 @@@ get_commands_spec() -
                         }
      ].
  
- oauth_issue_token(ScopesString) ->
+ oauth_issue_token(Jid, TTLSeconds, ScopesString) ->
      Scopes = [list_to_binary(Scope) || Scope <- string:tokens(ScopesString, ";")],
-     case oauth2:authorize_client_credentials(ejabberd_ctl, Scopes, none) of
-         {ok, {_AppCtx, Authorization}} ->
-             {ok, {_AppCtx2, Response}} = oauth2:issue_token(Authorization, none),
+     case jid:from_string(list_to_binary(Jid)) of
+         #jid{luser =Username, lserver = Server} ->
+             case oauth2:authorize_password({Username, Server},  Scopes, admin_generated) of
+                 {ok, {_Ctx,Authorization}} ->
+                     {ok, {_AppCtx2, Response}} = oauth2:issue_token(Authorization, [{expiry_time, TTLSeconds}]),
 -                    {ok, AccessToken} = oauth2_response:access_token(Response),
 -                    {ok, VerifiedScope} = oauth2_response:scope(Response),
 +            {ok, AccessToken} = oauth2_response:access_token(Response),
-             {ok, Expires} = oauth2_response:expires_in(Response),
 +            {ok, VerifiedScope} = oauth2_response:scope(Response),
-             {AccessToken, VerifiedScope, integer_to_list(Expires) ++ " seconds"};
+                     {AccessToken, VerifiedScope, integer_to_list(TTLSeconds) ++ " seconds"};
 -                {error, Error} ->
 -                    {error, Error}
 +        {error, Error} ->
 +            {error, Error}
+             end;
+         error ->
+             {error, "Invalid JID: " ++ Jid}
      end.
  
  oauth_list_tokens() ->
@@@ -213,12 -210,17 +210,17 @@@ authenticate_user({User, Server}, Ctx) 
                    none),
              case acl:match_rule(JID#jid.lserver, Access, JID) of
                  allow ->
 -                            case ejabberd_auth:check_password(User, <<"">>, Server, Password) of
 -                                true ->
 -                                    {ok, {Ctx, {user, User, Server}}};
 -                                false ->
 -                                    {error, badpass}
 -                            end;
+                     case Ctx of
+                         {password, Password} ->
 +                    case ejabberd_auth:check_password(User, <<"">>, Server, Password) of
 +                        true ->
 +                            {ok, {Ctx, {user, User, Server}}};
 +                        false ->
 +                            {error, badpass}
 +                    end;
+                         admin_generated ->
+                             {ok, {Ctx, {user, User, Server}}}
+                     end;
                  deny ->
                      {error, badpass}
              end;
@@@ -272,17 -282,21 +282,21 @@@ associate_access_code(_AccessCode, _Con
      {ok, AppContext}.
  
  associate_access_token(AccessToken, Context, AppContext) ->
-     %% Tokens generated using the API/WEB belongs to users and always include the user, server pair.
-     %% Tokens generated form command line aren't tied to an user, and instead belongs to the ejabberd sysadmin
-     US = case proplists:get_value(<<"resource_owner">>, Context, <<"">>) of
-                                {user, User, Server} -> {jid:nodeprep(User), jid:nodeprep(Server)};
-                                undefined -> server_admin
+     {user, User, Server} = proplists:get_value(<<"resource_owner">>, Context, <<"">>),
+     Expire = case proplists:get_value(expiry_time, AppContext, undefined) of
+         undefined ->
+             proplists:get_value(<<"expiry_time">>, Context, 0);
+         ExpiresIn ->
+             %% There is no clean way in oauth2 lib to actually override the TTL of the generated token.
+             %% It always pass the global configured value.  Here we use the app context to pass the per-case
+             %% ttl if we want to override it.
+             seconds_since_epoch(ExpiresIn)
 -    end,
 +                           end,
+     {user, User, Server} = proplists:get_value(<<"resource_owner">>, Context, <<"">>),
      Scope = proplists:get_value(<<"scope">>, Context, []),
-     Expire = proplists:get_value(<<"expiry_time">>, Context, 0),
      R = #oauth_token{
        token = AccessToken,
-       us = US,
+       us = {jid:nodeprep(User), jid:nodeprep(Server)},
        scope = Scope,
        expire = Expire
       },
@@@ -293,41 -307,72 +307,72 @@@ associate_refresh_token(_RefreshToken, 
      %put(?REFRESH_TOKEN_TABLE, RefreshToken, Context),
      {ok, AppContext}.
  
+ scope_in_scope_list(Scope, ScopeList) ->
+     TokenScopeSet = oauth2_priv_set:new(Scope),
+     lists:any(fun(Scope2) ->
+         oauth2_priv_set:is_member(Scope2, TokenScopeSet) end,
+               ScopeList).
+ check_token(Token) ->
+     case lookup(Token) of
+         {ok, #oauth_token{us = US,
+                           scope = TokenScope,
+                           expire = Expire}} ->
+             {MegaSecs, Secs, _} = os:timestamp(),
+             TS = 1000000 * MegaSecs + Secs,
+             if
+                 Expire > TS ->
+                     {ok, US, TokenScope};
+                 true ->
+                     {false, expired}
+             end;
+         _ ->
+             {false, not_found}
+     end.
  
- check_token(User, Server, Scope, Token) ->
+ check_token(User, Server, ScopeList, Token) ->
      LUser = jid:nodeprep(User),
      LServer = jid:nameprep(Server),
-     case catch mnesia:dirty_read(oauth_token, Token) of
-         [#oauth_token{us = {LUser, LServer},
+     case lookup(Token) of
+         {ok, #oauth_token{us = {LUser, LServer},
 -                          scope = TokenScope,
 +                      scope = TokenScope,
-                       expire = Expire}] ->
+                           expire = Expire}} ->
              {MegaSecs, Secs, _} = os:timestamp(),
              TS = 1000000 * MegaSecs + Secs,
-             oauth2_priv_set:is_member(
-               Scope, oauth2_priv_set:new(TokenScope)) andalso
-                 Expire > TS;
+             if
+                 Expire > TS ->
+                     TokenScopeSet = oauth2_priv_set:new(TokenScope),
+                     lists:any(fun(Scope) ->
+                                       oauth2_priv_set:is_member(Scope, TokenScopeSet) end,
+                               ScopeList);
+                 true ->
+                     {false, expired}
+             end;
          _ ->
-             false
+             {false, not_found}
      end.
  
- check_token(Scope, Token) ->
-     case catch mnesia:dirty_read(oauth_token, Token) of
-         [#oauth_token{us = US,
+ check_token(ScopeList, Token) ->
+     case lookup(Token) of
+         {ok, #oauth_token{us = US,
 -                          scope = TokenScope,
 +                      scope = TokenScope,
-                       expire = Expire}] ->
+                           expire = Expire}} ->
              {MegaSecs, Secs, _} = os:timestamp(),
              TS = 1000000 * MegaSecs + Secs,
-             case oauth2_priv_set:is_member(
-                    Scope, oauth2_priv_set:new(TokenScope)) andalso
-                 Expire > TS of
-                 true -> case US of
-                             {LUser, LServer} -> {ok, user, {LUser, LServer}};
-                             server_admin -> {ok, server_admin}
+             if
+                 Expire > TS ->
+                     TokenScopeSet = oauth2_priv_set:new(TokenScope),
+                     case lists:any(fun(Scope) ->
+                                            oauth2_priv_set:is_member(Scope, TokenScopeSet) end,
+                                    ScopeList) of
+                         true -> {ok, user, US};
+                         false -> {false, no_matching_scope}
 -                    end;
 +                        end;
-                 false -> false
+                 true ->
+                     {false, expired}
              end;
          _ ->
-             false
+             {false, not_found}
      end.
  
  
index 3c3e698ad049d7c4d716bbc4e06ce67333bb1b4e,2a17c75cb5741594a8340124e59296684a510938..97aef3cabdc3191c33a762724450bc4cb7b20470
@@@ -466,44 -473,35 +466,50 @@@ send_element(Pid, El) -
  %%% ejabberd commands
  
  get_commands_spec() ->
-     [#ejabberd_commands{name = incoming_s2s_number,
+     [#ejabberd_commands{
+         name = incoming_s2s_number,
 -        tags = [stats, s2s],
 +                      tags = [stats, s2s],
-                       desc =
-                           "Number of incoming s2s connections on "
-                           "the node",
+         desc = "Number of incoming s2s connections on the node",
 -        policy = admin,
 -        module = ?MODULE, function = incoming_s2s_number,
 -        args = [], result = {s2s_incoming, integer}},
 +                        policy = admin,
 +                      module = ?MODULE, function = incoming_s2s_number,
 +                      args = [], result = {s2s_incoming, integer}},
-      #ejabberd_commands{name = outgoing_s2s_number,
+      #ejabberd_commands{
+         name = outgoing_s2s_number,
 -        tags = [stats, s2s],
 +                      tags = [stats, s2s],
-                       desc =
-                           "Number of outgoing s2s connections on "
-                           "the node",
+         desc = "Number of outgoing s2s connections on the node",
 -        policy = admin,
 -        module = ?MODULE, function = outgoing_s2s_number,
 -        args = [], result = {s2s_outgoing, integer}}].
 +                        policy = admin,
 +                      module = ?MODULE, function = outgoing_s2s_number,
 +                      args = [], result = {s2s_outgoing, integer}},
 +     #ejabberd_commands{name = stop_all_connections,
 +                      tags = [s2s],
 +                      desc = "Stop all outgoing and incoming connections",
 +                      policy = admin,
 +                      module = ?MODULE, function = stop_all_connections,
 +                      args = [], result = {res, rescode}}].
  
+ %% TODO Move those stats commands to ejabberd stats command ?
  incoming_s2s_number() ->
-     length(supervisor:which_children(ejabberd_s2s_in_sup)).
+     supervisor_count(ejabberd_s2s_in_sup).
  
  outgoing_s2s_number() ->
-     length(supervisor:which_children(ejabberd_s2s_out_sup)).
+     supervisor_count(ejabberd_s2s_out_sup).
+ supervisor_count(Supervisor) ->
+     case catch supervisor:which_children(Supervisor) of
+         {'EXIT', _} -> 0;
+         Result ->
+             length(Result)
+     end.
  
 +stop_all_connections() ->
 +    lists:foreach(
 +      fun({_Id, Pid, _Type, _Module}) ->
 +            exit(Pid, kill)
 +      end,
 +      supervisor:which_children(ejabberd_s2s_in_sup) ++
 +        supervisor:which_children(ejabberd_s2s_out_sup)),
 +    mnesia:clear_table(s2s).
 +
  %%%----------------------------------------------------------------------
  %%% Update Mnesia tables
  
Simple merge
index b1a4b433eacba699ca6a99265c97524cd5ce88d6,26374c1f12abe592e21b4aa877b5b483727124a8..94cd68ecf79d286859d9f524bb82c9d904760fd9
@@@ -104,9 -141,24 +104,9 @@@ init([{SockMod, Socket}, Opts]) -
                   false ->
                       Pass = proplists:get_value(
                                password, Opts,
-                               p1_sha:sha(crypto:rand_bytes(20))),
+                               p1_sha:sha(randoms:bytes(20))),
                       dict:from_list([{global, Pass}])
               end,
 -    %% privilege access to entities data
 -    PrivAccess = case lists:keysearch(privilege_access, 1, Opts) of
 -                   {value, {_, PrivAcc}} -> PrivAcc;
 -                   _ -> []
 -               end,
 -    Delegations = case lists:keyfind(delegations, 1, Opts) of
 -                    {delegations, Del} ->
 -                        lists:foldl(
 -                          fun({Ns, FiltAttr}, D) when Ns /= ?NS_DELEGATION ->
 -                                  Attr = proplists:get_value(filtering, FiltAttr, []),
 -                                  D ++ [{Ns, Attr}];
 -                             (_Deleg, D) -> D
 -                          end, [], Del);
 -                    false -> []
 -                end,
      Shaper = case lists:keysearch(shaper_rule, 1, Opts) of
               {value, {_, S}} -> S;
               _ -> none
@@@ -168,70 -230,106 +168,66 @@@ wait_for_stream(closed, StateData) -
      {stop, normal, StateData}.
  
  wait_for_handshake({xmlstreamelement, El}, StateData) ->
 -    #xmlel{name = Name, children = Els} = El,
 -    case {Name, fxml:get_cdata(Els)} of
 -      {<<"handshake">>, Digest} ->
 -        case dict:find(StateData#state.host, StateData#state.host_opts) of
 -            {ok, Password} ->
 -                case p1_sha:sha(<<(StateData#state.streamid)/binary,
 -                                  Password/binary>>) of
 -                    Digest ->
 -                        send_text(StateData, <<"<handshake/>">>),
 -                        lists:foreach(
 -                          fun (H) ->
 -                                  ejabberd_router:register_route(H, ?MYNAME),
 -                                  ?INFO_MSG("Route registered for service ~p~n",
 -                                            [H]),
 -                                  ejabberd_hooks:run(component_connected,
 -                                      [H])
 -                          end, dict:fetch_keys(StateData#state.host_opts)),
 -
 -                        mod_privilege:advertise_permissions(StateData),
 -                        DelegatedNs = mod_delegation:advertise_delegations(StateData),
 -
 -                        RosterAccess = proplists:get_value(roster,
 -                                                           StateData#state.privilege_access),
 -
 -                        case proplists:get_value(presence,
 -                                                 StateData#state.privilege_access) of
 -                              <<"managed_entity">> ->
 -                                  mod_privilege:initial_presences(StateData),
 -                                  Fun = mod_privilege:process_presence(self()),
 -                                  add_hooks(user_send_packet, Fun);
 -                              <<"roster">> when (RosterAccess == <<"both">>) or
 -                                                (RosterAccess == <<"get">>) ->
 -                                  mod_privilege:initial_presences(StateData),
 -                                  Fun = mod_privilege:process_presence(self()),
 -                                  add_hooks(user_send_packet, Fun),
 -                                  Fun2 = mod_privilege:process_roster_presence(self()),
 -                                  add_hooks(s2s_receive_packet, Fun2);
 -                              _ -> ok
 -                          end,
 -                          {next_state, stream_established,
 -                           StateData#state{delegations = DelegatedNs}};
 -                    _ ->
 -                        send_text(StateData, ?INVALID_HANDSHAKE_ERR),
 -                        {stop, normal, StateData}
 -                end;
 -            _ ->
 -                send_text(StateData, ?INVALID_HANDSHAKE_ERR),
 -                {stop, normal, StateData}
 -        end;
 -      _ -> {next_state, wait_for_handshake, StateData}
 -    end;
 +    decode_element(El, wait_for_handshake, StateData);
 +wait_for_handshake(#handshake{data = Digest}, StateData) ->
-     case dict:find(StateData#state.host, StateData#state.host_opts) of
-       {ok, Password} ->
-           case p1_sha:sha(<<(StateData#state.streamid)/binary,
-                             Password/binary>>) of
-               Digest ->
-                   send_element(StateData, #handshake{}),
-                   lists:foreach(
-                     fun (H) ->
-                             ejabberd_router:register_route(H, ?MYNAME),
-                             ?INFO_MSG("Route registered for service ~p~n",
-                                       [H])
-                     end, dict:fetch_keys(StateData#state.host_opts)),
-                   {next_state, stream_established, StateData};
-               _ ->
-                   send_element(StateData, xmpp:serr_not_authorized()),
-                   {stop, normal, StateData}
-           end;
-       _ ->
-           send_element(StateData, xmpp:serr_not_authorized()),
-           {stop, normal, StateData}
-     end;
++    send_element(StateData, #handshake{}),
++    lists:foreach(
++      fun (H) ->
++            ejabberd_router:register_route(H, ?MYNAME),
++            ?INFO_MSG("Route registered for service ~p~n",
++                      [H]),
++            ejabberd_hooks:run(component_connected, [H])
++      end, dict:fetch_keys(StateData#state.host_opts)),
++    {next_state, stream_established, StateData};
++    %% case dict:find(StateData#state.host, StateData#state.host_opts) of
++    %%        {ok, Password} ->
++    %%            case p1_sha:sha(<<(StateData#state.streamid)/binary,
++    %%                              Password/binary>>) of
++    %%                Digest ->
++    %%                    send_element(StateData, #handshake{}),
++    %%                    lists:foreach(
++    %%                      fun (H) ->
++    %%                              ejabberd_router:register_route(H, ?MYNAME),
++    %%                              ?INFO_MSG("Route registered for service ~p~n",
++    %%                                        [H]),
++    %%                              ejabberd_hooks:run(component_connected, [H])
++    %%                      end, dict:fetch_keys(StateData#state.host_opts)),
++    %%                    {next_state, stream_established, StateData};
++    %%                _ ->
++    %%                    send_element(StateData, xmpp:serr_not_authorized()),
++    %%                    {stop, normal, StateData}
++    %%            end;
++    %%        _ ->
++    %%            send_element(StateData, xmpp:serr_not_authorized()),
++    %%            {stop, normal, StateData}
++    %% end;
  wait_for_handshake({xmlstreamend, _Name}, StateData) ->
      {stop, normal, StateData};
  wait_for_handshake({xmlstreamerror, _}, StateData) ->
 -    send_text(StateData,
 -            <<(?INVALID_XML_ERR)/binary,
 -              (?STREAM_TRAILER)/binary>>),
 +    send_element(StateData, xmpp:serr_not_well_formed()),
      {stop, normal, StateData};
  wait_for_handshake(closed, StateData) ->
 -    {stop, normal, StateData}.
 +    {stop, normal, StateData};
 +wait_for_handshake(_Pkt, StateData) ->
 +    {next_state, wait_for_handshake, StateData}.
  
  stream_established({xmlstreamelement, El}, StateData) ->
 -    NewEl = jlib:remove_attr(<<"xmlns">>, El),
 -    #xmlel{name = Name, attrs = Attrs} = NewEl,
 -    From = fxml:get_attr_s(<<"from">>, Attrs),
 -    FromJID = case StateData#state.check_from of
 -              %% If the admin does not want to check the from field
 -              %% when accept packets from any address.
 -              %% In this case, the component can send packet of
 -              %% behalf of the server users.
 -              false -> jid:from_string(From);
 -              %% The default is the standard behaviour in XEP-0114
 -              _ ->
 -                  FromJID1 = jid:from_string(From),
 -                  case FromJID1 of
 -                    #jid{lserver = Server} ->
 -                        case dict:is_key(Server, StateData#state.host_opts) of
 -                          true -> FromJID1;
 -                          false -> error
 -                        end;
 -                    _ -> error
 -                  end
 -            end,
 -    To = fxml:get_attr_s(<<"to">>, Attrs),
 -    ToJID = case To of
 -            <<"">> -> error;
 -            _ -> jid:from_string(To)
 -          end,
 -    if  (Name == <<"iq">>) and (ToJID /= error) and (FromJID /= error) ->
 -          mod_privilege:process_iq(StateData, FromJID, ToJID, NewEl);
 -      (Name == <<"presence">>) and (ToJID /= error) and (FromJID /= error) ->
 -          ejabberd_router:route(FromJID, ToJID, NewEl);
 -      (Name == <<"message">>) and (ToJID /= error) and (FromJID /= error) ->
 -          mod_privilege:process_message(StateData, FromJID, ToJID, NewEl);
 +    decode_element(El, stream_established, StateData);
 +stream_established(El, StateData) when ?is_stanza(El) ->
 +    From = xmpp:get_from(El),
 +    To = xmpp:get_to(El),
 +    Lang = xmpp:get_lang(El),
 +    if From == undefined orelse To == undefined ->
 +          Txt = <<"Missing 'from' or 'to' attribute">>,
 +          send_error(StateData, El, xmpp:err_jid_malformed(Txt, Lang));
         true ->
-           FromJID = case StateData#state.check_from of
-                         false ->
-                             %% If the admin does not want to check the from field
-                             %% when accept packets from any address.
-                             %% In this case, the component can send packet of
-                             %% behalf of the server users.
-                             From;
-                         _ ->
-                             %% The default is the standard behaviour in XEP-0114
-                             Server = From#jid.lserver,
-                             case dict:is_key(Server, StateData#state.host_opts) of
-                                 true -> From;
-                                 false -> error
-                             end
-                     end,
-           if FromJID /= error ->
-                   ejabberd_router:route(FromJID, To, El);
-              true ->
 -         Lang = fxml:get_tag_attr_s(<<"xml:lang">>, El),
 -         Txt = <<"Incorrect stanza name or from/to JID">>,
 -         Err = jlib:make_error_reply(NewEl, ?ERRT_BAD_REQUEST(Lang, Txt)),
 -         send_element(StateData, Err),
 -         error
++          case check_from(From, StateData) of
++              true ->
++                  ejabberd_router:route(From, To, El);
++              false ->
 +                  Txt = <<"Improper domain part of 'from' attribute">>,
 +                  send_error(StateData, El, xmpp:err_not_allowed(Txt, Lang))
 +          end
      end,
      {next_state, stream_established, StateData};
  stream_established({xmlstreamend, _Name}, StateData) ->
@@@ -281,12 -460,32 +277,14 @@@ terminate(Reason, StateName, StateData
      case StateName of
        stream_established ->
          lists:foreach(fun (H) ->
-                               ejabberd_router:unregister_route(H)
+                               ejabberd_router:unregister_route(H),
+                               ejabberd_hooks:run(component_disconnected,
 -                                      [StateData#state.host, Reason])
++                                                 [H, Reason])
                        end,
 -                      dict:fetch_keys(StateData#state.host_opts)),
 -
 -        lists:foreach(fun({Ns, _FilterAttr}) ->
 -                              ets:delete(delegated_namespaces, Ns),
 -                              remove_iq_handlers(Ns)
 -                      end, StateData#state.delegations),
 -
 -        RosterAccess = proplists:get_value(roster, StateData#state.privilege_access),
 -        case proplists:get_value(presence, StateData#state.privilege_access) of
 -            <<"managed_entity">> ->
 -                Fun = mod_privilege:process_presence(self()),
 -                remove_hooks(user_send_packet, Fun);
 -            <<"roster">> when (RosterAccess == <<"both">>) or
 -                              (RosterAccess == <<"get">>) ->
 -                Fun = mod_privilege:process_presence(self()),
 -                remove_hooks(user_send_packet, Fun),
 -                Fun2 = mod_privilege:process_roster_presence(self()),
 -                remove_hooks(s2s_receive_packet, Fun2);
 -            _ -> ok
 -        end;
 +                      dict:fetch_keys(StateData#state.host_opts));
        _ -> ok
      end,
 +    catch send_trailer(StateData),
      (StateData#state.sockmod):close(StateData#state.socket),
      ok.
  
@@@ -306,51 -504,9 +304,63 @@@ send_text(StateData, Text) -
      (StateData#state.sockmod):send(StateData#state.socket,
                                   Text).
  
 +-spec send_element(state(), xmpp_element()) -> ok.
  send_element(StateData, El) ->
 -    send_text(StateData, fxml:element_to_binary(El)).
 +    El1 = xmpp:encode(El, ?NS_COMPONENT),
 +    send_text(StateData, fxml:element_to_binary(El1)).
 +
 +-spec send_error(state(), xmlel() | stanza(), stanza_error()) -> ok.
 +send_error(StateData, Stanza, Error) ->
 +    Type = xmpp:get_type(Stanza),
 +    if Type == error; Type == result;
 +       Type == <<"error">>; Type == <<"result">> ->
 +          ok;
 +       true ->
 +          send_element(StateData, xmpp:make_error(Stanza, Error))
 +    end.
  
 +-spec send_header(state(), binary()) -> ok.
 +send_header(StateData, Host) ->
 +    Header = xmpp:encode(
 +             #stream_start{xmlns = ?NS_COMPONENT,
 +                           stream_xmlns = ?NS_STREAM,
 +                           from = jid:make(Host),
 +                           id = StateData#state.streamid}),
 +    send_text(StateData, fxml:element_to_header(Header)).
 +
 +-spec send_trailer(state()) -> ok.
 +send_trailer(StateData) ->
 +    send_text(StateData, <<"</stream:stream>">>).
 +
 +-spec decode_element(xmlel(), state_name(), state()) -> fsm_transition().
 +decode_element(#xmlel{} = El, StateName, StateData) ->
 +    try xmpp:decode(El, ?NS_COMPONENT, [ignore_els]) of
 +      Pkt -> ?MODULE:StateName(Pkt, StateData)
 +    catch error:{xmpp_codec, Why} ->
 +            case xmpp:is_stanza(El) of
 +                true ->
 +                    Lang = xmpp:get_lang(El),
 +                    Txt = xmpp:format_error(Why),
 +                    send_error(StateData, El, xmpp:err_bad_request(Txt, Lang));
 +                false ->
 +                    ok
 +            end,
 +            {next_state, StateName, StateData}
 +    end.
 +
++-spec check_from(jid(), state()) -> boolean().
++check_from(_From, #state{check_from = false}) ->
++    %% If the admin does not want to check the from field
++    %% when accept packets from any address.
++    %% In this case, the component can send packet of
++    %% behalf of the server users.
++    true;
++check_from(From, StateData) ->
++    %% The default is the standard behaviour in XEP-0114
++    Server = From#jid.lserver,
++    dict:is_key(Server, StateData#state.host_opts).
++
 +-spec new_id() -> binary().
  new_id() -> randoms:get_string().
  
  transform_listen_option({hosts, Hosts, O}, Opts) ->
index 0655bbcf3e8d8d5411c12a9b157cca117935b64f,3369b7ca0ba2cbfbc21b750d4aaf863bfacf542b..18703dc9c9cb5d9f0b8b68be386739aef653f9e1
@@@ -296,8 -285,13 +294,13 @@@ get_offline_info(Time, User, Server, Re
      LResource = jid:resourceprep(Resource),
      Mod = get_sm_backend(LServer),
      case Mod:get_sessions(LUser, LServer, LResource) of
-       [#session{sid = SID, info = Info}] ->
+       [#session{sid = {Time, _}, info = Info}] ->
+           case proplists:get_bool(offline, Info) of
+               true ->
 -                  Info;
 +          Info;
+               false ->
+                   none
+           end;
        _ ->
            none
      end.
@@@ -434,105 -428,166 +437,106 @@@ set_session(SID, User, Server, Resource
  -spec online([#session{}]) -> [#session{}].
  
  online(Sessions) ->
-     lists:filter(fun(#session{sid = {_, undefined}}) ->
-                        false;
-                   (_) ->
-                        true
-                end, Sessions).
+     lists:filter(fun is_online/1, Sessions).
+ -spec is_online(#session{}) -> boolean().
+ is_online(#session{info = Info}) ->
+     not proplists:get_bool(offline, Info).
  
  %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
 -
 +-spec do_route(jid(), jid(), stanza() | broadcast()) -> any().
 +do_route(From, #jid{lresource = <<"">>} = To, {broadcast, _} = Packet) ->
 +    ?DEBUG("processing broadcast to bare JID: ~p", [Packet]),
 +    lists:foreach(
 +      fun(R) ->
 +            do_route(From, jid:replace_resource(To, R), Packet)
 +      end, get_user_resources(To#jid.user, To#jid.server));
  do_route(From, To, {broadcast, _} = Packet) ->
 -    case To#jid.lresource of
 -        <<"">> ->
 -            lists:foreach(fun(R) ->
 -                                  do_route(From,
 -                                           jid:replace_resource(To, R),
 -                                           Packet)
 -                          end,
 -                          get_user_resources(To#jid.user, To#jid.server));
 -        _ ->
 -            {U, S, R} = jid:tolower(To),
 -          Mod = get_sm_backend(S),
 -          case online(Mod:get_sessions(U, S, R)) of
 -                [] ->
 -                    ?DEBUG("packet dropped~n", []);
 -                Ss ->
 -                    Session = lists:max(Ss),
 -                    Pid = element(2, Session#session.sid),
 -                    ?DEBUG("sending to process ~p~n", [Pid]),
 -                    Pid ! {route, From, To, Packet}
 -            end
 +    ?DEBUG("processing broadcast to full JID: ~p", [Packet]),
 +    {U, S, R} = jid:tolower(To),
 +    Mod = get_sm_backend(S),
 +    case online(Mod:get_sessions(U, S, R)) of
 +      [] ->
 +          ?DEBUG("dropping broadcast to unavailable resourse: ~p", [Packet]);
 +      Ss ->
 +          Session = lists:max(Ss),
 +          Pid = element(2, Session#session.sid),
 +          ?DEBUG("sending to process ~p: ~p", [Pid, Packet]),
 +          Pid ! {route, From, To, Packet}
      end;
 -do_route(From, To, #xmlel{} = Packet) ->
 -    ?DEBUG("session manager~n\tfrom ~p~n\tto ~p~n\tpacket "
 -         "~P~n",
 -         [From, To, Packet, 8]),
 +do_route(From, To, #presence{type = T, status = Status} = Packet)
 +  when T == subscribe; T == subscribed; T == unsubscribe; T == unsubscribed ->
 +    ?DEBUG("processing subscription:~n~s", [xmpp:pp(Packet)]),
      #jid{user = User, server = Server,
 -       luser = LUser, lserver = LServer, lresource = LResource} = To,
 -    #xmlel{name = Name, attrs = Attrs} = Packet,
 -    Lang = fxml:get_attr_s(<<"xml:lang">>, Attrs),
 -    case LResource of
 -      <<"">> ->
 -        case Name of
 -          <<"presence">> ->
 -              {Pass, _Subsc} = case fxml:get_attr_s(<<"type">>, Attrs)
 -                                   of
 -                                 <<"subscribe">> ->
 -                                     Reason = fxml:get_path_s(Packet,
 -                                                             [{elem,
 -                                                               <<"status">>},
 -                                                              cdata]),
 -                                     {is_privacy_allow(From, To, Packet)
 -                                        andalso
 -                                        ejabberd_hooks:run_fold(roster_in_subscription,
 -                                                                LServer,
 -                                                                false,
 -                                                                [User, Server,
 -                                                                 From,
 -                                                                 subscribe,
 -                                                                 Reason]),
 -                                      true};
 -                                 <<"subscribed">> ->
 -                                     {is_privacy_allow(From, To, Packet)
 -                                        andalso
 -                                        ejabberd_hooks:run_fold(roster_in_subscription,
 -                                                                LServer,
 -                                                                false,
 -                                                                [User, Server,
 -                                                                 From,
 -                                                                 subscribed,
 -                                                                 <<"">>]),
 -                                      true};
 -                                 <<"unsubscribe">> ->
 -                                     {is_privacy_allow(From, To, Packet)
 -                                        andalso
 -                                        ejabberd_hooks:run_fold(roster_in_subscription,
 -                                                                LServer,
 -                                                                false,
 -                                                                [User, Server,
 -                                                                 From,
 -                                                                 unsubscribe,
 -                                                                 <<"">>]),
 -                                      true};
 -                                 <<"unsubscribed">> ->
 -                                     {is_privacy_allow(From, To, Packet)
 -                                        andalso
 -                                        ejabberd_hooks:run_fold(roster_in_subscription,
 -                                                                LServer,
 -                                                                false,
 -                                                                [User, Server,
 -                                                                 From,
 -                                                                 unsubscribed,
 -                                                                 <<"">>]),
 -                                      true};
 -                                 _ -> {true, false}
 -                               end,
 -              if Pass ->
 -                     PResources = get_user_present_resources(LUser, LServer),
 -                     lists:foreach(fun ({_, R}) ->
 -                                           do_route(From,
 -                                                    jid:replace_resource(To,
 -                                                                              R),
 -                                                    Packet)
 -                                   end,
 -                                   PResources);
 -                 true -> ok
 -              end;
 -          <<"message">> ->
 -              case fxml:get_attr_s(<<"type">>, Attrs) of
 -                <<"chat">> -> route_message(From, To, Packet, chat);
 -                <<"headline">> -> route_message(From, To, Packet, headline);
 -                <<"error">> -> ok;
 -                <<"groupchat">> ->
 -                    ErrTxt = <<"User session not found">>,
 -                    Err = jlib:make_error_reply(
 -                            Packet, ?ERRT_SERVICE_UNAVAILABLE(Lang, ErrTxt)),
 -                    ejabberd_router:route(To, From, Err);
 -                _ ->
 -                    route_message(From, To, Packet, normal)
 -              end;
 -          <<"iq">> -> process_iq(From, To, Packet);
 -          _ -> ok
 -        end;
 -      _ ->
 -      Mod = get_sm_backend(LServer),
 -      case online(Mod:get_sessions(LUser, LServer, LResource)) of
 -          [] ->
 -              case Name of
 -                <<"message">> ->
 -                    case fxml:get_attr_s(<<"type">>, Attrs) of
 -                      <<"chat">> -> route_message(From, To, Packet, chat);
 -                      <<"headline">> -> ok;
 -                      <<"error">> -> ok;
 -                      <<"groupchat">> ->
 -                          ErrTxt = <<"User session not found">>,
 -                          Err = jlib:make_error_reply(
 -                                  Packet,
 -                                  ?ERRT_SERVICE_UNAVAILABLE(Lang, ErrTxt)),
 -                          ejabberd_router:route(To, From, Err);
 -                      _ ->
 -                          route_message(From, To, Packet, normal)
 -                    end;
 -                <<"iq">> ->
 -                    case fxml:get_attr_s(<<"type">>, Attrs) of
 -                      <<"error">> -> ok;
 -                      <<"result">> -> ok;
 -                      _ ->
 -                          ErrTxt = <<"User session not found">>,
 -                          Err = jlib:make_error_reply(
 -                                  Packet,
 -                                  ?ERRT_SERVICE_UNAVAILABLE(Lang, ErrTxt)),
 -                          ejabberd_router:route(To, From, Err)
 -                    end;
 -                _ -> ?DEBUG("packet dropped~n", [])
 -              end;
 -          Ss ->
 -              Session = lists:max(Ss),
 -              Pid = element(2, Session#session.sid),
 -              ?DEBUG("sending to process ~p~n", [Pid]),
 -              Pid ! {route, From, To, Packet}
 -        end
 +       luser = LUser, lserver = LServer} = To,
 +    Reason = if T == subscribe -> xmpp:get_text(Status);
 +              true -> <<"">>
 +           end,
 +    case is_privacy_allow(From, To, Packet) andalso
 +      ejabberd_hooks:run_fold(
 +        roster_in_subscription,
 +        LServer, false,
 +        [User, Server, From, T, Reason]) of
 +      true ->
 +          Mod = get_sm_backend(LServer),
 +          lists:foreach(
 +            fun(#session{sid = SID, usr = {_, _, R},
 +                         priority = Prio}) when is_integer(Prio) ->
 +                    Pid = element(2, SID),
 +                    ?DEBUG("sending to process ~p:~n~s",
 +                           [Pid, xmpp:pp(Packet)]),
 +                    Pid ! {route, From, jid:replace_resource(To, R), Packet};
 +               (_) ->
 +                    ok
 +            end, online(Mod:get_sessions(LUser, LServer)));
 +      false ->
 +          ok
 +    end;
 +do_route(From, #jid{lresource = <<"">>} = To, #presence{} = Packet) ->
 +    ?DEBUG("processing presence to bare JID:~n~s", [xmpp:pp(Packet)]),
 +    {LUser, LServer, _} = jid:tolower(To),
 +    lists:foreach(
 +      fun({_, R}) ->
 +            do_route(From, jid:replace_resource(To, R), Packet)
 +      end, get_user_present_resources(LUser, LServer));
 +do_route(From, #jid{lresource = <<"">>} = To, #message{type = T} = Packet) ->
 +    ?DEBUG("processing message to bare JID:~n~s", [xmpp:pp(Packet)]),
 +    if T == chat; T == headline; T == normal; T == groupchat ->
 +          route_message(From, To, Packet, T);
 +       true ->
 +          Lang = xmpp:get_lang(Packet),
 +          ErrTxt = <<"User session not found">>,
 +          Err = xmpp:err_service_unavailable(ErrTxt, Lang),
 +          ejabberd_router:route_error(To, From, Packet, Err)
 +    end;
 +do_route(From, #jid{lresource = <<"">>} = To, #iq{} = Packet) ->
 +    ?DEBUG("processing IQ to bare JID:~n~s", [xmpp:pp(Packet)]),
 +    process_iq(From, To, Packet);
 +do_route(From, To, Packet) ->
 +    ?DEBUG("processing packet to full JID:~n~s", [xmpp:pp(Packet)]),
 +    {LUser, LServer, LResource} = jid:tolower(To),
 +    Mod = get_sm_backend(LServer),
 +    case online(Mod:get_sessions(LUser, LServer, LResource)) of
 +      [] ->
 +          case Packet of
 +              #message{type = T} when T == chat; T == normal;
 +                                      T == headline; T == groupchat ->
 +                  route_message(From, To, Packet, T);
 +              #presence{} ->
 +                  ?DEBUG("dropping presence to unavalable resource:~n~s",
 +                         [xmpp:pp(Packet)]);
 +              _ ->
 +                  Lang = xmpp:get_lang(Packet),
 +                  ErrTxt = <<"User session not found">>,
 +                  Err = xmpp:err_service_unavailable(ErrTxt, Lang),
 +                  ejabberd_router:route_error(To, From, Packet, Err)
 +          end;
 +      Ss ->
 +          Session = lists:max(Ss),
 +          Pid = element(2, Session#session.sid),
 +          ?DEBUG("sending to process ~p:~n~s", [Pid, xmpp:pp(Packet)]),
 +          Pid ! {route, From, To, Packet}
      end.
  
  %% The default list applies to the user as a whole,
@@@ -627,17 -681,18 +631,19 @@@ check_for_sessions_to_replace(User, Ser
      check_existing_resources(LUser, LServer, LResource),
      check_max_sessions(LUser, LServer).
  
 +-spec check_existing_resources(binary(), binary(), binary()) -> ok.
  check_existing_resources(LUser, LServer, LResource) ->
-     SIDs = get_resource_sessions(LUser, LServer, LResource),
-     if SIDs == [] -> ok;
+     Mod = get_sm_backend(LServer),
+     Ss = Mod:get_sessions(LUser, LServer, LResource),
+     {OnlineSs, OfflineSs} = lists:partition(fun is_online/1, Ss),
+     lists:foreach(fun(#session{sid = S}) ->
+                         Mod:delete_session(LUser, LServer, LResource, S)
+                 end, OfflineSs),
+     if OnlineSs == [] -> ok;
         true ->
+          SIDs = [SID || #session{sid = SID} <- OnlineSs],
           MaxSID = lists:max(SIDs),
-          lists:foreach(fun ({_, undefined} = S) ->
-                                Mod = get_sm_backend(LServer),
-                                Mod:delete_session(LUser, LServer, LResource,
-                                                   S);
-                            ({_, Pid} = S) when S /= MaxSID ->
+          lists:foreach(fun ({_, Pid} = S) when S /= MaxSID ->
                                 Pid ! replaced;
                             (_) -> ok
                         end,
@@@ -657,13 -711,20 +663,21 @@@ get_resource_sessions(User, Server, Res
      Mod = get_sm_backend(LServer),
      [S#session.sid || S <- online(Mod:get_sessions(LUser, LServer, LResource))].
  
 +-spec check_max_sessions(binary(), binary()) -> ok | replaced.
  check_max_sessions(LUser, LServer) ->
      Mod = get_sm_backend(LServer),
-     SIDs = [S#session.sid || S <- online(Mod:get_sessions(LUser, LServer))],
+     Ss = Mod:get_sessions(LUser, LServer),
+     {OnlineSs, OfflineSs} = lists:partition(fun is_online/1, Ss),
      MaxSessions = get_max_user_sessions(LUser, LServer),
-     if length(SIDs) =< MaxSessions -> ok;
-        true -> {_, Pid} = lists:min(SIDs), Pid ! replaced
+     if length(OnlineSs) =< MaxSessions -> ok;
+        true ->
+           #session{sid = {_, Pid}} = lists:min(OnlineSs),
+           Pid ! replaced
+     end,
+     if length(OfflineSs) =< MaxSessions -> ok;
+        true ->
+           #session{sid = SID, usr = {_, _, R}} = lists:min(OfflineSs),
+           Mod:delete_session(LUser, LServer, R, SID)
      end.
  
  %% Get the user_max_session setting
Simple merge
Simple merge
index 498fcf9b0b5af0ff36575c00f9aec2c1c0712905,fb57fa56003b352d276a98611415951326584689..bf17c8ab19742eafa60ede22033eec0877ffaaee
@@@ -266,8 -273,8 +273,8 @@@ get_auth_account(HostOfRule, AccessRule
                 Pass) ->
      case ejabberd_auth:check_password(User, <<"">>, Server, Pass) of
        true ->
-         case is_acl_match(HostOfRule, AccessRule,
+         case acl:any_rules_allowed(HostOfRule, AccessRule,
 -                               jid:make(User, Server, <<"">>))
 +                          jid:make(User, Server, <<"">>))
              of
            false -> {unauthorized, <<"unprivileged-account">>};
            true -> {ok, {User, Server}}
Simple merge
diff --cc src/jid.erl
Simple merge
diff --cc src/jlib.erl
index b79b8fa7ce56975cc7ae561743c41d5720990426,3384e670ecbb6de30d43416ad2551222b1b4835b..aca3b0ee8641c89e8bbd31f5150517a8fa8e06fe
@@@ -579,33 -582,8 +584,8 @@@ add_delay_info(El, From, Time) -
                     binary()) -> xmlel().
  
  add_delay_info(El, From, Time, Desc) ->
-     case fxml:get_subtag_with_xmlns(El, <<"delay">>, ?NS_DELAY) of
-       false ->
-         %% Add new tag
 -    DelayTag = create_delay_tag(Time, From, Desc),
 +        DelayTag = create_delay_tag(Time, From, Desc),
-         fxml:append_subtags(El, [DelayTag]);
-       DelayTag ->
-         %% Update existing tag
-         NewDelayTag =
-             case {fxml:get_tag_cdata(DelayTag), Desc} of
-               {<<"">>, <<"">>} ->
-                   DelayTag;
-               {OldDesc, <<"">>} ->
-                   DelayTag#xmlel{children = [{xmlcdata, OldDesc}]};
-               {<<"">>, NewDesc} ->
-                   DelayTag#xmlel{children = [{xmlcdata, NewDesc}]};
-               {OldDesc, NewDesc} ->
-                   case binary:match(OldDesc, NewDesc) of
-                     nomatch ->
-                         FinalDesc = <<OldDesc/binary, ", ", NewDesc/binary>>,
-                         DelayTag#xmlel{children = [{xmlcdata, FinalDesc}]};
-                     _ ->
-                         DelayTag#xmlel{children = [{xmlcdata, OldDesc}]}
-                   end
-             end,
-         NewEl = fxml:remove_subtags(El, <<"delay">>, {<<"xmlns">>, ?NS_DELAY}),
-         fxml:append_subtags(NewEl, [NewDelayTag])
-     end.
+     fxml:append_subtags(El, [DelayTag]).
  
  -spec create_delay_tag(erlang:timestamp(), jid() | ljid() | binary(), binary())
                       -> xmlel() | error.
index 4598805c272d9daaef3643817a2bd0f4df86ebb8,48732ea35c4a60ae1e27c1a180757091f784619a..69fffbd7c51ddb1fe3dd42de73d0339871253b32
@@@ -864,12 -864,15 +865,15 @@@ connected_users_vhost(Host) -
  
  %% Code copied from ejabberd_sm.erl and customized
  dirty_get_sessions_list2() ->
-     mnesia:dirty_select(
+     Ss = mnesia:dirty_select(
 -         session,
 +      session,
-       [{#session{usr = '$1', sid = {'$2', '$3'}, priority = '$4', info = '$5',
+          [{#session{usr = '$1', sid = '$2', priority = '$3', info = '$4',
 -                    _ = '_'},
 +               _ = '_'},
-       [{is_pid, '$3'}],
-       [['$1', {{'$2', '$3'}}, '$4', '$5']]}]).
+            [],
+            [['$1', '$2', '$3', '$4']]}]),
+     lists:filter(fun([_USR, _SID, _Priority, Info]) ->
+                        not proplists:get_bool(offline, Info)
+                end, Ss).
  
  %% Make string more print-friendly
  stringize(String) ->
@@@ -1173,16 -1205,30 +1177,17 @@@ push_roster_item(LU, LS, R, U, S, Actio
      ejabberd_router:route(jid:remove_resource(LJID), LJID, ResIQ).
  
  build_roster_item(U, S, {add, Nick, Subs, Group}) ->
 -    GNames = binary:split(Group,<<";">>, [global]),
 -    GroupEls = [{xmlel, <<"group">>, [], [{xmlcdata, GName}]} || GName <- GNames],
 -    {xmlel, <<"item">>,
 -     [{<<"jid">>, jid:to_string(jid:make(U, S, <<>>))},
 -      {<<"name">>, Nick},
 -      {<<"subscription">>, Subs}],
 -     GroupEls
 -    };
++    Groups = binary:split(Group,<<";">>, [global]),
 +    #roster_item{jid = jid:make(U, S),
 +               name = Nick,
 +               subscription = jlib:binary_to_atom(Subs),
-                groups = [Group]};
++               groups = Groups};
  build_roster_item(U, S, remove) ->
 -    {xmlel, <<"item">>,
 -     [{<<"jid">>, jid:to_string(jid:make(U, S, <<>>))},
 -      {<<"subscription">>, <<"remove">>}],
 -     []
 -    }.
 +    #roster_item{jid = jid:make(U, S), subscription = remove}.
  
  build_iq_roster_push(Item) ->
 -    {xmlel, <<"iq">>,
 -     [{<<"type">>, <<"set">>}, {<<"id">>, <<"push">>}],
 -     [{xmlel, <<"query">>,
 -       [{<<"xmlns">>, ?NS_ROSTER}],
 -       [Item]
 -      }
 -     ]
 -    }.
 +    #iq{type = set, id = <<"push">>,
 +      sub_els = [#roster_query{items = [Item]}]}.
  
  build_broadcast(U, S, {add, _Nick, Subs, _Group}) ->
      build_broadcast(U, S, list_to_atom(binary_to_list(Subs)));
index 495cbf9469b0eb03c435a1e5b825c469dee0d17e,d74c46bf9723d8c482581d0cdcf2c68a115849fd..1d93cbe65458cc65b6e716e9432bd97b3d0f624c
@@@ -601,16 -687,16 +601,16 @@@ announce_all(From, To, Packet) -
      Access = get_access(Host),
      case acl:match_rule(Host, Access, From) of
        deny ->
 -          Lang = fxml:get_tag_attr_s(<<"xml:lang">>, Packet),
 +          Lang = xmpp:get_lang(Packet),
            Txt = <<"Denied by ACL">>,
 -          Err = jlib:make_error_reply(Packet, ?ERRT_FORBIDDEN(Lang, Txt)),
 +          Err = xmpp:make_error(Packet, xmpp:err_forbidden(Txt, Lang)),
            ejabberd_router:route(To, From, Err);
        allow ->
 -          Local = jid:make(<<>>, To#jid.server, <<>>),
 +          Local = jid:make(To#jid.server),
            lists:foreach(
              fun({User, Server}) ->
-                     Dest = jid:make(User, Server),
-                     ejabberd_router:route(Local, Dest, Packet)
+                     Dest = jid:make(User, Server, <<>>),
+                     ejabberd_router:route(Local, Dest, add_store_hint(Packet))
              end, ejabberd_auth:get_vh_registered_users(Host))
      end.
  
@@@ -618,16 -704,16 +618,16 @@@ announce_all_hosts_all(From, To, Packet
      Access = get_access(global),
      case acl:match_rule(global, Access, From) of
        deny ->
 -          Lang = fxml:get_tag_attr_s(<<"xml:lang">>, Packet),
 +          Lang = xmpp:get_lang(Packet),
            Txt = <<"Denied by ACL">>,
 -          Err = jlib:make_error_reply(Packet, ?ERRT_FORBIDDEN(Lang, Txt)),
 +          Err = xmpp:make_error(Packet, xmpp:err_forbidden(Txt, Lang)),
            ejabberd_router:route(To, From, Err);
        allow ->
 -          Local = jid:make(<<>>, To#jid.server, <<>>),
 +          Local = jid:make(To#jid.server),
            lists:foreach(
              fun({User, Server}) ->
-                     Dest = jid:make(User, Server),
-                     ejabberd_router:route(Local, Dest, Packet)
+                     Dest = jid:make(User, Server, <<>>),
+                     ejabberd_router:route(Local, Dest, add_store_hint(Packet))
              end, ejabberd_auth:dirty_get_registered_users())
      end.
  
@@@ -823,6 -909,12 +823,10 @@@ get_access(Host) -
                             fun(A) -> A end,
                             none).
  
 --spec add_store_hint(xmlel()) -> xmlel().
 -
++-spec add_store_hint(stanza()) -> stanza().
+ add_store_hint(El) ->
 -    Hint = #xmlel{name = <<"store">>, attrs = [{<<"xmlns">>, ?NS_HINTS}]},
 -    fxml:append_subtags(El, [Hint]).
++    xmpp:set_subtag(El, #hint{type = store}).
  %%-------------------------------------------------------------------------
  export(LServer) ->
      Mod = gen_mod:db_mod(LServer, ?MODULE),
index e35caa1c7a32f83053f7a09177877f529b2228c3,e1e6d63a2647384e15b82ddecf4fcc726d53806a..023e8dc6f8703801a220074ba38299a3d203aae4
@@@ -119,12 -129,11 +119,13 @@@ user_receive_packet(Packet, _C2SState, 
  %    - registered to the user_send_packet hook, to be called only once even for multicast
  %    - do not support "private" message mode, and do not modify the original packet in any way
  %    - we also replicate "read" notifications
 +-spec check_and_forward(jid(), jid(), stanza(), direction()) ->
 +                             stanza() | {stop, stanza()}.
  check_and_forward(JID, To, Packet, Direction)->
      case is_chat_message(Packet) andalso
 -           not is_muc_pm(To, Packet) andalso
 -               fxml:get_subtag(Packet, <<"private">>) == false andalso
 -                   fxml:get_subtag(Packet, <<"no-copy">>) == false of
++      not is_muc_pm(To, Packet) andalso
 +      xmpp:has_subtag(Packet, #carbons_private{}) == false andalso
 +      xmpp:has_subtag(Packet, #hint{type = 'no-copy'}) == false of
        true ->
            case is_carbon_copy(Packet) of
                false ->
@@@ -216,23 -243,42 +217,28 @@@ disable(Host, U, R)-
      Mod = gen_mod:db_mod(Host, ?MODULE),
      Mod:disable(U, Host, R).
  
 -complete_packet(From, #xmlel{name = <<"message">>, attrs = OrigAttrs} = Packet, sent) ->
 +-spec complete_packet(jid(), message(), direction()) -> message().
 +complete_packet(From, #message{from = undefined} = Msg, sent) ->
      %% if this is a packet sent by user on this host, then Packet doesn't
      %% include the 'from' attribute. We must add it.
 -    Attrs = lists:keystore(<<"xmlns">>, 1, OrigAttrs, {<<"xmlns">>, <<"jabber:client">>}),
 -    case proplists:get_value(<<"from">>, Attrs) of
 -      undefined ->
 -              Packet#xmlel{attrs = [{<<"from">>, jid:to_string(From)}|Attrs]};
 -      _ ->
 -              Packet#xmlel{attrs = Attrs}
 -    end;
 -complete_packet(_From, #xmlel{name = <<"message">>, attrs=OrigAttrs} = Packet, received) ->
 -    Attrs = lists:keystore(<<"xmlns">>, 1, OrigAttrs, {<<"xmlns">>, <<"jabber:client">>}),
 -    Packet#xmlel{attrs = Attrs}.
 -
 -message_type(#xmlel{attrs = Attrs}) ->
 -    case fxml:get_attr(<<"type">>, Attrs) of
 -      {value, Type} -> Type;
 -      false -> <<"normal">>
 -    end.
 -
 -is_chat_message(#xmlel{name = <<"message">>} = Packet) ->
 -    case message_type(Packet) of
 -      <<"chat">> -> true;
 -      <<"normal">> -> has_non_empty_body(Packet);
 -      _ -> false
 -    end;
 -is_chat_message(_Packet) -> false.
 +    Msg#message{from = From};
 +complete_packet(_From, Msg, _Direction) ->
 +    Msg.
 +
 +-spec is_chat_message(stanza()) -> boolean().
 +is_chat_message(#message{type = chat}) ->
 +    true;
 +is_chat_message(#message{type = normal, body = Body}) ->
 +    xmpp:get_text(Body) /= <<"">>;
 +is_chat_message(_) ->
 +    false.
  
 -    fxml:get_subtag_with_xmlns(Packet, <<"x">>, ?NS_MUC_USER) =/= false.
 -
 -has_non_empty_body(Packet) ->
 -    fxml:get_subtag_cdata(Packet, <<"body">>) =/= <<"">>.
+ is_muc_pm(#jid{lresource = <<>>}, _Packet) ->
+     false;
+ is_muc_pm(_To, Packet) ->
++    xmpp:has_subtag(Packet, #muc_user{}).
 +-spec list(binary(), binary()) -> [{binary(), binary()}].
  %% list {resource, cc_version} with carbons enabled for given user and host
  list(User, Server) ->
      Mod = gen_mod:db_mod(Server, ?MODULE),
index 7f0658eff8459f4edda813cbf884098b0c1d16b9,9d37d4f5bd4a5fd1cef3c34e7a46e7d0c268f037..2bae7a4f825ee73e58242fe0c7fb1c7a8431d13c
@@@ -151,69 -151,70 +151,71 @@@ depends(_Host, _Opts) -
  %% ejabberd_hooks callbacks.
  %%--------------------------------------------------------------------
  
- -spec filter_presence({ejabberd_c2s:state(), [stanza()]}, binary(), stanza())
 --spec filter_presence({term(), [xmlel()]}, binary(), jid(), xmlel())
 -      -> {term(), [xmlel()]} | {stop, {term(), [xmlel()]}}.
++-spec filter_presence({ejabberd_c2s:state(), [stanza()]}, binary(), jid(), stanza())
 +      -> {ejabberd_c2s:state(), [stanza()]} |
 +       {stop, {ejabberd_c2s:state(), [stanza()]}}.
  
- filter_presence({C2SState, _OutStanzas} = Acc, Host,
+ filter_presence({C2SState, _OutStanzas} = Acc, Host, To,
 -              #xmlel{name = <<"presence">>, attrs = Attrs} = Stanza) ->
 -    case fxml:get_attr(<<"type">>, Attrs) of
 -      {value, Type} when Type /= <<"unavailable">> ->
 -        Acc;
 -      _ ->
 -        ?DEBUG("Got availability presence stanza for ~s",
 -               [jid:to_string(To)]),
 -        queue_add(presence, Stanza, Host, C2SState)
 +              #presence{type = Type} = Stanza) ->
 +    if Type == available; Type == unavailable ->
-           ?DEBUG("Got availability presence stanza", []),
++          ?DEBUG("Got availability presence stanza for ~s",
++                 [jid:to_string(To)]),
 +          queue_add(presence, Stanza, Host, C2SState);
 +       true ->
 +          Acc
      end;
- filter_presence(Acc, _Host, _Stanza) -> Acc.
+ filter_presence(Acc, _Host, _To, _Stanza) -> Acc.
  
- -spec filter_chat_states({ejabberd_c2s:state(), [stanza()]}, binary(), stanza())
 --spec filter_chat_states({term(), [xmlel()]}, binary(), jid(), xmlel())
 -      -> {term(), [xmlel()]} | {stop, {term(), [xmlel()]}}.
++-spec filter_chat_states({ejabberd_c2s:state(), [stanza()]}, binary(), jid(), stanza())
 +      -> {ejabberd_c2s:state(), [stanza()]} |
 +       {stop, {ejabberd_c2s:state(), [stanza()]}}.
  
- filter_chat_states({C2SState, _OutStanzas} = Acc, Host,
-                  #message{from = From, to = To} = Stanza) ->
+ filter_chat_states({C2SState, _OutStanzas} = Acc, Host, To,
 -                 #xmlel{name = <<"message">>} = Stanza) ->
 -    case jlib:is_standalone_chat_state(Stanza) of
 -      true ->
 -        From = fxml:get_tag_attr_s(<<"from">>, Stanza),
 -        case {jid:from_string(From), To} of
 -          {#jid{luser = U, lserver = S}, #jid{luser = U, lserver = S}} ->
 -              %% Don't queue (carbon copies of) chat states from other
 -              %% resources, as they might be used to sync the state of
 -              %% conversations across clients.
 -              Acc;
 -          _ ->
++                 #message{from = From} = Stanza) ->
 +    case xmpp_util:is_standalone_chat_state(Stanza) of
 +      true ->
 +          case {From, To} of
 +              {#jid{luser = U, lserver = S}, #jid{luser = U, lserver = S}} ->
 +                  %% Don't queue (carbon copies of) chat states from other
 +                  %% resources, as they might be used to sync the state of
 +                  %% conversations across clients.
 +                  Acc;
 +              _ ->
-                   ?DEBUG("Got standalone chat state notification", []),
+               ?DEBUG("Got standalone chat state notification for ~s",
+                      [jid:to_string(To)]),
 -              queue_add(chatstate, Stanza, Host, C2SState)
 -        end;
 -      false ->
 -        Acc
 +                  queue_add(chatstate, Stanza, Host, C2SState)
 +          end;
 +      false ->
 +          Acc
      end;
- filter_chat_states(Acc, _Host, _Stanza) -> Acc.
+ filter_chat_states(Acc, _Host, _To, _Stanza) -> Acc.
  
- -spec filter_pep({ejabberd_c2s:state(), [stanza()]}, binary(), stanza())
 --spec filter_pep({term(), [xmlel()]}, binary(), jid(), xmlel())
 -      -> {term(), [xmlel()]} | {stop, {term(), [xmlel()]}}.
++-spec filter_pep({ejabberd_c2s:state(), [stanza()]}, binary(), jid(), stanza())
 +      -> {ejabberd_c2s:state(), [stanza()]} |
 +       {stop, {ejabberd_c2s:state(), [stanza()]}}.
  
- filter_pep({C2SState, _OutStanzas} = Acc, Host, #message{} = Stanza) ->
 -filter_pep({C2SState, _OutStanzas} = Acc, Host, To,
 -         #xmlel{name = <<"message">>} = Stanza) ->
++filter_pep({C2SState, _OutStanzas} = Acc, Host, To, #message{} = Stanza) ->
      case get_pep_node(Stanza) of
 -      {value, Node} ->
 -        ?DEBUG("Got PEP notification for ~s", [jid:to_string(To)]),
 -        queue_add({pep, Node}, Stanza, Host, C2SState);
 -      false ->
 -        Acc
 +      undefined ->
 +          Acc;
 +      Node ->
-           ?DEBUG("Got PEP notification", []),
++          ?DEBUG("Got PEP notification for ~s", [jid:to_string(To)]),
 +          queue_add({pep, Node}, Stanza, Host, C2SState)
      end;
- filter_pep(Acc, _Host, _Stanza) -> Acc.
+ filter_pep(Acc, _Host, _To, _Stanza) -> Acc.
  
- -spec filter_other({ejabberd_c2s:state(), [stanza()]}, binary(), stanza())
-       -> {stop, {ejabberd_c2s:state(), [stanza()]}}.
 --spec filter_other({term(), [xmlel()]}, binary(), jid(), xmlel())
 -      -> {term(), [xmlel()]}.
++-spec filter_other({ejabberd_c2s:state(), [stanza()]}, binary(), jid(), stanza())
++      -> {ejabberd_c2s:state(), [stanza()]}.
  
- filter_other({C2SState, _OutStanzas}, Host, Stanza) ->
-     ?DEBUG("Won't add stanza to CSI queue", []),
+ filter_other({C2SState, _OutStanzas}, Host, To, Stanza) ->
+     ?DEBUG("Won't add stanza for ~s to CSI queue", [jid:to_string(To)]),
      queue_take(Stanza, Host, C2SState).
  
- -spec flush_queue({ejabberd_c2s:state(), [stanza()]}, binary())
 --spec flush_queue({term(), [xmlel()]}, binary(), jid()) -> {term(), [xmlel()]}.
++-spec flush_queue({ejabberd_c2s:state(), [stanza()]}, binary(), jid())
 +      -> {ejabberd_c2s:state(), [stanza()]}.
  
- flush_queue({C2SState, _OutStanzas}, Host) ->
-     ?DEBUG("Going to flush CSI queue", []),
+ flush_queue({C2SState, _OutStanzas}, Host, JID) ->
+     ?DEBUG("Going to flush CSI queue of ~s", [jid:to_string(JID)]),
      Queue = get_queue(C2SState),
      NewState = set_queue([], C2SState),
      {NewState, get_stanzas(Queue, Host)}.
@@@ -246,11 -250,11 +248,11 @@@ queue_add(Type, Stanza, Host, C2SState
          {stop, {NewState, []}}
      end.
  
- -spec queue_take(stanza(), binary(), term()) -> {stop, {term(), [stanza()]}}.
 --spec queue_take(xmlel(), binary(), term()) -> {term(), [xmlel()]}.
++-spec queue_take(stanza(), binary(), term()) -> {term(), [stanza()]}.
  
  queue_take(Stanza, Host, C2SState) ->
 -    From = fxml:get_tag_attr_s(<<"from">>, Stanza),
 -    {LUser, LServer, _LResource} = jid:tolower(jid:from_string(From)),
 +    From = xmpp:get_from(Stanza),
 +    {LUser, LServer, _LResource} = jid:tolower(From),
      {Selected, Rest} = lists:partition(
                         fun({{{U, S, _R}, _Type}, _Time, _Stanza}) ->
                                 U == LUser andalso S == LServer
index 5e2ff351c04f9a736038c94886d869c5215c9782,03779d027abca4535ee2551ff3c27f56f6abfe2d..fc274dc03732dde5a0bd263beb65632654300993
@@@ -1069,81 -1289,150 +1069,81 @@@ get_form(_Host
                              Make_option(<<"5 ">>, <<"minutes">>, <<"300">>),
                              Make_option(<<"10 ">>, <<"minutes">>, <<"600">>),
                              Make_option(<<"15 ">>, <<"minutes">>, <<"900">>),
 -                            Make_option(<<"30 ">>, <<"minutes">>, <<"1800">>),
 -                            #xmlel{name = <<"required">>, attrs = [],
 -                                   children = []}]},
 -                #xmlel{name = <<"field">>,
 -                       attrs =
 -                           [{<<"type">>, <<"fixed">>},
 -                            {<<"label">>,
 -                             ?T(Lang,
 -                                <<"Send announcement to all online users "
 -                                  "on all hosts">>)}],
 -                       children = []},
 -                #xmlel{name = <<"field">>,
 -                       attrs =
 -                           [{<<"var">>, <<"subject">>},
 -                            {<<"type">>, <<"text-single">>},
 -                            {<<"label">>, ?T(Lang, <<"Subject">>)}],
 -                       children = []},
 -                #xmlel{name = <<"field">>,
 -                       attrs =
 -                           [{<<"var">>, <<"announcement">>},
 -                            {<<"type">>, <<"text-multi">>},
 -                            {<<"label">>, ?T(Lang, <<"Message body">>)}],
 -                       children = []}]}]};
 +                            Make_option(<<"30 ">>, <<"minutes">>, <<"1800">>)]},
 +                    #xdata_field{type = fixed,
 +                                 label = ?T(Lang,
 +                                            <<"Send announcement to all online users "
 +                                              "on all hosts">>)},
 +                    #xdata_field{var = <<"subject">>,
 +                                 type = 'text-single',
 +                                 label = ?T(Lang, <<"Subject">>)},
 +                    #xdata_field{var = <<"announcement">>,
 +                                 type = 'text-multi',
 +                                 label = ?T(Lang, <<"Message body">>)}]}};
  get_form(Host, [<<"config">>, <<"acls">>], Lang) ->
-                            [ets:select(
 +    ACLs = str:tokens(
 +           iolist_to_binary(
 +             io_lib:format("~p.",
++                           [mnesia:dirty_select(
 +                              acl,
 +                              ets:fun2ms(
 +                                fun({acl, {Name, H}, Spec}) when H == Host ->
 +                                        {acl, Name, Spec}
 +                                end))])),
 +           <<"\n">>),
      {result,
 -     [#xmlel{name = <<"x">>,
 -           attrs = [{<<"xmlns">>, ?NS_XDATA}],
 -           children =
 -               [?HFIELD(),
 -                #xmlel{name = <<"title">>, attrs = [],
 -                       children =
 -                           [{xmlcdata,
 -                             ?T(Lang,
 -                                <<"Access Control List Configuration">>)}]},
 -                #xmlel{name = <<"field">>,
 -                       attrs =
 -                           [{<<"type">>, <<"text-multi">>},
 -                            {<<"label">>,
 -                             ?T(Lang, <<"Access control lists">>)},
 -                            {<<"var">>, <<"acls">>}],
 -                       children =
 -                           lists:map(fun (S) ->
 -                                             #xmlel{name = <<"value">>,
 -                                                    attrs = [],
 -                                                    children =
 -                                                        [{xmlcdata, S}]}
 -                                     end,
 -                                     str:tokens(iolist_to_binary(io_lib:format("~p.",
 -                                                                               [mnesia:dirty_select(acl,
 -                                                                                           [{{acl,
 -                                                                                              {'$1',
 -                                                                                               '$2'},
 -                                                                                              '$3'},
 -                                                                                             [{'==',
 -                                                                                               '$2',
 -                                                                                               Host}],
 -                                                                                             [{{acl,
 -                                                                                                '$1',
 -                                                                                                '$3'}}]}])])),
 -                                                <<"\n">>))}]}]};
 +     #xdata{title = ?T(Lang, <<"Access Control List Configuration">>),
 +          type = form,
 +          fields = [?HFIELD(),
 +                    #xdata_field{type = 'text-multi',
 +                                 label = ?T(Lang, <<"Access control lists">>),
 +                                 var = <<"acls">>,
 +                                 values = ACLs}]}};
  get_form(Host, [<<"config">>, <<"access">>], Lang) ->
-                            [ets:select(
 +    Accs = str:tokens(
 +           iolist_to_binary(
 +             io_lib:format("~p.",
++                           [mnesia:dirty_select(
 +                              access,
 +                              ets:fun2ms(
 +                                fun({access, {Name, H}, Acc}) when H == Host ->
 +                                        {access, Name, Acc}
 +                                end))])),
 +           <<"\n">>),
      {result,
 -     [#xmlel{name = <<"x">>,
 -           attrs = [{<<"xmlns">>, ?NS_XDATA}],
 -           children =
 -               [?HFIELD(),
 -                #xmlel{name = <<"title">>, attrs = [],
 -                       children =
 -                           [{xmlcdata,
 -                             ?T(Lang, <<"Access Configuration">>)}]},
 -                #xmlel{name = <<"field">>,
 -                       attrs =
 -                           [{<<"type">>, <<"text-multi">>},
 -                            {<<"label">>, ?T(Lang, <<"Access rules">>)},
 -                            {<<"var">>, <<"access">>}],
 -                       children =
 -                           lists:map(fun (S) ->
 -                                             #xmlel{name = <<"value">>,
 -                                                    attrs = [],
 -                                                    children =
 -                                                        [{xmlcdata, S}]}
 -                                     end,
 -                                     str:tokens(iolist_to_binary(io_lib:format("~p.",
 -                                                                               [mnesia:dirty_select(access,
 -                                                                                           [{{access,
 -                                                                                              {'$1',
 -                                                                                               '$2'},
 -                                                                                              '$3'},
 -                                                                                             [{'==',
 -                                                                                               '$2',
 -                                                                                               Host}],
 -                                                                                             [{{access,
 -                                                                                                '$1',
 -                                                                                                '$3'}}]}])])),
 -                                                <<"\n">>))}]}]};
 +     #xdata{title = ?T(Lang, <<"Access Configuration">>),
 +          type = form,
 +          fields = [?HFIELD(),
 +                    #xdata_field{type = 'text-multi',
 +                                 label = ?T(Lang, <<"Access rules">>),
 +                                 var = <<"access">>,
 +                                 values = Accs}]}};
  get_form(_Host, ?NS_ADMINL(<<"add-user">>), Lang) ->
      {result,
 -     [#xmlel{name = <<"x">>,
 -           attrs = [{<<"xmlns">>, ?NS_XDATA}],
 -           children =
 -               [?HFIELD(),
 -                #xmlel{name = <<"title">>, attrs = [],
 -                       children = [{xmlcdata, ?T(Lang, <<"Add User">>)}]},
 -                #xmlel{name = <<"field">>,
 -                       attrs =
 -                           [{<<"type">>, <<"jid-single">>},
 -                            {<<"label">>, ?T(Lang, <<"Jabber ID">>)},
 -                            {<<"var">>, <<"accountjid">>}],
 -                       children =
 -                           [#xmlel{name = <<"required">>, attrs = [],
 -                                   children = []}]},
 -                #xmlel{name = <<"field">>,
 -                       attrs =
 -                           [{<<"type">>, <<"text-private">>},
 -                            {<<"label">>, ?T(Lang, <<"Password">>)},
 -                            {<<"var">>, <<"password">>}],
 -                       children =
 -                           [#xmlel{name = <<"required">>, attrs = [],
 -                                   children = []}]},
 -                #xmlel{name = <<"field">>,
 -                       attrs =
 -                           [{<<"type">>, <<"text-private">>},
 -                            {<<"label">>,
 -                             ?T(Lang, <<"Password Verification">>)},
 -                            {<<"var">>, <<"password-verify">>}],
 -                       children =
 -                           [#xmlel{name = <<"required">>, attrs = [],
 -                                   children = []}]}]}]};
 +     #xdata{title = ?T(Lang, <<"Add User">>),
 +          type = form,
 +          fields = [?HFIELD(),
 +                    #xdata_field{type = 'jid-single',
 +                                 label = ?T(Lang, <<"Jabber ID">>),
 +                                 required = true,
 +                                 var = <<"accountjid">>},
 +                    #xdata_field{type = 'text-private',
 +                                 label = ?T(Lang, <<"Password">>),
 +                                 required = true,
 +                                 var = <<"password">>},
 +                    #xdata_field{type = 'text-private',
 +                                 label = ?T(Lang, <<"Password Verification">>),
 +                                 required = true,
 +                                 var = <<"password-verify">>}]}};
  get_form(_Host, ?NS_ADMINL(<<"delete-user">>), Lang) ->
      {result,
 -     [#xmlel{name = <<"x">>,
 -           attrs = [{<<"xmlns">>, ?NS_XDATA}],
 -           children =
 -               [?HFIELD(),
 -                #xmlel{name = <<"title">>, attrs = [],
 -                       children = [{xmlcdata, ?T(Lang, <<"Delete User">>)}]},
 -                #xmlel{name = <<"field">>,
 -                       attrs =
 -                           [{<<"type">>, <<"jid-multi">>},
 -                            {<<"label">>, ?T(Lang, <<"Jabber ID">>)},
 -                            {<<"var">>, <<"accountjids">>}],
 -                       children =
 -                           [#xmlel{name = <<"required">>, attrs = [],
 -                                   children = []}]}]}]};
 +     #xdata{title = ?T(Lang, <<"Delete User">>),
 +          type = form,
 +          fields = [?HFIELD(),
 +                    #xdata_field{type = 'jid-multi',
 +                                 label = ?T(Lang, <<"Jabber ID">>),
 +                                 required = true,
 +                                 var = <<"accountjids">>}]}};
  get_form(_Host, ?NS_ADMINL(<<"end-user-session">>),
         Lang) ->
      {result,
@@@ -1565,26 -1914,34 +1565,34 @@@ set_form(From, Host, ?NS_ADMINL(<<"end-
      LServer = JID#jid.lserver,
      true = LServer == Host orelse
             get_permission_level(From) == global,
 -    Xmlelement = ?SERRT_POLICY_VIOLATION(Lang, <<"has been kicked">>),
 +    Xmlelement = xmpp:serr_policy_violation(<<"has been kicked">>, Lang),
      case JID#jid.lresource of
        <<>> ->
-         SIDs = mnesia:dirty_select(session,
-                                    [{#session{sid = {'$1', '$2'},
-                                               usr = {LUser, LServer, '_'},
+         SIs = mnesia:dirty_select(session,
+                                   [{#session{usr = {LUser, LServer, '_'},
+                                              sid = '$1',
+                                              info = '$2',
 -                                             _ = '_'},
 +                                              _ = '_'},
-                                      [{is_pid, '$2'}],
-                                      [{{'$1', '$2'}}]}]),
-         [Pid ! {kick, kicked_by_admin, Xmlelement} || {_, Pid} <- SIDs];
+                                     [], [{{'$1', '$2'}}]}]),
+         Pids = [P || {{_, P}, Info} <- SIs,
+                      not proplists:get_bool(offline, Info)],
+         lists:foreach(fun(Pid) ->
+                               Pid ! {kick, kicked_by_admin, Xmlelement}
+                       end, Pids);
        R ->
-         [{_, Pid}] = mnesia:dirty_select(session,
-                                          [{#session{sid = {'$1', '$2'},
-                                                     usr = {LUser, LServer, R},
+         [{{_, Pid}, Info}] = mnesia:dirty_select(
+                                session,
+                                [{#session{usr = {LUser, LServer, R},
+                                           sid = '$1',
+                                           info = '$2',
 -                                          _ = '_'},
 +                                                    _ = '_'},
-                                            [{is_pid, '$2'}],
-                                            [{{'$1', '$2'}}]}]),
-         Pid ! {kick, kicked_by_admin, Xmlelement}
+                                  [], [{{'$1', '$2'}}]}]),
+         case proplists:get_bool(offline, Info) of
+           true -> ok;
+           false -> Pid ! {kick, kicked_by_admin, Xmlelement}
+         end
      end,
 -    {result, []};
 +    {result, undefined};
  set_form(From, Host,
         ?NS_ADMINL(<<"get-user-password">>), Lang, XData) ->
      AccountString = get_value(<<"accountjid">>, XData),
index 0000000000000000000000000000000000000000,f2d1a13b520ac30e322f54aafc582cd1846ac947..7fec01dcbbd8359c4e0884d2b26d6a1cafdc6b05
mode 000000,100644..100644
--- /dev/null
@@@ -1,0 -1,538 +1,325 @@@
 -%%%--------------------------------------------------------------------------------------
 -%%% File    : mod_delegation.erl
 -%%% Author  : Anna Mukharram <amuhar3@gmail.com>
 -%%% Purpose : This module is an implementation for XEP-0355: Namespace Delegation
 -%%%--------------------------------------------------------------------------------------
 -
++%%%-------------------------------------------------------------------
++%%% @author Evgeny Khramtsov <ekhramtsov@process-one.net>
++%%% @copyright (C) 2016, Evgeny Khramtsov
++%%% @doc
++%%%
++%%% @end
++%%% Created : 10 Nov 2016 by Evgeny Khramtsov <ekhramtsov@process-one.net>
++%%%-------------------------------------------------------------------
+ -module(mod_delegation).
 --author('amuhar3@gmail.com').
 -
++-behaviour(gen_server).
+ -behaviour(gen_mod).
 --protocol({xep, 0355, '0.3'}).
 -
 --export([start/2, stop/1, depends/2, mod_opt_type/1]).
 -
 --export([advertise_delegations/1, process_iq/3,
 -         disco_local_features/5, disco_sm_features/5,
 -         disco_local_identity/5, disco_sm_identity/5, disco_info/5, clean/0]).
 -
 --include_lib("stdlib/include/ms_transform.hrl").
 -
 --include("ejabberd_service.hrl").
 -
 --define(CLEAN_INTERVAL, timer:minutes(10)).
 -
 -%%%--------------------------------------------------------------------------------------
 -%%%  API
 -%%%--------------------------------------------------------------------------------------
 -
 -start(Host, _Opts) ->
 -    mod_disco:register_feature(Host, ?NS_DELEGATION),
 -    %% start timer for hooks_tmp table cleaning 
 -    timer:apply_after(?CLEAN_INTERVAL, ?MODULE, clean, []),
++%% API
++-export([start_link/2]).
++-export([start/2, stop/1, mod_opt_type/1, depends/2]).
++%% gen_server callbacks
++-export([init/1, handle_call/3, handle_cast/2, handle_info/2,
++       terminate/2, code_change/3]).
++-export([component_connected/1, component_disconnected/2,
++       ejabberd_local/1, ejabberd_sm/1,
++       disco_local_features/5, disco_sm_features/5,
++       disco_local_identity/5, disco_sm_identity/5]).
++
++-include("ejabberd.hrl").
++-include("logger.hrl").
++-include("xmpp.hrl").
++
++-type disco_acc() :: {error, stanza_error()} | {result, [binary()]} | empty.
++-record(state, {server_host = <<"">> :: binary(),
++              delegations = dict:new() :: ?TDICT}).
++
++%%%===================================================================
++%%% API
++%%%===================================================================
++start_link(Host, Opts) ->
++    Proc = gen_mod:get_module_proc(Host, ?MODULE),
++    gen_server:start_link({local, Proc}, ?MODULE, [Host, Opts], []).
++
++start(Host, Opts) ->
++    Proc = gen_mod:get_module_proc(Host, ?MODULE),
++    PingSpec = {Proc, {?MODULE, start_link, [Host, Opts]},
++                transient, 2000, worker, [?MODULE]},
++    supervisor:start_child(ejabberd_sup, PingSpec).
++stop(Host) ->
++    Proc = gen_mod:get_module_proc(Host, ?MODULE),
++    gen_server:call(Proc, stop),
++    supervisor:delete_child(ejabberd_sup, Proc).
++
++mod_opt_type(iqdisc) -> fun gen_iq_handler:check_type/1;
++mod_opt_type(namespaces) -> validate_fun();
++mod_opt_type(_) ->
++    [namespaces, iqdisc].
++
++depends(_, _) ->
++    [].
++
++-spec component_connected(binary()) -> ok.
++component_connected(Host) ->
++    lists:foreach(
++      fun(ServerHost) ->
++            Proc = gen_mod:get_module_proc(ServerHost, ?MODULE),
++            gen_server:cast(Proc, {component_connected, Host})
++      end, ?MYHOSTS).
++
++-spec component_disconnected(binary(), binary()) -> ok.
++component_disconnected(Host, _Reason) ->
++    lists:foreach(
++      fun(ServerHost) ->
++            Proc = gen_mod:get_module_proc(ServerHost, ?MODULE),
++            gen_server:cast(Proc, {component_disconnected, Host})
++      end, ?MYHOSTS).
++
++-spec ejabberd_local(iq()) -> iq().
++ejabberd_local(IQ) ->
++    process_iq(IQ, ejabberd_local).
++
++-spec ejabberd_sm(iq()) -> iq().
++ejabberd_sm(IQ) ->
++    process_iq(IQ, ejabberd_sm).
++
++-spec disco_local_features(disco_acc(), jid(), jid(), binary(), binary()) -> disco_acc().
++disco_local_features(Acc, From, To, Node, Lang) ->
++    disco_features(Acc, From, To, Node, Lang, ejabberd_local).
++
++-spec disco_sm_features(disco_acc(), jid(), jid(), binary(), binary()) -> disco_acc().
++disco_sm_features(Acc, From, To, Node, Lang) ->
++    disco_features(Acc, From, To, Node, Lang, ejabberd_sm).
++
++-spec disco_local_identity(disco_acc(), jid(), jid(), binary(), binary()) -> disco_acc().
++disco_local_identity(Acc, From, To, Node, Lang) ->
++    disco_identity(Acc, From, To, Node, Lang, ejabberd_local).
++
++-spec disco_sm_identity(disco_acc(), jid(), jid(), binary(), binary()) -> disco_acc().
++disco_sm_identity(Acc, From, To, Node, Lang) ->
++    disco_identity(Acc, From, To, Node, Lang, ejabberd_sm).
++
++%%%===================================================================
++%%% gen_server callbacks
++%%%===================================================================
++init([Host, _Opts]) ->
++    ejabberd_hooks:add(component_connected, ?MODULE,
++                     component_connected, 50),
++    ejabberd_hooks:add(component_disconnected, ?MODULE,
++                     component_disconnected, 50),
+     ejabberd_hooks:add(disco_local_features, Host, ?MODULE,
 -                       disco_local_features, 500), %% This hook should be the last
++                     disco_local_features, 50),
++    ejabberd_hooks:add(disco_sm_features, Host, ?MODULE,
++                     disco_sm_features, 50),
+     ejabberd_hooks:add(disco_local_identity, Host, ?MODULE,
 -                       disco_local_identity, 500),
++                     disco_local_identity, 50),
+     ejabberd_hooks:add(disco_sm_identity, Host, ?MODULE,
 -                       disco_sm_identity, 500),
 -    ejabberd_hooks:add(disco_sm_features, Host, ?MODULE, 
 -                       disco_sm_features, 500),
 -    ejabberd_hooks:add(disco_info, Host, ?MODULE,
 -                       disco_info, 500).
 -
 -
 -stop(Host) ->
 -    mod_disco:unregister_feature(Host, ?NS_DELEGATION),
 -    ejabberd_hooks:delete(disco_local_features, Host, ?MODULE,
 -                          disco_local_features, 500), 
 -    ejabberd_hooks:delete(disco_local_identity, Host, ?MODULE,
 -                          disco_local_identity, 500),
 -    ejabberd_hooks:delete(disco_sm_identity, Host, ?MODULE,
 -                          disco_sm_identity, 500),
 -    ejabberd_hooks:delete(disco_sm_features, Host, ?MODULE, 
 -                          disco_sm_features, 500),
 -    ejabberd_hooks:delete(disco_info, Host, ?MODULE,
 -                          disco_info, 500).
 -
 -depends(_Host, _Opts) -> [].
 -
 -mod_opt_type(_Opt) -> [].
 -
 -%%%--------------------------------------------------------------------------------------
 -%%% 4.2 Functions to advertise service of delegated namespaces
 -%%%--------------------------------------------------------------------------------------
 -attribute_tag(Attrs) ->
 -    lists:map(fun(Attr) ->
 -                #xmlel{name = <<"attribute">>, attrs = [{<<"name">> , Attr}]}
 -              end, Attrs).
 -
 -delegations(From, To, Delegations) ->
 -    {Elem0, DelegatedNs} = 
 -      lists:foldl(fun({Ns, FiltAttr}, {Acc, AccNs}) ->
 -                    case ets:insert_new(delegated_namespaces, 
 -                                        {Ns, FiltAttr, self(), To, {}, {}}) of
 -                      true ->
 -                        Attrs = 
 -                          if
 -                            FiltAttr == [] ->
 -                              ?DEBUG("namespace ~s is delegated to ~s with"
 -                                     " no filtering attributes ~n",[Ns, To]),
 -                              [];
 -                            true ->
 -                              ?DEBUG("namespace ~s is delegated to ~s with"
 -                                     " ~p filtering attributes ~n",[Ns, To, FiltAttr]),
 -                              attribute_tag(FiltAttr)
 -                          end,
 -                        add_iq_handlers(Ns),
 -                        {[#xmlel{name = <<"delegated">>, 
 -                                 attrs = [{<<"namespace">>, Ns}],
 -                                 children = Attrs}| Acc], [{Ns, FiltAttr}|AccNs]};
 -                      false -> {Acc, AccNs}
 -                    end
 -                  end, {[], []}, Delegations),
 -    case Elem0 of
 -      [] -> {ignore, DelegatedNs};
 -      _ -> 
 -        Elem1 = #xmlel{name = <<"delegation">>, 
 -                       attrs = [{<<"xmlns">>, ?NS_DELEGATION}],
 -                       children = Elem0},
 -        Id = randoms:get_string(),
 -        {#xmlel{name = <<"message">>, 
 -                attrs = [{<<"id">>, Id}, {<<"from">>, From}, {<<"to">>, To}],
 -                children = [Elem1]}, DelegatedNs}
 -    end.
 -
 -add_iq_handlers(Ns) ->
 -    lists:foreach(fun(Host) ->
 -                    IQDisc = 
 -                      gen_mod:get_module_opt(Host, ?MODULE, iqdisc,
 -                                             fun gen_iq_handler:check_type/1, one_queue),
 -                    gen_iq_handler:add_iq_handler(ejabberd_sm, Host,
 -                                                  Ns, ?MODULE, 
 -                                                  process_iq, IQDisc),
 -                    gen_iq_handler:add_iq_handler(ejabberd_local, Host,
 -                                                  Ns, ?MODULE,
 -                                                  process_iq, IQDisc)
 -                  end, ?MYHOSTS).
 -
 -advertise_delegations(#state{delegations = []}) -> [];
 -advertise_delegations(StateData) ->
 -    {Delegated, DelegatedNs} = 
 -      delegations(?MYNAME, StateData#state.host, StateData#state.delegations),
 -    if 
 -      Delegated /= ignore ->
 -        ejabberd_service:send_element(StateData, Delegated),
 -        % server asks available features for delegated namespaces 
 -        disco_info(StateData#state{delegations = DelegatedNs});
 -      true -> ok
 -    end,
 -    DelegatedNs.
 -
 -%%%--------------------------------------------------------------------------------------
 -%%%  Delegated namespaces hook
 -%%%--------------------------------------------------------------------------------------
 -
 -check_filter_attr([], _Children) -> true;
 -check_filter_attr(_FilterAttr, []) -> false;
 -check_filter_attr(FilterAttr, [#xmlel{} = Stanza|_]) ->
 -    Attrs = proplists:get_keys(Stanza#xmlel.attrs),
 -    lists:all(fun(Attr) ->
 -                  lists:member(Attr, Attrs)
 -              end, FilterAttr);
 -check_filter_attr(_FilterAttr, _Children) -> false.
 -
 --spec get_client_server([attr()]) -> {jid(), jid()}. 
 -
 -get_client_server(Attrs) ->
 -    Client = fxml:get_attr_s(<<"from">>, Attrs),
 -    ClientJID = jid:from_string(Client),
 -    ServerJID = jid:from_string(ClientJID#jid.lserver),
 -    {ClientJID, ServerJID}.
 -
 -decapsulate_result(#xmlel{children = []}) -> ok;
 -decapsulate_result(#xmlel{children = Children}) ->
 -    decapsulate_result0(Children).
 -
 -decapsulate_result0([]) -> ok;
 -decapsulate_result0([#xmlel{name = <<"delegation">>, 
 -                            attrs = [{<<"xmlns">>, ?NS_DELEGATION}]} = Packet]) ->
 -    decapsulate_result1(Packet#xmlel.children);
 -decapsulate_result0(_Children) -> ok.
 -
 -decapsulate_result1([]) -> ok;
 -decapsulate_result1([#xmlel{name = <<"forwarded">>,
 -                            attrs = [{<<"xmlns">>, ?NS_FORWARD}]} = Packet]) ->
 -    decapsulate_result2(Packet#xmlel.children);
 -decapsulate_result1(_Children) -> ok.
 -
 -decapsulate_result2([]) -> ok;
 -decapsulate_result2([#xmlel{name = <<"iq">>, attrs = Attrs} = Packet]) ->
 -    Ns = fxml:get_attr_s(<<"xmlns">>, Attrs),
 -    if
 -      Ns /= <<"jabber:client">> ->
 -        ok;
 -      true -> Packet
 -    end;
 -decapsulate_result2(_Children) -> ok.
 -
 --spec check_iq(xmlel(), xmlel()) -> xmlel() | ignore.
 -
 -check_iq(#xmlel{attrs = Attrs} = Packet,
 -         #xmlel{attrs = AttrsOrigin} = OriginPacket) ->
 -    % Id attribute of OriginPacket Must be equil to Packet Id attribute
 -    Id1 = fxml:get_attr_s(<<"id">>, Attrs),
 -    Id2 = fxml:get_attr_s(<<"id">>, AttrsOrigin),
 -    % From attribute of OriginPacket Must be equil to Packet To attribute
 -    From = fxml:get_attr_s(<<"from">>, AttrsOrigin),
 -    To = fxml:get_attr_s(<<"to">>, Attrs),
 -    % Type attribute Must be error or result
 -    Type = fxml:get_attr_s(<<"type">>, Attrs),
 -    if
 -      ((Type == <<"result">>) or (Type == <<"error">>)),
 -      Id1 == Id2, To == From ->
 -        NewPacket = jlib:remove_attr(<<"xmlns">>, Packet),
 -        %% We can send the decapsulated stanza from Server to Client (To)
 -        NewPacket;
 -      true ->
 -        %% service-unavailable
 -        Err = jlib:make_error_reply(OriginPacket, ?ERR_SERVICE_UNAVAILABLE),
 -        Err
++                     disco_sm_identity, 50),
++    {ok, #state{server_host = Host}}.
++
++handle_call(get_delegations, _From, State) ->
++    {reply, {ok, State#state.delegations}, State};
++handle_call(_Request, _From, State) ->
++    Reply = ok,
++    {reply, Reply, State}.
++
++handle_cast({component_connected, Host}, State) ->
++    ServerHost = State#state.server_host,
++    To = jid:make(Host),
++    NSAttrsAccessList = gen_mod:get_module_opt(
++                        ServerHost, ?MODULE, namespaces,
++                        validate_fun(), []),
++    lists:foreach(
++      fun({NS, _Attrs, Access}) ->
++            case acl:match_rule(ServerHost, Access, To) of
++                allow ->
++                    send_disco_queries(ServerHost, Host, NS);
++                deny ->
++                    ok
++            end
++      end, NSAttrsAccessList),
++    {noreply, State};
++handle_cast({disco_info, Type, Host, NS, Info}, State) ->
++    From = jid:make(State#state.server_host),
++    To = jid:make(Host),
++    case dict:find({NS, Type}, State#state.delegations) of
++      error ->
++          Msg = #message{from = From, to = To,
++                         sub_els = [#delegation{delegated = [#delegated{ns = NS}]}]},
++          Delegations = dict:store({NS, Type}, {Host, Info}, State#state.delegations),
++          gen_iq_handler:add_iq_handler(Type, State#state.server_host, NS,
++                                        ?MODULE, Type, one_queue),
++          ejabberd_router:route(From, To, Msg),
++          ?INFO_MSG("Namespace '~s' is delegated to external component '~s'",
++                    [NS, Host]),
++          {noreply, State#state{delegations = Delegations}};
++      {ok, {AnotherHost, _}} ->
++          ?WARNING_MSG("Failed to delegate namespace '~s' to "
++                       "external component '~s' because it's already "
++                       "delegated to '~s'",
++                       [NS, Host, AnotherHost]),
++          {noreply, State}
+     end;
 -check_iq(_Packet, _OriginPacket) -> ignore.
 -
 --spec manage_service_result(atom(), atom(), binary(), xmlel()) -> ok.
 -
 -manage_service_result(HookRes, HookErr, Service, OriginPacket) ->
 -    fun(Packet) ->
 -        {ClientJID, ServerJID} = get_client_server(OriginPacket#xmlel.attrs),
 -        Server = ClientJID#jid.lserver,
 -
 -        ets:delete(hooks_tmp, {HookRes, Server}),
 -        ets:delete(hooks_tmp, {HookErr, Server}),
 -        % Check Packet "from" attribute
 -        % It Must be equil to current service host
 -        From = fxml:get_attr_s(<<"from">> , Packet#xmlel.attrs),
 -        if
 -          From == Service  ->
 -              % decapsulate iq result
 -              ResultIQ = decapsulate_result(Packet),
 -              ServResponse = check_iq(ResultIQ, OriginPacket),
 -              if
 -                ServResponse /= ignore ->
 -                  ejabberd_router:route(ServerJID, ClientJID, ServResponse);
 -                true -> ok
 -              end;
 -          true ->
 -              % service unavailable
 -              Err = jlib:make_error_reply(OriginPacket, ?ERR_SERVICE_UNAVAILABLE),
 -              ejabberd_router:route(ServerJID, ClientJID, Err) 
 -        end       
++handle_cast({component_disconnected, Host}, State) ->
++    ServerHost = State#state.server_host,
++    Delegations =
++      dict:filter(
++        fun({NS, Type}, {H, _}) when H == Host ->
++                ?INFO_MSG("Remove delegation of namespace '~s' "
++                          "from external component '~s'",
++                          [NS, Host]),
++                gen_iq_handler:remove_iq_handler(Type, ServerHost, NS),
++                false;
++           (_, _) ->
++                true
++        end, State#state.delegations),
++    {noreply, State#state{delegations = Delegations}};
++handle_cast(_Msg, State) ->
++    {noreply, State}.
++
++handle_info(_Info, State) ->
++    {noreply, State}.
++
++terminate(_Reason, State) ->
++    %% Note: we don't remove component_* hooks because they are global
++    %% and might be registered within a module on another virtual host
++    ServerHost = State#state.server_host,
++    ejabberd_hooks:delete(disco_local_features, ServerHost, ?MODULE,
++                        disco_local_features, 50),
++    ejabberd_hooks:delete(disco_sm_features, ServerHost, ?MODULE,
++                        disco_sm_features, 50),
++    ejabberd_hooks:delete(disco_local_identity, ServerHost, ?MODULE,
++                        disco_local_identity, 50),
++    ejabberd_hooks:delete(disco_sm_identity, ServerHost, ?MODULE,
++                        disco_sm_identity, 50),
++    lists:foreach(
++      fun({NS, Type}) ->
++            gen_iq_handler:remove_iq_handler(Type, ServerHost, NS)
++      end, dict:fetch_keys(State#state.delegations)).
++
++code_change(_OldVsn, State, _Extra) ->
++    {ok, State}.
++
++%%%===================================================================
++%%% Internal functions
++%%%===================================================================
++-spec get_delegations(binary()) -> ?TDICT.
++get_delegations(Host) ->
++    Proc = gen_mod:get_module_proc(Host, ?MODULE),
++    try gen_server:call(Proc, get_delegations) of
++      {ok, Delegations} -> Delegations
++    catch exit:{noproc, _} ->
++          %% No module is loaded for this virtual host
++          dict:new()
+     end.
 --spec manage_service_error(atom(), atom(), xmlel()) -> ok.
 -
 -manage_service_error(HookRes, HookErr, OriginPacket) ->
 -    fun(_Packet) ->
 -        {ClientJID, ServerJID} = get_client_server(OriginPacket#xmlel.attrs),
 -        Server = ClientJID#jid.lserver,
 -        ets:delete(hooks_tmp, {HookRes, Server}),
 -        ets:delete(hooks_tmp, {HookErr, Server}),
 -        Err = jlib:make_error_reply(OriginPacket, ?ERR_SERVICE_UNAVAILABLE),
 -        ejabberd_router:route(ServerJID, ClientJID, Err)        
++-spec process_iq(iq(), ejabberd_local | ejabberd_sm) -> ignore | iq().
++process_iq(#iq{to = To, lang = Lang, sub_els = [SubEl]} = IQ, Type) ->
++    LServer = To#jid.lserver,
++    NS = xmpp:get_ns(SubEl),
++    Delegations = get_delegations(LServer),
++    case dict:find({NS, Type}, Delegations) of
++      {ok, {Host, _}} ->
++          Delegation = #delegation{forwarded = #forwarded{sub_els = [IQ]}},
++          NewFrom = jid:make(LServer),
++          NewTo = jid:make(Host),
++          ejabberd_local:route_iq(
++            NewFrom, NewTo,
++            #iq{type = set,
++                from = NewFrom,
++                to = NewTo,
++                sub_els = [Delegation]},
++            fun(Result) -> process_iq_result(IQ, Result) end),
++          ignore;
++      error ->
++          Txt = <<"Failed to map delegated namespace to external component">>,
++          xmpp:make_error(IQ, xmpp:err_internal_server_error(Txt, Lang))
+     end.
 -
 --spec forward_iq(binary(), binary(), xmlel()) -> ok.
 -
 -forward_iq(Server, Service, Packet) ->
 -    Elem0 = #xmlel{name = <<"forwarded">>,
 -                   attrs = [{<<"xmlns">>, ?NS_FORWARD}], children = [Packet]},
 -    Elem1 = #xmlel{name = <<"delegation">>, 
 -                   attrs = [{<<"xmlns">>, ?NS_DELEGATION}], children = [Elem0]},
 -    Id = randoms:get_string(),
 -    Elem2 = #xmlel{name = <<"iq">>,
 -                   attrs = [{<<"from">>, Server}, {<<"to">>, Service},
 -                            {<<"type">>, <<"set">>}, {<<"id">>, Id}],
 -                   children = [Elem1]},
 -
 -    HookRes = {iq, result, Id},
 -    HookErr = {iq, error, Id},
 -
 -    FunRes = manage_service_result(HookRes, HookErr, Service, Packet),
 -    FunErr = manage_service_error(HookRes, HookErr, Packet),
 -    
 -    Timestamp = p1_time_compat:system_time(seconds),
 -    ets:insert(hooks_tmp, {{HookRes, Server}, FunRes, Timestamp}),
 -    ets:insert(hooks_tmp, {{HookErr, Server}, FunErr, Timestamp}),
 -
 -    From = jid:make(<<"">>, Server, <<"">>),
 -    To = jid:make(<<"">>, Service, <<"">>),
 -    ejabberd_router:route(From, To, Elem2).
 -
 -process_iq(From, #jid{lresource = <<"">>} = To, 
 -               #iq{type = Type, xmlns = XMLNS} = IQ) ->
 -    %% check if stanza directed to server
 -    %% or directed to the bare JID of the sender
 -    case ((Type == get) or (Type == set)) of
 -        true ->
 -            Packet = jlib:iq_to_xml(IQ),
 -            #xmlel{name = <<"iq">>, attrs = Attrs, children = Children} = Packet,
 -            AttrsNew = [{<<"xmlns">>, <<"jabber:client">>} | Attrs],
 -            AttrsNew2 = jlib:replace_from_to_attrs(jid:to_string(From),
 -                                                   jid:to_string(To), AttrsNew),
 -            case ets:lookup(delegated_namespaces, XMLNS) of
 -              [{XMLNS, FiltAttr, _Pid, ServiceHost, _, _}] ->
 -                case check_filter_attr(FiltAttr, Children) of
 -                    true ->
 -                        forward_iq(From#jid.server, ServiceHost,
 -                                   Packet#xmlel{attrs = AttrsNew2});
 -                    _ -> ok
 -                end;
 -              [] -> ok
 -            end, 
 -            ignore;
 -        _ -> 
 -            ignore
++-spec process_iq_result(iq(), iq()) -> ok.
++process_iq_result(#iq{from = From, to = To, id = ID, lang = Lang} = IQ,
++                #iq{type = result} = ResIQ) ->
++    case xmpp:get_subtag(ResIQ, #delegation{}) of
++      #delegation{
++         forwarded = #forwarded{
++                        sub_els = [#iq{from = To, to = From,
++                                       type = Type, id = ID} = Reply]}}
++        when Type == error; Type == result ->
++          ejabberd_router:route(From, To, Reply);
++      _ ->
++          ?ERROR_MSG("got iq-result with invalid delegated "
++                     "payload:~n~s", [xmpp:pp(ResIQ)]),
++          Txt = <<"External component failure">>,
++          Err = xmpp:err_internal_server_error(Txt, Lang),
++          ejabberd_router:route_error(To, From, IQ, Err)
+     end;
 -process_iq(_From, _To, _IQ) -> ignore.
 -
 -%%%--------------------------------------------------------------------------------------
 -%%%  7. Discovering Support
 -%%%--------------------------------------------------------------------------------------
 -
 -decapsulate_features(#xmlel{attrs = Attrs} = Packet, Node) ->
 -  case fxml:get_attr_s(<<"node">>, Attrs) of 
 -      Node ->
 -          PREFIX = << ?NS_DELEGATION/binary, "::" >>,
 -          Size = byte_size(PREFIX),
 -          BARE_PREFIX = << ?NS_DELEGATION/binary, ":bare:" >>,
 -          SizeBare = byte_size(BARE_PREFIX),
 -
 -          Features = [Feat || #xmlel{attrs = [{<<"var">>, Feat}]} <-
 -                              fxml:get_subtags(Packet, <<"feature">>)],
 -                       
 -          Identity = [I || I <- fxml:get_subtags(Packet, <<"identity">>)],
 -
 -          Exten = [I || I <- fxml:get_subtags_with_xmlns(Packet, <<"x">>, ?NS_XDATA)],
 -
 -          case Node of
 -            << PREFIX:Size/binary, NS/binary >> ->
 -              ets:update_element(delegated_namespaces, NS,
 -                                 {5, {Features, Identity, Exten}});
 -            << BARE_PREFIX:SizeBare/binary, NS/binary >> ->
 -              ets:update_element(delegated_namespaces, NS,
 -                                 {6, {Features, Identity, Exten}});
 -               _ -> ok
 -          end;
 -      _ -> ok 
 -  end;
 -decapsulate_features(_Packet, _Node) -> ok.
 -    
 --spec disco_result(atom(), atom(), binary()) -> ok.
 -
 -disco_result(HookRes, HookErr, Node) ->
 -    fun(Packet) ->
 -        Tag = fxml:get_subtag_with_xmlns(Packet, <<"query">>, ?NS_DISCO_INFO),
 -        decapsulate_features(Tag, Node),
 -        
 -        ets:delete(hooks_tmp, {HookRes, ?MYNAME}),
 -        ets:delete(hooks_tmp, {HookErr, ?MYNAME})
 -    end.
 -
 --spec disco_error(atom(), atom()) -> ok.
++process_iq_result(#iq{from = From, to = To}, #iq{type = error} = ResIQ) ->
++    Err = xmpp:set_from_to(ResIQ, To, From),
++    ejabberd_router:route(To, From, Err);
++process_iq_result(#iq{from = From, to = To, lang = Lang} = IQ, timeout) ->
++    Txt = <<"External component timeout">>,
++    Err = xmpp:err_internal_server_error(Txt, Lang),
++    ejabberd_router:route_error(To, From, IQ, Err).
++
++-spec send_disco_queries(binary(), binary(), binary()) -> ok.
++send_disco_queries(LServer, Host, NS) ->
++    From = jid:make(LServer),
++    To = jid:make(Host),
++    lists:foreach(
++      fun({Type, Node}) ->
++            ejabberd_local:route_iq(
++              From, To, #iq{type = get, from = From, to = To,
++                            sub_els = [#disco_info{node = Node}]},
++              fun(#iq{type = result, sub_els = [#disco_info{} = Info]}) ->
++                      Proc = gen_mod:get_module_proc(LServer, ?MODULE),
++                      gen_server:cast(Proc, {disco_info, Type, Host, NS, Info});
++                 (_) ->
++                      ok
++              end)
++      end, [{ejabberd_local, <<(?NS_DELEGATION)/binary, "::", NS/binary>>},
++          {ejabberd_sm, <<(?NS_DELEGATION)/binary, ":bare:", NS/binary>>}]).
++
++-spec disco_features(disco_acc(), jid(), jid(), binary(), binary(),
++                   ejabberd_local | ejabberd_sm) -> disco_acc().
++disco_features(Acc, _From, To, <<"">>, _Lang, Type) ->
++    Delegations = get_delegations(To#jid.lserver),
++    Features = my_features(Type) ++
++      lists:flatmap(
++        fun({{_, T}, {_, Info}}) when T == Type ->
++                Info#disco_info.features;
++           (_) ->
++                []
++        end, dict:to_list(Delegations)),
++    case Acc of
++      empty when Features /= [] -> {result, Features};
++      {result, Fs} -> {result, Fs ++ Features};
++      _ -> Acc
++    end;
++disco_features(Acc, _, _, _, _, _) ->
++    Acc.
 -disco_error(HookRes, HookErr) ->
 -    fun(_Packet) ->
 -        ets:delete(hooks_tmp, {HookRes, ?MYNAME}),
 -        ets:delete(hooks_tmp, {HookErr, ?MYNAME})
++-spec disco_identity(disco_acc(), jid(), jid(), binary(), binary(),
++                   ejabberd_local | ejabberd_sm) -> disco_acc().
++disco_identity(Acc, _From, To, <<"">>, _Lang, Type) ->
++    Delegations = get_delegations(To#jid.lserver),
++    Identities = lists:flatmap(
++                 fun({{_, T}, {_, Info}}) when T == Type ->
++                         Info#disco_info.identities;
++                    (_) ->
++                         []
++                 end, dict:to_list(Delegations)),
++    case Acc of
++      empty when Identities /= [] -> {result, Identities};
++      {result, Ids} -> {result, Ids ++ Identities};
++      Acc -> Acc
+     end.
 --spec disco_info(state()) -> ok.
 -
 -disco_info(StateData) -> 
 -    disco_info(StateData, <<"::">>),
 -    disco_info(StateData, <<":bare:">>).
 -
 --spec disco_info(state(), binary()) -> ok.
 -
 -disco_info(StateData, Sep) ->
 -    lists:foreach(fun({Ns, _FilterAttr}) ->
 -                    Id = randoms:get_string(),
 -                    Node = << ?NS_DELEGATION/binary, Sep/binary, Ns/binary >>,
 -
 -                    HookRes = {iq, result, Id},
 -                    HookErr = {iq, error, Id},
 -
 -                    FunRes = disco_result(HookRes, HookErr, Node),
 -                    FunErr = disco_error(HookRes, HookErr),
 -
 -                    Timestamp = p1_time_compat:system_time(seconds),
 -                    ets:insert(hooks_tmp, {{HookRes, ?MYNAME}, FunRes, Timestamp}),
 -                    ets:insert(hooks_tmp, {{HookErr, ?MYNAME}, FunErr, Timestamp}),
 -
 -                    Tag = #xmlel{name = <<"query">>,
 -                                 attrs = [{<<"xmlns">>, ?NS_DISCO_INFO}, 
 -                                          {<<"node">>, Node}],
 -                                 children = []},
 -                    DiscoReq = #xmlel{name = <<"iq">>,
 -                                      attrs = [{<<"type">>, <<"get">>}, {<<"id">>, Id},
 -                                               {<<"from">>, ?MYNAME},
 -                                               {<<"to">>, StateData#state.host }],
 -                                      children = [Tag]},
 -                    ejabberd_service:send_element(StateData, DiscoReq)
 -
 -                  end, StateData#state.delegations).
 -
 -
 -disco_features(Acc, Bare) ->
 -    Fun = fun(Feat) ->
 -            ets:foldl(fun({Ns, _, _, _, _, _}, A) ->  
 -                          A or str:prefix(Ns, Feat)
 -                      end, false, delegated_namespaces)
 -          end,
 -    % delete feature namespace which is delegated to service
 -    Features = lists:filter(fun ({{Feature, _Host}}) ->
 -                                  not Fun(Feature);
 -                                (Feature) when is_binary(Feature) ->
 -                                  not Fun(Feature)
 -                            end, Acc),
 -    % add service features
 -    FeaturesList =
 -      ets:foldl(fun({_, _, _, _, {Feats, _, _}, {FeatsBare, _, _}}, A) ->
 -                      if
 -                        Bare -> A ++ FeatsBare;
 -                        true -> A ++ Feats
 -                      end;
 -                   (_, A) -> A
 -                end, Features, delegated_namespaces),
 -    {result, FeaturesList}.
 -
 -disco_identity(Acc, Bare) ->
 -    % filter delegated identites
 -    Fun = fun(Ident) ->
 -            ets:foldl(fun({_, _, _, _, {_ , I, _}, {_ , IBare, _}}, A) ->
 -                            Identity = 
 -                              if
 -                                Bare -> IBare;
 -                                true -> I
 -                              end,
 -                            (fxml:get_attr_s(<<"category">> , Ident) ==
 -                             fxml:get_attr_s(<<"category">>, Identity)) and
 -                            (fxml:get_attr_s(<<"type">> , Ident) ==
 -                              fxml:get_attr_s(<<"type">>, Identity)) or A;
 -                            (_, A) -> A
 -                      end, false, delegated_namespaces)
 -          end,
 -
 -    Identities =
 -      lists:filter(fun (#xmlel{attrs = Attrs}) ->
 -                      not Fun(Attrs)
 -                   end, Acc),
 -    % add service features
 -    ets:foldl(fun({_, _, _, _, {_, I, _}, {_, IBare, _}}, A) ->
 -                    if
 -                      Bare -> A ++ IBare;
 -                      true -> A ++ I
 -                    end;
 -                  (_, A) -> A
 -              end, Identities, delegated_namespaces).
 -
 -%% xmlns from value element
 -
 --spec get_field_value([xmlel()]) -> binary().
 -
 -get_field_value([]) -> <<"">>;
 -get_field_value([Elem| Elems]) ->
 -    case (fxml:get_attr_s(<<"var">>, Elem#xmlel.attrs) == <<"FORM_TYPE">>) and
 -         (fxml:get_attr_s(<<"type">>, Elem#xmlel.attrs) == <<"hidden">>) of
 -      true ->
 -        Ns = fxml:get_subtag_cdata(Elem, <<"value">>),
 -        if
 -          Ns /= <<"">> -> Ns;
 -          true -> get_field_value(Elems)
 -        end;
 -      _ -> get_field_value(Elems)
++my_features(ejabberd_local) -> [?NS_DELEGATION];
++my_features(ejabberd_sm) -> [].
++
++validate_fun() ->
++    fun(L) ->
++          lists:map(
++            fun({NS, Opts}) ->
++                    Attrs = proplists:get_value(filtering, Opts, []),
++                    Access = proplists:get_value(access, Opts, none),
++                    {NS, Attrs, Access}
++            end, L)
+     end.
 -
 -get_info(Acc, Bare) ->
 -    Fun = fun(Feat) ->
 -            ets:foldl(fun({Ns, _, _, _, _, _}, A) ->  
 -                        (A or str:prefix(Ns, Feat))
 -                      end, false, delegated_namespaces)
 -          end,
 -    Exten = lists:filter(fun(Xmlel) ->
 -                           Tags = fxml:get_subtags(Xmlel, <<"field">>),
 -                           case get_field_value(Tags) of
 -                             <<"">> -> true;
 -                             Value -> not Fun(Value)
 -                           end
 -                         end, Acc),
 -    ets:foldl(fun({_, _, _, _, {_, _, Ext}, {_, _, ExtBare}}, A) ->
 -                    if
 -                      Bare -> A ++ ExtBare;
 -                      true -> A ++ Ext
 -                      end;
 -                 (_, A) -> A
 -              end, Exten, delegated_namespaces).
 -    
 -%% 7.2.1 General Case
 -
 -disco_local_features({error, _Error} = Acc, _From, _To, _Node, _Lang) ->
 -    Acc;
 -disco_local_features(Acc, _From, _To, <<>>, _Lang) ->
 -    FeatsOld = case Acc of
 -                 {result, I} -> I;
 -                 _ -> []
 -               end,
 -    disco_features(FeatsOld, false);
 -disco_local_features(Acc, _From, _To, _Node, _Lang) ->
 -    Acc.
 -
 -disco_local_identity(Acc, _From, _To, <<>>, _Lang) ->
 -    disco_identity(Acc, false);
 -disco_local_identity(Acc, _From, _To, _Node, _Lang) ->
 -    Acc.
 -
 -%% 7.2.2 Rediction Of Bare JID Disco Info
 -
 -disco_sm_features({error, ?ERR_ITEM_NOT_FOUND}, _From,
 -                  #jid{lresource = <<"">>}, <<>>, _Lang) ->
 -    disco_features([], true);
 -disco_sm_features({error, _Error} = Acc, _From, _To, _Node, _Lang) ->
 -    Acc;
 -disco_sm_features(Acc, _From, #jid{lresource = <<"">>}, <<>>, _Lang) ->
 -    FeatsOld = case Acc of
 -                 {result, I} -> I;
 -                 _ -> []
 -               end,
 -    disco_features(FeatsOld, true);
 -disco_sm_features(Acc, _From, _To, _Node, _Lang) ->
 -    Acc.
 -
 -disco_sm_identity(Acc, _From, #jid{lresource = <<"">>}, <<>>, _Lang) ->
 -    disco_identity(Acc, true);
 -disco_sm_identity(Acc, _From, _To, _Node, _Lang) ->
 -    Acc.
 -
 -disco_info(Acc, #jid{}, #jid{lresource = <<"">>}, <<>>, _Lang) ->
 -    get_info(Acc, true);
 -disco_info(Acc, _Host, _Mod, <<>>, _Lang) ->
 -    get_info(Acc, false);
 -disco_info(Acc, _Host, _Mod, _Node, _Lang) ->
 -    Acc.
 -
 -%% clean hooks_tmp table
 -
 -clean() ->
 -    ?DEBUG("cleaning ~p ETS table~n", [hooks_tmp]),
 -    Now = p1_time_compat:system_time(seconds),
 -    catch ets:select_delete(hooks_tmp, 
 -                            ets:fun2ms(fun({_, _, Timestamp}) -> 
 -                                         Now - 300 >= Timestamp
 -                                       end)),
 -    %% start timer for table cleaning 
 -    timer:apply_after(?CLEAN_INTERVAL, ?MODULE, clean, []).
Simple merge
index 1578be964569927e9315c2caec9bccdda0c1a85c,4913837694b93986327dd054c28609e8fef77650..881587edeb76e2b5f1b60a3ed7b9a83f6ea8d154
@@@ -130,79 -132,39 +132,39 @@@ depends(_Host, _Opts) -
  %% basic auth
  %% ----------
  
- check_permissions(Request, Command) ->
-     case catch binary_to_existing_atom(Command, utf8) of
-         Call when is_atom(Call) ->
-             {ok, CommandPolicy} = ejabberd_commands:get_command_policy(Call),
-             check_permissions2(Request, Call, CommandPolicy);
-         _ ->
-             unauthorized_response()
-     end.
- check_permissions2(#request{auth = HTTPAuth, headers = Headers}, Call, _)
-   when HTTPAuth /= undefined ->
-     Admin =
-         case lists:keysearch(<<"X-Admin">>, 1, Headers) of
-             {value, {_, <<"true">>}} -> true;
-             _ -> false
-         end,
-     Auth =
-         case HTTPAuth of
+ extract_auth(#request{auth = HTTPAuth, ip = {IP, _}}) ->
+     Info = case HTTPAuth of
 -             {SJID, Pass} ->
 -                 case jid:from_string(SJID) of
 +            {SJID, Pass} ->
 +                case jid:from_string(SJID) of
-                     #jid{user = User, server = Server} ->
+                      #jid{luser = User, lserver = Server} ->
 -                         case ejabberd_auth:check_password(User, <<"">>, Server, Pass) of
 +                        case ejabberd_auth:check_password(User, <<"">>, Server, Pass) of
-                             true -> {ok, {User, Server, Pass, Admin}};
-                             false -> false
+                              true ->
+                                  #{usr => {User, Server, <<"">>}, caller_server => Server};
+                              false ->
+                                  {error, invalid_auth}
 -                         end;
 -                     _ ->
 +                        end;
 +                    _ ->
-                         false
+                          {error, invalid_auth}
 -                 end;
 -             {oauth, Token, _} ->
 +                end;
 +            {oauth, Token, _} ->
-                 case oauth_check_token(Call, Token) of
-                     {ok, user, {User, Server}} ->
-                         {ok, {User, Server, {oauth, Token}, Admin}};
-                     {ok, server_admin} ->  %% token whas generated using issue_token command line
-                         {ok, admin};
-                     false ->
-                         false
+                  case ejabberd_oauth:check_token(Token) of
+                      {ok, {U, S}, Scope} ->
+                          #{usr => {U, S, <<"">>}, oauth_scope => Scope, caller_server => S};
+                      {false, Reason} ->
+                          {error, Reason}
 -                 end;
 -             _ ->
 +                end;
 +            _ ->
-                 false
+                  #{}
 -         end,
 +        end,
-     case Auth of
-         {ok, A} -> {allowed, Call, A};
-         _ -> unauthorized_response()
-     end;
- check_permissions2(_Request, Call, open) ->
-     {allowed, Call, noauth};
- check_permissions2(#request{ip={IP, _Port}}, Call, _Policy) ->
-     Access = gen_mod:get_module_opt(global, ?MODULE, admin_ip_access,
-                                     fun(V) -> V end,
-                                     none),
-     Res = acl:match_rule(global, Access, IP),
-     case Res of
-         all ->
-             {allowed, Call, admin};
-         [all] ->
-             {allowed, Call, admin};
-         allow ->
-             {allowed, Call, admin};
-         Commands when is_list(Commands) ->
-             case lists:member(Call, Commands) of
-                 true -> {allowed, Call, admin};
-                 _ -> unauthorized_response()
-             end;
-         _E ->
-             {allowed, Call, noauth}
+     case Info of
+       Map when is_map(Map) ->
+           Map#{caller_module => ?MODULE, ip => IP};
+       _ ->
+           ?DEBUG("Invalid auth data: ~p", [Info]),
+           Info
      end;
- check_permissions2(_Request, _Call, _Policy) ->
-     unauthorized_response().
- oauth_check_token(Scope, Token) when is_atom(Scope) ->
-     oauth_check_token(atom_to_binary(Scope, utf8), Token);
- oauth_check_token(Scope, Token) ->
-     ejabberd_oauth:check_token(Scope, Token).
+ extract_auth(#request{ip = IP}) ->
+     #{ip => IP, caller_module => ?MODULE}.
  
  %% ------------------
  %% command processing
  process(_, #request{method = 'POST', data = <<>>}) ->
      ?DEBUG("Bad Request: no data", []),
      badrequest_response(<<"Missing POST data">>);
- process([Call], #request{method = 'POST', data = Data, ip = {IP, _} = IPPort} = Req) ->
+ process([Call], #request{method = 'POST', data = Data, ip = IPPort} = Req) ->
      Version = get_api_version(Req),
      try
-         Args = case jiffy:decode(Data) of
-             List when is_list(List) -> List;
-             {List} when is_list(List) -> List;
-             Other -> [Other]
-         end,
+         Args = extract_args(Data),
          log(Call, Args, IPPort),
-         case check_permissions(Req, Call) of
-             {allowed, Cmd, Auth} ->
-                 {Code, Result} = handle(Cmd, Auth, Args, Version, IP),
-                 json_response(Code, jiffy:encode(Result));
-             %% Warning: check_permission direcly formats 401 reply if not authorized
-             ErrorResponse ->
-                 ErrorResponse
-         end
-     catch _:{error,{_,invalid_json}} = _Err ->
+       perform_call(Call, Args, Req, Version)
+     catch
+         %% TODO We need to refactor to remove redundant error return formatting
+         throw:{error, unknown_command} ->
+             json_format({404, 44, <<"Command not found.">>});
+         _:{error,{_,invalid_json}} = _Err ->
 -            ?DEBUG("Bad Request: ~p", [_Err]),
 -            badrequest_response(<<"Invalid JSON input">>);
 -          _:_Error ->
 +          ?DEBUG("Bad Request: ~p", [_Err]),
 +          badrequest_response(<<"Invalid JSON input">>);
 +        _:_Error ->
              ?DEBUG("Bad Request: ~p ~p", [_Error, erlang:get_stacktrace()]),
              badrequest_response()
      end;
@@@ -313,8 -295,10 +295,10 @@@ handle(Call, Auth, Args, Version) when 
                    {401, jlib:atom_to_binary(Why)};
                  throw:{not_allowed, Msg} ->
                    {401, iolist_to_binary(Msg)};
 -      throw:{error, account_unprivileged} ->
 +                  throw:{error, account_unprivileged} ->
-                     {401, iolist_to_binary(<<"Unauthorized: Account Unpriviledged">>)};
+         {403, 31, <<"Command need to be run with admin priviledge.">>};
+       throw:{error, access_rules_unauthorized} ->
+         {403, 32, <<"AccessRules: Account associated to token does not have the right to perform the operation.">>};
                  throw:{invalid_parameter, Msg} ->
                    {400, iolist_to_binary(Msg)};
                  throw:{error, Why} when is_atom(Why) ->
@@@ -423,34 -431,24 +431,24 @@@ match(Args, Spec) -
  format_command_result(Cmd, Auth, Result, Version) ->
      {_, ResultFormat} = ejabberd_commands:get_command_format(Cmd, Auth, Version),
      case {ResultFormat, Result} of
 -        {{_, rescode}, V} when V == true; V == ok ->
 -            {200, 0};
 -        {{_, rescode}, _} ->
 -            {200, 1};
 +      {{_, rescode}, V} when V == true; V == ok ->
 +          {200, 0};
 +      {{_, rescode}, _} ->
 +          {200, 1};
-       {{_, restuple}, {V1, Text1}} when V1 == true; V1 == ok ->
-           {200, iolist_to_binary(Text1)};
-       {{_, restuple}, {_, Text2}} ->
-           {500, iolist_to_binary(Text2)};
+         {_, {error, ErrorAtom, Code, Msg}} ->
+             format_error_result(ErrorAtom, Code, Msg);
+         {{_, restuple}, {V, Text}} when V == true; V == ok ->
+             {200, iolist_to_binary(Text)};
+         {{_, restuple}, {ErrorAtom, Msg}} ->
+             format_error_result(ErrorAtom, 0, Msg);
 -        {{_, {list, _}}, _V} ->
 -            {_, L} = format_result(Result, ResultFormat),
 -            {200, L};
 -        {{_, {tuple, _}}, _V} ->
 -            {_, T} = format_result(Result, ResultFormat),
 -            {200, T};
 -        _ ->
 -            {200, {[format_result(Result, ResultFormat)]}}
 +      {{_, {list, _}}, _V} ->
 +          {_, L} = format_result(Result, ResultFormat),
 +          {200, L};
 +      {{_, {tuple, _}}, _V} ->
 +          {_, T} = format_result(Result, ResultFormat),
 +          {200, T};
 +      _ ->
 +          {200, {[format_result(Result, ResultFormat)]}}
      end.
  
  format_result(Atom, {Name, atom}) ->
Simple merge
diff --cc src/mod_irc.erl
Simple merge
diff --cc src/mod_mam.erl
index 4c3050df1e6614e921a9dff7edc93e6cdcdd42f1,8f6492047bbcbcef4af3de7a74ef0bdf5ed6481b..3d5c8f64dd5b91dbb773f326c7b43d2ef316f0a3
@@@ -482,95 -498,120 +457,93 @@@ process_iq(LServer, #iq{from = #jid{lus
        {groupchat, _Role, _MUCState} ->
            ok
      end,
 -    case catch lists:foldl(
 -               fun({<<"start">>, [Data|_]}, {_, End, With, RSM}) ->
 -                       {{_, _, _} = jlib:datetime_string_to_timestamp(Data),
 -                        End, With, RSM};
 -                  ({<<"end">>, [Data|_]}, {Start, _, With, RSM}) ->
 -                       {Start,
 -                        {_, _, _} = jlib:datetime_string_to_timestamp(Data),
 -                        With, RSM};
 -                  ({<<"with">>, [Data|_]}, {Start, End, _, RSM}) ->
 -                       {Start, End, jid:tolower(jid:from_string(Data)), RSM};
 -                  ({<<"withtext">>, [Data|_]}, {Start, End, _, RSM}) ->
 -                       {Start, End, {text, Data}, RSM};
 -                  ({<<"set">>, El}, {Start, End, With, _}) ->
 -                       {Start, End, With, jlib:rsm_decode(El)};
 -                  (_, Acc) ->
 -                       Acc
 -               end, {none, [], none, none}, Fs) of
 -      {'EXIT', _} ->
 -          IQ#iq{type = error, sub_el = [SubEl, ?ERR_BAD_REQUEST]};
 -      {_Start, _End, _With, #rsm_in{index = Index}} when is_integer(Index) ->
 -          IQ#iq{type = error, sub_el = [SubEl, ?ERR_FEATURE_NOT_IMPLEMENTED]};
 -      {Start, End, With, RSM} ->
 -          NS = fxml:get_tag_attr_s(<<"xmlns">>, SubEl),
 -          select_and_send(LServer, From, To, Start, End,
 -                          With, limit_max(RSM, NS), IQ, MsgType)
 +    case parse_query(SubEl, Lang) of
 +      #mam_query{rsm = #rsm_set{index = I}} when is_integer(I) ->
 +          xmpp:make_error(IQ, xmpp:err_feature_not_implemented());
 +      #mam_query{rsm = RSM, xmlns = NS} = Query ->
 +          NewRSM = limit_max(RSM, NS),
 +          NewQuery = Query#mam_query{rsm = NewRSM},
 +          select_and_send(LServer, NewQuery, IQ, MsgType);
 +      {error, Err} ->
 +          xmpp:make_error(IQ, Err)
      end.
  
- should_archive(#message{type = T}, _LServer) when T == error; T == result ->
 -muc_process_iq(#iq{lang = Lang, sub_el = SubEl} = IQ, MUCState, From, To, Fs) ->
 -    case may_enter_room(From, MUCState) of
 -      true ->
 -          LServer = MUCState#state.server_host,
 -          Role = mod_muc_room:get_role(From, MUCState),
 -          process_iq(LServer, From, To, IQ, SubEl, Fs,
 -                     {groupchat, Role, MUCState});
 -      false ->
 -          Text = <<"Only members may query archives of this room">>,
 -          Error = ?ERRT_FORBIDDEN(Lang, Text),
 -          IQ#iq{type = error, sub_el = [SubEl, Error]}
 -    end.
 -
 -parse_query_v0_2(Query) ->
 -    lists:flatmap(
 -      fun (#xmlel{name = <<"start">>} = El) ->
 -            [{<<"start">>, [fxml:get_tag_cdata(El)]}];
 -        (#xmlel{name = <<"end">>} = El) ->
 -            [{<<"end">>, [fxml:get_tag_cdata(El)]}];
 -        (#xmlel{name = <<"with">>} = El) ->
 -            [{<<"with">>, [fxml:get_tag_cdata(El)]}];
 -        (#xmlel{name = <<"withtext">>} = El) ->
 -            [{<<"withtext">>, [fxml:get_tag_cdata(El)]}];
 -        (#xmlel{name = <<"set">>}) ->
 -            [{<<"set">>, Query}];
 -        (_) ->
 -           []
 -      end, Query#xmlel.children).
 -
 -should_archive(#xmlel{name = <<"message">>} = Pkt, LServer) ->
++should_archive(#message{type = error}, _LServer) ->
 +    false;
- should_archive(#message{body = Body} = Pkt, LServer) ->
++should_archive(#message{body = Body, subject = Subject,
++                      type = Type} = Pkt, LServer) ->
      case is_resent(Pkt, LServer) of
        true ->
            false;
        false ->
 -          case {check_store_hint(Pkt),
 -                fxml:get_attr_s(<<"type">>, Pkt#xmlel.attrs)} of
 -              {_Hint, <<"error">>} ->
 -                  false;
 -              {store, _Type} ->
 +          case check_store_hint(Pkt) of
 +              store ->
                    true;
 -              {no_store, _Type} ->
 -                  false;
 -              {none, <<"groupchat">>} ->
 +              no_store ->
                    false;
 -              {none, <<"headline">>} ->
++              none when Type == groupchat; Type == headline ->
+                   false;
 -              {none, _Type} ->
 -                  case fxml:get_subtag_cdata(Pkt, <<"body">>) of
 -                      <<>> ->
 -                          %% Empty body
 -                          false;
 -                      _ ->
 -                          true
 -                  end
 +              none ->
-                   case xmpp:get_text(Body) of
-                       <<>> ->
-                           %% Empty body
-                           false;
-                       _ ->
-                           true
-                   end
++                  xmpp:get_text(Body) /= <<>> orelse
++                      xmpp:get_text(Subject) /= <<>>
            end
      end;
 -should_archive(#xmlel{}, _LServer) ->
 +should_archive(_, _LServer) ->
      false.
  
 +-spec strip_my_archived_tag(stanza(), binary()) -> stanza().
  strip_my_archived_tag(Pkt, LServer) ->
 +    NewPkt = xmpp:decode_els(
 +             Pkt, ?NS_CLIENT,
 +             fun(El) ->
 +                     case xmpp:get_name(El) of
 +                         <<"archived">> ->
 +                             xmpp:get_ns(El) == ?NS_MAM_TMP;
 +                         <<"stanza-id">> ->
 +                             xmpp:get_ns(El) == ?NS_SID_0;
 +                         _ ->
 +                             false
 +                     end
 +             end),
      NewEls = lists:filter(
 -          fun(#xmlel{name = Tag, attrs = Attrs})
 -                      when Tag == <<"archived">>; Tag == <<"stanza-id">> ->
 -                  case catch jid:nameprep(
 -                          fxml:get_attr_s(
 -                              <<"by">>, Attrs)) of
 -                      LServer ->
 -                          false;
 -                      _ ->
 -                          true
 -                  end;
 -              (_) ->
 -                  true
 -          end, Pkt#xmlel.children),
 -    Pkt#xmlel{children = NewEls}.
 +             fun(#mam_archived{by = By}) ->
 +                     By#jid.lserver /= LServer;
 +                (#stanza_id{by = By}) ->
 +                     By#jid.lserver /= LServer;
 +                (_) ->
 +                     true
 +             end, xmpp:get_els(NewPkt)),
 +    xmpp:set_els(NewPkt, NewEls).
  
  strip_x_jid_tags(Pkt) ->
 +    NewPkt = xmpp:decode_els(
 +             Pkt, ?NS_CLIENT,
 +             fun(El) ->
 +                     case xmpp:get_name(El) of
 +                         <<"x">> ->
 +                             case xmpp:get_ns(El) of
 +                                 ?NS_MUC_USER -> true;
 +                                 ?NS_MUC_ADMIN -> true;
 +                                 ?NS_MUC_OWNER -> true;
 +                                 _ -> false
 +                             end;
 +                         _ ->
 +                             false
 +                     end
 +             end),
      NewEls = lists:filter(
 -            fun(#xmlel{name = <<"x">>} = XEl) ->
 -                    not lists:any(fun(ItemEl) ->
 -                                          fxml:get_tag_attr(<<"jid">>, ItemEl)
 -                                            /= false
 -                                  end, fxml:get_subtags(XEl, <<"item">>));
 -               (_) ->
 -                    true
 -            end, Pkt#xmlel.children),
 -    Pkt#xmlel{children = NewEls}.
 +             fun(El) ->
 +                     Items = case El of
 +                                 #muc_user{items = Is} -> Is;
 +                                 #muc_admin{items = Is} -> Is;
 +                                 #muc_owner{items = Is} -> Is;
 +                                 _ -> []
 +                             end,
 +                     not lists:any(fun(#muc_item{jid = JID}) ->
 +                                           JID /= undefined
 +                                   end, Items)
 +             end, xmpp:get_els(NewPkt)),
 +    xmpp:set_els(NewPkt, NewEls).
  
  should_archive_peer(C2SState,
                    #archive_prefs{default = Default,
@@@ -669,9 -718,14 +642,15 @@@ store_msg(C2SState, Pkt, LUser, LServer
      case should_archive_peer(C2SState, Prefs, Peer) of
        true ->
            US = {LUser, LServer},
-           Mod = gen_mod:db_mod(LServer, ?MODULE),
-           El = xmpp:encode(Pkt),
-           Mod:store(El, LServer, US, chat, Peer, <<"">>, Dir);
+           case ejabberd_hooks:run_fold(store_mam_message, LServer, Pkt,
+                                        [LUser, LServer, Peer, chat, Dir]) of
+               drop ->
+                   pass;
+               NewPkt ->
+                   Mod = gen_mod:db_mod(LServer, ?MODULE),
 -                  Mod:store(NewPkt, LServer, US, chat, Peer, <<"">>, Dir)
++                  El = xmpp:encode(NewPkt),
++                  Mod:store(El, LServer, US, chat, Peer, <<"">>, Dir)
+           end;
        false ->
            pass
      end.
  store_muc(MUCState, Pkt, RoomJID, Peer, Nick) ->
      case should_archive_muc(Pkt) of
        true ->
-           LServer = MUCState#state.server_host,
            {U, S, _} = jid:tolower(RoomJID),
-           Mod = gen_mod:db_mod(LServer, ?MODULE),
-           El = xmpp:encode(Pkt),
-           Mod:store(El, LServer, {U, S}, groupchat, Peer, Nick, recv);
+           LServer = MUCState#state.server_host,
+           case ejabberd_hooks:run_fold(store_mam_message, LServer, Pkt,
+                                        [U, S, Peer, groupchat, recv]) of
+               drop ->
+                   pass;
+               NewPkt ->
+                   Mod = gen_mod:db_mod(LServer, ?MODULE),
 -                  Mod:store(NewPkt, LServer, {U, S}, groupchat, Peer, Nick, recv)
++                  El = xmpp:encode(NewPkt),
++                  Mod:store(El, LServer, {U, S}, groupchat, Peer, Nick, recv)
+           end;
        false ->
            pass
      end.
@@@ -874,25 -953,29 +859,26 @@@ is_bare_copy(#jid{luser = U, lserver = 
            false
      end.
  
 -send(From, To, Msgs, RSM, Count, IsComplete, #iq{sub_el = SubEl} = IQ) ->
 -    QID = fxml:get_tag_attr_s(<<"queryid">>, SubEl),
 -    NS = fxml:get_tag_attr_s(<<"xmlns">>, SubEl),
 -    QIDAttr = if QID /= <<>> ->
 -                    [{<<"queryid">>, QID}];
 -               true ->
 -                  []
 -            end,
 -    CompleteAttr = if NS == ?NS_MAM_TMP ->
 -                         [];
 -                    NS == ?NS_MAM_0; NS == ?NS_MAM_1 ->
 -                         [{<<"complete">>, jlib:atom_to_binary(IsComplete)}]
 -                 end,
 -    Hint = [#xmlel{name = <<"no-store">>, attrs = [{<<"xmlns">>, ?NS_HINTS}]}],
 +-spec send([{binary(), integer(), xmlel()}],
 +         non_neg_integer(), boolean(), iq()) -> iq() | ignore.
 +send(Msgs, Count, IsComplete,
 +     #iq{from = From, to = To,
 +       sub_els = [#mam_query{id = QID, xmlns = NS}]} = IQ) ->
++    Hint = #hint{type = 'no-store'},
      Els = lists:map(
            fun({ID, _IDInt, El}) ->
 -                  #xmlel{name = <<"message">>,
 -                         children = [#xmlel{name = <<"result">>,
 -                                            attrs = [{<<"xmlns">>, NS},
 -                                                     {<<"id">>, ID}|QIDAttr],
 -                                            children = [El]} | Hint]}
 +                  #message{sub_els = [#mam_result{xmlns = NS,
 +                                                  id = ID,
 +                                                  queryid = QID,
 +                                                  sub_els = [El]}]}
            end, Msgs),
 -    RSMOut = make_rsm_out(Msgs, RSM, Count, QIDAttr ++ CompleteAttr, NS),
 +    RSMOut = make_rsm_out(Msgs, Count),
 +    Result = if NS == ?NS_MAM_TMP ->
 +                   #mam_query{xmlns = NS, id = QID, rsm = RSMOut};
 +              true ->
 +                   #mam_fin{xmlns = NS, id = QID, rsm = RSMOut,
 +                            complete = IsComplete}
 +           end,
      if NS == ?NS_MAM_TMP; NS == ?NS_MAM_1 ->
            lists:foreach(
              fun(El) ->
              fun(El) ->
                      ejabberd_router:route(To, From, El)
              end, Els),
-           ejabberd_router:route(To, From, #message{sub_els = [Result]}),
 -          ejabberd_router:route(
 -            To, From, #xmlel{name = <<"message">>,
 -                             children = RSMOut ++ Hint}),
++          ejabberd_router:route(To, From, #message{sub_els = [Result, Hint]}),
            ignore
      end.
  
@@@ -923,13 -1018,14 +909,15 @@@ filter_by_max(Msgs, Len) when is_intege
  filter_by_max(_Msgs, _Junk) ->
      {[], true}.
  
 +-spec limit_max(rsm_set(), binary()) -> rsm_set() | undefined.
  limit_max(RSM, ?NS_MAM_TMP) ->
      RSM; % XEP-0313 v0.2 doesn't require clients to support RSM.
 -limit_max(none, _NS) ->
 -    #rsm_in{max = ?DEF_PAGE_SIZE};
 -limit_max(#rsm_in{max = Max} = RSM, _NS) when not is_integer(Max) ->
 -    RSM#rsm_in{max = ?DEF_PAGE_SIZE};
 -limit_max(#rsm_in{max = Max} = RSM, _NS) when Max > ?MAX_PAGE_SIZE ->
 -    RSM#rsm_in{max = ?MAX_PAGE_SIZE};
++limit_max(undefined, _NS) ->
++    #rsm_set{max = ?DEF_PAGE_SIZE};
 +limit_max(#rsm_set{max = Max} = RSM, _NS) when not is_integer(Max) ->
 +    RSM#rsm_set{max = ?DEF_PAGE_SIZE};
 +limit_max(#rsm_set{max = Max} = RSM, _NS) when Max > ?MAX_PAGE_SIZE ->
 +    RSM#rsm_set{max = ?MAX_PAGE_SIZE};
  limit_max(RSM, _NS) ->
      RSM.
  
diff --cc src/mod_mix.erl
Simple merge
diff --cc src/mod_muc.erl
index 9c17643b87cbe700321ebd43be93ec4fda846fca,6b878b05bfd0892f0f88ada3eec66935eb1f471e..ea8bff5e310a653cebbc719e22ef7a0ad1c94744
@@@ -339,191 -330,215 +344,195 @@@ code_change(_OldVsn, State, _Extra) -> 
  %%--------------------------------------------------------------------
  
  do_route(Host, ServerHost, Access, HistorySize, RoomShaper,
-        From, To, Packet, DefRoomOpts) ->
 -       From, To, Packet, DefRoomOpts, MaxRoomsDiscoItems) ->
++       From, To, Packet, DefRoomOpts, _MaxRoomsDiscoItems) ->
      {AccessRoute, _AccessCreate, _AccessAdmin, _AccessPersistent} = Access,
      case acl:match_rule(ServerHost, AccessRoute, From) of
        allow ->
            do_route1(Host, ServerHost, Access, HistorySize, RoomShaper,
-               From, To, Packet, DefRoomOpts);
 -              From, To, Packet, DefRoomOpts, MaxRoomsDiscoItems);
 -      _ ->
 -          #xmlel{attrs = Attrs} = Packet,
 -          Lang = fxml:get_attr_s(<<"xml:lang">>, Attrs),
++                    From, To, Packet, DefRoomOpts);
 +      deny ->
 +          Lang = xmpp:get_lang(Packet),
            ErrText = <<"Access denied by service policy">>,
 -          Err = jlib:make_error_reply(Packet,
 -                  ?ERRT_FORBIDDEN(Lang, ErrText)),
 -          ejabberd_router:route_error(To, From, Err, Packet)
 +          Err = xmpp:err_forbidden(ErrText, Lang),
 +          ejabberd_router:route_error(To, From, Packet, Err)
      end.
  
 -
 +do_route1(_Host, _ServerHost, _Access, _HistorySize, _RoomShaper,
 +        From, #jid{luser = <<"">>, lresource = <<"">>} = To,
 +        #iq{} = IQ, _DefRoomOpts) ->
 +    ejabberd_local:process_iq(From, To, IQ);
 +do_route1(Host, ServerHost, Access, _HistorySize, _RoomShaper,
 +        From, #jid{luser = <<"">>, lresource = <<"">>} = To,
 +        #message{lang = Lang, body = Body, type = Type} = Packet, _) ->
 +    {_AccessRoute, _AccessCreate, AccessAdmin, _AccessPersistent} = Access,
 +    if Type == error ->
 +          ok;
 +       true ->
 +          case acl:match_rule(ServerHost, AccessAdmin, From) of
 +              allow ->
 +                  Msg = xmpp:get_text(Body),
 +                  broadcast_service_message(Host, Msg);
 +              deny ->
 +                  ErrText = <<"Only service administrators are allowed "
 +                              "to send service messages">>,
 +                  Err = xmpp:make_error(
 +                          Packet, xmpp:err_forbidden(ErrText, Lang)),
 +                  ejabberd_router:route(To, From, Err)
 +          end
 +    end;
 +do_route1(_Host, _ServerHost, _Access, _HistorySize, _RoomShaper,
 +        From, #jid{luser = <<"">>} = To, Packet, _DefRoomOpts) ->
 +    Err = xmpp:err_service_unavailable(),
 +    ejabberd_router:route_error(To, From, Packet, Err);
  do_route1(Host, ServerHost, Access, HistorySize, RoomShaper,
 -        From, To, Packet, DefRoomOpts, MaxRoomsDiscoItems) ->
 -    {_AccessRoute, AccessCreate, AccessAdmin, _AccessPersistent} = Access,
 +        From, To, Packet, DefRoomOpts) ->
 +    {_AccessRoute, AccessCreate, _AccessAdmin, _AccessPersistent} = Access,
      {Room, _, Nick} = jid:tolower(To),
 -    #xmlel{name = Name, attrs = Attrs} = Packet,
 -    case Room of
 -      <<"">> ->
 -        case Nick of
 -          <<"">> ->
 -              case Name of
 -                <<"iq">> ->
 -                    case jlib:iq_query_info(Packet) of
 -                      #iq{type = get, xmlns = (?NS_DISCO_INFO) = XMLNS,
 -                          sub_el = _SubEl, lang = Lang} =
 -                          IQ ->
 -                          Info = ejabberd_hooks:run_fold(disco_info,
 -                                                         ServerHost, [],
 -                                                         [ServerHost, ?MODULE,
 -                                                          <<"">>, <<"">>]),
 -                          Res = IQ#iq{type = result,
 -                                      sub_el =
 -                                          [#xmlel{name = <<"query">>,
 -                                                  attrs =
 -                                                      [{<<"xmlns">>, XMLNS}],
 -                                                  children =
 -                                                      iq_disco_info(
 -                                                        ServerHost, Lang) ++
 -                                                        Info}]},
 -                          ejabberd_router:route(To, From,
 -                                                jlib:iq_to_xml(Res));
 -                      #iq{type = get, xmlns = ?NS_DISCO_ITEMS} = IQ ->
 -                          spawn(?MODULE, process_iq_disco_items,
 -                                [Host, From, To, MaxRoomsDiscoItems, IQ]);
 -                      #iq{type = get, xmlns = (?NS_REGISTER) = XMLNS,
 -                          lang = Lang, sub_el = _SubEl} =
 -                          IQ ->
 -                          Res = IQ#iq{type = result,
 -                                      sub_el =
 -                                          [#xmlel{name = <<"query">>,
 -                                                  attrs =
 -                                                      [{<<"xmlns">>, XMLNS}],
 -                                                  children =
 -                                                      iq_get_register_info(ServerHost,
 -                                                                           Host,
 -                                                                           From,
 -                                                                           Lang)}]},
 -                          ejabberd_router:route(To, From,
 -                                                jlib:iq_to_xml(Res));
 -                      #iq{type = set, xmlns = (?NS_REGISTER) = XMLNS,
 -                          lang = Lang, sub_el = SubEl} =
 -                          IQ ->
 -                          case process_iq_register_set(ServerHost, Host, From,
 -                                                       SubEl, Lang)
 -                              of
 -                            {result, IQRes} ->
 -                                Res = IQ#iq{type = result,
 -                                            sub_el =
 -                                                [#xmlel{name = <<"query">>,
 -                                                        attrs =
 -                                                            [{<<"xmlns">>,
 -                                                              XMLNS}],
 -                                                        children = IQRes}]},
 -                                ejabberd_router:route(To, From,
 -                                                      jlib:iq_to_xml(Res));
 -                            {error, Error} ->
 -                                Err = jlib:make_error_reply(Packet, Error),
 -                                ejabberd_router:route(To, From, Err)
 -                          end;
 -                      #iq{type = get, xmlns = (?NS_VCARD) = XMLNS,
 -                          lang = Lang, sub_el = _SubEl} =
 -                          IQ ->
 -                          Res = IQ#iq{type = result,
 -                                      sub_el =
 -                                          [#xmlel{name = <<"vCard">>,
 -                                                  attrs =
 -                                                      [{<<"xmlns">>, XMLNS}],
 -                                                  children =
 -                                                      iq_get_vcard(Lang)}]},
 -                          ejabberd_router:route(To, From,
 -                                                jlib:iq_to_xml(Res));
 -                      #iq{type = get, xmlns = ?NS_MUCSUB,
 -                          sub_el = #xmlel{name = <<"subscriptions">>} = SubEl} = IQ ->
 -                            RoomJIDs = get_subscribed_rooms(ServerHost, Host, From),
 -                            Subs = lists:map(
 -                                     fun(J) ->
 -                                             #xmlel{name = <<"subscription">>,
 -                                                    attrs = [{<<"jid">>,
 -                                                              jid:to_string(J)}]}
 -                                     end, RoomJIDs),
 -                            Res = IQ#iq{type = result,
 -                                        sub_el = [SubEl#xmlel{children = Subs}]},
 -                            ejabberd_router:route(To, From, jlib:iq_to_xml(Res));
 -                      #iq{type = get, xmlns = ?NS_MUC_UNIQUE} = IQ ->
 -                          Res = IQ#iq{type = result,
 -                                      sub_el =
 -                                          [#xmlel{name = <<"unique">>,
 -                                                  attrs =
 -                                                      [{<<"xmlns">>,
 -                                                        ?NS_MUC_UNIQUE}],
 -                                                  children =
 -                                                      [iq_get_unique(From)]}]},
 -                          ejabberd_router:route(To, From,
 -                                                jlib:iq_to_xml(Res));
 -                      #iq{} ->
 -                          Err = jlib:make_error_reply(Packet,
 -                                                      ?ERR_FEATURE_NOT_IMPLEMENTED),
 -                          ejabberd_router:route(To, From, Err);
 -                      _ -> ok
 -                    end;
 -                <<"message">> ->
 -                    case fxml:get_attr_s(<<"type">>, Attrs) of
 -                      <<"error">> -> ok;
 -                      _ ->
 -                          case acl:match_rule(ServerHost, AccessAdmin, From)
 -                              of
 -                            allow ->
 -                                Msg = fxml:get_path_s(Packet,
 -                                                     [{elem, <<"body">>},
 -                                                      cdata]),
 -                                broadcast_service_message(Host, Msg);
 -                            _ ->
 -                                Lang = fxml:get_attr_s(<<"xml:lang">>, Attrs),
 -                                ErrText =
 -                                    <<"Only service administrators are allowed "
 -                                      "to send service messages">>,
 -                                Err = jlib:make_error_reply(Packet,
 -                                                            ?ERRT_FORBIDDEN(Lang,
 -                                                                            ErrText)),
 -                                ejabberd_router:route(To, From, Err)
 -                          end
 -                    end;
 -                <<"presence">> -> ok
 -              end;
 -          _ ->
 -              case fxml:get_attr_s(<<"type">>, Attrs) of
 -                <<"error">> -> ok;
 -                <<"result">> -> ok;
 -                _ ->
 -                    Err = jlib:make_error_reply(Packet,
 -                                                ?ERR_ITEM_NOT_FOUND),
 -                    ejabberd_router:route(To, From, Err)
 -              end
 -        end;
 -      _ ->
 -          case mnesia:dirty_read(muc_online_room, {Room, Host}) of
 -              [] ->
 -                  case is_create_request(Packet) of
 +    case mnesia:dirty_read(muc_online_room, {Room, Host}) of
 +      [] ->
 +          case is_create_request(Packet) of
 +              true ->
 +                  case check_user_can_create_room(
 +                         ServerHost, AccessCreate, From, Room) and
 +                      check_create_roomid(ServerHost, Room) of
                        true ->
 -                          case check_user_can_create_room(ServerHost,
 -                                  AccessCreate, From, Room) and
 -                              check_create_roomid(ServerHost, Room) of
 -                              true ->
 -                                  {ok, Pid} = start_new_room(Host, ServerHost, Access,
 -                                          Room, HistorySize,
 -                                          RoomShaper, From, Nick, DefRoomOpts),
 -                                  register_room(Host, Room, Pid),
 -                                  mod_muc_room:route(Pid, From, Nick, Packet),
 -                                  ok;
 -                              false ->
 -                                  Lang = fxml:get_attr_s(<<"xml:lang">>, Attrs),
 -                                  ErrText = <<"Room creation is denied by service policy">>,
 -                                  Err = jlib:make_error_reply(
 -                                          Packet, ?ERRT_FORBIDDEN(Lang, ErrText)),
 -                                  ejabberd_router:route(To, From, Err)
 -                          end;
 +                          {ok, Pid} = start_new_room(
 +                                        Host, ServerHost, Access,
 +                                        Room, HistorySize,
 +                                        RoomShaper, From, Nick, DefRoomOpts),
 +                          register_room(Host, Room, Pid),
 +                          mod_muc_room:route(Pid, From, Nick, Packet),
 +                          ok;
                        false ->
 -                          Lang = fxml:get_attr_s(<<"xml:lang">>, Attrs),
 -                          ErrText = <<"Conference room does not exist">>,
 -                          Err = jlib:make_error_reply(Packet,
 -                                  ?ERRT_ITEM_NOT_FOUND(Lang, ErrText)),
 +                          Lang = xmpp:get_lang(Packet),
 +                          ErrText = <<"Room creation is denied by service policy">>,
 +                          Err = xmpp:make_error(
 +                                  Packet, xmpp:err_forbidden(ErrText, Lang)),
                            ejabberd_router:route(To, From, Err)
                    end;
 -              [R] ->
 -                  Pid = R#muc_online_room.pid,
 -                  ?DEBUG("MUC: send to process ~p~n", [Pid]),
 -                  mod_muc_room:route(Pid, From, Nick, Packet),
 -                  ok
 -          end
 +              false ->
 +                  Lang = xmpp:get_lang(Packet),
 +                  ErrText = <<"Conference room does not exist">>,
 +                  Err = xmpp:err_item_not_found(ErrText, Lang),
 +                  ejabberd_router:route_error(To, From, Packet, Err)
 +          end;
 +      [R] ->
 +          Pid = R#muc_online_room.pid,
 +          ?DEBUG("MUC: send to process ~p~n", [Pid]),
 +          mod_muc_room:route(Pid, From, Nick, Packet),
 +          ok
      end.
  
 --spec is_create_request(xmlel()) -> boolean().
 -is_create_request(#xmlel{name = <<"presence">>} = Packet) ->
 -    <<"">> == fxml:get_tag_attr_s(<<"type">>, Packet);
 -is_create_request(#xmlel{name = <<"iq">>} = Packet) ->
 -    case jlib:iq_query_info(Packet) of
 -      #iq{type = set, xmlns = ?NS_MUCSUB,
 -          sub_el = #xmlel{name = <<"subscribe">>}} ->
 -          true;
 -      #iq{type = get, xmlns = ?NS_MUC_OWNER, sub_el = SubEl} ->
 -          [] == fxml:remove_cdata(SubEl#xmlel.children);
 -      _ ->
 -          false
 -    end;
 +-spec process_vcard(iq()) -> iq().
 +process_vcard(#iq{type = get, lang = Lang, sub_els = [#vcard_temp{}]} = IQ) ->
 +    Desc = translate:translate(Lang, <<"ejabberd MUC module">>),
 +    Copyright = <<"Copyright (c) 2003-2016 ProcessOne">>,
 +    xmpp:make_iq_result(
 +      IQ, #vcard_temp{fn = <<"ejabberd/mod_muc">>,
 +                    url = ?EJABBERD_URI,
 +                    desc = <<Desc/binary, $\n, Copyright/binary>>});
 +process_vcard(#iq{type = set, lang = Lang} = IQ) ->
 +    Txt = <<"Value 'set' of 'type' attribute is not allowed">>,
 +    xmpp:make_error(IQ, xmpp:err_not_allowed(Txt, Lang));
 +process_vcard(#iq{lang = Lang} = IQ) ->
 +    Txt = <<"No module is handling this query">>,
 +    xmpp:make_error(IQ, xmpp:err_service_unavailable(Txt, Lang)).
 +
 +-spec process_register(iq()) -> iq().
 +process_register(#iq{type = get, from = From, to = To, lang = Lang,
 +                   sub_els = [#register{}]} = IQ) ->
 +    Host = To#jid.lserver,
 +    ServerHost = ejabberd_router:host_of_route(Host),
 +    xmpp:make_iq_result(IQ, iq_get_register_info(ServerHost, Host, From, Lang));
 +process_register(#iq{type = set, from = From, to = To,
 +                   lang = Lang, sub_els = [El = #register{}]} = IQ) ->
 +    Host = To#jid.lserver,
 +    ServerHost = ejabberd_router:host_of_route(Host),
 +    case process_iq_register_set(ServerHost, Host, From, El, Lang) of
 +      {result, Result} ->
 +          xmpp:make_iq_result(IQ, Result);
 +      {error, Err} ->
 +          xmpp:make_error(IQ, Err)
 +    end.
 +
 +-spec process_disco_info(iq()) -> iq().
 +process_disco_info(#iq{type = set, lang = Lang} = IQ) ->
 +    Txt = <<"Value 'set' of 'type' attribute is not allowed">>,
 +    xmpp:make_error(IQ, xmpp:err_not_allowed(Txt, Lang));
 +process_disco_info(#iq{type = get, to = To, lang = Lang,
 +                     sub_els = [#disco_info{node = <<"">>}]} = IQ) ->
 +    ServerHost = ejabberd_router:host_of_route(To#jid.lserver),
 +    X = ejabberd_hooks:run_fold(disco_info, ServerHost, [],
 +                              [ServerHost, ?MODULE, <<"">>, Lang]),
 +    MAMFeatures = case gen_mod:is_loaded(ServerHost, mod_mam) of
 +                    true -> [?NS_MAM_TMP, ?NS_MAM_0, ?NS_MAM_1];
 +                    false -> []
 +                end,
 +    Features = [?NS_DISCO_INFO, ?NS_DISCO_ITEMS,
 +              ?NS_REGISTER, ?NS_MUC, ?NS_RSM,
 +              ?NS_VCARD, ?NS_MUCSUB, ?NS_MUC_UNIQUE | MAMFeatures],
 +    Identity = #identity{category = <<"conference">>,
 +                       type = <<"text">>,
 +                       name = translate:translate(Lang, <<"Chatrooms">>)},
 +    xmpp:make_iq_result(
 +      IQ, #disco_info{features = Features,
 +                    identities = [Identity],
 +                    xdata = X});
 +process_disco_info(#iq{type = get, lang = Lang,
 +                     sub_els = [#disco_info{}]} = IQ) ->
 +    xmpp:make_error(IQ, xmpp:err_item_not_found(<<"Node not found">>, Lang));
 +process_disco_info(#iq{lang = Lang} = IQ) ->
 +    Txt = <<"No module is handling this query">>,
 +    xmpp:make_error(IQ, xmpp:err_service_unavailable(Txt, Lang)).
 +
 +-spec process_disco_items(iq()) -> iq().
 +process_disco_items(#iq{type = set, lang = Lang} = IQ) ->
 +    Txt = <<"Value 'set' of 'type' attribute is not allowed">>,
 +    xmpp:make_error(IQ, xmpp:err_not_allowed(Txt, Lang));
 +process_disco_items(#iq{type = get, from = From, to = To, lang = Lang,
 +                      sub_els = [#disco_items{node = Node, rsm = RSM}]} = IQ) ->
 +    Host = To#jid.lserver,
-     xmpp:make_iq_result(
-       IQ, #disco_items{node = Node,
-                      items = iq_disco_items(Host, From, Lang, Node, RSM)});
++    ServerHost = ejabberd_router:host_of_route(Host),
++    MaxRoomsDiscoItems = gen_mod:get_module_opt(
++                         ServerHost, ?MODULE, max_rooms_discoitems,
++                         fun(I) when is_integer(I), I>=0 -> I end,
++                         100),
++    Items = iq_disco_items(Host, From, Lang, MaxRoomsDiscoItems, Node, RSM),
++    xmpp:make_iq_result(IQ, #disco_items{node = Node, items = Items});
 +process_disco_items(#iq{lang = Lang} = IQ) ->
 +    Txt = <<"No module is handling this query">>,
 +    xmpp:make_error(IQ, xmpp:err_service_unavailable(Txt, Lang)).
 +
 +-spec process_muc_unique(iq()) -> iq().
 +process_muc_unique(#iq{type = set, lang = Lang} = IQ) ->
 +    Txt = <<"Value 'set' of 'type' attribute is not allowed">>,
 +    xmpp:make_error(IQ, xmpp:err_not_allowed(Txt, Lang));
 +process_muc_unique(#iq{from = From, type = get,
 +                     sub_els = [#muc_unique{}]} = IQ) ->
 +    Name = p1_sha:sha(term_to_binary([From, p1_time_compat:timestamp(),
 +                                    randoms:get_string()])),
 +    xmpp:make_iq_result(IQ, #muc_unique{name = Name}).
 +
 +-spec process_mucsub(iq()) -> iq().
 +process_mucsub(#iq{type = set, lang = Lang} = IQ) ->
 +    Txt = <<"Value 'set' of 'type' attribute is not allowed">>,
 +    xmpp:make_error(IQ, xmpp:err_not_allowed(Txt, Lang));
 +process_mucsub(#iq{type = get, from = From, to = To,
 +                 sub_els = [#muc_subscriptions{}]} = IQ) ->
 +    Host = To#jid.lserver,
 +    ServerHost = ejabberd_router:host_of_route(Host),
 +    RoomJIDs = get_subscribed_rooms(ServerHost, Host, From),
 +    xmpp:make_iq_result(IQ, #muc_subscriptions{list = RoomJIDs});
 +process_mucsub(#iq{lang = Lang} = IQ) ->
 +    Txt = <<"No module is handling this query">>,
 +    xmpp:make_error(IQ, xmpp:err_service_unavailable(Txt, Lang)).
 +
 +-spec is_create_request(stanza()) -> boolean().
 +is_create_request(#presence{type = available}) ->
 +    true;
 +is_create_request(#iq{type = T} = IQ) when T == get; T == set ->
 +    xmpp:has_subtag(IQ, #muc_subscribe{}) orelse
 +    xmpp:has_subtag(IQ, #muc_owner{});
  is_create_request(_) ->
      false.
  
@@@ -588,84 -603,132 +597,84 @@@ register_room(Host, Room, Pid) -
      end,
      mnesia:transaction(F).
  
- iq_disco_items(Host, From, Lang, <<"">>, undefined) ->
 -
 -iq_disco_info(ServerHost, Lang) ->
 -    [#xmlel{name = <<"identity">>,
 -          attrs =
 -              [{<<"category">>, <<"conference">>},
 -               {<<"type">>, <<"text">>},
 -               {<<"name">>,
 -                translate:translate(Lang, <<"Chatrooms">>)}],
 -          children = []},
 -     #xmlel{name = <<"feature">>,
 -          attrs = [{<<"var">>, ?NS_DISCO_INFO}], children = []},
 -     #xmlel{name = <<"feature">>,
 -          attrs = [{<<"var">>, ?NS_DISCO_ITEMS}], children = []},
 -     #xmlel{name = <<"feature">>,
 -          attrs = [{<<"var">>, ?NS_MUC}], children = []},
 -     #xmlel{name = <<"feature">>,
 -          attrs = [{<<"var">>, ?NS_MUC_UNIQUE}], children = []},
 -     #xmlel{name = <<"feature">>,
 -          attrs = [{<<"var">>, ?NS_REGISTER}], children = []},
 -     #xmlel{name = <<"feature">>,
 -          attrs = [{<<"var">>, ?NS_RSM}], children = []},
 -     #xmlel{name = <<"feature">>,
 -          attrs = [{<<"var">>, ?NS_MUCSUB}], children = []},
 -     #xmlel{name = <<"feature">>,
 -          attrs = [{<<"var">>, ?NS_VCARD}], children = []}] ++
 -      case gen_mod:is_loaded(ServerHost, mod_mam) of
 -          true ->
 -              [#xmlel{name = <<"feature">>,
 -                      attrs = [{<<"var">>, ?NS_MAM_TMP}]},
 -               #xmlel{name = <<"feature">>,
 -                      attrs = [{<<"var">>, ?NS_MAM_0}]},
 -               #xmlel{name = <<"feature">>,
 -                      attrs = [{<<"var">>, ?NS_MAM_1}]}];
 -          false ->
 -              []
 -      end.
 -
 -iq_disco_items(Host, From, Lang, MaxRoomsDiscoItems, <<>>, none) ->
++iq_disco_items(Host, From, Lang, MaxRoomsDiscoItems, <<"">>, undefined) ->
      Rooms = get_vh_rooms(Host),
-     case erlang:length(Rooms) < ?MAX_ROOMS_DISCOITEMS of
+     case erlang:length(Rooms) < MaxRoomsDiscoItems of
        true ->
            iq_disco_items_list(Host, Rooms, {get_disco_item, all, From, Lang});
        false ->
-           iq_disco_items(Host, From, Lang, <<"nonemptyrooms">>, undefined)
 -          iq_disco_items(Host, From, Lang, MaxRoomsDiscoItems, <<"nonemptyrooms">>, none)
++          iq_disco_items(Host, From, Lang, MaxRoomsDiscoItems, <<"nonemptyrooms">>, undefined)
      end;
- iq_disco_items(Host, From, Lang, <<"nonemptyrooms">>, undefined) ->
 -iq_disco_items(Host, From, Lang, _MaxRoomsDiscoItems, <<"nonemptyrooms">>, none) ->
 -    XmlEmpty = #xmlel{name = <<"item">>,
 -                                 attrs =
 -                                     [{<<"jid">>, <<"conference.localhost">>},
 -                                      {<<"node">>, <<"emptyrooms">>},
 -                                      {<<"name">>, translate:translate(Lang, <<"Empty Rooms">>)}],
 -                                 children = []},
++iq_disco_items(Host, From, Lang, _MaxRoomsDiscoItems, <<"nonemptyrooms">>, undefined) ->
 +    Empty = #disco_item{jid = jid:make(<<"conference.localhost">>),
 +                      node = <<"emptyrooms">>,
 +                      name = translate:translate(Lang, <<"Empty Rooms">>)},
      Query = {get_disco_item, only_non_empty, From, Lang},
 -    [XmlEmpty | iq_disco_items_list(Host, get_vh_rooms(Host), Query)];
 -iq_disco_items(Host, From, Lang, _MaxRoomsDiscoItems, <<"emptyrooms">>, none) ->
 +    [Empty | iq_disco_items_list(Host, get_vh_rooms(Host), Query)];
- iq_disco_items(Host, From, Lang, <<"emptyrooms">>, undefined) ->
++iq_disco_items(Host, From, Lang, _MaxRoomsDiscoItems, <<"emptyrooms">>, undefined) ->
      iq_disco_items_list(Host, get_vh_rooms(Host), {get_disco_item, 0, From, Lang});
- iq_disco_items(Host, From, Lang, _DiscoNode, Rsm) ->
+ iq_disco_items(Host, From, Lang, _MaxRoomsDiscoItems, _DiscoNode, Rsm) ->
      {Rooms, RsmO} = get_vh_rooms(Host, Rsm),
      RsmOut = jlib:rsm_encode(RsmO),
      iq_disco_items_list(Host, Rooms, {get_disco_item, all, From, Lang}) ++ RsmOut.
  
  iq_disco_items_list(Host, Rooms, Query) ->
 -    lists:zf(fun (#muc_online_room{name_host =
 -                                     {Name, _Host},
 -                                 pid = Pid}) ->
 -                   case catch gen_fsm:sync_send_all_state_event(Pid,
 -                                                                Query,
 -                                                                100)
 -                       of
 -                     {item, Desc} ->
 -                         flush(),
 -                         {true,
 -                          #xmlel{name = <<"item">>,
 -                                 attrs =
 -                                     [{<<"jid">>,
 -                                       jid:to_string({Name, Host,
 -                                                           <<"">>})},
 -                                      {<<"name">>, Desc}],
 -                                 children = []}};
 -                     _ -> false
 -                   end
 -           end, Rooms).
 -
 -get_vh_rooms(Host, #rsm_in{max=M, direction=Direction, id=I, index=Index})->
 -    AllRooms = lists:sort(get_vh_rooms(Host)),
 -    Count = erlang:length(AllRooms),
 -    Guard = case Direction of
 -              _ when Index =/= undefined -> [{'==', {element, 2, '$1'}, Host}];
 -              aft -> [{'==', {element, 2, '$1'}, Host}, {'>=',{element, 1, '$1'} ,I}];
 -              before when I =/= []-> [{'==', {element, 2, '$1'}, Host}, {'=<',{element, 1, '$1'} ,I}];
 -              _ -> [{'==', {element, 2, '$1'}, Host}]
 -          end,
 -    L = lists:sort(
 -        mnesia:dirty_select(muc_online_room,
 -                            [{#muc_online_room{name_host = '$1', _ = '_'},
 -                              Guard,
 -                              ['$_']}])),
 -    L2 = if
 -           Index == undefined andalso Direction == before ->
 -               lists:reverse(lists:sublist(lists:reverse(L), 1, M));
 -           Index == undefined ->
 -               lists:sublist(L, 1, M);
 -           Index > Count  orelse Index < 0 ->
 -               [];
 -           true ->
 -               lists:sublist(L, Index+1, M)
 -       end,
 -    if L2 == [] -> {L2, #rsm_out{count = Count}};
 -       true ->
 -         H = hd(L2),
 -         NewIndex = get_room_pos(H, AllRooms),
 -         T = lists:last(L2),
 -         {F, _} = H#muc_online_room.name_host,
 -         {Last, _} = T#muc_online_room.name_host,
 -         {L2,
 -          #rsm_out{first = F, last = Last, count = Count,
 -                   index = NewIndex}}
 -    end.
 +    lists:zf(
 +      fun(#muc_online_room{name_host = {Name, _Host}, pid = Pid}) ->
 +            case catch gen_fsm:sync_send_all_state_event(Pid, Query, 100) of
 +                {item, Desc} ->
 +                    flush(),
 +                    {true, #disco_item{jid = jid:make(Name, Host),
 +                                       name = Desc}};
 +                _ ->
 +                    false
 +            end
 +      end, Rooms).
  
 -get_subscribed_rooms(_ServerHost, Host1, From) ->
 -    Rooms = get_vh_rooms(Host1),
 +get_vh_rooms(_, _) ->
 +    todo.
- %% get_vh_rooms(Host, #rsm_in{max=M, direction=Direction, id=I, index=Index})->
- %%     AllRooms = lists:sort(get_vh_rooms(Host)),
- %%     Count = erlang:length(AllRooms),
- %%     Guard = case Direction of
- %%            _ when Index =/= undefined -> [{'==', {element, 2, '$1'}, Host}];
- %%            aft -> [{'==', {element, 2, '$1'}, Host}, {'>=',{element, 1, '$1'} ,I}];
- %%            before when I =/= []-> [{'==', {element, 2, '$1'}, Host}, {'=<',{element, 1, '$1'} ,I}];
- %%            _ -> [{'==', {element, 2, '$1'}, Host}]
- %%        end,
- %%     L = lists:sort(
- %%      mnesia:dirty_select(muc_online_room,
- %%                          [{#muc_online_room{name_host = '$1', _ = '_'},
- %%                            Guard,
- %%                            ['$_']}])),
- %%     L2 = if
- %%         Index == undefined andalso Direction == before ->
- %%             lists:reverse(lists:sublist(lists:reverse(L), 1, M));
- %%         Index == undefined ->
- %%             lists:sublist(L, 1, M);
- %%         Index > Count  orelse Index < 0 ->
- %%             [];
- %%         true ->
- %%             lists:sublist(L, Index+1, M)
- %%     end,
- %%     if L2 == [] -> {L2, #rsm_out{count = Count}};
- %%        true ->
- %%       H = hd(L2),
- %%       NewIndex = get_room_pos(H, AllRooms),
- %%       T = lists:last(L2),
- %%       {F, _} = H#muc_online_room.name_host,
- %%       {Last, _} = T#muc_online_room.name_host,
- %%       {L2,
- %%        #rsm_out{first = F, last = Last, count = Count,
- %%                 index = NewIndex}}
- %%     end.
++    %% AllRooms = lists:sort(get_vh_rooms(Host)),
++    %% Count = erlang:length(AllRooms),
++    %% Guard = case Direction of
++    %%                _ when Index =/= undefined -> [{'==', {element, 2, '$1'}, Host}];
++    %%                aft -> [{'==', {element, 2, '$1'}, Host}, {'>=',{element, 1, '$1'} ,I}];
++    %%                before when I =/= []-> [{'==', {element, 2, '$1'}, Host}, {'=<',{element, 1, '$1'} ,I}];
++    %%                _ -> [{'==', {element, 2, '$1'}, Host}]
++    %%            end,
++    %% L = lists:sort(
++    %%          mnesia:dirty_select(muc_online_room,
++    %%                              [{#muc_online_room{name_host = '$1', _ = '_'},
++    %%                                Guard,
++    %%                                ['$_']}])),
++    %% L2 = if
++    %%             Index == undefined andalso Direction == before ->
++    %%                 lists:reverse(lists:sublist(lists:reverse(L), 1, M));
++    %%             Index == undefined ->
++    %%                 lists:sublist(L, 1, M);
++    %%             Index > Count  orelse Index < 0 ->
++    %%                 [];
++    %%             true ->
++    %%                 lists:sublist(L, Index+1, M)
++    %%         end,
++    %% if L2 == [] -> {L2, #rsm_out{count = Count}};
++    %%    true ->
++    %%           H = hd(L2),
++    %%           NewIndex = get_room_pos(H, AllRooms),
++    %%           T = lists:last(L2),
++    %%           {F, _} = H#muc_online_room.name_host,
++    %%           {Last, _} = T#muc_online_room.name_host,
++    %%           {L2,
++    %%            #rsm_out{first = F, last = Last, count = Count,
++    %%                     index = NewIndex}}
++    %% end.
 +
 +get_subscribed_rooms(_ServerHost, Host, From) ->
 +    Rooms = get_vh_rooms(Host),
+     BareFrom = jid:remove_resource(From),
      lists:flatmap(
 -      fun(#muc_online_room{name_host = {Name, Host}, pid = Pid}) ->
 +      fun(#muc_online_room{name_host = {Name, _}, pid = Pid}) ->
-             case gen_fsm:sync_send_all_state_event(Pid, {is_subscriber, From}) of
+             case gen_fsm:sync_send_all_state_event(Pid, {is_subscribed, BareFrom}) of
 -                true -> [jid:make(Name, Host, <<>>)];
 +                true -> [jid:make(Name, Host)];
                  false -> []
              end;
         (_) ->
index 4d56093e1379327e4983bbaae5a4f7d76bbb18e8,bd1c55f665452ac1b53281182bb3f7c5f62f90fd..8f1f649d26ee433a4c4d15b9db893abe61cb8280
@@@ -761,15 -806,10 +806,10 @@@ format_room_option(OptionString, ValueS
                password -> ValueString;
                subject ->ValueString;
                subject_author ->ValueString;
 -              max_users -> jlib:binary_to_integer(ValueString);
 +              max_users -> binary_to_integer(ValueString);
                _ -> jlib:binary_to_atom(ValueString)
            end,
-     change_room_option(Name, Service, Option, Value).
- change_room_option(Pid, Option, Value) ->
-     Config = get_room_config(Pid),
-     Config2 = change_option(Option, Value, Config),
-     gen_fsm:sync_send_all_state_event(Pid, {change_config, Config2}).
+     {Option, Value}.
  
  %% @doc Get the Pid of an existing MUC room, or 'room_not_found'.
  get_room_pid(Name, Service) ->
Simple merge
index ce6851bc5da8728499916c5fbd78e567f7b49e2f,6010e0bbf5e8c5236fb57ba2aed0762288d0895f..c83565734917736a3ff7f5e8ada7f89e93f64acd
@@@ -140,194 -133,343 +140,195 @@@ init([Host, ServerHost, Access, Room, H
      {ok, normal_state, State}.
  
  normal_state({route, From, <<"">>,
 -            #xmlel{name = <<"message">>, attrs = Attrs,
 -                   children = Els} =
 -                Packet},
 -           StateData) ->
 -    Lang = fxml:get_attr_s(<<"xml:lang">>, Attrs),
 +            #message{type = Type, lang = Lang} = Packet}, StateData) ->
      case is_user_online(From, StateData) orelse
 -      is_user_allowed_message_nonparticipant(From, StateData)
 -      of
 -      true ->
 -        case fxml:get_attr_s(<<"type">>, Attrs) of
 -          <<"groupchat">> ->
 -              Activity = get_user_activity(From, StateData),
 -              Now = p1_time_compat:system_time(micro_seconds),
 -              MinMessageInterval =
 -                  trunc(gen_mod:get_module_opt(StateData#state.server_host,
 -                                               mod_muc, min_message_interval, fun(MMI) when is_number(MMI) -> MMI end, 0)
 -                          * 1000000),
 -              Size = element_size(Packet),
 -              {MessageShaper, MessageShaperInterval} =
 -                  shaper:update(Activity#activity.message_shaper, Size),
 -              if Activity#activity.message /= undefined ->
 -                     ErrText = <<"Traffic rate limit is exceeded">>,
 -                     Err = jlib:make_error_reply(Packet,
 -                                                 ?ERRT_RESOURCE_CONSTRAINT(Lang,
 -                                                                           ErrText)),
 -                     ejabberd_router:route(StateData#state.jid, From, Err),
 -                     {next_state, normal_state, StateData};
 -                 Now >=
 -                   Activity#activity.message_time + MinMessageInterval,
 -                 MessageShaperInterval == 0 ->
 -                     {RoomShaper, RoomShaperInterval} =
 -                         shaper:update(StateData#state.room_shaper, Size),
 -                     RoomQueueEmpty =
 -                         queue:is_empty(StateData#state.room_queue),
 -                     if RoomShaperInterval == 0, RoomQueueEmpty ->
 -                            NewActivity = Activity#activity{message_time =
 -                                                                Now,
 -                                                            message_shaper =
 -                                                                MessageShaper},
 -                            StateData1 = store_user_activity(From,
 -                                                             NewActivity,
 -                                                             StateData),
 -                            StateData2 = StateData1#state{room_shaper =
 -                                                              RoomShaper},
 -                            process_groupchat_message(From, Packet,
 -                                                      StateData2);
 -                        true ->
 -                            StateData1 = if RoomQueueEmpty ->
 -                                                erlang:send_after(RoomShaperInterval,
 -                                                                  self(),
 -                                                                  process_room_queue),
 -                                                StateData#state{room_shaper =
 -                                                                    RoomShaper};
 -                                            true -> StateData
 -                                         end,
 -                            NewActivity = Activity#activity{message_time =
 -                                                                Now,
 -                                                            message_shaper =
 -                                                                MessageShaper,
 -                                                            message = Packet},
 -                            RoomQueue = queue:in({message, From},
 -                                                 StateData#state.room_queue),
 -                            StateData2 = store_user_activity(From,
 -                                                             NewActivity,
 -                                                             StateData1),
 -                            StateData3 = StateData2#state{room_queue =
 -                                                              RoomQueue},
 -                            {next_state, normal_state, StateData3}
 -                     end;
 -                 true ->
 -                     MessageInterval = (Activity#activity.message_time +
 -                                          MinMessageInterval
 -                                          - Now)
 -                                         div 1000,
 -                     Interval = lists:max([MessageInterval,
 -                                           MessageShaperInterval]),
 -                     erlang:send_after(Interval, self(),
 -                                       {process_user_message, From}),
 -                     NewActivity = Activity#activity{message = Packet,
 -                                                     message_shaper =
 -                                                         MessageShaper},
 -                     StateData1 = store_user_activity(From, NewActivity,
 -                                                      StateData),
 -                     {next_state, normal_state, StateData1}
 -              end;
 -          <<"error">> ->
 -              case is_user_online(From, StateData) of
 -                true ->
 -                    ErrorText = <<"It is not allowed to send error messages to the"
 -                                  " room. The participant (~s) has sent an error "
 -                                  "message (~s) and got kicked from the room">>,
 -                    NewState = expulse_participant(Packet, From, StateData,
 -                                                   translate:translate(Lang,
 -                                                                       ErrorText)),
 -                    close_room_if_temporary_and_empty(NewState);
 -                _ -> {next_state, normal_state, StateData}
 -              end;
 -          <<"chat">> ->
 -              ErrText =
 -                  <<"It is not allowed to send private messages "
 -                    "to the conference">>,
 -              Err = jlib:make_error_reply(Packet,
 -                                          ?ERRT_NOT_ACCEPTABLE(Lang,
 -                                                               ErrText)),
 -              ejabberd_router:route(StateData#state.jid, From, Err),
 -              {next_state, normal_state, StateData};
 -          Type when (Type == <<"">>) or (Type == <<"normal">>) ->
 -              IsInvitation = is_invitation(Els),
 -              IsVoiceRequest = is_voice_request(Els) and
 -                                 is_visitor(From, StateData),
 -              IsVoiceApprovement = is_voice_approvement(Els) and
 -                                     not is_visitor(From, StateData),
 -              if IsInvitation ->
 -                     case catch check_invitation(From, Packet, Lang, StateData)
 -                         of
 -                       {error, Error} ->
 -                           Err = jlib:make_error_reply(Packet, Error),
 -                           ejabberd_router:route(StateData#state.jid, From, Err),
 -                           {next_state, normal_state, StateData};
 -                       IJIDs ->
 -                           Config = StateData#state.config,
 -                           case Config#config.members_only of
 -                             true ->
 -                                 NSD = process_invitees(IJIDs, StateData),
 -                                 store_room(NSD),
 -                                 {next_state, normal_state, NSD};
 -                             false -> {next_state, normal_state, StateData}
 -                           end
 -                     end;
 -                 IsVoiceRequest ->
 -                     NewStateData = case
 -                                      (StateData#state.config)#config.allow_voice_requests
 -                                        of
 -                                      true ->
 -                                          MinInterval =
 -                                              (StateData#state.config)#config.voice_request_min_interval,
 -                                          BareFrom =
 -                                              jid:remove_resource(jid:tolower(From)),
 -                                          NowPriority = -p1_time_compat:system_time(micro_seconds),
 -                                          CleanPriority = NowPriority +
 -                                                            MinInterval *
 -                                                              1000000,
 -                                          Times =
 -                                              clean_treap(StateData#state.last_voice_request_time,
 -                                                          CleanPriority),
 -                                          case treap:lookup(BareFrom, Times)
 -                                              of
 -                                            error ->
 -                                                Times1 =
 -                                                    treap:insert(BareFrom,
 -                                                                 NowPriority,
 -                                                                 true, Times),
 -                                                NSD =
 -                                                    StateData#state{last_voice_request_time
 -                                                                        =
 -                                                                        Times1},
 -                                                send_voice_request(From, NSD),
 -                                                NSD;
 -                                            {ok, _, _} ->
 -                                                ErrText =
 -                                                    <<"Please, wait for a while before sending "
 -                                                      "new voice request">>,
 -                                                Err =
 -                                                    jlib:make_error_reply(Packet,
 -                                                                          ?ERRT_NOT_ACCEPTABLE(Lang,
 -                                                                                               ErrText)),
 -                                                ejabberd_router:route(StateData#state.jid,
 -                                                             From, Err),
 -                                                StateData#state{last_voice_request_time
 -                                                                    = Times}
 -                                          end;
 -                                      false ->
 -                                          ErrText =
 -                                              <<"Voice requests are disabled in this "
 -                                                "conference">>,
 -                                          Err = jlib:make_error_reply(Packet,
 -                                                                      ?ERRT_FORBIDDEN(Lang,
 -                                                                                      ErrText)),
 -                                          ejabberd_router:route(StateData#state.jid,
 -                                                       From, Err),
 -                                          StateData
 -                                    end,
 -                     {next_state, normal_state, NewStateData};
 -                 IsVoiceApprovement ->
 -                     NewStateData = case is_moderator(From, StateData) of
 -                                      true ->
 -                                          case
 -                                            extract_jid_from_voice_approvement(Els)
 -                                              of
 -                                            error ->
 -                                                ErrText =
 -                                                    <<"Failed to extract JID from your voice "
 -                                                      "request approval">>,
 -                                                Err =
 -                                                    jlib:make_error_reply(Packet,
 -                                                                          ?ERRT_BAD_REQUEST(Lang,
 -                                                                                            ErrText)),
 -                                                ejabberd_router:route(StateData#state.jid,
 -                                                             From, Err),
 -                                                StateData;
 -                                            {ok, TargetJid} ->
 -                                                case is_visitor(TargetJid,
 -                                                                StateData)
 -                                                    of
 -                                                  true ->
 -                                                      Reason = <<>>,
 -                                                      NSD =
 -                                                          set_role(TargetJid,
 -                                                                   participant,
 -                                                                   StateData),
 -                                                      catch
 -                                                        send_new_presence(TargetJid,
 -                                                                          Reason,
 -                                                                          NSD,
 -                                                                            StateData),
 -                                                      NSD;
 -                                                  _ -> StateData
 -                                                end
 -                                          end;
 -                                      _ ->
 -                                          ErrText =
 -                                              <<"Only moderators can approve voice requests">>,
 -                                          Err = jlib:make_error_reply(Packet,
 -                                                                      ?ERRT_NOT_ALLOWED(Lang,
 -                                                                                        ErrText)),
 -                                          ejabberd_router:route(StateData#state.jid,
 -                                                       From, Err),
 -                                          StateData
 -                                    end,
 -                     {next_state, normal_state, NewStateData};
 -                 true -> {next_state, normal_state, StateData}
 -              end;
 -          _ ->
 -              ErrText = <<"Improper message type">>,
 -              Err = jlib:make_error_reply(Packet,
 -                                          ?ERRT_NOT_ACCEPTABLE(Lang,
 -                                                               ErrText)),
 -              ejabberd_router:route(StateData#state.jid, From, Err),
 -              {next_state, normal_state, StateData}
 -        end;
 -      _ ->
 -        case fxml:get_attr_s(<<"type">>, Attrs) of
 -          <<"error">> -> ok;
 -          _ ->
 -              handle_roommessage_from_nonparticipant(Packet, Lang,
 -                                                     StateData, From)
 -        end,
 -        {next_state, normal_state, StateData}
 -    end;
 -normal_state({route, From, <<"">>,
 -            #xmlel{name = <<"iq">>} = Packet},
 -           StateData) ->
 -    case jlib:iq_query_info(Packet) of
 -      reply ->
 -          {next_state, normal_state, StateData};
 -      IQ0 ->
 -          case ejabberd_hooks:run_fold(
 -                 muc_process_iq,
 -                 StateData#state.server_host,
 -                 IQ0, [StateData, From, StateData#state.jid]) of
 -              ignore ->
 -                  {next_state, normal_state, StateData};
 -              #iq{type = T} = IQRes when T == error; T == result ->
 -                  ejabberd_router:route(StateData#state.jid, From, jlib:iq_to_xml(IQRes)),
+       is_subscriber(From, StateData) orelse
 +      is_user_allowed_message_nonparticipant(From, StateData) of
 +      true when Type == groupchat ->
 +          Activity = get_user_activity(From, StateData),
 +          Now = p1_time_compat:system_time(micro_seconds),
 +          MinMessageInterval = trunc(gen_mod:get_module_opt(
 +                                       StateData#state.server_host,
 +                                       mod_muc, min_message_interval,
 +                                       fun(MMI) when is_number(MMI) -> MMI end, 0)
 +                                     * 1000000),
 +          Size = element_size(Packet),
 +          {MessageShaper, MessageShaperInterval} =
 +              shaper:update(Activity#activity.message_shaper, Size),
 +          if Activity#activity.message /= undefined ->
 +                  ErrText = <<"Traffic rate limit is exceeded">>,
 +                  Err = xmpp:make_error(
 +                          Packet,
 +                          xmpp:err_resource_constraint(ErrText, Lang)),
 +                  ejabberd_router:route(StateData#state.jid, From, Err),
                    {next_state, normal_state, StateData};
 -              #iq{type = Type, xmlns = XMLNS, lang = Lang,
 -                  sub_el = #xmlel{name = SubElName, attrs = Attrs} = SubEl} = IQ
 -                when (XMLNS == (?NS_MUC_ADMIN)) or
 -                     (XMLNS == (?NS_MUC_OWNER))
 -                     or (XMLNS == (?NS_DISCO_INFO))
 -                     or (XMLNS == (?NS_DISCO_ITEMS))
 -                     or (XMLNS == (?NS_VCARD))
 -                     or (XMLNS == (?NS_MUCSUB))
 -                     or (XMLNS == (?NS_CAPTCHA)) ->
 -                  Res1 = case XMLNS of
 -                             ?NS_MUC_ADMIN ->
 -                                 process_iq_admin(From, Type, Lang, SubEl, StateData);
 -                             ?NS_MUC_OWNER ->
 -                                 process_iq_owner(From, Type, Lang, SubEl, StateData);
 -                             ?NS_DISCO_INFO ->
 -                                 case fxml:get_attr(<<"node">>, Attrs) of
 -                                     false -> process_iq_disco_info(From, Type, Lang, StateData);
 -                                     {value, _} ->
 -                                         Txt = <<"Disco info is not available for this node">>,
 -                                         {error, ?ERRT_SERVICE_UNAVAILABLE(Lang, Txt)}
 -                                 end;
 -                             ?NS_DISCO_ITEMS ->
 -                                 process_iq_disco_items(From, Type, Lang, StateData);
 -                             ?NS_VCARD ->
 -                                 process_iq_vcard(From, Type, Lang, SubEl, StateData);
 -                             ?NS_MUCSUB ->
 -                                 process_iq_mucsub(From, Packet, IQ, StateData);
 -                             ?NS_CAPTCHA ->
 -                                 process_iq_captcha(From, Type, Lang, SubEl, StateData)
 -                         end,
 -                  {IQRes, NewStateData} =
 -                      case Res1 of
 -                          {result, Res, SD} ->
 -                              {IQ#iq{type = result,
 -                                     sub_el =
 -                                         [#xmlel{name = SubElName,
 -                                                 attrs =
 -                                                     [{<<"xmlns">>,
 -                                                       XMLNS}],
 -                                                 children = Res}]},
 -                               SD};
 -                          {ignore, SD} -> {ignore, SD};
 -                          {error, Error, ResStateData} ->
 -                              {IQ#iq{type = error,
 -                                     sub_el = [SubEl, Error]},
 -                               ResStateData};
 -                          {error, Error} ->
 -                              {IQ#iq{type = error,
 -                                     sub_el = [SubEl, Error]},
 -                               StateData}
 -                      end,
 -                  if IQRes /= ignore ->
 -                          ejabberd_router:route(
 -                            StateData#state.jid, From, jlib:iq_to_xml(IQRes));
 +             Now >= Activity#activity.message_time + MinMessageInterval,
 +             MessageShaperInterval == 0 ->
 +                  {RoomShaper, RoomShaperInterval} =
 +                      shaper:update(StateData#state.room_shaper, Size),
 +                  RoomQueueEmpty = queue:is_empty(StateData#state.room_queue),
 +                  if RoomShaperInterval == 0, RoomQueueEmpty ->
 +                          NewActivity = Activity#activity{
 +                                          message_time = Now,
 +                                          message_shaper = MessageShaper},
 +                          StateData1 = store_user_activity(From,
 +                                                           NewActivity,
 +                                                           StateData),
 +                          StateData2 = StateData1#state{room_shaper =
 +                                                            RoomShaper},
 +                          process_groupchat_message(From, Packet,
 +                                                    StateData2);
                       true ->
 -                          ok
 -                  end,
 -                  case NewStateData of
 -                      stop -> {stop, normal, StateData};
 -                      _ -> {next_state, normal_state, NewStateData}
 +                          StateData1 = if RoomQueueEmpty ->
 +                                               erlang:send_after(RoomShaperInterval,
 +                                                                 self(),
 +                                                                 process_room_queue),
 +                                               StateData#state{room_shaper =
 +                                                                   RoomShaper};
 +                                          true -> StateData
 +                                       end,
 +                          NewActivity = Activity#activity{
 +                                          message_time = Now,
 +                                          message_shaper = MessageShaper,
 +                                          message = Packet},
 +                          RoomQueue = queue:in({message, From},
 +                                               StateData#state.room_queue),
 +                          StateData2 = store_user_activity(From,
 +                                                           NewActivity,
 +                                                           StateData1),
 +                          StateData3 = StateData2#state{room_queue = RoomQueue},
 +                          {next_state, normal_state, StateData3}
                    end;
 +             true ->
 +                  MessageInterval = (Activity#activity.message_time +
 +                                         MinMessageInterval - Now) div 1000,
 +                  Interval = lists:max([MessageInterval,
 +                                        MessageShaperInterval]),
 +                  erlang:send_after(Interval, self(),
 +                                    {process_user_message, From}),
 +                  NewActivity = Activity#activity{
 +                                  message = Packet,
 +                                  message_shaper = MessageShaper},
 +                  StateData1 = store_user_activity(From, NewActivity, StateData),
 +                  {next_state, normal_state, StateData1}
 +          end;
 +      true when Type == error ->
 +          case is_user_online(From, StateData) of
 +              true ->
 +                  ErrorText = <<"It is not allowed to send error messages to the"
 +                                " room. The participant (~s) has sent an error "
 +                                "message (~s) and got kicked from the room">>,
 +                  NewState = expulse_participant(Packet, From, StateData,
 +                                                 translate:translate(Lang,
 +                                                                     ErrorText)),
 +                  close_room_if_temporary_and_empty(NewState);
                _ ->
 -                  Err = jlib:make_error_reply(Packet,
 -                                              ?ERR_FEATURE_NOT_IMPLEMENTED),
 -                  ejabberd_router:route(StateData#state.jid, From, Err),
                    {next_state, normal_state, StateData}
 -          end
 +          end;
 +      true when Type == chat ->
 +          ErrText = <<"It is not allowed to send private messages "
 +                      "to the conference">>,
 +          Err = xmpp:err_not_acceptable(ErrText, Lang),
 +          ejabberd_router:route_error(StateData#state.jid, From, Packet, Err),
 +          {next_state, normal_state, StateData};
 +      true when Type == normal ->
 +          {next_state, normal_state,
 +           try xmpp:decode_els(Packet) of
 +               Pkt -> process_normal_message(From, Pkt, StateData)
 +           catch _:{xmpp_codec, Why} ->
 +                   Txt = xmpp:format_error(Why),
 +                   Err = xmpp:err_bad_request(Txt, Lang),
 +                   ejabberd_router:route_error(
 +                     StateData#state.jid, From, Packet, Err),
 +                   StateData
 +           end};
 +      true ->
 +          ErrText = <<"Improper message type">>,
 +          Err = xmpp:err_not_acceptable(ErrText, Lang),
 +          ejabberd_router:route_error(StateData#state.jid, From, Packet, Err),
 +          {next_state, normal_state, StateData};
 +      false when Type /= error ->
 +          handle_roommessage_from_nonparticipant(Packet, StateData, From),
 +          {next_state, normal_state, StateData};
 +      false ->
 +          {next_state, normal_state, StateData}
      end;
 -normal_state({route, From, Nick,
 -            #xmlel{name = <<"presence">>} = Packet},
 -           StateData) ->
 +normal_state({route, From, <<"">>,
 +            #iq{type = Type, lang = Lang, sub_els = [_]} = IQ0},
 +           StateData) when Type == get; Type == set ->
 +    try
 +      case ejabberd_hooks:run_fold(
 +             muc_process_iq,
 +             StateData#state.server_host,
 +             xmpp:set_from_to(xmpp:decode_els(IQ0),
 +                              From, StateData#state.jid),
 +             [StateData]) of
 +          ignore ->
 +              {next_state, normal_state, StateData};
 +          #iq{type = T} = IQRes when T == error; T == result ->
 +              ejabberd_router:route(StateData#state.jid, From, IQRes),
 +              {next_state, normal_state, StateData};
 +          #iq{sub_els = [SubEl]} = IQ ->
 +              Res1 = case xmpp:get_ns(SubEl) of
 +                         ?NS_MUC_ADMIN ->
 +                             process_iq_admin(From, IQ, StateData);
 +                         ?NS_MUC_OWNER ->
 +                             process_iq_owner(From, IQ, StateData);
 +                         ?NS_DISCO_INFO when SubEl#disco_info.node == <<>> ->
 +                             process_iq_disco_info(From, IQ, StateData);
 +                         ?NS_DISCO_ITEMS ->
 +                             process_iq_disco_items(From, IQ, StateData);
 +                         ?NS_VCARD ->
 +                             process_iq_vcard(From, IQ, StateData);
 +                         ?NS_MUCSUB ->
 +                             process_iq_mucsub(From, IQ, StateData);
 +                         ?NS_CAPTCHA ->
 +                             process_iq_captcha(From, IQ, StateData);
 +                         _ ->
 +                             Txt = <<"The feature requested is not "
 +                                     "supported by the conference">>,
 +                             {error, xmpp:err_service_unavailable(Txt, Lang)}
 +                     end,
 +              {IQRes, NewStateData} =
 +                  case Res1 of
 +                      {result, Res, SD} ->
 +                          {xmpp:make_iq_result(IQ, Res), SD};
 +                      {result, Res} ->
 +                          {xmpp:make_iq_result(IQ, Res), StateData};
 +                      {ignore, SD} ->
 +                          {ignore, SD};
 +                      {error, Error, ResStateData} ->
 +                          {xmpp:make_error(IQ0, Error), ResStateData};
 +                      {error, Error} ->
 +                          {xmpp:make_error(IQ0, Error), StateData}
 +                  end,
 +              if IQRes /= ignore ->
 +                      ejabberd_router:route(StateData#state.jid, From, IQRes);
 +                 true ->
 +                      ok
 +              end,
 +              case NewStateData of
 +                  stop ->
 +                      {stop, normal, StateData};
 +                  _ when NewStateData#state.just_created ->
 +                      close_room_if_temporary_and_empty(NewStateData);
 +                  _ ->
 +                      {next_state, normal_state, NewStateData}
 +              end
 +      end
 +    catch _:{xmpp_codec, Why} ->
 +          ErrTxt = xmpp:format_error(Why),
 +          Err = xmpp:make_error(IQ0, xmpp:err_bad_request(ErrTxt, Lang)),
 +          ejabberd_router:route(StateData#state.jid, From, Err)
 +    end;
 +normal_state({route, From, <<"">>, #iq{} = IQ}, StateData) ->
 +    Err = xmpp:err_bad_request(),
 +    ejabberd_router:route_error(StateData#state.jid, From, IQ, Err),
 +    case StateData#state.just_created of
 +      true -> {stop, normal, StateData};
 +      false -> {next_state, normal_state, StateData}
 +    end;
 +normal_state({route, From, Nick, #presence{} = Packet}, StateData) ->
      Activity = get_user_activity(From, StateData),
      Now = p1_time_compat:system_time(micro_seconds),
      MinPresenceInterval =
                                               I
                                       end, 0)
                * 1000000),
 -    if (Now >=
 -        Activity#activity.presence_time + MinPresenceInterval)
 -       and (Activity#activity.presence == undefined) ->
 -         NewActivity = Activity#activity{presence_time = Now},
 -         StateData1 = store_user_activity(From, NewActivity,
 -                                          StateData),
 -         process_presence(From, Nick, Packet, StateData1);
 +    if (Now >= Activity#activity.presence_time + MinPresenceInterval)
 +       and (Activity#activity.presence == undefined) ->
 +          NewActivity = Activity#activity{presence_time = Now},
 +          StateData1 = store_user_activity(From, NewActivity,
 +                                           StateData),
 +          process_presence(From, Nick, Packet, StateData1);
         true ->
 -         if Activity#activity.presence == undefined ->
 -                Interval = (Activity#activity.presence_time +
 -                              MinPresenceInterval
 -                              - Now)
 -                             div 1000,
 -                erlang:send_after(Interval, self(),
 -                                  {process_user_presence, From});
 -            true -> ok
 -         end,
 -         NewActivity = Activity#activity{presence =
 -                                             {Nick, Packet}},
 -         StateData1 = store_user_activity(From, NewActivity,
 -                                          StateData),
 -         {next_state, normal_state, StateData1}
 +          if Activity#activity.presence == undefined ->
 +                  Interval = (Activity#activity.presence_time +
 +                                  MinPresenceInterval - Now) div 1000,
 +                  erlang:send_after(Interval, self(),
 +                                    {process_user_presence, From});
 +             true -> ok
 +          end,
 +          NewActivity = Activity#activity{presence = {Nick, Packet}},
 +          StateData1 = store_user_activity(From, NewActivity,
 +                                           StateData),
 +          {next_state, normal_state, StateData1}
      end;
  normal_state({route, From, ToNick,
 -            #xmlel{name = <<"message">>, attrs = Attrs} = Packet},
 +            #message{type = Type, lang = Lang} = Packet},
             StateData) ->
 -    Type = fxml:get_attr_s(<<"type">>, Attrs),
 -    Lang = fxml:get_attr_s(<<"xml:lang">>, Attrs),
 -    case decide_fate_message(Type, Packet, From, StateData)
 -      of
 -      {expulse_sender, Reason} ->
 -        ?DEBUG(Reason, []),
 -        ErrorText = <<"It is not allowed to send error messages to the"
 -                  " room. The participant (~s) has sent an error "
 -                  "message (~s) and got kicked from the room">>,
 -        NewState = expulse_participant(Packet, From, StateData,
 -                                       translate:translate(Lang, ErrorText)),
 -        {next_state, normal_state, NewState};
 -      forget_message -> {next_state, normal_state, StateData};
 -      continue_delivery ->
 -        case
 -          {(StateData#state.config)#config.allow_private_messages,
 -           is_user_online(From, StateData) orelse
 -           is_subscriber(From, StateData)}
 -            of
 -          {true, true} ->
 -              case Type of
 -                <<"groupchat">> ->
 -                    ErrText =
 -                        <<"It is not allowed to send private messages "
 -                          "of type \"groupchat\"">>,
 -                    Err = jlib:make_error_reply(Packet,
 -                                                ?ERRT_BAD_REQUEST(Lang,
 -                                                                  ErrText)),
 -                    ejabberd_router:route(jid:replace_resource(StateData#state.jid,
 -                                                           ToNick),
 -                                 From, Err);
 -                _ ->
 -                    case find_jids_by_nick(ToNick, StateData) of
 -                      false ->
 -                          ErrText =
 -                              <<"Recipient is not in the conference room">>,
 -                          Err = jlib:make_error_reply(Packet,
 -                                                      ?ERRT_ITEM_NOT_FOUND(Lang,
 -                                                                           ErrText)),
 -                          ejabberd_router:route(jid:replace_resource(StateData#state.jid,
 -                                                                 ToNick),
 -                                       From, Err);
 +    case decide_fate_message(Packet, From, StateData) of
 +      {expulse_sender, Reason} ->
 +          ?DEBUG(Reason, []),
 +          ErrorText = <<"It is not allowed to send error messages to the"
 +                        " room. The participant (~s) has sent an error "
 +                        "message (~s) and got kicked from the room">>,
 +          NewState = expulse_participant(Packet, From, StateData,
 +                                         translate:translate(Lang, ErrorText)),
 +          {next_state, normal_state, NewState};
 +      forget_message ->
 +          {next_state, normal_state, StateData};
 +      continue_delivery ->
 +          case {(StateData#state.config)#config.allow_private_messages,
-                 is_user_online(From, StateData)} of
++                is_user_online(From, StateData) orelse
++                is_subscriber(From, StateData)} of
 +              {true, true} when Type == groupchat ->
 +                  ErrText = <<"It is not allowed to send private messages "
 +                              "of type \"groupchat\"">>,
 +                  Err = xmpp:err_bad_request(ErrText, Lang),
 +                  ejabberd_router:route_error(
 +                    jid:replace_resource(StateData#state.jid, ToNick),
 +                    From, Packet, Err);
 +              {true, true} ->
 +                  case find_jids_by_nick(ToNick, StateData) of
 +                      [] ->
 +                          ErrText = <<"Recipient is not in the conference room">>,
 +                          Err = xmpp:err_item_not_found(ErrText, Lang),
 +                          ejabberd_router:route_error(
 +                            jid:replace_resource(StateData#state.jid, ToNick),
 +                            From, Packet, Err);
                        ToJIDs ->
                            SrcIsVisitor = is_visitor(From, StateData),
 -                          DstIsModerator = is_moderator(hd(ToJIDs),
 -                                                        StateData),
 +                          DstIsModerator = is_moderator(hd(ToJIDs), StateData),
                            PmFromVisitors =
                                (StateData#state.config)#config.allow_private_messages_from_visitors,
                            if SrcIsVisitor == false;
                               PmFromVisitors == anyone;
                               (PmFromVisitors == moderators) and
 -                               DstIsModerator ->
 +                             DstIsModerator ->
-                                   {ok, #user{nick = FromNick}} =
-                                       (?DICT):find(jid:tolower(From),
-                                                    StateData#state.users),
+                                  {FromNick, _} = get_participant_data(From, StateData),
 -                                 FromNickJID =
 -                                     jid:replace_resource(StateData#state.jid,
 -                                                               FromNick),
 -                                 X = #xmlel{name = <<"x">>,
 -                                            attrs = [{<<"xmlns">>, ?NS_MUC_USER}]},
 -                                 PrivMsg = fxml:append_subtags(Packet, [X]),
 -                                 [ejabberd_router:route(FromNickJID, ToJID, PrivMsg)
 -                                  || ToJID <- ToJIDs];
 +                                  FromNickJID =
 +                                      jid:replace_resource(StateData#state.jid,
 +                                                           FromNick),
 +                                  X = #muc_user{},
 +                                  PrivMsg = xmpp:set_subtag(Packet, X),
 +                                  [ejabberd_router:route(FromNickJID, ToJID, PrivMsg)
 +                                   || ToJID <- ToJIDs];
                               true ->
 -                                 ErrText =
 -                                     <<"It is not allowed to send private messages">>,
 -                                 Err = jlib:make_error_reply(Packet,
 -                                                             ?ERRT_FORBIDDEN(Lang,
 -                                                                             ErrText)),
 -                                 ejabberd_router:route(jid:replace_resource(StateData#state.jid,
 -                                                                        ToNick),
 -                                              From, Err)
 +                                  ErrText = <<"It is not allowed to send private messages">>,
 +                                  Err = xmpp:err_forbidden(ErrText, Lang),
 +                                  ejabberd_router:route_error(
 +                                    jid:replace_resource(StateData#state.jid, ToNick),
 +                                    From, Packet, Err)
                            end
 -                    end
 -              end;
 -          {true, false} ->
 -              ErrText =
 -                  <<"Only occupants are allowed to send messages "
 -                    "to the conference">>,
 -              Err = jlib:make_error_reply(Packet,
 -                                          ?ERRT_NOT_ACCEPTABLE(Lang,
 -                                                               ErrText)),
 -              ejabberd_router:route(jid:replace_resource(StateData#state.jid,
 -                                                     ToNick),
 -                           From, Err);
 -          {false, _} ->
 -              ErrText =
 -                  <<"It is not allowed to send private messages">>,
 -              Err = jlib:make_error_reply(Packet,
 -                                          ?ERRT_FORBIDDEN(Lang, ErrText)),
 -              ejabberd_router:route(jid:replace_resource(StateData#state.jid,
 -                                                     ToNick),
 -                           From, Err)
 -        end,
 +                  end;
 +              {true, false} ->
 +                  ErrText = <<"Only occupants are allowed to send messages "
 +                              "to the conference">>,
 +                  Err = xmpp:err_not_acceptable(ErrText, Lang),
 +                  ejabberd_router:route_error(
 +                    jid:replace_resource(StateData#state.jid, ToNick),
 +                    From, Packet, Err);
 +              {false, _} ->
 +                  ErrText = <<"It is not allowed to send private messages">>,
 +                  Err = xmpp:err_forbidden(ErrText, Lang),
 +                  ejabberd_router:route_error(
 +                    jid:replace_resource(StateData#state.jid, ToNick),
 +                    From, Packet, Err)
 +          end,
          {next_state, normal_state, StateData}
      end;
  normal_state({route, From, ToNick,
@@@ -473,10 -664,14 +473,10 @@@ normal_state(_Event, StateData) -
  
  handle_event({service_message, Msg}, _StateName,
             StateData) ->
 -    MessagePkt = #xmlel{name = <<"message">>,
 -                      attrs = [{<<"type">>, <<"groupchat">>}],
 -                      children =
 -                          [#xmlel{name = <<"body">>, attrs = [],
 -                                  children = [{xmlcdata, Msg}]}]},
 +    MessagePkt = #message{type = groupchat, body = xmpp:mk_text(Msg)},
      send_wrapped_multiple(
        StateData#state.jid,
-       StateData#state.users,
+       get_users_and_subscribers(StateData),
        MessagePkt,
        ?NS_MUCSUB_NODES_MESSAGES,
        StateData),
@@@ -532,14 -740,69 +532,65 @@@ handle_sync_event({change_state, NewSta
                  StateName, _StateData) ->
      {reply, {ok, NewStateData}, StateName, NewStateData};
  handle_sync_event({process_item_change, Item, UJID}, _From, StateName, StateData) ->
 -    NSD = process_item_change(Item, StateData, UJID),
 -    {reply, {ok, NSD}, StateName, NSD};
 +    case process_item_change(Item, StateData, UJID) of
 +      {error, _} = Err ->
 +          {reply, Err, StateName, StateData};
 +      NSD ->
 +          {reply, {ok, NSD}, StateName, NSD}
 +    end;
- handle_sync_event({is_subscriber, From}, _From, StateName, StateData) ->
-     {reply, is_subscriber(From, StateData), StateName, StateData};
+ handle_sync_event(get_subscribers, _From, StateName, StateData) ->
+     JIDs = lists:map(fun jid:make/1,
+                    ?DICT:fetch_keys(StateData#state.subscribers)),
+     {reply, {ok, JIDs}, StateName, StateData};
+ handle_sync_event({muc_subscribe, From, Nick, Nodes}, _From,
+                 StateName, StateData) ->
 -    SubEl = #xmlel{name = <<"subscribe">>,
 -                 attrs = [{<<"xmlns">>, ?NS_MUCSUB}, {<<"nick">>, Nick}],
 -                 children = [#xmlel{name = <<"event">>,
 -                                    attrs = [{<<"node">>, Node}]}
 -                             || Node <- Nodes]},
+     IQ = #iq{type = set, id = randoms:get_string(),
 -           xmlns = ?NS_MUCSUB, sub_el = SubEl},
 -    Packet = jlib:iq_to_xml(IQ#iq{sub_el = [SubEl]}),
++           from = From, sub_els = [#muc_subscribe{nick = Nick,
++                                                  events = Nodes}]},
+     Config = StateData#state.config,
+     CaptchaRequired = Config#config.captcha_protected,
+     PasswordProtected = Config#config.password_protected,
+     TmpConfig = Config#config{captcha_protected = false,
+                              password_protected = false},
+     TmpState = StateData#state{config = TmpConfig},
 -    case process_iq_mucsub(From, Packet, IQ, TmpState) of
 -      {result, _, NewState} ->
++    case process_iq_mucsub(From, IQ, TmpState) of
++      {result, #muc_subscribe{events = NewNodes}, NewState} ->
+           NewConfig = (NewState#state.config)#config{
+                         captcha_protected = CaptchaRequired,
+                         password_protected = PasswordProtected},
 -          {reply, {ok, get_subscription_nodes(Packet)}, StateName,
++          {reply, {ok, NewNodes}, StateName,
+            NewState#state{config = NewConfig}};
+       {ignore, NewState} ->
+           NewConfig = (NewState#state.config)#config{
+                         captcha_protected = CaptchaRequired,
+                         password_protected = PasswordProtected},
+           {reply, {error, <<"Requrest is ignored">>},
+            NewState#state{config = NewConfig}};
+       {error, Err, NewState} ->
+           NewConfig = (NewState#state.config)#config{
+                         captcha_protected = CaptchaRequired,
+                         password_protected = PasswordProtected},
+           {reply, {error, get_error_text(Err)}, StateName,
+            NewState#state{config = NewConfig}};
+       {error, Err} ->
+           {reply, {error, get_error_text(Err)}, StateName, StateData}
+     end;
+ handle_sync_event({muc_unsubscribe, From}, _From, StateName, StateData) ->
 -    SubEl = #xmlel{name = <<"unsubscribe">>,
 -                 attrs = [{<<"xmlns">>, ?NS_MUCSUB}]},
+     IQ = #iq{type = set, id = randoms:get_string(),
 -           xmlns = ?NS_MUCSUB, sub_el = SubEl},
 -    Packet = jlib:iq_to_xml(IQ),
 -    case process_iq_mucsub(From, Packet, IQ, StateData) of
++           from = From, sub_els = [#muc_unsubscribe{}]},
++    case process_iq_mucsub(From, IQ, StateData) of
+       {result, _, NewState} ->
+           {reply, ok, StateName, NewState};
+       {ignore, NewState} ->
+           {reply, {error, <<"Requrest is ignored">>}, NewState};
+       {error, Err, NewState} ->
+           {reply, {error, get_error_text(Err)}, StateName, NewState};
+       {error, Err} ->
+           {reply, {error, get_error_text(Err)}, StateName, StateData}
+     end;
+ handle_sync_event({is_subscribed, From}, _From, StateName, StateData) ->
+     IsSubs = ?DICT:is_key(jid:split(From), StateData#state.subscribers),
+     {reply, IsSubs, StateName, StateData};
  handle_sync_event(_Event, _From, StateName,
                  StateData) ->
      Reply = ok, {reply, Reply, StateName, StateData}.
@@@ -667,9 -941,12 +718,10 @@@ terminate(Reason, _StateName, StateData
  route(Pid, From, ToNick, Packet) ->
      gen_fsm:send_event(Pid, {route, From, ToNick, Packet}).
  
 -process_groupchat_message(From,
 -                        #xmlel{name = <<"message">>, attrs = Attrs} = Packet,
 -                        StateData) ->
 -    Lang = fxml:get_attr_s(<<"xml:lang">>, Attrs),
 +-spec process_groupchat_message(jid(), message(), state()) -> fsm_next().
 +process_groupchat_message(From, #message{lang = Lang} = Packet, StateData) ->
-     case is_user_online(From, StateData) orelse
+     IsSubscriber = is_subscriber(From, StateData),
+     case is_user_online(From, StateData) orelse IsSubscriber orelse
           is_user_allowed_message_nonparticipant(From, StateData)
        of
        true ->
@@@ -907,21 -1058,29 +960,28 @@@ is_user_allowed_message_nonparticipant(
  
  %% @doc Get information of this participant, or default values.
  %% If the JID is not a participant, return values for a service message.
- -spec get_participant_data(jid(), state()) -> {binary(), role(), boolean()}.
++-spec get_participant_data(jid(), state()) -> {binary(), role()}.
  get_participant_data(From, StateData) ->
      case (?DICT):find(jid:tolower(From),
                      StateData#state.users)
        of
-       {ok, #user{nick = FromNick, role = Role, is_subscriber = IsSubscriber}} ->
-         {FromNick, Role, IsSubscriber};
-       error -> {<<"">>, moderator, false}
+       {ok, #user{nick = FromNick, role = Role}} ->
+         {FromNick, Role};
+       error ->
+           case ?DICT:find(jid:tolower(jid:remove_resource(From)),
+                           StateData#state.subscribers) of
+               {ok, #subscriber{nick = FromNick}} ->
+                   {FromNick, none};
+               error ->
+                   {<<"">>, moderator}
+           end
      end.
  
 -process_presence(From, Nick,
 -               #xmlel{name = <<"presence">>, attrs = Attrs0} = Packet0,
 -               StateData) ->
 -    Type0 = fxml:get_attr_s(<<"type">>, Attrs0),
 +-spec process_presence(jid(), binary(), presence(), state()) -> fsm_transition().
 +process_presence(From, Nick, #presence{type = Type0} = Packet0, StateData) ->
      IsOnline = is_user_online(From, StateData),
 -    if Type0 == <<"">>;
 -       IsOnline and ((Type0 == <<"unavailable">>) or (Type0 == <<"error">>)) ->
 +    if Type0 == available;
 +       IsOnline and ((Type0 == unavailable) or (Type0 == error)) ->
           case ejabberd_hooks:run_fold(muc_filter_presence,
                                        StateData#state.server_host,
                                        Packet0,
                                         From, Nick]) of
             drop ->
                 {next_state, normal_state, StateData};
 -           #xmlel{attrs = Attrs} = Packet ->
 -               Type = fxml:get_attr_s(<<"type">>, Attrs),
 -               Lang = fxml:get_attr_s(<<"xml:lang">>, Attrs),
 -               StateData1 = case Type of
 -                              <<"unavailable">> ->
 -                                  NewPacket = case
 -                                                {(StateData#state.config)#config.allow_visitor_status,
 -                                                 is_visitor(From, StateData)}
 -                                                  of
 -                                                {false, true} ->
 -                                                    strip_status(Packet);
 -                                                _ -> Packet
 -                                              end,
 -                                  NewState = add_user_presence_un(From, NewPacket,
 -                                                                  StateData),
 -                                  case (?DICT):find(Nick, StateData#state.nicks) of
 -                                    {ok, [_, _ | _]} -> ok;
 -                                    _ -> send_new_presence(From, NewState, StateData)
 -                                  end,
 -                                  Reason = case fxml:get_subtag(NewPacket,
 -                                                               <<"status">>)
 -                                               of
 -                                             false -> <<"">>;
 -                                             Status_el ->
 -                                                 fxml:get_tag_cdata(Status_el)
 -                                           end,
 -                                  remove_online_user(From, NewState, Reason);
 -                              <<"error">> ->
 -                                  ErrorText = <<"It is not allowed to send error messages to the"
 -                                      " room. The participant (~s) has sent an error "
 -                                      "message (~s) and got kicked from the room">>,
 -                                  expulse_participant(Packet, From, StateData,
 -                                                      translate:translate(Lang,
 -                                                                          ErrorText));
 -                              <<"">> ->
 -                                  if not IsOnline ->
 -                                         add_new_user(From, Nick, Packet, StateData);
 -                                     true ->
 -                                         case is_nick_change(From, Nick, StateData) of
 -                                           true ->
 -                                               case {nick_collision(From, Nick, StateData),
 -                                                     mod_muc:can_use_nick(StateData#state.server_host,
 -                                                                          StateData#state.host,
 -                                                                          From, Nick),
 -                                                     {(StateData#state.config)#config.allow_visitor_nickchange,
 -                                                      is_visitor(From, StateData)}}
 -                                                   of
 -                                                 {_, _, {false, true}} ->
 -                                                     ErrText =
 -                                                         <<"Visitors are not allowed to change their "
 -                                                           "nicknames in this room">>,
 -                                                     Err = jlib:make_error_reply(Packet,
 -                                                                                 ?ERRT_NOT_ALLOWED(Lang,
 -                                                                                                   ErrText)),
 -                                                     ejabberd_router:route(jid:replace_resource(StateData#state.jid,
 -                                                                                            Nick),
 -                                                                  From, Err),
 -                                                     StateData;
 -                                                 {true, _, _} ->
 -                                                     Lang = fxml:get_attr_s(<<"xml:lang">>,
 -                                                                           Attrs),
 -                                                     ErrText =
 -                                                         <<"That nickname is already in use by another "
 -                                                           "occupant">>,
 -                                                     Err = jlib:make_error_reply(Packet,
 -                                                                                 ?ERRT_CONFLICT(Lang,
 -                                                                                                ErrText)),
 -                                                     ejabberd_router:route(jid:replace_resource(StateData#state.jid,
 -                                                                                            Nick), % TODO: s/Nick/""/
 -                                                                  From, Err),
 -                                                     StateData;
 -                                                 {_, false, _} ->
 -                                                     ErrText =
 -                                                         <<"That nickname is registered by another "
 -                                                           "person">>,
 -                                                     Err = jlib:make_error_reply(Packet,
 -                                                                                 ?ERRT_CONFLICT(Lang,
 -                                                                                                ErrText)),
 -                                                     ejabberd_router:route(jid:replace_resource(StateData#state.jid,
 -                                                                                            Nick),
 -                                                                 From, Err),
 -                                                     StateData;
 -                                                 _ ->
 -                                                     change_nick(From, Nick, StateData)
 -                                               end;
 -                                           _NotNickChange ->
 -                                                 Stanza = maybe_strip_status_from_presence(
 -                                                            From, Packet, StateData),
 -                                                 NewState = add_user_presence(From, Stanza,
 -                                                                              StateData),
 -                                                 send_new_presence(From, NewState, StateData),
 -                                                 NewState
 -                                         end
 -                                  end
 -                            end,
 -               close_room_if_temporary_and_empty(StateData1)
 +           #presence{} = Packet ->
 +               close_room_if_temporary_and_empty(
 +                 do_process_presence(From, Nick, Packet, StateData))
           end;
         true ->
 -         {next_state, normal_state, StateData}
 +          {next_state, normal_state, StateData}
      end.
  
-                           case is_initial_presence(From, StateData) of
-                               true ->
-                                   subscriber_becomes_available(
-                                     From, Nick, Packet, StateData);
-                               false ->
 +-spec do_process_presence(jid(), binary(), presence(), state()) ->
 +                               state().
 +do_process_presence(From, Nick, #presence{type = available, lang = Lang} = Packet,
 +                  StateData) ->
 +    case is_user_online(From, StateData) of
 +      false ->
 +          add_new_user(From, Nick, Packet, StateData);
 +      true ->
 +          case is_nick_change(From, Nick, StateData) of
 +              true ->
 +                  case {nick_collision(From, Nick, StateData),
 +                        mod_muc:can_use_nick(StateData#state.server_host,
 +                                             StateData#state.host,
 +                                             From, Nick),
 +                        {(StateData#state.config)#config.allow_visitor_nickchange,
 +                         is_visitor(From, StateData)}} of
 +                      {_, _, {false, true}} ->
 +                          ErrText = <<"Visitors are not allowed to change their "
 +                                      "nicknames in this room">>,
 +                          Err = xmpp:err_not_allowed(ErrText, Lang),
 +                          ejabberd_router:route_error(
 +                            jid:replace_resource(StateData#state.jid, Nick),
 +                            From, Packet, Err),
 +                          StateData;
 +                      {true, _, _} ->
 +                          ErrText = <<"That nickname is already in use by another "
 +                                      "occupant">>,
 +                          Err = xmpp:err_conflict(ErrText, Lang),
 +                          ejabberd_router:route_error(
 +                            jid:replace_resource(StateData#state.jid, Nick),
 +                            From, Packet, Err),
 +                          StateData;
 +                      {_, false, _} ->
 +                          ErrText = <<"That nickname is registered by another "
 +                                      "person">>,
 +                          Err = xmpp:err_conflict(ErrText, Lang),
 +                          ejabberd_router:route_error(
 +                            jid:replace_resource(StateData#state.jid, Nick),
 +                            From, Packet, Err),
 +                          StateData;
 +                      _ ->
-                           end
 +                                  change_nick(From, Nick, StateData)
-               _NotNickChange ->
-                   case is_initial_presence(From, StateData) of
-                       true ->
-                           subscriber_becomes_available(
-                             From, Nick, Packet, StateData);
-                       false ->
-                           Stanza = maybe_strip_status_from_presence(
-                                      From, Packet, StateData),
-                           NewState = add_user_presence(From, Stanza,
-                                                        StateData),
-                           send_new_presence(From, NewState, StateData),
-                           NewState
-                   end
 +                  end;
-     IsSubscriber = is_subscriber(From, StateData),
++              false ->
++                  Stanza = maybe_strip_status_from_presence(
++                             From, Packet, StateData),
++                  NewState = add_user_presence(From, Stanza,
++                                               StateData),
++                  send_new_presence(From, NewState, StateData),
++                  NewState
 +          end
 +    end;
 +do_process_presence(From, Nick, #presence{type = unavailable} = Packet,
 +                  StateData) ->
-     remove_online_user(From, NewState, IsSubscriber, Reason);
 +    NewPacket = case {(StateData#state.config)#config.allow_visitor_status,
 +                    is_visitor(From, StateData)} of
 +                  {false, true} ->
 +                      strip_status(Packet);
 +                  _ -> Packet
 +              end,
 +    NewState = add_user_presence_un(From, NewPacket, StateData),
 +    case (?DICT):find(Nick, StateData#state.nicks) of
 +      {ok, [_, _ | _]} -> ok;
 +      _ -> send_new_presence(From, NewState, StateData)
 +    end,
 +    Reason = xmpp:get_text(NewPacket#presence.status),
++    remove_online_user(From, NewState, Reason);
 +do_process_presence(From, _Nick, #presence{type = error, lang = Lang} = Packet,
 +                  StateData) ->
 +    ErrorText = <<"It is not allowed to send error messages to the"
 +                " room. The participant (~s) has sent an error "
 +                "message (~s) and got kicked from the room">>,
 +    expulse_participant(Packet, From, StateData,
 +                      translate:translate(Lang, ErrorText)).
 +
 +-spec maybe_strip_status_from_presence(jid(), presence(),
 +                                     state()) -> presence().
  maybe_strip_status_from_presence(From, Packet, StateData) ->
      case {(StateData#state.config)#config.allow_visitor_status,
          is_visitor(From, StateData)} of
        _Allowed -> Packet
      end.
  
- -spec subscriber_becomes_available(jid(), binary(), presence(),
-                                  state()) -> state().
- subscriber_becomes_available(From, Nick, Packet, StateData) ->
-     Stanza = maybe_strip_status_from_presence(From, Packet, StateData),
-     State1 = add_user_presence(From, Stanza, StateData),
-     Aff = get_affiliation(From, State1),
-     Role = get_default_role(Aff, State1),
-     State2 = set_role(From, Role, State1),
-     State3 = set_nick(From, Nick, State2),
-     send_existing_presences(From, State3),
-     send_initial_presence(From, State3, StateData),
-     State3.
 +-spec close_room_if_temporary_and_empty(state()) -> fsm_transition().
  close_room_if_temporary_and_empty(StateData1) ->
      case not (StateData1#state.config)#config.persistent
-          andalso (?DICT):size(StateData1#state.users) == 0
-       of
+       andalso (?DICT):size(StateData1#state.users) == 0
+       andalso (?DICT):size(StateData1#state.subscribers) == 0 of
        true ->
          ?INFO_MSG("Destroyed MUC room ~s because it's temporary "
                    "and empty",
        _ -> {next_state, normal_state, StateData1}
      end.
  
+ get_users_and_subscribers(StateData) ->
+     OnlineSubscribers = ?DICT:fold(
+                          fun(LJID, _, Acc) ->
+                                  LBareJID = jid:remove_resource(LJID),
+                                  case is_subscriber(LBareJID, StateData) of
+                                      true ->
+                                          ?SETS:add_element(LBareJID, Acc);
+                                      false ->
+                                          Acc
+                                  end
+                          end, ?SETS:new(), StateData#state.users),
+     ?DICT:fold(
+        fun(LBareJID, #subscriber{nick = Nick}, Acc) ->
+              case ?SETS:is_element(LBareJID, OnlineSubscribers) of
+                  false ->
+                      ?DICT:store(LBareJID,
+                                  #user{jid = jid:make(LBareJID),
+                                        nick = Nick,
+                                        role = none,
+                                        last_presence = undefined},
+                                  Acc);
+                  true ->
+                      Acc
+              end
+        end, StateData#state.users, StateData#state.subscribers).
 +-spec is_user_online(jid(), state()) -> boolean().
  is_user_online(JID, StateData) ->
      LJID = jid:tolower(JID),
      (?DICT):is_key(LJID, StateData#state.users).
  
 +-spec is_subscriber(jid(), state()) -> boolean().
  is_subscriber(JID, StateData) ->
-     LJID = jid:tolower(JID),
-     case (?DICT):find(LJID, StateData#state.users) of
-       {ok, #user{is_subscriber = IsSubscriber}} ->
-           IsSubscriber;
-       _ ->
-           false
-     end.
+     LJID = jid:tolower(jid:remove_resource(JID)),
+     (?DICT):is_key(LJID, StateData#state.subscribers).
  
  %% Check if the user is occupant of the room, or at least is an admin or owner.
 +-spec is_occupant_or_admin(jid(), state()) -> boolean().
  is_occupant_or_admin(JID, StateData) ->
      FAffiliation = get_affiliation(JID, StateData),
      FRole = get_role(JID, StateData),
@@@ -1174,52 -1376,66 +1229,59 @@@ decide_fate_message(_, _, _) -> continu
  %% Check if the elements of this error stanza indicate
  %% that the sender is a dead participant.
  %% If so, return true to kick the participant.
 -check_error_kick(Packet) ->
 -    case get_error_condition(Packet) of
 -      <<"gone">> -> true;
 -      <<"internal-server-error">> -> true;
 -      <<"item-not-found">> -> true;
 -      <<"jid-malformed">> -> true;
 -      <<"recipient-unavailable">> -> true;
 -      <<"redirect">> -> true;
 -      <<"remote-server-not-found">> -> true;
 -      <<"remote-server-timeout">> -> true;
 -      <<"service-unavailable">> -> true;
 -      _ -> false
 -    end.
 -
 -get_error_condition(Packet) ->
 -    case catch get_error_condition2(Packet) of
 -      {condition, ErrorCondition} -> ErrorCondition;
 -      {'EXIT', _} -> <<"badformed error stanza">>
 -    end.
 +-spec check_error_kick(stanza_error()) -> boolean().
 +check_error_kick(#stanza_error{reason = Reason}) ->
 +    case Reason of
 +      #gone{} -> true;
 +      'internal-server-error' -> true;
 +      'item-not-found' -> true;
 +      'jid-malformed' -> true;
 +      'recipient-unavailable' -> true;
 +      #redirect{} -> true;
 +      'remote-server-not-found' -> true;
 +      'remote-server-timeout' -> true;
 +      'service-unavailable' -> true;
 +      _ -> false
 +    end;
 +check_error_kick(undefined) ->
 +    false.
  
 -get_error_condition2(Packet) ->
 -    #xmlel{children = EEls} = fxml:get_subtag(Packet,
 -                                           <<"error">>),
 -    [Condition] = [Name
 -                 || #xmlel{name = Name,
 -                           attrs = [{<<"xmlns">>, ?NS_STANZAS}],
 -                           children = []}
 -                        <- EEls],
 -    {condition, Condition}.
 +-spec get_error_condition(stanza_error()) -> string().
 +get_error_condition(#stanza_error{reason = Reason}) ->
 +    case Reason of
 +      #gone{} -> "gone";
 +      #redirect{} -> "redirect";
 +      Atom -> atom_to_list(Atom)
 +    end;
 +get_error_condition(undefined) ->
 +    "undefined".
  
+ get_error_text(Error) ->
+     case fxml:get_subtag_with_xmlns(Error, <<"text">>, ?NS_STANZAS) of
+       #xmlel{} = Tag ->
+           fxml:get_tag_cdata(Tag);
+       false ->
+           <<"">>
+     end.
 +-spec make_reason(stanza(), jid(), state(), binary()) -> binary().
  make_reason(Packet, From, StateData, Reason1) ->
      {ok, #user{nick = FromNick}} = (?DICT):find(jid:tolower(From), StateData#state.users),
 -    Condition = get_error_condition(Packet),
 -    iolist_to_binary(io_lib:format(Reason1, [FromNick, Condition])).
 +    Condition = get_error_condition(xmpp:get_error(Packet)),
 +    str:format(Reason1, [FromNick, Condition]).
  
 +-spec expulse_participant(stanza(), jid(), state(), binary()) ->
 +                               state().
  expulse_participant(Packet, From, StateData, Reason1) ->
-     IsSubscriber = is_subscriber(From, StateData),
      Reason2 = make_reason(Packet, From, StateData, Reason1),
      NewState = add_user_presence_un(From,
 -                                  #xmlel{name = <<"presence">>,
 -                                         attrs =
 -                                             [{<<"type">>,
 -                                               <<"unavailable">>}],
 -                                         children =
 -                                             [#xmlel{name = <<"status">>,
 -                                                     attrs = [],
 -                                                     children =
 -                                                         [{xmlcdata,
 -                                                           Reason2}]}]},
 +                                  #presence{type = unavailable,
 +                                            status = xmpp:mk_text(Reason2)},
                                    StateData),
      send_new_presence(From, NewState, StateData),
-     remove_online_user(From, NewState, IsSubscriber).
+     remove_online_user(From, NewState).
  
 +-spec set_affiliation(jid(), affiliation(), state()) -> state().
  set_affiliation(JID, Affiliation, StateData) ->
      set_affiliation(JID, Affiliation, StateData, <<"">>).
  
@@@ -1513,9 -1714,7 +1575,8 @@@ prepare_room_queue(StateData) -
        {empty, _} -> StateData
      end.
  
- update_online_user(JID, #user{nick = Nick, subscriptions = Nodes,
-                             is_subscriber = IsSubscriber} = User, StateData) ->
 +-spec update_online_user(jid(), #user{}, state()) -> state().
+ update_online_user(JID, #user{nick = Nick} = User, StateData) ->
      LJID = jid:tolower(JID),
      Nicks1 = case (?DICT):find(LJID, StateData#state.users) of
                 {ok, #user{nick = OldNick}} ->
      end,
      NewStateData.
  
- -spec add_online_user(jid(), binary(), role(), boolean(), [binary()], state()) -> state().
- add_online_user(JID, Nick, Role, IsSubscriber, Nodes, StateData) ->
+ set_subscriber(JID, Nick, Nodes, StateData) ->
+     BareJID = jid:remove_resource(JID),
+     LBareJID = jid:tolower(BareJID),
+     Subscribers = ?DICT:store(LBareJID,
+                             #subscriber{jid = BareJID,
+                                         nick = Nick,
+                                         nodes = Nodes},
+                             StateData#state.subscribers),
+     Nicks = ?DICT:store(Nick, [LBareJID], StateData#state.subscriber_nicks),
+     NewStateData = StateData#state{subscribers = Subscribers,
+                                  subscriber_nicks = Nicks},
+     store_room(NewStateData),
+     NewStateData.
++-spec add_online_user(jid(), binary(), role(), state()) -> state().
+ add_online_user(JID, Nick, Role, StateData) ->
      tab_add_online_user(JID, StateData),
-     User = #user{jid = JID, nick = Nick, role = Role,
-                is_subscriber = IsSubscriber, subscriptions = Nodes},
-     StateData1 = update_online_user(JID, User, StateData),
-     if IsSubscriber ->
-           store_room(StateData1);
-        true ->
-           ok
-     end,
-     StateData1.
+     User = #user{jid = JID, nick = Nick, role = Role},
+     update_online_user(JID, User, StateData).
  
- -spec remove_online_user(jid(), state(), boolean()) -> state().
- remove_online_user(JID, StateData, IsSubscriber) ->
-     remove_online_user(JID, StateData, IsSubscriber, <<"">>).
++-spec remove_online_user(jid(), state()) -> state().
+ remove_online_user(JID, StateData) ->
+     remove_online_user(JID, StateData, <<"">>).
  
- -spec remove_online_user(jid(), state(), boolean(), binary()) -> state().
- remove_online_user(JID, StateData, _IsSubscriber = true, _Reason) ->
-     LJID = jid:tolower(JID),
-     Users = case (?DICT):find(LJID, StateData#state.users) of
-               {ok, U} ->
-                   (?DICT):store(LJID, U#user{last_presence = undefined},
-                                 StateData#state.users);
-               error ->
-                   StateData#state.users
-           end,
-     StateData#state{users = Users};
- remove_online_user(JID, StateData, _IsSubscriber, Reason) ->
++-spec remove_online_user(jid(), state(), binary()) -> state().
+ remove_online_user(JID, StateData, Reason) ->
      LJID = jid:tolower(JID),
      {ok, #user{nick = Nick}} = (?DICT):find(LJID,
                                            StateData#state.users),
@@@ -1634,12 -1839,14 +1690,15 @@@ add_user_presence_un(JID, Presence, Sta
  
  %% Find and return a list of the full JIDs of the users of Nick.
  %% Return jid record.
 +-spec find_jids_by_nick(binary(), state()) -> [jid()].
  find_jids_by_nick(Nick, StateData) ->
-     case (?DICT):find(Nick, StateData#state.nicks) of
+     Nicks = ?DICT:merge(fun(_, Val, _) -> Val end,
+                       StateData#state.nicks,
+                       StateData#state.subscriber_nicks),
+     case (?DICT):find(Nick, Nicks) of
 -      {ok, [User]} -> [jid:make(User)];
 -      {ok, Users} -> [jid:make(LJID) || LJID <- Users];
 -      error -> false
 +      {ok, [User]} -> [jid:make(User)];
 +      {ok, Users} -> [jid:make(LJID) || LJID <- Users];
 +      error -> []
      end.
  
  %% Find and return the full JID of the user of Nick with
@@@ -1702,9 -1912,15 +1761,16 @@@ is_nick_change(JID, Nick, StateData) -
          Nick /= OldNick
      end.
  
 +-spec nick_collision(jid(), binary(), state()) -> boolean().
  nick_collision(User, Nick, StateData) ->
-     UserOfNick = find_jid_by_nick(Nick, StateData),
+     UserOfNick = case find_jid_by_nick(Nick, StateData) of
+                    false ->
+                        case ?DICT:find(Nick, StateData#state.subscriber_nicks) of
+                            {ok, [J]} -> J;
+                            error -> false
+                        end;
+                    J -> J
+                end,
      (UserOfNick /= false andalso
        jid:remove_resource(jid:tolower(UserOfNick))
        /= jid:remove_resource(jid:tolower(User))).
@@@ -1819,18 -2032,17 +1885,15 @@@ add_new_user(From, Nick, Packet, StateD
                              NewState = add_user_presence(
                                           From, Packet,
                                           add_online_user(From, Nick, Role,
-                                                          IsSubscribeRequest,
-                                                          Nodes, StateData)),
+                                                          StateData)),
                              send_existing_presences(From, NewState),
                              send_initial_presence(From, NewState, StateData),
 -                            Shift = count_stanza_shift(Nick, Els, NewState),
 -                            case send_history(From, Shift, NewState) of
 -                                true -> ok;
 -                                _ -> send_subject(From, StateData)
 -                            end,
 +                            History = get_history(Nick, Packet, NewState),
 +                            send_history(From, History, NewState),
 +                            send_subject(From, StateData),
                              NewState;
                         true ->
-                             add_online_user(From, Nick, none,
-                                             IsSubscribeRequest,
-                                             Nodes, StateData)
+                             set_subscriber(From, Nick, Nodes, StateData)
                      end,
                  ResultState =
                      case NewStateData#state.just_created of
@@@ -2020,17 -2282,6 +2083,7 @@@ presence_broadcast_allowed(JID, StateDa
      Role = get_role(JID, StateData),
      lists:member(Role, (StateData#state.config)#config.presence_broadcast).
  
- -spec is_initial_presence(jid(), state()) -> boolean().
- is_initial_presence(From, StateData) ->
-     LJID = jid:tolower(From),
-     case (?DICT):find(LJID, StateData#state.users) of
-       {ok, #user{last_presence = Pres}} when Pres /= undefined ->
-           false;
-       _ ->
-           true
-     end.
 +-spec send_initial_presence(jid(), state(), state()) -> ok.
  send_initial_presence(NJID, StateData, OldStateData) ->
      send_new_presence1(NJID, <<"">>, true, StateData, OldStateData).
  
@@@ -2157,11 -2430,11 +2210,11 @@@ send_new_presence1(NJID, Reason, IsInit
                      end,
              send_wrapped(jid:replace_resource(StateData#state.jid, Nick),
                           Info#user.jid, Packet, Node1, StateData),
 -            Type = fxml:get_tag_attr_s(<<"type">>, Packet),
 +            Type = xmpp:get_type(Packet),
-             IsSubscriber = Info#user.is_subscriber,
+             IsSubscriber = is_subscriber(Info#user.jid, StateData),
              IsOccupant = Info#user.last_presence /= undefined,
              if (IsSubscriber and not IsOccupant) and
 -               (IsInitialPresence or (Type == <<"unavailable">>)) ->
 +               (IsInitialPresence or (Type == unavailable)) ->
                      Node2 = ?NS_MUCSUB_NODES_PARTICIPANTS,
                      send_wrapped(jid:replace_resource(StateData#state.jid, Nick),
                                   Info#user.jid, Packet, Node2, StateData);
@@@ -2267,50 -2559,107 +2320,51 @@@ send_nick_changing(JID, OldNick, StateD
        (?DICT):find(jid:tolower(JID),
                     StateData#state.users),
      Affiliation = get_affiliation(JID, StateData),
 -    SAffiliation = affiliation_to_list(Affiliation),
 -    SRole = role_to_list(Role),
 -    lists:foreach(fun ({_LJID, Info}) when Presence /= undefined ->
 -                        ItemAttrs1 = case Info#user.role == moderator orelse
 -                                            (StateData#state.config)#config.anonymous
 -                                              == false
 -                                         of
 -                                       true ->
 -                                           [{<<"jid">>,
 -                                             jid:to_string(RealJID)},
 -                                            {<<"affiliation">>, SAffiliation},
 -                                            {<<"role">>, SRole},
 -                                            {<<"nick">>, Nick}];
 -                                       _ ->
 -                                           [{<<"affiliation">>, SAffiliation},
 -                                            {<<"role">>, SRole},
 -                                            {<<"nick">>, Nick}]
 -                                     end,
 -                        ItemAttrs2 = case Info#user.role == moderator orelse
 -                                            (StateData#state.config)#config.anonymous
 -                                              == false
 -                                         of
 -                                       true ->
 -                                           [{<<"jid">>,
 -                                             jid:to_string(RealJID)},
 -                                            {<<"affiliation">>, SAffiliation},
 -                                            {<<"role">>, SRole}];
 -                                       _ ->
 -                                           [{<<"affiliation">>, SAffiliation},
 -                                            {<<"role">>, SRole}]
 -                                     end,
 -                        Status110 = case JID == Info#user.jid of
 -                                      true ->
 -                                          [#xmlel{name = <<"status">>,
 -                                                  attrs = [{<<"code">>, <<"110">>}]
 -                                                                     }];
 -                                      false ->
 -                                          []
 -                                  end,
 -                        Packet1 = #xmlel{name = <<"presence">>,
 -                                         attrs =
 -                                             [{<<"type">>,
 -                                               <<"unavailable">>}],
 -                                         children =
 -                                             [#xmlel{name = <<"x">>,
 -                                                     attrs =
 -                                                         [{<<"xmlns">>,
 -                                                           ?NS_MUC_USER}],
 -                                                     children =
 -                                                         [#xmlel{name =
 -                                                                     <<"item">>,
 -                                                                 attrs =
 -                                                                     ItemAttrs1,
 -                                                                 children =
 -                                                                     []},
 -                                                          #xmlel{name =
 -                                                                     <<"status">>,
 -                                                                 attrs =
 -                                                                     [{<<"code">>,
 -                                                                       <<"303">>}],
 -                                                                 children =
 -                                                                     []}|Status110]}]},
 -                        Packet2 = fxml:append_subtags(Presence,
 -                                                     [#xmlel{name = <<"x">>,
 -                                                             attrs =
 -                                                                 [{<<"xmlns">>,
 -                                                                   ?NS_MUC_USER}],
 -                                                             children =
 -                                                                 [#xmlel{name
 -                                                                             =
 -                                                                             <<"item">>,
 -                                                                         attrs
 -                                                                             =
 -                                                                             ItemAttrs2,
 -                                                                         children
 -                                                                             =
 -                                                                             []}|Status110]}]),
 -                        if SendOldUnavailable ->
 -                                send_wrapped(jid:replace_resource(StateData#state.jid,
 -                                                                  OldNick),
 -                                             Info#user.jid, Packet1,
 -                                             ?NS_MUCSUB_NODES_PRESENCE,
 -                                             StateData);
 -                           true -> ok
 +    lists:foreach(
 +      fun({LJID, Info}) when Presence /= undefined ->
 +            IsSelfPresence = LJID == jid:tolower(JID),
 +            Item0 = #muc_item{affiliation = Affiliation, role = Role},
 +            Item = case Info#user.role == moderator orelse
 +                       (StateData#state.config)#config.anonymous
 +                       == false orelse IsSelfPresence of
 +                       true -> Item0#muc_item{jid = RealJID};
 +                       false -> Item0
 +                   end,
 +            Status110 = case IsSelfPresence of
 +                            true -> [110];
 +                            false -> []
                          end,
 -                        if SendNewAvailable ->
 -                                send_wrapped(jid:replace_resource(StateData#state.jid,
 -                                                                  Nick),
 -                                             Info#user.jid, Packet2,
 -                                             ?NS_MUCSUB_NODES_PRESENCE,
 -                                             StateData);
 -                           true -> ok
 -                        end;
 -                    (_) ->
 -                        ok
 -                end,
 +            Packet1 = #presence{
 +                         type = unavailable,
 +                         sub_els = [#muc_user{
 +                                       items = [Item#muc_item{nick = Nick}],
 +                                       status_codes = [303|Status110]}]},
 +            Packet2 = xmpp:set_subtag(Presence,
 +                                      #muc_user{items = [Item],
 +                                                status_codes = Status110}),
 +            if SendOldUnavailable ->
 +                    send_wrapped(
 +                      jid:replace_resource(StateData#state.jid, OldNick),
 +                      Info#user.jid, Packet1, ?NS_MUCSUB_NODES_PRESENCE,
 +                      StateData);
 +               true -> ok
 +            end,
 +            if SendNewAvailable ->
 +                    send_wrapped(
 +                      jid:replace_resource(StateData#state.jid, Nick),
 +                      Info#user.jid, Packet2, ?NS_MUCSUB_NODES_PRESENCE,
 +                      StateData);
 +               true -> ok
 +            end;
 +       (_) ->
 +            ok
 +      end,
-       (?DICT):to_list(StateData#state.users)).
+                 ?DICT:to_list(get_users_and_subscribers(StateData))).
  
 +-spec maybe_send_affiliation(jid(), affiliation(), state()) -> ok.
  maybe_send_affiliation(JID, Affiliation, StateData) ->
      LJID = jid:tolower(JID),
+     Users = get_users_and_subscribers(StateData),
      IsOccupant = case LJID of
                   {LUser, LServer, <<"">>} ->
                       not (?DICT):is_empty(
        true ->
          ok; % The new affiliation is published via presence.
        false ->
 -        send_affiliation(LJID, Affiliation, StateData)
 +        send_affiliation(JID, Affiliation, StateData)
      end.
  
 -send_affiliation(LJID, Affiliation, StateData) ->
 -    ItemAttrs = [{<<"jid">>, jid:to_string(LJID)},
 -               {<<"affiliation">>, affiliation_to_list(Affiliation)},
 -               {<<"role">>, <<"none">>}],
 -    Message = #xmlel{name = <<"message">>,
 -                   attrs = [{<<"id">>, randoms:get_string()}],
 -                   children =
 -                       [#xmlel{name = <<"x">>,
 -                               attrs = [{<<"xmlns">>, ?NS_MUC_USER}],
 -                               children =
 -                                   [#xmlel{name = <<"item">>,
 -                                           attrs = ItemAttrs}]}]},
 +-spec send_affiliation(jid(), affiliation(), state()) -> ok.
 +send_affiliation(JID, Affiliation, StateData) ->
 +    Item = #muc_item{jid = JID,
 +                   affiliation = Affiliation,
 +                   role = none},
 +    Message = #message{id = randoms:get_string(),
 +                     sub_els = [#muc_user{items = [Item]}]},
+     Users = get_users_and_subscribers(StateData),
      Recipients = case (StateData#state.config)#config.anonymous of
                   true ->
                       (?DICT):filter(fun(_, #user{role = moderator}) ->
                                              true;
                                         (_, _) ->
                                              false
-                                     end, StateData#state.users);
+                                     end, Users);
                   false ->
-                      StateData#state.users
+                      Users
                 end,
-     send_multiple(StateData#state.jid,
-                 StateData#state.server_host,
-                 Recipients, Message).
+     send_wrapped_multiple(StateData#state.jid, Recipients, Message,
+                         ?NS_MUCSUB_NODES_AFFILIATIONS, StateData).
  
 -status_els(IsInitialPresence, JID, #user{jid = JID}, StateData) ->
 -    Status = case IsInitialPresence of
 -             true ->
 -                 S1 = case StateData#state.just_created of
 -                        true ->
 -                            [#xmlel{name = <<"status">>,
 -                                    attrs = [{<<"code">>, <<"201">>}],
 -                                    children = []}];
 -                        false -> []
 -                      end,
 -                 S2 = case (StateData#state.config)#config.anonymous of
 -                        true -> S1;
 -                        false ->
 -                            [#xmlel{name = <<"status">>,
 -                                    attrs = [{<<"code">>, <<"100">>}],
 -                                    children = []} | S1]
 -                      end,
 -                 S3 = case (StateData#state.config)#config.logging of
 -                        true ->
 -                            [#xmlel{name = <<"status">>,
 -                                    attrs = [{<<"code">>, <<"170">>}],
 -                                    children = []} | S2];
 -                        false -> S2
 -                      end,
 -                 S3;
 -             false -> []
 -           end,
 -    [#xmlel{name = <<"status">>,
 -          attrs =
 -              [{<<"code">>,
 -                <<"110">>}],
 -          children = []} | Status];
 -status_els(_IsInitialPresence, _JID, _Info, _StateData) -> [].
 +-spec status_codes(boolean(), boolean(), state()) -> [pos_integer()].
 +status_codes(IsInitialPresence, _IsSelfPresence = true, StateData) ->
 +    S0 = [110],
 +    case IsInitialPresence of
 +      true ->
 +          S1 = case StateData#state.just_created of
 +                   true -> [201|S0];
 +                   false -> S0
 +               end,
 +          S2 = case (StateData#state.config)#config.anonymous of
 +                   true -> S1;
 +                   false -> [100|S1]
 +               end,
 +          S3 = case (StateData#state.config)#config.logging of
 +                   true -> [170|S2];
 +                   false -> S2
 +               end,
 +          S3;
 +      false -> S0
 +    end;
 +status_codes(_IsInitialPresence, _IsSelfPresence = false, _StateData) -> [].
  
 +-spec lqueue_new(non_neg_integer()) -> lqueue().
  lqueue_new(Max) ->
      #lqueue{queue = queue:new(), len = 0, max = Max}.
  
@@@ -2445,18 -2816,16 +2499,18 @@@ send_subject(JID, #state{subject_autho
      ejabberd_router:route(jid:replace_resource(StateData#state.jid, Nick), JID,
                          Packet).
  
 -check_subject(Packet) ->
 -    case fxml:get_subtag(Packet, <<"subject">>) of
 -      false -> false;
 -      SubjEl -> fxml:get_tag_cdata(SubjEl)
 -    end.
 +-spec check_subject(message()) -> false | binary().
 +check_subject(#message{subject = [_|_] = Subj, body = [],
 +                     thread = undefined}) ->
 +    xmpp:get_text(Subj);
 +check_subject(_) ->
 +    false.
  
- -spec can_change_subject(role(), state()) -> boolean().
- can_change_subject(Role, StateData) ->
++-spec can_change_subject(role(), boolean(), state()) -> boolean().
+ can_change_subject(Role, IsSubscriber, StateData) ->
      case (StateData#state.config)#config.allow_change_subj
        of
-       true -> Role == moderator orelse Role == participant;
+       true -> Role == moderator orelse Role == participant orelse IsSubscriber == true;
        _ -> Role == moderator
      end.
  
@@@ -2899,44 -3353,72 +2953,44 @@@ send_kickban_presence1(MJID, UJID, Reas
      {ok, #user{jid = RealJID, nick = Nick}} =
        (?DICT):find(jid:tolower(UJID),
                     StateData#state.users),
 -    SAffiliation = affiliation_to_list(Affiliation),
 -    BannedJIDString = jid:to_string(RealJID),
      ActorNick = get_actor_nick(MJID, StateData),
 -    lists:foreach(fun ({_LJID, Info}) ->
 -                        JidAttrList = case Info#user.role == moderator orelse
 -                                             (StateData#state.config)#config.anonymous
 -                                               == false
 -                                          of
 -                                        true ->
 -                                            [{<<"jid">>, BannedJIDString}];
 -                                        false -> []
 -                                      end,
 -                        ItemAttrs = [{<<"affiliation">>, SAffiliation},
 -                                     {<<"role">>, <<"none">>}]
 -                                      ++ JidAttrList,
 -                        ItemEls = case Reason of
 -                                    <<"">> -> [];
 -                                    _ ->
 -                                        [#xmlel{name = <<"reason">>,
 -                                                attrs = [],
 -                                                children =
 -                                                    [{xmlcdata, Reason}]}]
 -                                  end,
 -                        ItemElsActor = case MJID of
 -                                         <<"">> -> [];
 -                                         _ -> [#xmlel{name = <<"actor">>,
 -                                              attrs =
 -                                                  [{<<"nick">>, ActorNick}]}]
 -                                  end,
 -                        Packet = #xmlel{name = <<"presence">>,
 -                                        attrs =
 -                                            [{<<"type">>, <<"unavailable">>}],
 -                                        children =
 -                                            [#xmlel{name = <<"x">>,
 -                                                    attrs =
 -                                                        [{<<"xmlns">>,
 -                                                          ?NS_MUC_USER}],
 -                                                    children =
 -                                                        [#xmlel{name =
 -                                                                    <<"item">>,
 -                                                                attrs =
 -                                                                    ItemAttrs,
 -                                                                children =
 -                                                                     ItemElsActor ++  ItemEls},
 -                                                         #xmlel{name =
 -                                                                    <<"status">>,
 -                                                                attrs =
 -                                                                    [{<<"code">>,
 -                                                                      Code}],
 -                                                                children =
 -                                                                    []}]}]},
 -                        RoomJIDNick = jid:replace_resource(
 -                                        StateData#state.jid, Nick),
 -                        send_wrapped(RoomJIDNick, Info#user.jid, Packet,
 -                                     ?NS_MUCSUB_NODES_AFFILIATIONS, StateData),
 +    lists:foreach(
 +      fun({LJID, Info}) ->
 +            IsSelfPresence = jid:tolower(UJID) == LJID,
 +            Item0 = #muc_item{affiliation = Affiliation,
 +                              role = none},
 +            Item1 = case Info#user.role == moderator orelse
 +                        (StateData#state.config)#config.anonymous
 +                        == false orelse IsSelfPresence of
 +                        true -> Item0#muc_item{jid = RealJID};
 +                        false -> Item0
 +                    end,
 +            Item2 = Item1#muc_item{reason = Reason},
 +            Item = case ActorNick of
 +                       <<"">> -> Item2;
 +                       _ -> Item2#muc_item{actor = #muc_actor{nick = ActorNick}}
 +                   end,
 +            Codes = if IsSelfPresence -> [110, Code];
 +                       true -> [Code]
 +                    end,
 +            Packet = #presence{type = unavailable,
 +                               sub_els = [#muc_user{items = [Item],
 +                                                    status_codes = Codes}]},
 +            RoomJIDNick = jid:replace_resource(StateData#state.jid, Nick),
 +            send_wrapped(RoomJIDNick, Info#user.jid, Packet,
 +                         ?NS_MUCSUB_NODES_AFFILIATIONS, StateData),
-             IsSubscriber = Info#user.is_subscriber,
+                         IsSubscriber = is_subscriber(Info#user.jid, StateData),
 -                        IsOccupant = Info#user.last_presence /= undefined,
 -                        if (IsSubscriber and not IsOccupant) ->
 -                                send_wrapped(RoomJIDNick, Info#user.jid, Packet,
 -                                             ?NS_MUCSUB_NODES_PARTICIPANTS, StateData);
 -                           true ->
 -                                ok
 -                        end
 -                end,
 +            IsOccupant = Info#user.last_presence /= undefined,
 +            if (IsSubscriber and not IsOccupant) ->
 +                    send_wrapped(RoomJIDNick, Info#user.jid, Packet,
 +                                 ?NS_MUCSUB_NODES_PARTICIPANTS, StateData);
 +               true ->
 +                    ok
 +            end
 +      end,
-       (?DICT):to_list(StateData#state.users)).
+                 (?DICT):to_list(get_users_and_subscribers(StateData))).
  
 +-spec get_actor_nick(binary() | jid(), state()) -> binary().
  get_actor_nick(<<"">>, _StateData) ->
      <<"">>;
  get_actor_nick(MJID, StateData) ->
@@@ -3291,25 -4233,25 +3345,25 @@@ send_config_change_info(New, #state{con
              end
                ++
                case Old#config{anonymous = New#config.anonymous,
 +                              vcard = New#config.vcard,
                                logging = New#config.logging} of
                  New -> [];
 -                _ -> [<<"104">>]
 +                _ -> [104]
                end,
 -    StatusEls = [#xmlel{name = <<"status">>,
 -                      attrs = [{<<"code">>, Code}],
 -                      children = []} || Code <- Codes],
 -    Message = #xmlel{name = <<"message">>,
 -                   attrs = [{<<"type">>, <<"groupchat">>},
 -                            {<<"id">>, randoms:get_string()}],
 -                   children = [#xmlel{name = <<"x">>,
 -                                      attrs = [{<<"xmlns">>, ?NS_MUC_USER}],
 -                                      children = StatusEls}]},
 -    send_wrapped_multiple(StateData#state.jid,
 +    if Codes /= [] ->
 +          Message = #message{type = groupchat,
 +                             id = randoms:get_string(),
 +                             sub_els = [#muc_user{status_codes = Codes}]},
 +          send_wrapped_multiple(StateData#state.jid,
-                                 StateData#state.users,
+                         get_users_and_subscribers(StateData),
 -                        Message,
 -                        ?NS_MUCSUB_NODES_CONFIG,
 -                        StateData).
 +                                Message,
 +                                ?NS_MUCSUB_NODES_CONFIG,
 +                                StateData);
 +       true ->
 +          ok
 +    end.
  
 +-spec remove_nonmembers(state()) -> state().
  remove_nonmembers(StateData) ->
      lists:foldl(fun ({_LJID, #user{jid = JID}}, SD) ->
                        Affiliation = get_affiliation(JID, SD),
                          _ -> SD
                        end
                end,
-               StateData, (?DICT):to_list(StateData#state.users)).
+               StateData, (?DICT):to_list(get_users_and_subscribers(StateData))).
  
 +-spec set_opts([{atom(), any()}], state()) -> state().
  set_opts([], StateData) -> StateData;
  set_opts([{Opt, Val} | Opts], StateData) ->
      NSD = case Opt of
  make_opts(StateData) ->
      Config = StateData#state.config,
      Subscribers = (?DICT):fold(
-                   fun(_LJID, #user{is_subscriber = true} = User, Acc) ->
-                           [{User#user.jid, User#user.nick,
-                             User#user.subscriptions}|Acc];
-                      (_, _, Acc) ->
-                           Acc
-                   end, [], StateData#state.users),
+                   fun(_LJID, Sub, Acc) ->
+                           [{Sub#subscriber.jid,
+                             Sub#subscriber.nick,
+                             Sub#subscriber.nodes}|Acc]
+                   end, [], StateData#state.subscribers),
 -    [?MAKE_CONFIG_OPT(title), ?MAKE_CONFIG_OPT(description),
 -     ?MAKE_CONFIG_OPT(allow_change_subj),
 -     ?MAKE_CONFIG_OPT(allow_query_users),
 -     ?MAKE_CONFIG_OPT(allow_private_messages),
 -     ?MAKE_CONFIG_OPT(allow_private_messages_from_visitors),
 -     ?MAKE_CONFIG_OPT(allow_visitor_status),
 -     ?MAKE_CONFIG_OPT(allow_visitor_nickchange),
 -     ?MAKE_CONFIG_OPT(public), ?MAKE_CONFIG_OPT(public_list),
 -     ?MAKE_CONFIG_OPT(persistent),
 -     ?MAKE_CONFIG_OPT(moderated),
 -     ?MAKE_CONFIG_OPT(members_by_default),
 -     ?MAKE_CONFIG_OPT(members_only),
 -     ?MAKE_CONFIG_OPT(allow_user_invites),
 -     ?MAKE_CONFIG_OPT(password_protected),
 -     ?MAKE_CONFIG_OPT(captcha_protected),
 -     ?MAKE_CONFIG_OPT(password), ?MAKE_CONFIG_OPT(anonymous),
 -     ?MAKE_CONFIG_OPT(logging), ?MAKE_CONFIG_OPT(max_users),
 -     ?MAKE_CONFIG_OPT(allow_voice_requests),
 -     ?MAKE_CONFIG_OPT(allow_subscription),
 -     ?MAKE_CONFIG_OPT(mam),
 -     ?MAKE_CONFIG_OPT(voice_request_min_interval),
 -     ?MAKE_CONFIG_OPT(vcard),
 +    [?MAKE_CONFIG_OPT(#config.title), ?MAKE_CONFIG_OPT(#config.description),
 +     ?MAKE_CONFIG_OPT(#config.allow_change_subj),
 +     ?MAKE_CONFIG_OPT(#config.allow_query_users),
 +     ?MAKE_CONFIG_OPT(#config.allow_private_messages),
 +     ?MAKE_CONFIG_OPT(#config.allow_private_messages_from_visitors),
 +     ?MAKE_CONFIG_OPT(#config.allow_visitor_status),
 +     ?MAKE_CONFIG_OPT(#config.allow_visitor_nickchange),
 +     ?MAKE_CONFIG_OPT(#config.public), ?MAKE_CONFIG_OPT(#config.public_list),
 +     ?MAKE_CONFIG_OPT(#config.persistent),
 +     ?MAKE_CONFIG_OPT(#config.moderated),
 +     ?MAKE_CONFIG_OPT(#config.members_by_default),
 +     ?MAKE_CONFIG_OPT(#config.members_only),
 +     ?MAKE_CONFIG_OPT(#config.allow_user_invites),
 +     ?MAKE_CONFIG_OPT(#config.password_protected),
 +     ?MAKE_CONFIG_OPT(#config.captcha_protected),
 +     ?MAKE_CONFIG_OPT(#config.password), ?MAKE_CONFIG_OPT(#config.anonymous),
 +     ?MAKE_CONFIG_OPT(#config.logging), ?MAKE_CONFIG_OPT(#config.max_users),
 +     ?MAKE_CONFIG_OPT(#config.allow_voice_requests),
++     ?MAKE_CONFIG_OPT(#config.allow_subscription),
 +     ?MAKE_CONFIG_OPT(#config.mam),
 +     ?MAKE_CONFIG_OPT(#config.voice_request_min_interval),
 +     ?MAKE_CONFIG_OPT(#config.vcard),
       {captcha_whitelist,
        (?SETS):to_list((StateData#state.config)#config.captcha_whitelist)},
       {affiliations,
       {subject_author, StateData#state.subject_author},
       {subscribers, Subscribers}].
  
 +-spec destroy_room(muc_destroy(), state()) -> {result, undefined, stop}.
  destroy_room(DEl, StateData) ->
 -    lists:foreach(fun ({_LJID, Info}) ->
 -                        Nick = Info#user.nick,
 -                        ItemAttrs = [{<<"affiliation">>, <<"none">>},
 -                                     {<<"role">>, <<"none">>}],
 -                        Packet = #xmlel{name = <<"presence">>,
 -                                        attrs =
 -                                            [{<<"type">>, <<"unavailable">>}],
 -                                        children =
 -                                            [#xmlel{name = <<"x">>,
 -                                                    attrs =
 -                                                        [{<<"xmlns">>,
 -                                                          ?NS_MUC_USER}],
 -                                                    children =
 -                                                        [#xmlel{name =
 -                                                                    <<"item">>,
 -                                                                attrs =
 -                                                                    ItemAttrs,
 -                                                                children =
 -                                                                    []},
 -                                                         DEl]}]},
 -                        send_wrapped(jid:replace_resource(StateData#state.jid,
 -                                                          Nick),
 -                                     Info#user.jid, Packet,
 -                                     ?NS_MUCSUB_NODES_CONFIG, StateData)
 -                end,
 +    Destroy = DEl#muc_destroy{xmlns = ?NS_MUC_USER},
 +    lists:foreach(
 +      fun({_LJID, Info}) ->
 +            Nick = Info#user.nick,
 +            Item = #muc_item{affiliation = none,
 +                             role = none},
 +            Packet = #presence{
 +                        type = unavailable,
 +                        sub_els = [#muc_user{items = [Item],
 +                                             destroy = Destroy}]},
 +            send_wrapped(jid:replace_resource(StateData#state.jid, Nick),
 +                         Info#user.jid, Packet,
 +                         ?NS_MUCSUB_NODES_CONFIG, StateData)
 +      end,
-       (?DICT):to_list(StateData#state.users)),
+                 (?DICT):to_list(get_users_and_subscribers(StateData))),
      case (StateData#state.config)#config.persistent of
        true ->
          mod_muc:forget_room(StateData#state.server_host,
@@@ -3640,84 -4618,89 +3697,83 @@@ process_iq_vcard(From, #iq{type = set, 
            change_config(NewConfig, StateData);
        _ ->
            ErrText = <<"Owner privileges required">>,
 -          {error, ?ERRT_FORBIDDEN(Lang, ErrText)}
 -    end.
 -
 -process_iq_mucsub(From, Packet,
 +          {error, xmpp:err_forbidden(ErrText, Lang)}
 +    end.
 +
 +-spec process_iq_mucsub(jid(), iq(), state()) ->
 +                             {error, stanza_error()} |
 +                             {result, undefined | muc_subscribe(), state()} |
 +                             {ignore, state()}.
 +process_iq_mucsub(_From, #iq{type = set, lang = Lang,
 +                           sub_els = [#muc_subscribe{}]},
 +                #state{config = #config{allow_subscription = false}}) ->
 +    {error, xmpp:err_not_allowed(<<"Subscriptions are not allowed">>, Lang)};
 +process_iq_mucsub(From,
                  #iq{type = set, lang = Lang,
 -                    sub_el = #xmlel{name = <<"subscribe">>} = SubEl},
 -                #state{config = Config} = StateData) ->
 -    case fxml:get_tag_attr_s(<<"nick">>, SubEl) of
 -      <<"">> ->
 -          Err = ?ERRT_BAD_REQUEST(Lang, <<"Missing 'nick' attribute">>),
 -          {error, Err};
 -      Nick when Config#config.allow_subscription ->
 -          LBareJID = jid:tolower(jid:remove_resource(From)),
 -          case (?DICT):find(LBareJID, StateData#state.subscribers) of
 -              {ok, #subscriber{nick = Nick1}} when Nick1 /= Nick ->
 -                  Nodes = get_subscription_nodes(Packet),
 -                  case {nick_collision(From, Nick, StateData),
 -                        mod_muc:can_use_nick(StateData#state.server_host,
 -                                             StateData#state.host,
 -                                             From, Nick)} of
 -                      {true, _} ->
 -                          ErrText = <<"That nickname is already in use by another occupant">>,
 -                          {error, ?ERRT_CONFLICT(Lang, ErrText)};
 -                      {_, false} ->
 -                          ErrText = <<"That nickname is registered by another person">>,
 -                          {error, ?ERRT_CONFLICT(Lang, ErrText)};
 -                      _ ->
 -                          NewStateData = set_subscriber(From, Nick, Nodes, StateData),
 -                          {result, subscription_nodes_to_events(Nodes), NewStateData}
 -                  end;
 -              {ok, #subscriber{}} ->
 -                  Nodes = get_subscription_nodes(Packet),
 +                    sub_els = [#muc_subscribe{nick = Nick}]} = Packet,
 +                StateData) ->
-     LJID = jid:tolower(From),
-     case (?DICT):find(LJID, StateData#state.users) of
-       {ok, #user{role = Role, nick = Nick1}} when Nick1 /= Nick ->
++    LBareJID = jid:tolower(jid:remove_resource(From)),
++    case (?DICT):find(LBareJID, StateData#state.subscribers) of
++      {ok, #subscriber{nick = Nick1}} when Nick1 /= Nick ->
 +          Nodes = get_subscription_nodes(Packet),
 +          case {nick_collision(From, Nick, StateData),
 +                mod_muc:can_use_nick(StateData#state.server_host,
 +                                     StateData#state.host,
 +                                     From, Nick)} of
 +              {true, _} ->
 +                  ErrText = <<"That nickname is already in use by another occupant">>,
 +                  {error, xmpp:err_conflict(ErrText, Lang)};
 +              {_, false} ->
 +                  ErrText = <<"That nickname is registered by another person">>,
 +                  {error, xmpp:err_conflict(ErrText, Lang)};
 +              _ ->
-                   NewStateData = add_online_user(
-                                    From, Nick, Role, true, Nodes, StateData),
+                   NewStateData = set_subscriber(From, Nick, Nodes, StateData),
 -                  {result, subscription_nodes_to_events(Nodes), NewStateData};
 -              error ->
 -                  add_new_user(From, Nick, Packet, StateData)
 +                  {result, subscribe_result(Packet), NewStateData}
            end;
-       {ok, #user{role = Role}} ->
 -      _ ->
 -          Err = ?ERRT_NOT_ALLOWED(Lang, <<"Subscriptions are not allowed">>),
 -          {error, Err}
++      {ok, #subscriber{}} ->
 +          Nodes = get_subscription_nodes(Packet),
-           NewStateData = add_online_user(
-                            From, Nick, Role, true, Nodes, StateData),
++          NewStateData = set_subscriber(From, Nick, Nodes, StateData),
 +          {result, subscribe_result(Packet), NewStateData};
 +      error ->
 +          add_new_user(From, Nick, Packet, StateData)
      end;
 -process_iq_mucsub(From, _Packet,
 -                #iq{type = set,
 -                    sub_el = #xmlel{name = <<"unsubscribe">>}},
 +process_iq_mucsub(From, #iq{type = set, sub_els = [#muc_unsubscribe{}]},
                  StateData) ->
-     LJID = jid:tolower(From),
-     case ?DICT:find(LJID, StateData#state.users) of
-       {ok, #user{is_subscriber = true} = User} ->
-           NewStateData = remove_subscription(From, User, StateData),
+     LBareJID = jid:tolower(jid:remove_resource(From)),
+     case ?DICT:find(LBareJID, StateData#state.subscribers) of
+       {ok, #subscriber{nick = Nick}} ->
+           Nicks = ?DICT:erase(Nick, StateData#state.subscriber_nicks),
+           Subscribers = ?DICT:erase(LBareJID, StateData#state.subscribers),
+           NewStateData = StateData#state{subscribers = Subscribers,
+                                          subscriber_nicks = Nicks},
            store_room(NewStateData),
 -          {result, [], NewStateData};
 -      error ->
 -          {result, [], StateData}
 +          {result, undefined, NewStateData};
 +      _ ->
 +          {result, undefined, StateData}
      end;
 -process_iq_mucsub(From, _Packet,
 -                #iq{type = get, lang = Lang,
 -                    sub_el = #xmlel{name = <<"subscriptions">>}},
++process_iq_mucsub(From, #iq{type = get, lang = Lang,
++                          sub_els = [#muc_subscriptions{}]},
+                 StateData) ->
+     FAffiliation = get_affiliation(From, StateData),
+     FRole = get_role(From, StateData),
+     if FRole == moderator; FAffiliation == owner; FAffiliation == admin ->
 -          Subs = dict:fold(
++          JIDs = dict:fold(
+                    fun(_, #subscriber{jid = J}, Acc) ->
 -                           SJID = jid:to_string(J),
 -                           [#xmlel{name = <<"subscription">>,
 -                                   attrs = [{<<"jid">>, SJID}]}|Acc]
++                           [J|Acc]
+                    end, [], StateData#state.subscribers),
 -          {result, Subs, StateData};
++          {result, #muc_subscriptions{list = JIDs}, StateData};
+        true ->
+           Txt = <<"Moderator privileges required">>,
 -          {error, ?ERRT_FORBIDDEN(Lang, Txt)}
++          {error, xmpp:err_forbidden(Txt, Lang)}
+     end;
 -process_iq_mucsub(_From, _Packet, #iq{lang = Lang}, _StateData) ->
 -    Txt = <<"Unrecognized subscription command">>,
 -    {error, ?ERRT_BAD_REQUEST(Lang, Txt)}.
 +process_iq_mucsub(_From, #iq{type = get, lang = Lang}, _StateData) ->
 +    Txt = <<"Value 'get' of 'type' attribute is not allowed">>,
 +    {error, xmpp:err_bad_request(Txt, Lang)}.
  
- -spec remove_subscription(jid(), #user{}, state()) -> state().
- remove_subscription(JID, #user{is_subscriber = true} = User, StateData) ->
-     case User#user.last_presence of
-       undefined ->
-           remove_online_user(JID, StateData, false);
-       _ ->
-           LJID = jid:tolower(JID),
-           Users = ?DICT:store(LJID, User#user{is_subscriber = false},
-                               StateData#state.users),
-           StateData#state{users = Users}
-     end;
- remove_subscription(_JID, #user{}, StateData) ->
-     StateData.
- -spec remove_subscriptions(state()) -> state().
  remove_subscriptions(StateData) ->
      if not (StateData#state.config)#config.allow_subscription ->
-           dict:fold(
-             fun(_LJID, User, State) ->
-                     remove_subscription(User#user.jid, User, State)
-             end, StateData, StateData#state.users);
+           StateData#state{subscribers = ?DICT:new(),
+                           subscriber_nicks = ?DICT:new()};
         true ->
            StateData
      end.
@@@ -3954,44 -5185,52 +4010,49 @@@ store_room(StateData) -
            ok
      end.
  
 +-spec send_wrapped(jid(), jid(), stanza(), binary(), state()) -> ok.
  send_wrapped(From, To, Packet, Node, State) ->
      LTo = jid:tolower(To),
-     case ?DICT:find(LTo, State#state.users) of
-       {ok, #user{is_subscriber = true,
-                  subscriptions = Nodes,
-                  last_presence = undefined}} ->
+     LBareTo = jid:tolower(jid:remove_resource(To)),
+     IsOffline = case ?DICT:find(LTo, State#state.users) of
+                   {ok, #user{last_presence = undefined}} -> true;
+                   error -> true;
+                   _ -> false
+               end,
+     if IsOffline ->
+           case ?DICT:find(LBareTo, State#state.subscribers) of
+               {ok, #subscriber{nodes = Nodes, jid = JID}} ->
 -                  case lists:member(Node, Nodes) of
 -                      true ->
 +          case lists:member(Node, Nodes) of
 +              true ->
-                   NewPacket = wrap(From, To, Packet, Node),
-                   ejabberd_router:route(State#state.jid, To, NewPacket);
+                           NewPacket = wrap(From, JID, Packet, Node),
+                           ejabberd_router:route(State#state.jid, JID, NewPacket);
 -                      false ->
 -                          ok
 -                  end;
 -              _ ->
 +              false ->
 +                  ok
 +          end;
 +      _ ->
+                   ok
+           end;
+        true ->
            ejabberd_router:route(From, To, Packet)
      end.
  
 +-spec wrap(jid(), jid(), stanza(), binary()) -> message().
  wrap(From, To, Packet, Node) ->
 -    Pkt1 = jlib:replace_from_to(From, To, Packet),
 -    Pkt2 = #xmlel{attrs = Attrs} = jlib:remove_attr(<<"xmlns">>, Pkt1),
 -    Pkt3 = Pkt2#xmlel{attrs = [{<<"xmlns">>, <<"jabber:client">>}|Attrs]},
 -    Item = #xmlel{name = <<"item">>,
 -                attrs = [{<<"id">>, randoms:get_string()}],
 -                children = [Pkt3]},
 -    Items = #xmlel{name = <<"items">>, attrs = [{<<"node">>, Node}],
 -                 children = [Item]},
 -    Event = #xmlel{name = <<"event">>,
 -                 attrs = [{<<"xmlns">>, ?NS_PUBSUB_EVENT}],
 -                 children = [Items]},
 -    #xmlel{name = <<"message">>, children = [Event]}.
 -
 -%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
 -%% Multicast
 -
 +    El = xmpp:encode(xmpp:set_from_to(Packet, From, To)),
 +    #message{
 +       sub_els = [#ps_event{
 +                   items = #ps_items{
 +                              node = Node,
 +                              items = [#ps_item{
 +                                          id = randoms:get_string(),
 +                                          xml_els = [El]}]}}]}.
 +
- %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
- %% Multicast
- -spec send_multiple(jid(), binary(), [#user{}], stanza()) -> ok.
- send_multiple(From, Server, Users, Packet) ->
-     JIDs = [ User#user.jid || {_, User} <- ?DICT:to_list(Users)],
-     ejabberd_router_multicast:route_multicast(From, Server, JIDs, Packet).
++%% -spec send_multiple(jid(), binary(), [#user{}], stanza()) -> ok.
+ %% send_multiple(From, Server, Users, Packet) ->
+ %%     JIDs = [ User#user.jid || {_, User} <- ?DICT:to_list(Users)],
+ %%     ejabberd_router_multicast:route_multicast(From, Server, JIDs, Packet).
  
 +-spec send_wrapped_multiple(jid(), [#user{}], stanza(), binary(), state()) -> ok.
  send_wrapped_multiple(From, Users, Packet, Node, State) ->
      lists:foreach(
        fun({_, #user{jid = To}}) ->
index 6134823c110209e76f81fee97d4cdbfb405c5b29,1d9417117df6715baecea700ea585894176f025d..dfe3c9e8e1245247a078370f189322944e30102c
@@@ -450,12 -458,12 +450,12 @@@ need_to_store(LServer, #message{type = 
                              (unless_chat_state) -> unless_chat_state
                           end,
                           unless_chat_state) of
+                       true ->
+                           true;
                        false ->
 -                          fxml:get_subtag(Packet, <<"body">>) /= false;
 +                          Packet#message.body /= [];
                        unless_chat_state ->
-                           not xmpp_util:is_standalone_chat_state(Packet);
-                       true ->
-                           true
 -                          not jlib:is_standalone_chat_state(Packet)
++                          not xmpp_util:is_standalone_chat_state(Packet)
                    end
            end;
        true ->
@@@ -469,14 -476,22 +469,20 @@@ store_packet(From, To, Packet) -
            case check_event(From, To, Packet) of
                true ->
                    #jid{luser = LUser, lserver = LServer} = To,
-                   TimeStamp = p1_time_compat:timestamp(),
-                   Expire = find_x_expire(TimeStamp, Packet),
-                   El = xmpp:encode(Packet),
-                   gen_mod:get_module_proc(To#jid.lserver, ?PROCNAME) !
-                     #offline_msg{us = {LUser, LServer},
-                                  timestamp = TimeStamp, expire = Expire,
-                                  from = From, to = To, packet = El},
-                   stop;
+                   case ejabberd_hooks:run_fold(store_offline_message, LServer,
+                                                Packet, [From, To]) of
+                       drop ->
+                           ok;
+                       NewPacket ->
+                           TimeStamp = p1_time_compat:timestamp(),
 -                          #xmlel{children = Els} = NewPacket,
 -                          Expire = find_x_expire(TimeStamp, Els),
++                          Expire = find_x_expire(TimeStamp, NewPacket),
++                          El = xmpp:encode(NewPacket),
+                           gen_mod:get_module_proc(To#jid.lserver, ?PROCNAME) !
 -                            #offline_msg{us = {LUser, LServer},
 -                                         timestamp = TimeStamp,
 -                                         expire = Expire,
 -                                         from = From, to = To,
 -                                         packet = NewPacket},
++                              #offline_msg{us = {LUser, LServer},
++                                           timestamp = TimeStamp, expire = Expire,
++                                           from = From, to = To, packet = El},
+                           stop
+                   end;
                _ -> ok
            end;
        false -> ok
Simple merge
Simple merge
index 0000000000000000000000000000000000000000,af6dacec40326958ae83081f2391ecc0ccf1dd46..50212b7aeb92138304fda9bfe048c6818cfb4f55
mode 000000,100644..100644
--- /dev/null
@@@ -1,0 -1,363 +1,348 @@@
 -%%%--------------------------------------------------------------------------------------
 -%%% File    : mod_privilege.erl
 -%%% Author  : Anna Mukharram <amuhar3@gmail.com>
 -%%% Purpose : This module is an implementation for XEP-0356: Privileged Entity
 -%%%--------------------------------------------------------------------------------------
 -
++%%%-------------------------------------------------------------------
++%%% @author Evgeny Khramtsov <ekhramtsov@process-one.net>
++%%% @copyright (C) 2016, Evgeny Khramtsov
++%%% @doc
++%%%
++%%% @end
++%%% Created : 11 Nov 2016 by Evgeny Khramtsov <ekhramtsov@process-one.net>
++%%%-------------------------------------------------------------------
+ -module(mod_privilege).
 --author('amuhar3@gmail.com').
++-behaviour(gen_server).
++-behaviour(gen_mod).
 --protocol({xep, 0356, '0.2.1'}).
++%% API
++-export([start_link/2]).
++-export([start/2, stop/1, mod_opt_type/1, depends/2]).
++%% gen_server callbacks
++-export([init/1, handle_call/3, handle_cast/2, handle_info/2,
++       terminate/2, code_change/3]).
++-export([component_connected/1, component_disconnected/2,
++       roster_access/2, process_message/3,
++       process_presence_out/4, process_presence_in/5]).
 --export([advertise_permissions/1, initial_presences/1, process_presence/1, 
 -         process_roster_presence/1, compare_presences/2,
 -         process_message/4, process_iq/4]).
++-include("ejabberd.hrl").
++-include("logger.hrl").
++-include("xmpp.hrl").
 --include("ejabberd_service.hrl").
++-record(state, {server_host = <<"">> :: binary(),
++              permissions = dict:new() :: ?TDICT}).
 --include("mod_privacy.hrl").
++%%%===================================================================
++%%% API
++%%%===================================================================
++start_link(Host, Opts) ->
++    Proc = gen_mod:get_module_proc(Host, ?MODULE),
++    gen_server:start_link({local, Proc}, ?MODULE, [Host, Opts], []).
 -%%%--------------------------------------------------------------------------------------
 -%%% Functions to advertise services of allowed permission
 -%%%--------------------------------------------------------------------------------------
++start(Host, Opts) ->
++    Proc = gen_mod:get_module_proc(Host, ?MODULE),
++    PingSpec = {Proc, {?MODULE, start_link, [Host, Opts]},
++                transient, 2000, worker, [?MODULE]},
++    supervisor:start_child(ejabberd_sup, PingSpec).
 --spec permissions(binary(), binary(), list()) -> xmlel().
++stop(Host) ->
++    Proc = gen_mod:get_module_proc(Host, ?MODULE),
++    gen_server:call(Proc, stop),
++    supervisor:delete_child(ejabberd_sup, Proc).
 -permissions(From, To, PrivAccess) ->
 -    Perms = lists:map(fun({Access, Type}) ->
 -                          ?DEBUG("Advertise service ~s of allowed permission: ~s = ~s~n",
 -                                 [To, Access, Type]),
 -                          #xmlel{name = <<"perm">>, 
 -                                 attrs = [{<<"access">>, 
 -                                           atom_to_binary(Access,latin1)},
 -                                          {<<"type">>, Type}]}
 -                      end, PrivAccess),
 -    Stanza = #xmlel{name = <<"privilege">>, 
 -                    attrs = [{<<"xmlns">> ,?NS_PRIVILEGE}],
 -                    children = Perms},
 -    Id = randoms:get_string(),
 -    #xmlel{name = <<"message">>, 
 -           attrs = [{<<"id">>, Id}, {<<"from">>, From}, {<<"to">>, To}],
 -           children = [Stanza]}.
++mod_opt_type(roster) -> v_roster();
++mod_opt_type(message) -> v_message();
++mod_opt_type(presence) -> v_presence();
++mod_opt_type(_) ->
++    [roster, message, presence].
 -advertise_permissions(#state{privilege_access = []}) -> ok;
 -advertise_permissions(StateData) ->
 -    Stanza =
 -      permissions(?MYNAME, StateData#state.host, StateData#state.privilege_access),
 -    ejabberd_service:send_element(StateData, Stanza).
++depends(_, _) ->
++    [].
 -%%%--------------------------------------------------------------------------------------
 -%%%  Process presences
 -%%%--------------------------------------------------------------------------------------
++-spec component_connected(binary()) -> ok.
++component_connected(Host) ->
++    lists:foreach(
++      fun(ServerHost) ->
++            Proc = gen_mod:get_module_proc(ServerHost, ?MODULE),
++            gen_server:cast(Proc, {component_connected, Host})
++      end, ?MYHOSTS).
 -initial_presences(StateData) ->
 -    Pids = ejabberd_sm:get_all_pids(),
++-spec component_disconnected(binary(), binary()) -> ok.
++component_disconnected(Host, _Reason) ->
+     lists:foreach(
 -      fun(Pid) ->
 -          {User, Server, Resource, PresenceLast} = ejabberd_c2s:get_last_presence(Pid),
 -          From = #jid{user = User, server = Server, resource = Resource},
 -          To = jid:from_string(StateData#state.host),
 -          PacketNew = jlib:replace_from_to(From, To, PresenceLast),
 -          ejabberd_service:send_element(StateData, PacketNew)
 -      end, Pids).
++      fun(ServerHost) ->
++            Proc = gen_mod:get_module_proc(ServerHost, ?MODULE),
++            gen_server:cast(Proc, {component_disconnected, Host})
++      end, ?MYHOSTS).
 -%% hook user_send_packet(Packet, C2SState, From, To) -> Packet
 -%% for Managed Entity Presence
 -process_presence(Pid) ->
 -    fun(#xmlel{name = <<"presence">>} = Packet, _C2SState, From, _To) ->
 -          case fxml:get_attr_s(<<"type">>, Packet#xmlel.attrs) of
 -            T when (T == <<"">>) or (T == <<"unavailable">>) ->
 -              Pid ! {user_presence, Packet, From};   
 -            _ -> ok
 -          end,
 -          Packet;
 -       (Packet, _C2SState, _From, _To) ->
 -          Packet
 -    end.
 -%% s2s_receive_packet(From, To, Packet) -> ok
 -%% for Roster Presence
 -%% From subscription "from" or "both"
 -process_roster_presence(Pid) ->  
 -    fun(From, To, #xmlel{name = <<"presence">>} = Packet) ->
 -          case fxml:get_attr_s(<<"type">>, Packet#xmlel.attrs) of
 -            T when (T == <<"">>) or (T == <<"unavailable">>) ->
 -              Server = To#jid.server,
 -              User = To#jid.user,
 -              PrivList = ejabberd_hooks:run_fold(privacy_get_user_list,
 -                                                 Server, #userlist{}, [User, Server]),
 -              case privacy_check_packet(Server, User, PrivList, From, To, Packet, in) of
 -                allow ->
 -                  Pid ! {roster_presence, Packet, From};
 -                _ -> ok
 -              end,
 -              ok;
 -            _ -> ok
 -          end;
 -       (_From, _To, _Packet) -> ok
++-spec process_message(jid(), jid(), stanza()) -> stop | ok.
++process_message(#jid{luser = <<"">>, lresource = <<"">>} = From,
++              #jid{lresource = <<"">>} = To,
++              #message{lang = Lang, type = T} = Msg) when T /= error ->
++    Host = From#jid.lserver,
++    ServerHost = To#jid.lserver,
++    Permissions = get_permissions(ServerHost),
++    case dict:find(Host, Permissions) of
++      {ok, Access} ->
++          case proplists:get_value(message, Access, none) of
++              outgoing ->
++                  forward_message(From, To, Msg);
++              none ->
++                  Txt = <<"Insufficient privilege">>,
++                  Err = xmpp:err_forbidden(Txt, Lang),
++                  ejabberd_router:route_error(To, From, Msg, Err)
++          end,
++          stop;
++      error ->
++          %% Component is disconnected
++          ok
++    end;
++process_message(_From, _To, _Stanza) ->
++    ok.
++
++-spec roster_access(boolean(), iq()) -> boolean().
++roster_access(true, _) ->
++    true;
++roster_access(false, #iq{from = From, to = To, type = Type}) ->
++    Host = From#jid.lserver,
++    ServerHost = To#jid.lserver,
++    Permissions = get_permissions(ServerHost),
++    case dict:find(Host, Permissions) of
++      {ok, Access} ->
++          Permission = proplists:get_value(roster, Access, none),
++          (Permission == both)
++              orelse (Permission == get andalso Type == get)
++              orelse (Permission == set andalso Type == set);
++      error ->
++          %% Component is disconnected
++          false
+     end.
 -%%%--------------------------------------------------------------------------------------
 -%%%  Manage Roster
 -%%%--------------------------------------------------------------------------------------
++-spec process_presence_out(stanza(), ejabberd_c2s:state(), jid(), jid()) -> stanza().
++process_presence_out(#presence{type = Type} = Pres, _C2SState,
++                   #jid{luser = LUser, lserver = LServer} = From,
++                   #jid{luser = LUser, lserver = LServer, lresource = <<"">>})
++  when Type == available; Type == unavailable ->
++    %% Self-presence processing
++    Permissions = get_permissions(LServer),
++    lists:foreach(
++      fun({Host, Access}) ->
++            Permission = proplists:get_value(presence, Access, none),
++            if Permission == roster; Permission == managed_entity ->
++                    To = jid:make(Host),
++                    ejabberd_router:route(
++                      From, To, xmpp:set_from_to(Pres, From, To));
++               true ->
++                    ok
++            end
++      end, dict:to_list(Permissions)),
++    Pres;
++process_presence_out(Acc, _, _, _) ->
++    Acc.
 -process_iq(StateData, FromJID, ToJID, Packet) ->
 -    IQ = jlib:iq_query_or_response_info(Packet),
 -    case IQ of
 -      #iq{xmlns = ?NS_ROSTER} -> 
 -        case (ToJID#jid.luser /= <<"">>) and
 -             (FromJID#jid.luser == <<"">>) and
 -             lists:member(ToJID#jid.lserver, ?MYHOSTS) of
 -          true ->
 -            AccessType = 
 -              proplists:get_value(roster, StateData#state.privilege_access, none),
 -            case IQ#iq.type of
 -              get when (AccessType == <<"both">>) or (AccessType == <<"get">>) -> 
 -                RosterIQ = roster_management(ToJID, FromJID, IQ),
 -                ejabberd_service:send_element(StateData, RosterIQ);
 -              set when (AccessType == <<"both">>) or (AccessType == <<"set">>) ->
 -                %% check if user ToJID  exist
 -                #jid{lserver = Server, luser = User} = ToJID,
 -                case ejabberd_auth:is_user_exists(User,Server) of
 -                  true ->
 -                    ResIQ = roster_management(ToJID, FromJID, IQ),
 -                    ejabberd_service:send_element(StateData, ResIQ);
 -                  _ -> ok
 -                end;
 -              _ ->
 -                Err = jlib:make_error_reply(Packet, ?ERR_FORBIDDEN), 
 -                ejabberd_service:send_element(StateData, Err)
 -            end;
 -          _ ->
 -            ejabberd_router:route(FromJID, ToJID, Packet)
 -        end;
 -      #iq{type = Type, id = Id} when (Type == error) or (Type == result) -> % for XEP-0355
 -        Hook = {iq, Type, Id},
 -        Host = ToJID#jid.lserver,
 -        case (ToJID#jid.luser == <<"">>) and
 -             (FromJID#jid.luser == <<"">>) and
 -             lists:member(ToJID#jid.lserver, ?MYHOSTS) of
 -          true ->
 -            case ets:lookup(hooks_tmp, {Hook, Host}) of
 -              [{_, Function, _Timestamp}] -> 
 -                catch apply(Function, [Packet]);
 -              [] -> 
 -                ejabberd_router:route(FromJID, ToJID, Packet)
 -            end;
 -          _ ->
 -            ejabberd_router:route(FromJID, ToJID, Packet)
 -        end;
 -      _ ->
 -        ejabberd_router:route(FromJID, ToJID, Packet)
 -    end.
++-spec process_presence_in(stanza(), ejabberd_c2s:state(),
++                        jid(), jid(), jid()) -> stanza().
++process_presence_in(#presence{type = Type} = Pres, _C2SState, _,
++                  #jid{luser = U, lserver = S} = From,
++                  #jid{luser = LUser, lserver = LServer})
++  when {U, S} /= {LUser, LServer} andalso
++       (Type == available orelse Type == unavailable) ->
++    Permissions = get_permissions(LServer),
++    lists:foreach(
++      fun({Host, Access}) ->
++            case proplists:get_value(presence, Access, none) of
++                roster ->
++                    Permission = proplists:get_value(roster, Access, none),
++                    if Permission == both; Permission == get ->
++                            To = jid:make(Host),
++                            ejabberd_router:route(
++                              From, To, xmpp:set_from_to(Pres, From, To));
++                       true ->
++                            ok
++                    end;
++               true ->
++                    ok
++            end
++      end, dict:to_list(Permissions)),
++    Pres;
++process_presence_in(Acc, _, _, _, _) ->
++    Acc.
 -roster_management(FromJID, ToJID, IQ) ->
 -    ResIQ = mod_roster:process_iq(FromJID, FromJID, IQ),
 -    ResXml = jlib:iq_to_xml(ResIQ),
 -    jlib:replace_from_to(FromJID, ToJID, ResXml).
++%%%===================================================================
++%%% gen_server callbacks
++%%%===================================================================
++init([Host, _Opts]) ->
++    ejabberd_hooks:add(component_connected, ?MODULE,
++                       component_connected, 50),
++    ejabberd_hooks:add(component_disconnected, ?MODULE,
++                       component_disconnected, 50),
++    ejabberd_hooks:add(local_send_to_resource_hook, Host, ?MODULE,
++                     process_message, 50),
++    ejabberd_hooks:add(roster_remote_access, Host, ?MODULE,
++                     roster_access, 50),
++    ejabberd_hooks:add(user_send_packet, Host, ?MODULE,
++                     process_presence_out, 50),
++    ejabberd_hooks:add(user_receive_packet, Host, ?MODULE,
++                     process_presence_in, 50),
++    {ok, #state{server_host = Host}}.
 -%%%--------------------------------------------------------------------------------------
 -%%%  Message permission
 -%%%--------------------------------------------------------------------------------------
++handle_call(get_permissions, _From, State) ->
++    {reply, {ok, State#state.permissions}, State};
++handle_call(_Request, _From, State) ->
++    Reply = ok,
++    {reply, Reply, State}.
 -process_message(StateData, FromJID, ToJID, #xmlel{children = Children} = Packet) ->
 -    %% if presence was send from service to server,
 -    case lists:member(ToJID#jid.lserver, ?MYHOSTS) and
 -         (ToJID#jid.luser == <<"">>) and
 -         (FromJID#jid.luser == <<"">>) of %% service
 -      true -> 
 -        %% if stanza contains privilege element
 -        case Children of
 -          [#xmlel{name = <<"privilege">>, 
 -                  attrs = [{<<"xmlns">>, ?NS_PRIVILEGE}],
 -                  children = [#xmlel{name = <<"forwarded">>,
 -                                     attrs = [{<<"xmlns">>, ?NS_FORWARD}],
 -                                     children = Children2}]}] ->
 -              %% 1 case : privilege service send subscription message
 -              %% on behalf of the client
 -              %% 2 case : privilege service send message on behalf
 -              %% of the client
 -              case Children2 of
 -                %% it isn't case of 0356 extension
 -                [#xmlel{name = <<"presence">>} = Child] ->
 -                    forward_subscribe(StateData, Child, Packet);
 -                [#xmlel{name = <<"message">>} = Child] -> %% xep-0356
 -                    forward_message(StateData, Child, Packet);
 -                _ -> 
 -                    Lang = fxml:get_tag_attr_s(<<"xml:lang">>, Packet),
 -                    Txt = <<"invalid forwarded element">>,
 -                    Err = jlib:make_error_reply(Packet, ?ERRT_BAD_REQUEST(Lang, Txt)),
 -                    ejabberd_service:send_element(StateData, Err)
 -              end;
 -          _ ->
 -              ejabberd_router:route(FromJID, ToJID, Packet)
 -        end;
++handle_cast({component_connected, Host}, State) ->
++    ServerHost = State#state.server_host,
++    From = jid:make(ServerHost),
++    To = jid:make(Host),
++    RosterPerm = get_roster_permission(ServerHost, Host),
++    PresencePerm = get_presence_permission(ServerHost, Host),
++    MessagePerm = get_message_permission(ServerHost, Host),
++    if RosterPerm /= none, PresencePerm /= none, MessagePerm /= none ->
++          Priv = #privilege{perms = [#privilege_perm{access = message,
++                                                     type = MessagePerm},
++                                     #privilege_perm{access = roster,
++                                                     type = RosterPerm},
++                                     #privilege_perm{access = presence,
++                                                     type = PresencePerm}]},
++          ?INFO_MSG("Granting permissions to external "
++                    "component '~s': roster = ~s, presence = ~s, "
++                    "message = ~s",
++                    [Host, RosterPerm, PresencePerm, MessagePerm]),
++          Msg = #message{from = From, to = To,  sub_els = [Priv]},
++          ejabberd_router:route(From, To, Msg),
++          Permissions = dict:store(Host, [{roster, RosterPerm},
++                                          {presence, PresencePerm},
++                                          {message, MessagePerm}],
++                                   State#state.permissions),
++          {noreply, State#state{permissions = Permissions}};
++       true ->
++          ?INFO_MSG("Granting no permissions to external component '~s'",
++                    [Host]),
++          {noreply, State}
++    end;
++handle_cast({component_disconnected, Host}, State) ->
++    Permissions = dict:erase(Host, State#state.permissions),
++    {noreply, State#state{permissions = Permissions}};
++handle_cast(_Msg, State) ->
++    {noreply, State}.
 -      _ ->
 -        ejabberd_router:route(FromJID, ToJID, Packet)
 -    end.
++handle_info(_Info, State) ->
++    {noreply, State}.
 -forward_subscribe(StateData, Presence, Packet) ->
 -    PrivAccess = StateData#state.privilege_access,
 -    T = proplists:get_value(roster, PrivAccess, none),
 -    Type = fxml:get_attr_s(<<"type">>, Presence#xmlel.attrs),
 -    if
 -      ((T == <<"both">>) or (T == <<"set">>)) and (Type == <<"subscribe">>) ->
 -        From = fxml:get_attr_s(<<"from">>, Presence#xmlel.attrs),
 -        FromJ = jid:from_string(From),
 -        To = fxml:get_attr_s(<<"to">>, Presence#xmlel.attrs),
 -        ToJ = case To of 
 -                <<"">> -> error;
 -                _ -> jid:from_string(To)
 -              end,
 -        if  
 -          (ToJ /= error) and (FromJ /= error) ->
 -            Server = FromJ#jid.lserver,
 -            User = FromJ#jid.luser,
 -            case (FromJ#jid.lresource == <<"">>) and 
 -                  lists:member(Server, ?MYHOSTS) of
 -              true ->
 -                if  
 -                  (Server /= ToJ#jid.lserver) or
 -                  (User /= ToJ#jid.luser) ->
 -                    %% 0356 server MUST NOT allow the privileged entity
 -                    %% to do anything that the managed entity could not do
 -                    try_roster_subscribe(Server,User, FromJ, ToJ, Presence);   
 -                  true -> %% we don't want presence sent to self
 -                    ok
 -                end;
 -              _ ->
 -                Err = jlib:make_error_reply(Packet, ?ERR_FORBIDDEN),
 -                ejabberd_service:send_element(StateData, Err)
 -            end;
 -          true ->
 -            Lang = fxml:get_tag_attr_s(<<"xml:lang">>, Packet),
 -            Txt = <<"Incorrect stanza from/to JID">>,
 -            Err = jlib:make_error_reply(Packet, ?ERRT_BAD_REQUEST(Lang, Txt)),
 -            ejabberd_service:send_element(StateData, Err)
 -            end;
 -      true ->
 -        Err = jlib:make_error_reply(Packet, ?ERR_FORBIDDEN),
 -        ejabberd_service:send_element(StateData, Err)
 -    end.
++terminate(_Reason, State) ->
++    %% Note: we don't remove component_* hooks because they are global
++    %% and might be registered within a module on another virtual host
++    Host = State#state.server_host,
++    ejabberd_hooks:delete(local_send_to_resource_hook, Host, ?MODULE,
++                        process_message, 50),
++    ejabberd_hooks:delete(roster_remote_access, Host, ?MODULE,
++                        roster_access, 50),
++    ejabberd_hooks:delete(user_send_packet, Host, ?MODULE,
++                        process_presence_out, 50),
++    ejabberd_hooks:delete(user_receive_packet, Host, ?MODULE,
++                        process_presence_in, 50).
 -forward_message(StateData, Message, Packet) ->
 -    PrivAccess = StateData#state.privilege_access,
 -    T = proplists:get_value(message, PrivAccess, none),
 -    if  
 -      (T == <<"outgoing">>) ->            
 -        From = fxml:get_attr_s(<<"from">>, Message#xmlel.attrs),
 -        FromJ = jid:from_string(From),
 -        To = fxml:get_attr_s(<<"to">>, Message#xmlel.attrs),
 -        ToJ = case To of 
 -                <<"">> -> FromJ;
 -                _ -> jid:from_string(To)
 -              end,
 -        if  
 -          (ToJ /= error) and (FromJ /= error) ->
 -            Server = FromJ#jid.server,
 -            User = FromJ#jid.user,
 -            case (FromJ#jid.lresource == <<"">>) and 
 -                 lists:member(Server, ?MYHOSTS) of
 -              true ->
 -                %% there are no restriction on to attribute
 -                PrivList = ejabberd_hooks:run_fold(privacy_get_user_list,
 -                                                   Server, #userlist{},
 -                                                   [User, Server]),
 -                check_privacy_route(Server, User, PrivList,
 -                                                  FromJ, ToJ, Message);
 -              _ ->
 -                Err = jlib:make_error_reply(Packet, ?ERR_FORBIDDEN),
 -                ejabberd_service:send_element(StateData, Err)
 -            end;
 -          true ->
 -            Lang = fxml:get_tag_attr_s(<<"xml:lang">>, Packet),
 -            Txt = <<"Incorrect stanza from/to JID">>,
 -            Err = jlib:make_error_reply(Packet, ?ERRT_BAD_REQUEST(Lang, Txt)),
 -            ejabberd_service:send_element(StateData, Err)
 -        end;
 -      true ->
 -        Err = jlib:make_error_reply(Packet,?ERR_FORBIDDEN),
 -        ejabberd_service:send_element(StateData, Err)
 -    end.
++code_change(_OldVsn, State, _Extra) ->
++    {ok, State}.
 -%%%--------------------------------------------------------------------------------------
 -%%%  helper functions
 -%%%--------------------------------------------------------------------------------------
++%%%===================================================================
++%%% Internal functions
++%%%===================================================================
++get_permissions(ServerHost) ->
++    Proc = gen_mod:get_module_proc(ServerHost, ?MODULE),
++    try gen_server:call(Proc, get_permissions) of
++      {ok, Permissions} ->
++          Permissions
++    catch exit:{noproc, _} ->
++          %% No module is loaded for this virtual host
++          dict:new()
++    end.
 -compare_presences(undefined, _Presence) -> false;                       
 -compare_presences(#xmlel{attrs = Attrs, children = Child},
 -                  #xmlel{attrs = Attrs2, children = Child2}) ->
 -    Id1 = fxml:get_attr_s(<<"id">>, Attrs),
 -    Id2 = fxml:get_attr_s(<<"id">>, Attrs2),
 -    if
 -      (Id1 /= Id2) ->
 -        false;
 -      (Id1 /= <<"">>) and (Id1 == Id2) -> 
 -        true;
 -      true -> 
 -        case not compare_attrs(Attrs, Attrs2) of
 -          true -> false;
 -          _ -> 
 -            compare_elements(Child, Child2)
 -        end
++forward_message(From, To, Msg) ->
++    Host = From#jid.lserver,
++    ServerHost = To#jid.lserver,
++    case xmpp:get_subtag(Msg, #privilege{}) of
++      #privilege{forwarded = #forwarded{sub_els = [#message{} = SubEl]}} ->
++          case SubEl#message.from of
++              #jid{lresource = <<"">>, lserver = ServerHost} ->
++                  ejabberd_router:route(
++                    xmpp:get_from(SubEl), xmpp:get_to(SubEl), SubEl);
++              _ ->
++                  Lang = xmpp:get_lang(Msg),
++                  Txt = <<"Invalid 'from' attribute">>,
++                  Err = xmpp:err_forbidden(Txt, Lang),
++                  ejabberd_router:route_error(To, From, Msg, Err)
++          end;
++      _ ->
++          ?ERROR_MSG("got invalid forwarded payload from external "
++                     "component '~s':~n~s", [Host, xmpp:pp(Msg)]),
++          Lang = xmpp:get_lang(Msg),
++          Txt = <<"Invalid forwarded payload">>,
++          Err = xmpp:err_bad_request(Txt, Lang),
++          ejabberd_router:route_error(To, From, Msg, Err)
+     end.
++get_roster_permission(ServerHost, Host) ->
++    Perms = gen_mod:get_module_opt(ServerHost, ?MODULE, roster,
++                                 v_roster(), []),
++    case match_rule(ServerHost, Host, Perms, both) of
++      allow ->
++          both;
++      deny ->
++          Get = match_rule(ServerHost, Host, Perms, get),
++          Set = match_rule(ServerHost, Host, Perms, set),
++          if Get == allow, Set == allow -> both;
++             Get == allow -> get;
++             Set == allow -> set;
++             true -> none
++          end
++    end.
 -compare_elements([],[]) -> true;
 -compare_elements(Tags1, Tags2) when length(Tags1) == length(Tags2) ->
 -    compare_tags(Tags1,Tags2);
 -compare_elements(_Tags1, _Tags2) -> false.
++get_message_permission(ServerHost, Host) ->
++    Perms = gen_mod:get_module_opt(ServerHost, ?MODULE, message,
++                                 v_message(), []),
++    case match_rule(ServerHost, Host, Perms, outgoing) of
++      allow -> outgoing;
++      deny -> none
++    end.
 -compare_tags([],[]) -> true;
 -compare_tags([{xmlcdata, CData}|Tags1], [{xmlcdata, CData}|Tags2]) ->
 -    compare_tags(Tags1, Tags2);
 -compare_tags([{xmlcdata, _CData1}|_Tags1], [{xmlcdata, _CData2}|_Tags2]) ->
 -    false;
 -compare_tags([#xmlel{} = Stanza1|Tags1], [#xmlel{} = Stanza2|Tags2]) ->
 -    case (Stanza1#xmlel.name == Stanza2#xmlel.name) and
 -         compare_attrs(Stanza1#xmlel.attrs, Stanza2#xmlel.attrs) and
 -         compare_tags(Stanza1#xmlel.children, Stanza2#xmlel.children) of
 -      true -> 
 -        compare_tags(Tags1,Tags2);
 -      false ->
 -        false
++get_presence_permission(ServerHost, Host) ->
++    Perms = gen_mod:get_module_opt(ServerHost, ?MODULE, presence,
++                                 v_presence(), []),
++    case match_rule(ServerHost, Host, Perms, roster) of
++      allow ->
++          roster;
++      deny ->
++          case match_rule(ServerHost, Host, Perms, managed_entity) of
++              allow -> managed_entity;
++              deny -> none
++          end
+     end.
 -%% attr() :: {Name, Value}
 --spec compare_attrs([attr()], [attr()]) -> boolean().
 -compare_attrs([],[]) -> true;
 -compare_attrs(Attrs1, Attrs2) when length(Attrs1) == length(Attrs2) ->
 -    lists:foldl(fun(Attr,Acc) -> lists:member(Attr, Attrs2) and Acc end, true, Attrs1);
 -compare_attrs(_Attrs1, _Attrs2) -> false.
++match_rule(ServerHost, Host, Perms, Type) ->
++    Access = proplists:get_value(Type, Perms, none),
++    acl:match_rule(ServerHost, Access, jid:make(Host)).
 -%% Check if privacy rules allow this delivery
 -%% from ejabberd_c2s.erl
 -privacy_check_packet(Server, User, PrivList, From, To, Packet , Dir) ->
 -    ejabberd_hooks:run_fold(privacy_check_packet,
 -                            Server, allow, [User, Server, PrivList, 
 -                            {From, To, Packet}, Dir]).
++v_roster() ->
++    fun(Props) ->
++          lists:map(
++            fun({both, ACL}) -> {both, acl:access_rules_validator(ACL)};
++               ({get, ACL}) -> {get, acl:access_rules_validator(ACL)};
++               ({set, ACL}) -> {set, acl:access_rules_validator(ACL)}
++            end, Props)
++    end.
 -check_privacy_route(Server, User, PrivList, From, To, Packet) ->
 -    case privacy_check_packet(Server, User, PrivList, From, To, Packet, out) of
 -        allow ->
 -            ejabberd_router:route(From, To, Packet);
 -        _ -> ok %% who should receive error : service or user?
++v_message() ->
++    fun(Props) ->
++          lists:map(
++            fun({outgoing, ACL}) -> {outgoing, acl:access_rules_validator(ACL)}
++            end, Props)
+     end.
 -try_roster_subscribe(Server,User, From, To, Packet) ->
 -    Access = 
 -      gen_mod:get_module_opt(Server, mod_roster, access,
 -                             fun(A) when is_atom(A) -> A end, all),
 -    case acl:match_rule(Server, Access, From) of
 -        deny ->
 -            ok;
 -        allow ->
 -            ejabberd_hooks:run(roster_out_subscription, Server,
 -                               [User, Server, To, subscribe]),
 -            PrivList = ejabberd_hooks:run_fold(privacy_get_user_list,
 -                                               Server,
 -                                               #userlist{},
 -                                               [User, Server]),
 -            check_privacy_route(Server, User, PrivList, From, To, Packet)            
++v_presence() ->
++    fun(Props) ->
++          lists:map(
++            fun({managed_entity, ACL}) ->
++                    {managed_entity, acl:access_rules_validator(ACL)};
++               ({roster, ACL}) ->
++                    {roster, acl:access_rules_validator(ACL)}
++            end, Props)
+     end.
Simple merge
index fa27f866cfb6bd5dd2b04674a8e02b2c27f0e284,a75041bc7335789cb8cc53f3e3b0af662024b3e5..c344213f38b21007ce09c12b8da7e40471187669
@@@ -139,57 -139,25 +139,60 @@@ stop(Host) -
  depends(_Host, _Opts) ->
      [].
  
- process_iq(#iq{from = #jid{luser = <<"">>},
-              to = #jid{resource = <<"">>}} = IQ) ->
-     process_iq_manager(IQ);
 -process_iq(From, To, IQ) when ((From#jid.luser == <<"">>) andalso (From#jid.resource == <<"">>)) ->
 -    process_iq_manager(From, To, IQ);
 -
 -process_iq(From, To, IQ) ->
 -    #iq{sub_el = SubEl, lang = Lang} = IQ,
 -    #jid{lserver = LServer} = From,
 -    case lists:member(LServer, ?MYHOSTS) of
 -      true -> process_local_iq(From, To, IQ);
 -      _ ->
 -        Txt = <<"The query is only allowed from local users">>,
 -        IQ#iq{type = error,
 -              sub_el = [SubEl, ?ERRT_ITEM_NOT_FOUND(Lang, Txt)]}
 +process_iq(#iq{from = #jid{luser = U, lserver = S},
 +             to =   #jid{luser = U, lserver = S}} = IQ) ->
 +    process_local_iq(IQ);
- process_iq(#iq{lang = Lang} = IQ) ->
-     Txt = <<"Query to another users is forbidden">>,
-     xmpp:make_error(IQ, xmpp:err_forbidden(Txt, Lang)).
++process_iq(#iq{lang = Lang, to = To} = IQ) ->
++    case ejabberd_hooks:run_fold(roster_remote_access,
++                               To#jid.lserver, false, [IQ]) of
++      false ->
++          Txt = <<"Query to another users is forbidden">>,
++          xmpp:make_error(IQ, xmpp:err_forbidden(Txt, Lang));
++      true ->
++          process_local_iq(IQ)
+     end.
  
 -process_local_iq(From, To, #iq{type = Type} = IQ) ->
 -    case Type of
 -      set -> try_process_iq_set(From, To, IQ);
 -      get -> process_iq_get(From, To, IQ)
 -    end.
 +process_local_iq(#iq{type = set,lang = Lang,
 +                   sub_els = [#roster_query{
 +                                 items = [#roster_item{ask = Ask}]}]} = IQ)
 +  when Ask /= undefined ->
 +    Txt = <<"Possessing 'ask' attribute is not allowed by RFC6121">>,
 +    xmpp:make_error(IQ, xmpp:err_bad_request(Txt, Lang));
 +process_local_iq(#iq{type = set, from = From, lang = Lang,
 +                   sub_els = [#roster_query{
 +                                 items = [#roster_item{} = Item]}]} = IQ) ->
 +    case has_duplicated_groups(Item#roster_item.groups) of
 +      true ->
 +          Txt = <<"Duplicated groups are not allowed by RFC6121">>,
 +          xmpp:make_error(IQ, xmpp:err_bad_request(Txt, Lang));
 +      false ->
 +          #jid{server = Server} = From,
 +          Access = gen_mod:get_module_opt(Server, ?MODULE,
 +                                          access, fun(A) -> A end, all),
 +          case acl:match_rule(Server, Access, From) of
 +              deny ->
 +                  Txt = <<"Denied by ACL">>,
 +                  xmpp:make_error(IQ, xmpp:err_not_allowed(Txt, Lang));
 +              allow ->
 +                  process_iq_set(IQ)
 +          end
 +    end;
 +process_local_iq(#iq{type = set, lang = Lang,
 +                   sub_els = [#roster_query{items = [_|_]}]} = IQ) ->
 +    Txt = <<"Multiple <item/> elements are not allowed by RFC6121">>,
 +    xmpp:make_error(IQ, xmpp:err_bad_request(Txt, Lang));
 +process_local_iq(#iq{type = get, lang = Lang,
 +                   sub_els = [#roster_query{items = Items}]} = IQ) ->
 +    case Items of
 +      [] ->
 +          process_iq_get(IQ);
 +      [_|_] ->
 +          Txt = <<"The query must not contain <item/> elements">>,
 +          xmpp:make_error(IQ, xmpp:err_bad_request(Txt, Lang))
 +    end;
 +process_local_iq(#iq{lang = Lang} = IQ) ->
 +    Txt = <<"No module is handling this query">>,
 +    xmpp:make_error(IQ, xmpp:err_service_unavailable(Txt, Lang)).
  
  roster_hash(Items) ->
      p1_sha:sha(term_to_binary(lists:sort([R#roster{groups =
@@@ -251,64 -221,84 +254,64 @@@ write_roster_version(LUser, LServer, In
  %%     - roster versioning is not used by the client OR
  %%     - roster versioning is used by server and client, BUT the server isn't storing versions on db OR
  %%     - the roster version from client don't match current version.
- process_iq_get(#iq{from = From, to = To, lang = Lang,
 -process_iq_get(From, To, #iq{sub_el = SubEl} = IQ) ->
 -    LUser = From#jid.luser,
 -    LServer = From#jid.lserver,
++process_iq_get(#iq{to = To, lang = Lang,
 +                 sub_els = [#roster_query{ver = RequestedVersion}]} = IQ) ->
-     LUser = From#jid.luser,
-     LServer = From#jid.lserver,
++    LUser = To#jid.luser,
++    LServer = To#jid.lserver,
      US = {LUser, LServer},
 -    try {ItemsToSend, VersionToSend} = case
 -                                       {fxml:get_tag_attr(<<"ver">>, SubEl),
 -                                        roster_versioning_enabled(LServer),
 -                                        roster_version_on_db(LServer)}
 -                                         of
 -                                       {{value, RequestedVersion}, true,
 -                                        true} ->
 -                                           case read_roster_version(LUser,
 -                                                                    LServer)
 -                                               of
 -                                             error ->
 -                                                 RosterVersion =
 -                                                     write_roster_version(LUser,
 -                                                                          LServer),
 -                                                 {lists:map(fun item_to_xml/1,
 -                                                            ejabberd_hooks:run_fold(roster_get,
 -                                                                                    To#jid.lserver,
 -                                                                                    [],
 -                                                                                    [US])),
 -                                                  RosterVersion};
 -                                             RequestedVersion ->
 -                                                 {false, false};
 -                                             NewVersion ->
 -                                                 {lists:map(fun item_to_xml/1,
 -                                                            ejabberd_hooks:run_fold(roster_get,
 -                                                                                    To#jid.lserver,
 -                                                                                    [],
 -                                                                                    [US])),
 -                                                  NewVersion}
 -                                           end;
 -                                       {{value, RequestedVersion}, true,
 -                                        false} ->
 -                                           RosterItems =
 -                                               ejabberd_hooks:run_fold(roster_get,
 -                                                                       To#jid.lserver,
 -                                                                       [],
 -                                                                       [US]),
 -                                           case roster_hash(RosterItems) of
 -                                             RequestedVersion ->
 -                                                 {false, false};
 -                                             New ->
 -                                                 {lists:map(fun item_to_xml/1,
 -                                                            RosterItems),
 -                                                  New}
 -                                           end;
 -                                       _ ->
 -                                           {lists:map(fun item_to_xml/1,
 -                                                      ejabberd_hooks:run_fold(roster_get,
 -                                                                              To#jid.lserver,
 -                                                                              [],
 -                                                                              [US])),
 -                                            false}
 -                                     end,
 -      IQ#iq{type = result,
 -            sub_el =
 -                case {ItemsToSend, VersionToSend} of
 -                  {false, false} -> [];
 -                  {Items, false} ->
 -                      [#xmlel{name = <<"query">>,
 -                              attrs = [{<<"xmlns">>, ?NS_ROSTER}],
 -                              children = Items}];
 -                  {Items, Version} ->
 -                      [#xmlel{name = <<"query">>,
 -                              attrs =
 -                                  [{<<"xmlns">>, ?NS_ROSTER},
 -                                   {<<"ver">>, Version}],
 -                              children = Items}]
 -                end}
 -    catch
 -      _:_ ->
 -        IQ#iq{type = error,
 -              sub_el = [SubEl, ?ERR_INTERNAL_SERVER_ERROR]}
 +    try {ItemsToSend, VersionToSend} =
 +           case {roster_versioning_enabled(LServer),
 +                 roster_version_on_db(LServer)} of
 +               {true, true} when RequestedVersion /= undefined ->
 +                   case read_roster_version(LUser, LServer) of
 +                       error ->
 +                           RosterVersion = write_roster_version(LUser, LServer),
 +                           {lists:map(fun encode_item/1,
 +                                      ejabberd_hooks:run_fold(
 +                                        roster_get, To#jid.lserver, [], [US])),
 +                            RosterVersion};
 +                       RequestedVersion ->
 +                           {false, false};
 +                       NewVersion ->
 +                           {lists:map(fun encode_item/1,
 +                                      ejabberd_hooks:run_fold(
 +                                        roster_get, To#jid.lserver, [], [US])),
 +                            NewVersion}
 +                   end;
 +               {true, false} when RequestedVersion /= undefined ->
 +                   RosterItems = ejabberd_hooks:run_fold(
 +                                   roster_get, To#jid.lserver, [], [US]),
 +                   case roster_hash(RosterItems) of
 +                       RequestedVersion ->
 +                           {false, false};
 +                       New ->
 +                           {lists:map(fun encode_item/1, RosterItems), New}
 +                   end;
 +               _ ->
 +                   {lists:map(fun encode_item/1,
 +                              ejabberd_hooks:run_fold(
 +                                roster_get, To#jid.lserver, [], [US])),
 +                    false}
 +           end,
 +       xmpp:make_iq_result(
 +         IQ,
 +         case {ItemsToSend, VersionToSend} of
 +             {false, false} ->
 +                 undefined;
 +             {Items, false} ->
 +                 #roster_query{items = Items};
 +             {Items, Version} ->
 +                 #roster_query{items = Items,
 +                               ver = Version}
 +         end)
 +    catch E:R ->
 +          ?ERROR_MSG("failed to process roster get for ~s: ~p",
-                      [jid:to_string(From), {E, {R, erlang:get_stacktrace()}}]),
++                     [jid:to_string(To), {E, {R, erlang:get_stacktrace()}}]),
 +          Txt = <<"Roster module has failed">>,
 +          xmpp:make_error(IQ, xmpp:err_internal_server_error(Txt, Lang))
      end.
  
 +-spec get_user_roster([#roster{}], {binary(), binary()}) -> [#roster{}].
  get_user_roster(Acc, {LUser, LServer}) ->
      Items = get_roster(LUser, LServer),
      lists:filter(fun (#roster{subscription = none,
@@@ -369,50 -352,112 +372,49 @@@ get_roster_by_jid_t(LUser, LServer, LJI
      Mod = gen_mod:db_mod(LServer, ?MODULE),
      Mod:get_roster_by_jid(LUser, LServer, LJID).
  
- process_iq_set(#iq{from = From, to = To, id = Id,
 -try_process_iq_set(From, To, #iq{sub_el = SubEl, lang = Lang} = IQ) ->
 -    #jid{server = Server} = From,
 -    Access = gen_mod:get_module_opt(Server, ?MODULE, access, fun(A) -> A end, all),
 -    case acl:match_rule(Server, Access, From) of
 -      deny ->
 -          Txt = <<"Denied by ACL">>,
 -          IQ#iq{type = error, sub_el = [SubEl, ?ERRT_NOT_ALLOWED(Lang, Txt)]};
 -      allow ->
 -          process_iq_set(From, To, IQ)
++process_iq_set(#iq{from = From, to = To,
 +                 sub_els = [#roster_query{items = QueryItems}]} = IQ) ->
-     Managed = is_managed_from_id(Id),
-     #jid{user = User, luser = LUser, lserver = LServer} = From,
++    #jid{user = User, luser = LUser, lserver = LServer} = To,
++    Managed = {From#jid.luser, From#jid.lserver} /= {LUser, LServer},
 +    F = fun () ->
 +              lists:map(
 +                fun(#roster_item{jid = JID1} = QueryItem) ->
 +                        LJID = jid:tolower(JID1),
 +                        Item = get_roster_by_jid_t(LUser, LServer, LJID),
 +                        Item2 = decode_item(QueryItem, Item, Managed),
 +                        Item3 = ejabberd_hooks:run_fold(roster_process_item,
 +                                                        LServer, Item2,
 +                                                        [LServer]),
 +                        case Item3#roster.subscription of
 +                            remove -> del_roster_t(LUser, LServer, LJID);
 +                            _ -> update_roster_t(LUser, LServer, LJID, Item3)
 +                        end,
 +                        case roster_version_on_db(LServer) of
 +                            true -> write_roster_version_t(LUser, LServer);
 +                            false -> ok
 +                        end,
 +                        {Item, Item3}
 +                end, QueryItems)
 +      end,
 +    case transaction(LServer, F) of
 +      {atomic, ItemPairs} ->
 +          lists:foreach(
 +            fun({OldItem, Item}) ->
-                     send_itemset_to_managers(From, Item, Managed),
 +                    push_item(User, LServer, To, Item),
 +                    case Item#roster.subscription of
 +                        remove ->
-                             send_unsubscribing_presence(From, OldItem);
++                            send_unsubscribing_presence(To, OldItem);
 +                        _ ->
 +                            ok
 +                    end
 +            end, ItemPairs),
 +          xmpp:make_iq_result(IQ);
 +      E ->
 +          ?ERROR_MSG("roster set failed:~nIQ = ~s~nError = ~p",
 +                     [xmpp:pp(IQ), E]),
 +          xmpp:make_error(IQ, xmpp:err_internal_server_error())
      end.
  
 -process_iq_set(From, To, #iq{sub_el = SubEl, id = Id} = IQ) ->
 -    #xmlel{children = Els} = SubEl,
 -    Managed = is_managed_from_id(Id),
 -    lists:foreach(fun (El) -> process_item_set(From, To, El, Managed)
 -                end,
 -                Els),
 -    IQ#iq{type = result, sub_el = []}.
 -
 -process_item_set(From, To,
 -               #xmlel{attrs = Attrs, children = Els}, Managed) ->
 -    JID1 = jid:from_string(fxml:get_attr_s(<<"jid">>,
 -                                           Attrs)),
 -    #jid{user = User, luser = LUser, lserver = LServer} =
 -      From,
 -    case JID1 of
 -      error -> ok;
 -      _ ->
 -        LJID = jid:tolower(JID1),
 -        F = fun () ->
 -                    Item = get_roster_by_jid_t(LUser, LServer, LJID),
 -                    Item1 = process_item_attrs_managed(Item, Attrs, Managed),
 -                    Item2 = process_item_els(Item1, Els),
 -                    Item3 = ejabberd_hooks:run_fold(roster_process_item,
 -                                                    LServer, Item2,
 -                                                    [LServer]),
 -                    case Item3#roster.subscription of
 -                      remove -> del_roster_t(LUser, LServer, LJID);
 -                      _ -> update_roster_t(LUser, LServer, LJID, Item3)
 -                    end,
 -                      send_itemset_to_managers(From, Item3, Managed),
 -                    case roster_version_on_db(LServer) of
 -                      true -> write_roster_version_t(LUser, LServer);
 -                      false -> ok
 -                    end,
 -                    {Item, Item3}
 -            end,
 -        case transaction(LServer, F) of
 -          {atomic, {OldItem, Item}} ->
 -              push_item(User, LServer, To, Item),
 -              case Item#roster.subscription of
 -                remove ->
 -                    send_unsubscribing_presence(From, OldItem), ok;
 -                _ -> ok
 -              end;
 -          E ->
 -              ?DEBUG("ROSTER: roster item set error: ~p~n", [E]), ok
 -        end
 -    end;
 -process_item_set(_From, _To, _, _Managed) -> ok.
 -
 -process_item_attrs(Item, [{Attr, Val} | Attrs]) ->
 -    case Attr of
 -      <<"jid">> ->
 -        case jid:from_string(Val) of
 -          error -> process_item_attrs(Item, Attrs);
 -          JID1 ->
 -              JID = {JID1#jid.luser, JID1#jid.lserver,
 -                     JID1#jid.lresource},
 -              process_item_attrs(Item#roster{jid = JID}, Attrs)
 -        end;
 -      <<"name">> ->
 -        process_item_attrs(Item#roster{name = Val}, Attrs);
 -      <<"subscription">> ->
 -        case Val of
 -          <<"remove">> ->
 -              process_item_attrs(Item#roster{subscription = remove},
 -                                 Attrs);
 -          _ -> process_item_attrs(Item, Attrs)
 -        end;
 -      <<"ask">> -> process_item_attrs(Item, Attrs);
 -      _ -> process_item_attrs(Item, Attrs)
 -    end;
 -process_item_attrs(Item, []) -> Item.
 -
 -process_item_els(Item,
 -               [#xmlel{name = Name, attrs = Attrs, children = SEls}
 -                | Els]) ->
 -    case Name of
 -      <<"group">> ->
 -        Groups = [fxml:get_cdata(SEls) | Item#roster.groups],
 -        process_item_els(Item#roster{groups = Groups}, Els);
 -      _ ->
 -        case fxml:get_attr_s(<<"xmlns">>, Attrs) of
 -          <<"">> -> process_item_els(Item, Els);
 -          _ ->
 -              XEls = [#xmlel{name = Name, attrs = Attrs,
 -                             children = SEls}
 -                      | Item#roster.xs],
 -              process_item_els(Item#roster{xs = XEls}, Els)
 -        end
 -    end;
 -process_item_els(Item, [{xmlcdata, _} | Els]) ->
 -    process_item_els(Item, Els);
 -process_item_els(Item, []) -> Item.
 -
  push_item(User, Server, From, Item) ->
      ejabberd_sm:route(jid:make(<<"">>, <<"">>, <<"">>),
                      jid:make(User, Server, <<"">>),
@@@ -1012,69 -1141,89 +1014,9 @@@ webadmin_user(Acc, _User, _Server, Lang
        [?XE(<<"h3">>, [?ACT(<<"roster/">>, <<"Roster">>)])].
  
  %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
--
--%% Implement XEP-0321 Remote Roster Management
--
- process_iq_manager(#iq{from = From, to = To, lang = Lang} = IQ) ->
 -process_iq_manager(From, To, IQ) ->
--    %% Check what access is allowed for From to To
--    MatchDomain = From#jid.lserver,
--    case is_domain_managed(MatchDomain, To#jid.lserver) of
--      true ->
-           process_iq_manager2(MatchDomain, IQ);
 -          process_iq_manager2(MatchDomain, To, IQ);
--      false ->
 -          #iq{sub_el = SubEl, lang = Lang} = IQ,
--          Txt = <<"Roster management is not allowed from this domain">>,
-           xmpp:make_error(IQ, xmpp:err_bad_request(Txt, Lang))
 -          IQ#iq{type = error, sub_el = [SubEl, ?ERRT_BAD_REQUEST(Lang, Txt)]}
--    end.
--
- process_iq_manager2(MatchDomain, #iq{to = To} = IQ) ->
 -process_iq_manager2(MatchDomain, To, IQ) ->
--    %% If IQ is SET, filter the input IQ
--    IQFiltered = maybe_filter_request(MatchDomain, IQ),
--    %% Call the standard function with reversed JIDs
--    IdInitial = IQFiltered#iq.id,
-     ResIQ = process_iq(IQFiltered#iq{from = To, to = To,
-                                    id = <<"roster-remotely-managed">>}),
 -    ResIQ = process_iq(To, To, IQFiltered#iq{id = <<"roster-remotely-managed">>}),
--    %% Filter the output IQ
--    filter_stanza(MatchDomain, ResIQ#iq{id = IdInitial}).
--
--is_domain_managed(ContactHost, UserHost) ->
--    Managers = gen_mod:get_module_opt(UserHost, ?MODULE, managers,
--                                              fun(B) when is_list(B) -> B end,
--                                              []),
--    lists:member(ContactHost, Managers).
--
--maybe_filter_request(MatchDomain, IQ) when IQ#iq.type == set ->
--    filter_stanza(MatchDomain, IQ);
--maybe_filter_request(_MatchDomain, IQ) ->
--    IQ.
--
- filter_stanza(MatchDomain,
-             #iq{sub_els = [#roster_query{items = Items} = R]} = IQ) ->
 -filter_stanza(_MatchDomain, #iq{sub_el = []} = IQ) ->
 -    IQ;
 -filter_stanza(MatchDomain, #iq{sub_el = [SubEl | _]} = IQ) ->
 -    #iq{sub_el = SubElFiltered} = IQRes =
 -      filter_stanza(MatchDomain, IQ#iq{sub_el = SubEl}),
 -    IQRes#iq{sub_el = [SubElFiltered]};
 -filter_stanza(MatchDomain, #iq{sub_el = SubEl} = IQ) ->
 -    #xmlel{name = Type, attrs = Attrs, children = Items} = SubEl,
--    ItemsFiltered = lists:filter(
-                     fun(#roster_item{jid = #jid{lserver = S}}) ->
-                             S == MatchDomain
-                     end, Items),
-     IQ#iq{sub_els = [R#roster_query{items = ItemsFiltered}]}.
 -                    fun(Item) ->
 -                            is_item_of_domain(MatchDomain, Item) end, Items),
 -    SubElFiltered = #xmlel{name=Type, attrs = Attrs, children = ItemsFiltered},
 -    IQ#iq{sub_el = SubElFiltered}.
 -
 -is_item_of_domain(MatchDomain, #xmlel{} = El) ->
 -    lists:any(fun(Attr) -> is_jid_of_domain(MatchDomain, Attr) end, El#xmlel.attrs);
 -is_item_of_domain(_MatchDomain, {xmlcdata, _}) ->
 -    false.
 -
 -is_jid_of_domain(MatchDomain, {<<"jid">>, JIDString}) ->
 -    case jid:from_string(JIDString) of
 -      JID when JID#jid.lserver == MatchDomain -> true;
 -      _ -> false
 -    end;
 -is_jid_of_domain(_, _) ->
 -    false.
 -
 -process_item_attrs_managed(Item, Attrs, true) ->
 -    process_item_attrs_ws(Item, Attrs);
 -process_item_attrs_managed(Item, _Attrs, false) ->
 -    process_item_attrs(Item, _Attrs).
--
--send_itemset_to_managers(_From, _Item, true) ->
--    ok;
--send_itemset_to_managers(From, Item, false) ->
--    {_, UserHost} = Item#roster.us,
--    {_ContactUser, ContactHost, _ContactResource} = Item#roster.jid,
--    %% Check if the component is an allowed manager
--    IsManager = is_domain_managed(ContactHost, UserHost),
--    case IsManager of
--      true -> push_item(<<"">>, ContactHost, <<"">>, From, Item);
--      false -> ok
--    end.
--
--is_managed_from_id(<<"roster-remotely-managed">>) ->
--    true;
--is_managed_from_id(_Id) ->
--    false.
 +has_duplicated_groups(Groups) ->
 +    GroupsPrep = lists:usort([jid:resourceprep(G) || G <- Groups]),
 +    not (length(GroupsPrep) == length(Groups)).
  
  export(LServer) ->
      Mod = gen_mod:db_mod(LServer, ?MODULE),
Simple merge
index c1dfd0e81b4c332c47ce9e312f2e31977b93049c,61156ee064b74c649655a45d3b32c2c5fef2e3a7..5adf1e559539d71226ac8f2fd25deeec73ecd0ed
@@@ -646,60 -653,73 +646,60 @@@ del_state(Nidx, JID) -
                   " where jid=%(J)s and nodeid=%(Nidx)d")),
      ok.
  
 -%get_items(Nidx, _From) ->
 -%    case catch
 -%     ejabberd_sql:sql_query_t([<<"select itemid, publisher, creation, modification, payload "
 -%                 "from pubsub_item where nodeid='">>, Nidx,
 -%             <<"' order by modification desc;">>])
 -%    of
 -%     {selected,
 -%                 [<<"itemid">>, <<"publisher">>, <<"creation">>, <<"modification">>, <<"payload">>], RItems} ->
 -%         {result, [raw_to_item(Nidx, RItem) || RItem <- RItems]};
 -%     _ ->
 -%         {result, []}
 -%    end.
 -
 -get_items(Nidx, From, none) ->
 -    MaxItems = case catch
 -      ejabberd_sql:sql_query_t(
 -          ?SQL("select @(val)s from pubsub_node_option "
 -               "where nodeid=%(Nidx)d and name='max_items'"))
 -    of
 -      {selected, [{Value}]} ->
 -            jlib:expr_to_term(Value);
 -      _ ->
 -          ?MAXITEMS
 -    end,
 -    get_items(Nidx, From, #rsm_in{max = MaxItems});
 -get_items(Nidx, _From,
 -          #rsm_in{max = M, direction = Direction, id = I, index = IncIndex}) ->
 -    Max = ejabberd_sql:escape(jlib:i2l(M)),
 -    {Way, Order} = case Direction of
 -           aft when I == <<>> -> {<<"is not">>, <<"desc">>};
 -           aft -> {<<"<">>, <<"desc">>};
 -           before when I == <<>> -> {<<"is not">>, <<"asc">>};
 -           before -> {<<">">>, <<"asc">>};
 -           _ -> {<<"is not">>, <<"desc">>}
 -    end,
 +get_items(Nidx, From, undefined) ->
 +    MaxItems = case ejabberd_sql:sql_query_t(
 +                    ?SQL("select @(val)s from pubsub_node_option "
 +                         "where nodeid=%(Nidx)d and name='max_items'")) of
 +                 {selected, [{Value}]} ->
 +                     jlib:expr_to_term(Value);
 +                 _ ->
 +                     ?MAXITEMS
 +             end,
 +    get_items(Nidx, From, #rsm_set{max = MaxItems});
 +get_items(Nidx, _From, #rsm_set{max = Max, index = IncIndex,
 +                              'after' = After, before = Before}) ->
 +    {Way, Order} = if After == <<>> -> {<<"is not">>, <<"desc">>};
 +                    After /= undefined -> {<<"<">>, <<"desc">>};
 +                    Before == <<>> -> {<<"is not">>, <<"asc">>};
 +                    Before /= undefined -> {<<">">>, <<"asc">>};
 +                    true -> {<<"is not">>, <<"desc">>}
 +                 end,
-     SNidx = integer_to_binary(Nidx),
+     SNidx = jlib:i2l(Nidx),
 -    [AttrName, Id] = case I of
 -      undefined when IncIndex =/= undefined ->
 -          case catch
 -              ejabberd_sql:sql_query_t([<<"select modification from pubsub_item pi "
 -                          "where exists ( select count(*) as count1 "
 -                          "from pubsub_item where nodeid='">>, SNidx,
 +    I = if After /= undefined -> After;
 +         Before /= undefined -> Before;
 +         true -> undefined
 +      end,
 +    [AttrName, Id] =
 +      case I of
 +          undefined when IncIndex =/= undefined ->
 +              case ejabberd_sql:sql_query_t(
 +                     [<<"select modification from pubsub_item pi "
 +                        "where exists ( select count(*) as count1 "
 +                        "from pubsub_item where nodeid='">>, SNidx,
                        <<"' and modification > pi.modification having count1 = ">>,
 -                      ejabberd_sql:escape(jlib:i2l(IncIndex)), <<" );">>])
 -          of
 -              {selected, [_], [[O]]} ->
 -                  [<<"modification">>, <<"'", O/binary, "'">>];
 -              _ ->
 -                  [<<"modification">>, <<"null">>]
 -          end;
 -      undefined ->
 -          [<<"modification">>, <<"null">>];
 -      <<>> ->
 -          [<<"modification">>, <<"null">>];
 -      I ->
 -          [A, B] = str:tokens(ejabberd_sql:escape(jlib:i2l(I)), <<"@">>),
 -          [A, <<"'", B/binary, "'">>]
 -    end,
 -    Count = case catch
 -      ejabberd_sql:sql_query_t([<<"select count(*) from pubsub_item where nodeid='">>, SNidx, <<"';">>])
 -    of
 -      {selected, [_], [[C]]} -> C;
 -      _ -> <<"0">>
 -    end,
 +                      integer_to_binary(IncIndex), <<" );">>]) of
 +                  {selected, [_], [[O]]} ->
 +                      [<<"modification">>, <<"'", O/binary, "'">>];
 +                  _ ->
 +                      [<<"modification">>, <<"null">>]
 +              end;
 +          undefined ->
 +              [<<"modification">>, <<"null">>];
 +          <<>> ->
 +              [<<"modification">>, <<"null">>];
 +          I ->
 +              [A, B] = str:tokens(ejabberd_sql:escape(I), <<"@">>),
 +              [A, <<"'", B/binary, "'">>]
 +      end,
 +    Count = case ejabberd_sql:sql_query_t(
 +                 [<<"select count(*) from pubsub_item where nodeid='">>,
 +                  SNidx, <<"';">>]) of
 +              {selected, [_], [[C]]} -> binary_to_integer(C);
 +              _ -> 0
 +          end,
      Query = fun(mssql, _) ->
                    ejabberd_sql:sql_query_t(
 -                    [<<"select top ">>, jlib:i2l(Max),
 +                    [<<"select top ">>, integer_to_binary(Max),
                       <<" itemid, publisher, creation, modification, payload "
                         "from pubsub_item where nodeid='">>, SNidx,
                       <<"' and ">>, AttrName, <<" ">>, Way, <<" ">>, Id, <<" order by ">>,
diff --cc src/node_mb.erl
Simple merge
Simple merge
index 345de7031f81c1dc51457384b236edd071fe95f6,0000000000000000000000000000000000000000..8713365cc11016faa1c0fc64c8afcc143be48bd9
mode 100644,000000..100644
--- /dev/null
@@@ -1,34115 -1,0 +1,34660 @@@
-     encode_thumbnail(Thumbnail, TopXMLNS).
 +%% Created automatically by XML generator (fxml_gen.erl)
 +%% Source: xmpp_codec.spec
 +
 +-module(xmpp_codec).
 +
 +-compile({nowarn_unused_function,
 +        [{dec_int, 3}, {dec_int, 1}, {dec_enum, 2},
 +         {enc_int, 1}, {get_attr, 2}, {enc_enum, 1},
 +         {choose_top_xmlns, 3}, {enc_xmlns_attrs, 2}]}).
 +
 +-export([pp/1, format_error/1, decode/1, decode/2,
 +       decode/3, is_known_tag/2, encode/1, encode/2,
 +       get_name/1, get_ns/1]).
 +
 +decode(_el) -> decode(_el, <<>>, []).
 +
 +decode(_el, Opts) -> decode(_el, <<>>, Opts).
 +
 +decode({xmlel, _name, _attrs, _} = _el, TopXMLNS,
 +       Opts) ->
 +    IgnoreEls = proplists:get_bool(ignore_els, Opts),
 +    case {_name, get_attr(<<"xmlns">>, _attrs), TopXMLNS} of
++      {<<"query">>, <<"urn:xmpp:delegation:1">>, _} ->
++        decode_delegation_query(<<"urn:xmpp:delegation:1">>,
++                                IgnoreEls, _el);
++      {<<"query">>, <<>>, <<"urn:xmpp:delegation:1">>} ->
++        decode_delegation_query(<<"urn:xmpp:delegation:1">>,
++                                IgnoreEls, _el);
++      {<<"delegate">>, <<"urn:xmpp:delegation:1">>, _} ->
++        decode_delegate(<<"urn:xmpp:delegation:1">>, IgnoreEls,
++                        _el);
++      {<<"delegate">>, <<>>, <<"urn:xmpp:delegation:1">>} ->
++        decode_delegate(<<"urn:xmpp:delegation:1">>, IgnoreEls,
++                        _el);
++      {<<"delegation">>, <<"urn:xmpp:delegation:1">>, _} ->
++        decode_delegation(<<"urn:xmpp:delegation:1">>,
++                          IgnoreEls, _el);
++      {<<"delegation">>, <<>>, <<"urn:xmpp:delegation:1">>} ->
++        decode_delegation(<<"urn:xmpp:delegation:1">>,
++                          IgnoreEls, _el);
++      {<<"delegated">>, <<"urn:xmpp:delegation:1">>, _} ->
++        decode_delegated(<<"urn:xmpp:delegation:1">>, IgnoreEls,
++                         _el);
++      {<<"delegated">>, <<>>, <<"urn:xmpp:delegation:1">>} ->
++        decode_delegated(<<"urn:xmpp:delegation:1">>, IgnoreEls,
++                         _el);
++      {<<"attribute">>, <<"urn:xmpp:delegation:1">>, _} ->
++        decode_delegated_attribute(<<"urn:xmpp:delegation:1">>,
++                                   IgnoreEls, _el);
++      {<<"attribute">>, <<>>, <<"urn:xmpp:delegation:1">>} ->
++        decode_delegated_attribute(<<"urn:xmpp:delegation:1">>,
++                                   IgnoreEls, _el);
++      {<<"privilege">>, <<"urn:xmpp:privilege:1">>, _} ->
++        decode_privilege(<<"urn:xmpp:privilege:1">>, IgnoreEls,
++                         _el);
++      {<<"privilege">>, <<>>, <<"urn:xmpp:privilege:1">>} ->
++        decode_privilege(<<"urn:xmpp:privilege:1">>, IgnoreEls,
++                         _el);
++      {<<"perm">>, <<"urn:xmpp:privilege:1">>, _} ->
++        decode_privilege_perm(<<"urn:xmpp:privilege:1">>,
++                              IgnoreEls, _el);
++      {<<"perm">>, <<>>, <<"urn:xmpp:privilege:1">>} ->
++        decode_privilege_perm(<<"urn:xmpp:privilege:1">>,
++                              IgnoreEls, _el);
 +      {<<"thumbnail">>, <<"urn:xmpp:thumbs:1">>, _} ->
 +        decode_thumbnail(<<"urn:xmpp:thumbs:1">>, IgnoreEls,
 +                         _el);
 +      {<<"thumbnail">>, <<>>, <<"urn:xmpp:thumbs:1">>} ->
 +        decode_thumbnail(<<"urn:xmpp:thumbs:1">>, IgnoreEls,
 +                         _el);
 +      {<<"slot">>, <<"urn:xmpp:http:upload">>, _} ->
 +        decode_upload_slot(<<"urn:xmpp:http:upload">>,
 +                           IgnoreEls, _el);
 +      {<<"slot">>, <<>>, <<"urn:xmpp:http:upload">>} ->
 +        decode_upload_slot(<<"urn:xmpp:http:upload">>,
 +                           IgnoreEls, _el);
 +      {<<"slot">>, <<"eu:siacs:conversations:http:upload">>,
 +       _} ->
 +        decode_upload_slot(<<"eu:siacs:conversations:http:upload">>,
 +                           IgnoreEls, _el);
 +      {<<"slot">>, <<>>,
 +       <<"eu:siacs:conversations:http:upload">>} ->
 +        decode_upload_slot(<<"eu:siacs:conversations:http:upload">>,
 +                           IgnoreEls, _el);
 +      {<<"put">>, <<"urn:xmpp:http:upload">>, _} ->
 +        decode_upload_put(<<"urn:xmpp:http:upload">>, IgnoreEls,
 +                          _el);
 +      {<<"put">>, <<>>, <<"urn:xmpp:http:upload">>} ->
 +        decode_upload_put(<<"urn:xmpp:http:upload">>, IgnoreEls,
 +                          _el);
 +      {<<"put">>, <<"eu:siacs:conversations:http:upload">>,
 +       _} ->
 +        decode_upload_put(<<"eu:siacs:conversations:http:upload">>,
 +                          IgnoreEls, _el);
 +      {<<"put">>, <<>>,
 +       <<"eu:siacs:conversations:http:upload">>} ->
 +        decode_upload_put(<<"eu:siacs:conversations:http:upload">>,
 +                          IgnoreEls, _el);
 +      {<<"get">>, <<"urn:xmpp:http:upload">>, _} ->
 +        decode_upload_get(<<"urn:xmpp:http:upload">>, IgnoreEls,
 +                          _el);
 +      {<<"get">>, <<>>, <<"urn:xmpp:http:upload">>} ->
 +        decode_upload_get(<<"urn:xmpp:http:upload">>, IgnoreEls,
 +                          _el);
 +      {<<"get">>, <<"eu:siacs:conversations:http:upload">>,
 +       _} ->
 +        decode_upload_get(<<"eu:siacs:conversations:http:upload">>,
 +                          IgnoreEls, _el);
 +      {<<"get">>, <<>>,
 +       <<"eu:siacs:conversations:http:upload">>} ->
 +        decode_upload_get(<<"eu:siacs:conversations:http:upload">>,
 +                          IgnoreEls, _el);
 +      {<<"request">>, <<"urn:xmpp:http:upload">>, _} ->
 +        decode_upload_request(<<"urn:xmpp:http:upload">>,
 +                              IgnoreEls, _el);
 +      {<<"request">>, <<>>, <<"urn:xmpp:http:upload">>} ->
 +        decode_upload_request(<<"urn:xmpp:http:upload">>,
 +                              IgnoreEls, _el);
 +      {<<"request">>,
 +       <<"eu:siacs:conversations:http:upload">>, _} ->
 +        decode_upload_request(<<"eu:siacs:conversations:http:upload">>,
 +                              IgnoreEls, _el);
 +      {<<"request">>, <<>>,
 +       <<"eu:siacs:conversations:http:upload">>} ->
 +        decode_upload_request(<<"eu:siacs:conversations:http:upload">>,
 +                              IgnoreEls, _el);
 +      {<<"content-type">>, <<"urn:xmpp:http:upload">>, _} ->
 +        decode_upload_content_type(<<"urn:xmpp:http:upload">>,
 +                                   IgnoreEls, _el);
 +      {<<"content-type">>, <<>>,
 +       <<"urn:xmpp:http:upload">>} ->
 +        decode_upload_content_type(<<"urn:xmpp:http:upload">>,
 +                                   IgnoreEls, _el);
 +      {<<"content-type">>,
 +       <<"eu:siacs:conversations:http:upload">>, _} ->
 +        decode_upload_content_type(<<"eu:siacs:conversations:http:upload">>,
 +                                   IgnoreEls, _el);
 +      {<<"content-type">>, <<>>,
 +       <<"eu:siacs:conversations:http:upload">>} ->
 +        decode_upload_content_type(<<"eu:siacs:conversations:http:upload">>,
 +                                   IgnoreEls, _el);
 +      {<<"size">>, <<"urn:xmpp:http:upload">>, _} ->
 +        decode_upload_size(<<"urn:xmpp:http:upload">>,
 +                           IgnoreEls, _el);
 +      {<<"size">>, <<>>, <<"urn:xmpp:http:upload">>} ->
 +        decode_upload_size(<<"urn:xmpp:http:upload">>,
 +                           IgnoreEls, _el);
 +      {<<"size">>, <<"eu:siacs:conversations:http:upload">>,
 +       _} ->
 +        decode_upload_size(<<"eu:siacs:conversations:http:upload">>,
 +                           IgnoreEls, _el);
 +      {<<"size">>, <<>>,
 +       <<"eu:siacs:conversations:http:upload">>} ->
 +        decode_upload_size(<<"eu:siacs:conversations:http:upload">>,
 +                           IgnoreEls, _el);
 +      {<<"filename">>, <<"urn:xmpp:http:upload">>, _} ->
 +        decode_upload_filename(<<"urn:xmpp:http:upload">>,
 +                               IgnoreEls, _el);
 +      {<<"filename">>, <<>>, <<"urn:xmpp:http:upload">>} ->
 +        decode_upload_filename(<<"urn:xmpp:http:upload">>,
 +                               IgnoreEls, _el);
 +      {<<"filename">>,
 +       <<"eu:siacs:conversations:http:upload">>, _} ->
 +        decode_upload_filename(<<"eu:siacs:conversations:http:upload">>,
 +                               IgnoreEls, _el);
 +      {<<"filename">>, <<>>,
 +       <<"eu:siacs:conversations:http:upload">>} ->
 +        decode_upload_filename(<<"eu:siacs:conversations:http:upload">>,
 +                               IgnoreEls, _el);
 +      {<<"address">>, <<"urn:xmpp:sic:0">>, _} ->
 +        decode_sic(<<"urn:xmpp:sic:0">>, IgnoreEls, _el);
 +      {<<"address">>, <<>>, <<"urn:xmpp:sic:0">>} ->
 +        decode_sic(<<"urn:xmpp:sic:0">>, IgnoreEls, _el);
 +      {<<"address">>, <<"urn:xmpp:sic:1">>, _} ->
 +        decode_sic(<<"urn:xmpp:sic:1">>, IgnoreEls, _el);
 +      {<<"address">>, <<>>, <<"urn:xmpp:sic:1">>} ->
 +        decode_sic(<<"urn:xmpp:sic:1">>, IgnoreEls, _el);
 +      {<<"port">>, <<"urn:xmpp:sic:1">>, _} ->
 +        decode_sip_port(<<"urn:xmpp:sic:1">>, IgnoreEls, _el);
 +      {<<"port">>, <<>>, <<"urn:xmpp:sic:1">>} ->
 +        decode_sip_port(<<"urn:xmpp:sic:1">>, IgnoreEls, _el);
 +      {<<"ip">>, <<"urn:xmpp:sic:0">>, _} ->
 +        decode_sic_ip(<<"urn:xmpp:sic:0">>, IgnoreEls, _el);
 +      {<<"ip">>, <<>>, <<"urn:xmpp:sic:0">>} ->
 +        decode_sic_ip(<<"urn:xmpp:sic:0">>, IgnoreEls, _el);
 +      {<<"ip">>, <<"urn:xmpp:sic:1">>, _} ->
 +        decode_sic_ip(<<"urn:xmpp:sic:1">>, IgnoreEls, _el);
 +      {<<"ip">>, <<>>, <<"urn:xmpp:sic:1">>} ->
 +        decode_sic_ip(<<"urn:xmpp:sic:1">>, IgnoreEls, _el);
 +      {<<"x">>, <<"jabber:x:oob">>, _} ->
 +        decode_oob_x(<<"jabber:x:oob">>, IgnoreEls, _el);
 +      {<<"x">>, <<>>, <<"jabber:x:oob">>} ->
 +        decode_oob_x(<<"jabber:x:oob">>, IgnoreEls, _el);
 +      {<<"desc">>, <<"jabber:x:oob">>, _} ->
 +        decode_oob_desc(<<"jabber:x:oob">>, IgnoreEls, _el);
 +      {<<"desc">>, <<>>, <<"jabber:x:oob">>} ->
 +        decode_oob_desc(<<"jabber:x:oob">>, IgnoreEls, _el);
 +      {<<"url">>, <<"jabber:x:oob">>, _} ->
 +        decode_oob_url(<<"jabber:x:oob">>, IgnoreEls, _el);
 +      {<<"url">>, <<>>, <<"jabber:x:oob">>} ->
 +        decode_oob_url(<<"jabber:x:oob">>, IgnoreEls, _el);
 +      {<<"media">>, <<"urn:xmpp:media-element">>, _} ->
 +        decode_media(<<"urn:xmpp:media-element">>, IgnoreEls,
 +                     _el);
 +      {<<"media">>, <<>>, <<"urn:xmpp:media-element">>} ->
 +        decode_media(<<"urn:xmpp:media-element">>, IgnoreEls,
 +                     _el);
 +      {<<"uri">>, <<"urn:xmpp:media-element">>, _} ->
 +        decode_media_uri(<<"urn:xmpp:media-element">>,
 +                         IgnoreEls, _el);
 +      {<<"uri">>, <<>>, <<"urn:xmpp:media-element">>} ->
 +        decode_media_uri(<<"urn:xmpp:media-element">>,
 +                         IgnoreEls, _el);
 +      {<<"captcha">>, <<"urn:xmpp:captcha">>, _} ->
 +        decode_captcha(<<"urn:xmpp:captcha">>, IgnoreEls, _el);
 +      {<<"captcha">>, <<>>, <<"urn:xmpp:captcha">>} ->
 +        decode_captcha(<<"urn:xmpp:captcha">>, IgnoreEls, _el);
 +      {<<"data">>, <<"urn:xmpp:bob">>, _} ->
 +        decode_bob_data(<<"urn:xmpp:bob">>, IgnoreEls, _el);
 +      {<<"data">>, <<>>, <<"urn:xmpp:bob">>} ->
 +        decode_bob_data(<<"urn:xmpp:bob">>, IgnoreEls, _el);
 +      {<<"stream:stream">>, <<"jabber:client">>, _} ->
 +        decode_stream_start(<<"jabber:client">>, IgnoreEls,
 +                            _el);
 +      {<<"stream:stream">>, <<>>, <<"jabber:client">>} ->
 +        decode_stream_start(<<"jabber:client">>, IgnoreEls,
 +                            _el);
 +      {<<"stream:stream">>, <<"jabber:server">>, _} ->
 +        decode_stream_start(<<"jabber:server">>, IgnoreEls,
 +                            _el);
 +      {<<"stream:stream">>, <<>>, <<"jabber:server">>} ->
 +        decode_stream_start(<<"jabber:server">>, IgnoreEls,
 +                            _el);
 +      {<<"stream:stream">>, <<"jabber:component:accept">>,
 +       _} ->
 +        decode_stream_start(<<"jabber:component:accept">>,
 +                            IgnoreEls, _el);
 +      {<<"stream:stream">>, <<>>,
 +       <<"jabber:component:accept">>} ->
 +        decode_stream_start(<<"jabber:component:accept">>,
 +                            IgnoreEls, _el);
 +      {<<"handshake">>, <<"jabber:component:accept">>, _} ->
 +        decode_handshake(<<"jabber:component:accept">>,
 +                         IgnoreEls, _el);
 +      {<<"handshake">>, <<>>,
 +       <<"jabber:component:accept">>} ->
 +        decode_handshake(<<"jabber:component:accept">>,
 +                         IgnoreEls, _el);
 +      {<<"db:verify">>, <<"jabber:server">>, _} ->
 +        decode_db_verify(<<"jabber:server">>, IgnoreEls, _el);
 +      {<<"db:verify">>, <<>>, <<"jabber:server">>} ->
 +        decode_db_verify(<<"jabber:server">>, IgnoreEls, _el);
 +      {<<"db:result">>, <<"jabber:server">>, _} ->
 +        decode_db_result(<<"jabber:server">>, IgnoreEls, _el);
 +      {<<"db:result">>, <<>>, <<"jabber:server">>} ->
 +        decode_db_result(<<"jabber:server">>, IgnoreEls, _el);
 +      {<<"command">>,
 +       <<"http://jabber.org/protocol/commands">>, _} ->
 +        decode_adhoc_command(<<"http://jabber.org/protocol/commands">>,
 +                             IgnoreEls, _el);
 +      {<<"command">>, <<>>,
 +       <<"http://jabber.org/protocol/commands">>} ->
 +        decode_adhoc_command(<<"http://jabber.org/protocol/commands">>,
 +                             IgnoreEls, _el);
 +      {<<"note">>, <<"http://jabber.org/protocol/commands">>,
 +       _} ->
 +        decode_adhoc_command_notes(<<"http://jabber.org/protocol/commands">>,
 +                                   IgnoreEls, _el);
 +      {<<"note">>, <<>>,
 +       <<"http://jabber.org/protocol/commands">>} ->
 +        decode_adhoc_command_notes(<<"http://jabber.org/protocol/commands">>,
 +                                   IgnoreEls, _el);
 +      {<<"actions">>,
 +       <<"http://jabber.org/protocol/commands">>, _} ->
 +        decode_adhoc_command_actions(<<"http://jabber.org/protocol/commands">>,
 +                                     IgnoreEls, _el);
 +      {<<"actions">>, <<>>,
 +       <<"http://jabber.org/protocol/commands">>} ->
 +        decode_adhoc_command_actions(<<"http://jabber.org/protocol/commands">>,
 +                                     IgnoreEls, _el);
 +      {<<"complete">>,
 +       <<"http://jabber.org/protocol/commands">>, _} ->
 +        decode_adhoc_command_complete(<<"http://jabber.org/protocol/commands">>,
 +                                      IgnoreEls, _el);
 +      {<<"complete">>, <<>>,
 +       <<"http://jabber.org/protocol/commands">>} ->
 +        decode_adhoc_command_complete(<<"http://jabber.org/protocol/commands">>,
 +                                      IgnoreEls, _el);
 +      {<<"next">>, <<"http://jabber.org/protocol/commands">>,
 +       _} ->
 +        decode_adhoc_command_next(<<"http://jabber.org/protocol/commands">>,
 +                                  IgnoreEls, _el);
 +      {<<"next">>, <<>>,
 +       <<"http://jabber.org/protocol/commands">>} ->
 +        decode_adhoc_command_next(<<"http://jabber.org/protocol/commands">>,
 +                                  IgnoreEls, _el);
 +      {<<"prev">>, <<"http://jabber.org/protocol/commands">>,
 +       _} ->
 +        decode_adhoc_command_prev(<<"http://jabber.org/protocol/commands">>,
 +                                  IgnoreEls, _el);
 +      {<<"prev">>, <<>>,
 +       <<"http://jabber.org/protocol/commands">>} ->
 +        decode_adhoc_command_prev(<<"http://jabber.org/protocol/commands">>,
 +                                  IgnoreEls, _el);
 +      {<<"client-id">>, <<"urn:xmpp:sid:0">>, _} ->
 +        decode_client_id(<<"urn:xmpp:sid:0">>, IgnoreEls, _el);
 +      {<<"client-id">>, <<>>, <<"urn:xmpp:sid:0">>} ->
 +        decode_client_id(<<"urn:xmpp:sid:0">>, IgnoreEls, _el);
 +      {<<"stanza-id">>, <<"urn:xmpp:sid:0">>, _} ->
 +        decode_stanza_id(<<"urn:xmpp:sid:0">>, IgnoreEls, _el);
 +      {<<"stanza-id">>, <<>>, <<"urn:xmpp:sid:0">>} ->
 +        decode_stanza_id(<<"urn:xmpp:sid:0">>, IgnoreEls, _el);
 +      {<<"addresses">>,
 +       <<"http://jabber.org/protocol/address">>, _} ->
 +        decode_addresses(<<"http://jabber.org/protocol/address">>,
 +                         IgnoreEls, _el);
 +      {<<"addresses">>, <<>>,
 +       <<"http://jabber.org/protocol/address">>} ->
 +        decode_addresses(<<"http://jabber.org/protocol/address">>,
 +                         IgnoreEls, _el);
 +      {<<"address">>,
 +       <<"http://jabber.org/protocol/address">>, _} ->
 +        decode_address(<<"http://jabber.org/protocol/address">>,
 +                       IgnoreEls, _el);
 +      {<<"address">>, <<>>,
 +       <<"http://jabber.org/protocol/address">>} ->
 +        decode_address(<<"http://jabber.org/protocol/address">>,
 +                       IgnoreEls, _el);
 +      {<<"nick">>, <<"http://jabber.org/protocol/nick">>,
 +       _} ->
 +        decode_nick(<<"http://jabber.org/protocol/nick">>,
 +                    IgnoreEls, _el);
 +      {<<"nick">>, <<>>,
 +       <<"http://jabber.org/protocol/nick">>} ->
 +        decode_nick(<<"http://jabber.org/protocol/nick">>,
 +                    IgnoreEls, _el);
 +      {<<"x">>, <<"jabber:x:expire">>, _} ->
 +        decode_expire(<<"jabber:x:expire">>, IgnoreEls, _el);
 +      {<<"x">>, <<>>, <<"jabber:x:expire">>} ->
 +        decode_expire(<<"jabber:x:expire">>, IgnoreEls, _el);
 +      {<<"x">>, <<"jabber:x:event">>, _} ->
 +        decode_xevent(<<"jabber:x:event">>, IgnoreEls, _el);
 +      {<<"x">>, <<>>, <<"jabber:x:event">>} ->
 +        decode_xevent(<<"jabber:x:event">>, IgnoreEls, _el);
 +      {<<"id">>, <<"jabber:x:event">>, _} ->
 +        decode_xevent_id(<<"jabber:x:event">>, IgnoreEls, _el);
 +      {<<"id">>, <<>>, <<"jabber:x:event">>} ->
 +        decode_xevent_id(<<"jabber:x:event">>, IgnoreEls, _el);
 +      {<<"composing">>, <<"jabber:x:event">>, _} ->
 +        decode_xevent_composing(<<"jabber:x:event">>, IgnoreEls,
 +                                _el);
 +      {<<"composing">>, <<>>, <<"jabber:x:event">>} ->
 +        decode_xevent_composing(<<"jabber:x:event">>, IgnoreEls,
 +                                _el);
 +      {<<"displayed">>, <<"jabber:x:event">>, _} ->
 +        decode_xevent_displayed(<<"jabber:x:event">>, IgnoreEls,
 +                                _el);
 +      {<<"displayed">>, <<>>, <<"jabber:x:event">>} ->
 +        decode_xevent_displayed(<<"jabber:x:event">>, IgnoreEls,
 +                                _el);
 +      {<<"delivered">>, <<"jabber:x:event">>, _} ->
 +        decode_xevent_delivered(<<"jabber:x:event">>, IgnoreEls,
 +                                _el);
 +      {<<"delivered">>, <<>>, <<"jabber:x:event">>} ->
 +        decode_xevent_delivered(<<"jabber:x:event">>, IgnoreEls,
 +                                _el);
 +      {<<"offline">>, <<"jabber:x:event">>, _} ->
 +        decode_xevent_offline(<<"jabber:x:event">>, IgnoreEls,
 +                              _el);
 +      {<<"offline">>, <<>>, <<"jabber:x:event">>} ->
 +        decode_xevent_offline(<<"jabber:x:event">>, IgnoreEls,
 +                              _el);
 +      {<<"query">>, <<"jabber:iq:search">>, _} ->
 +        decode_search(<<"jabber:iq:search">>, IgnoreEls, _el);
 +      {<<"query">>, <<>>, <<"jabber:iq:search">>} ->
 +        decode_search(<<"jabber:iq:search">>, IgnoreEls, _el);
 +      {<<"item">>, <<"jabber:iq:search">>, _} ->
 +        decode_search_item(<<"jabber:iq:search">>, IgnoreEls,
 +                           _el);
 +      {<<"item">>, <<>>, <<"jabber:iq:search">>} ->
 +        decode_search_item(<<"jabber:iq:search">>, IgnoreEls,
 +                           _el);
 +      {<<"email">>, <<"jabber:iq:search">>, _} ->
 +        decode_search_email(<<"jabber:iq:search">>, IgnoreEls,
 +                            _el);
 +      {<<"email">>, <<>>, <<"jabber:iq:search">>} ->
 +        decode_search_email(<<"jabber:iq:search">>, IgnoreEls,
 +                            _el);
 +      {<<"nick">>, <<"jabber:iq:search">>, _} ->
 +        decode_search_nick(<<"jabber:iq:search">>, IgnoreEls,
 +                           _el);
 +      {<<"nick">>, <<>>, <<"jabber:iq:search">>} ->
 +        decode_search_nick(<<"jabber:iq:search">>, IgnoreEls,
 +                           _el);
 +      {<<"last">>, <<"jabber:iq:search">>, _} ->
 +        decode_search_last(<<"jabber:iq:search">>, IgnoreEls,
 +                           _el);
 +      {<<"last">>, <<>>, <<"jabber:iq:search">>} ->
 +        decode_search_last(<<"jabber:iq:search">>, IgnoreEls,
 +                           _el);
 +      {<<"first">>, <<"jabber:iq:search">>, _} ->
 +        decode_search_first(<<"jabber:iq:search">>, IgnoreEls,
 +                            _el);
 +      {<<"first">>, <<>>, <<"jabber:iq:search">>} ->
 +        decode_search_first(<<"jabber:iq:search">>, IgnoreEls,
 +                            _el);
 +      {<<"instructions">>, <<"jabber:iq:search">>, _} ->
 +        decode_search_instructions(<<"jabber:iq:search">>,
 +                                   IgnoreEls, _el);
 +      {<<"instructions">>, <<>>, <<"jabber:iq:search">>} ->
 +        decode_search_instructions(<<"jabber:iq:search">>,
 +                                   IgnoreEls, _el);
 +      {<<"no-permanent-storage">>, <<"urn:xmpp:hints">>, _} ->
 +        decode_hint_no_permanent_storage(<<"urn:xmpp:hints">>,
 +                                         IgnoreEls, _el);
 +      {<<"no-permanent-storage">>, <<>>,
 +       <<"urn:xmpp:hints">>} ->
 +        decode_hint_no_permanent_storage(<<"urn:xmpp:hints">>,
 +                                         IgnoreEls, _el);
 +      {<<"no-permanent-store">>, <<"urn:xmpp:hints">>, _} ->
 +        decode_hint_no_permanent_store(<<"urn:xmpp:hints">>,
 +                                       IgnoreEls, _el);
 +      {<<"no-permanent-store">>, <<>>,
 +       <<"urn:xmpp:hints">>} ->
 +        decode_hint_no_permanent_store(<<"urn:xmpp:hints">>,
 +                                       IgnoreEls, _el);
 +      {<<"store">>, <<"urn:xmpp:hints">>, _} ->
 +        decode_hint_store(<<"urn:xmpp:hints">>, IgnoreEls, _el);
 +      {<<"store">>, <<>>, <<"urn:xmpp:hints">>} ->
 +        decode_hint_store(<<"urn:xmpp:hints">>, IgnoreEls, _el);
 +      {<<"no-storage">>, <<"urn:xmpp:hints">>, _} ->
 +        decode_hint_no_storage(<<"urn:xmpp:hints">>, IgnoreEls,
 +                               _el);
 +      {<<"no-storage">>, <<>>, <<"urn:xmpp:hints">>} ->
 +        decode_hint_no_storage(<<"urn:xmpp:hints">>, IgnoreEls,
 +                               _el);
 +      {<<"no-store">>, <<"urn:xmpp:hints">>, _} ->
 +        decode_hint_no_store(<<"urn:xmpp:hints">>, IgnoreEls,
 +                             _el);
 +      {<<"no-store">>, <<>>, <<"urn:xmpp:hints">>} ->
 +        decode_hint_no_store(<<"urn:xmpp:hints">>, IgnoreEls,
 +                             _el);
 +      {<<"no-copy">>, <<"urn:xmpp:hints">>, _} ->
 +        decode_hint_no_copy(<<"urn:xmpp:hints">>, IgnoreEls,
 +                            _el);
 +      {<<"no-copy">>, <<>>, <<"urn:xmpp:hints">>} ->
 +        decode_hint_no_copy(<<"urn:xmpp:hints">>, IgnoreEls,
 +                            _el);
 +      {<<"participant">>, <<"urn:xmpp:mix:0">>, _} ->
 +        decode_mix_participant(<<"urn:xmpp:mix:0">>, IgnoreEls,
 +                               _el);
 +      {<<"participant">>, <<>>, <<"urn:xmpp:mix:0">>} ->
 +        decode_mix_participant(<<"urn:xmpp:mix:0">>, IgnoreEls,
 +                               _el);
 +      {<<"leave">>, <<"urn:xmpp:mix:0">>, _} ->
 +        decode_mix_leave(<<"urn:xmpp:mix:0">>, IgnoreEls, _el);
 +      {<<"leave">>, <<>>, <<"urn:xmpp:mix:0">>} ->
 +        decode_mix_leave(<<"urn:xmpp:mix:0">>, IgnoreEls, _el);
 +      {<<"join">>, <<"urn:xmpp:mix:0">>, _} ->
 +        decode_mix_join(<<"urn:xmpp:mix:0">>, IgnoreEls, _el);
 +      {<<"join">>, <<>>, <<"urn:xmpp:mix:0">>} ->
 +        decode_mix_join(<<"urn:xmpp:mix:0">>, IgnoreEls, _el);
 +      {<<"subscribe">>, <<"urn:xmpp:mix:0">>, _} ->
 +        decode_mix_subscribe(<<"urn:xmpp:mix:0">>, IgnoreEls,
 +                             _el);
 +      {<<"subscribe">>, <<>>, <<"urn:xmpp:mix:0">>} ->
 +        decode_mix_subscribe(<<"urn:xmpp:mix:0">>, IgnoreEls,
 +                             _el);
 +      {<<"offline">>,
 +       <<"http://jabber.org/protocol/offline">>, _} ->
 +        decode_offline(<<"http://jabber.org/protocol/offline">>,
 +                       IgnoreEls, _el);
 +      {<<"offline">>, <<>>,
 +       <<"http://jabber.org/protocol/offline">>} ->
 +        decode_offline(<<"http://jabber.org/protocol/offline">>,
 +                       IgnoreEls, _el);
 +      {<<"item">>, <<"http://jabber.org/protocol/offline">>,
 +       _} ->
 +        decode_offline_item(<<"http://jabber.org/protocol/offline">>,
 +                            IgnoreEls, _el);
 +      {<<"item">>, <<>>,
 +       <<"http://jabber.org/protocol/offline">>} ->
 +        decode_offline_item(<<"http://jabber.org/protocol/offline">>,
 +                            IgnoreEls, _el);
 +      {<<"fetch">>, <<"http://jabber.org/protocol/offline">>,
 +       _} ->
 +        decode_offline_fetch(<<"http://jabber.org/protocol/offline">>,
 +                             IgnoreEls, _el);
 +      {<<"fetch">>, <<>>,
 +       <<"http://jabber.org/protocol/offline">>} ->
 +        decode_offline_fetch(<<"http://jabber.org/protocol/offline">>,
 +                             IgnoreEls, _el);
 +      {<<"purge">>, <<"http://jabber.org/protocol/offline">>,
 +       _} ->
 +        decode_offline_purge(<<"http://jabber.org/protocol/offline">>,
 +                             IgnoreEls, _el);
 +      {<<"purge">>, <<>>,
 +       <<"http://jabber.org/protocol/offline">>} ->
 +        decode_offline_purge(<<"http://jabber.org/protocol/offline">>,
 +                             IgnoreEls, _el);
 +      {<<"failed">>, <<"urn:xmpp:sm:2">>, _} ->
 +        decode_sm_failed(<<"urn:xmpp:sm:2">>, IgnoreEls, _el);
 +      {<<"failed">>, <<>>, <<"urn:xmpp:sm:2">>} ->
 +        decode_sm_failed(<<"urn:xmpp:sm:2">>, IgnoreEls, _el);
 +      {<<"failed">>, <<"urn:xmpp:sm:3">>, _} ->
 +        decode_sm_failed(<<"urn:xmpp:sm:3">>, IgnoreEls, _el);
 +      {<<"failed">>, <<>>, <<"urn:xmpp:sm:3">>} ->
 +        decode_sm_failed(<<"urn:xmpp:sm:3">>, IgnoreEls, _el);
 +      {<<"a">>, <<"urn:xmpp:sm:2">>, _} ->
 +        decode_sm_a(<<"urn:xmpp:sm:2">>, IgnoreEls, _el);
 +      {<<"a">>, <<>>, <<"urn:xmpp:sm:2">>} ->
 +        decode_sm_a(<<"urn:xmpp:sm:2">>, IgnoreEls, _el);
 +      {<<"a">>, <<"urn:xmpp:sm:3">>, _} ->
 +        decode_sm_a(<<"urn:xmpp:sm:3">>, IgnoreEls, _el);
 +      {<<"a">>, <<>>, <<"urn:xmpp:sm:3">>} ->
 +        decode_sm_a(<<"urn:xmpp:sm:3">>, IgnoreEls, _el);
 +      {<<"r">>, <<"urn:xmpp:sm:2">>, _} ->
 +        decode_sm_r(<<"urn:xmpp:sm:2">>, IgnoreEls, _el);
 +      {<<"r">>, <<>>, <<"urn:xmpp:sm:2">>} ->
 +        decode_sm_r(<<"urn:xmpp:sm:2">>, IgnoreEls, _el);
 +      {<<"r">>, <<"urn:xmpp:sm:3">>, _} ->
 +        decode_sm_r(<<"urn:xmpp:sm:3">>, IgnoreEls, _el);
 +      {<<"r">>, <<>>, <<"urn:xmpp:sm:3">>} ->
 +        decode_sm_r(<<"urn:xmpp:sm:3">>, IgnoreEls, _el);
 +      {<<"resumed">>, <<"urn:xmpp:sm:2">>, _} ->
 +        decode_sm_resumed(<<"urn:xmpp:sm:2">>, IgnoreEls, _el);
 +      {<<"resumed">>, <<>>, <<"urn:xmpp:sm:2">>} ->
 +        decode_sm_resumed(<<"urn:xmpp:sm:2">>, IgnoreEls, _el);
 +      {<<"resumed">>, <<"urn:xmpp:sm:3">>, _} ->
 +        decode_sm_resumed(<<"urn:xmpp:sm:3">>, IgnoreEls, _el);
 +      {<<"resumed">>, <<>>, <<"urn:xmpp:sm:3">>} ->
 +        decode_sm_resumed(<<"urn:xmpp:sm:3">>, IgnoreEls, _el);
 +      {<<"resume">>, <<"urn:xmpp:sm:2">>, _} ->
 +        decode_sm_resume(<<"urn:xmpp:sm:2">>, IgnoreEls, _el);
 +      {<<"resume">>, <<>>, <<"urn:xmpp:sm:2">>} ->
 +        decode_sm_resume(<<"urn:xmpp:sm:2">>, IgnoreEls, _el);
 +      {<<"resume">>, <<"urn:xmpp:sm:3">>, _} ->
 +        decode_sm_resume(<<"urn:xmpp:sm:3">>, IgnoreEls, _el);
 +      {<<"resume">>, <<>>, <<"urn:xmpp:sm:3">>} ->
 +        decode_sm_resume(<<"urn:xmpp:sm:3">>, IgnoreEls, _el);
 +      {<<"enabled">>, <<"urn:xmpp:sm:2">>, _} ->
 +        decode_sm_enabled(<<"urn:xmpp:sm:2">>, IgnoreEls, _el);
 +      {<<"enabled">>, <<>>, <<"urn:xmpp:sm:2">>} ->
 +        decode_sm_enabled(<<"urn:xmpp:sm:2">>, IgnoreEls, _el);
 +      {<<"enabled">>, <<"urn:xmpp:sm:3">>, _} ->
 +        decode_sm_enabled(<<"urn:xmpp:sm:3">>, IgnoreEls, _el);
 +      {<<"enabled">>, <<>>, <<"urn:xmpp:sm:3">>} ->
 +        decode_sm_enabled(<<"urn:xmpp:sm:3">>, IgnoreEls, _el);
 +      {<<"enable">>, <<"urn:xmpp:sm:2">>, _} ->
 +        decode_sm_enable(<<"urn:xmpp:sm:2">>, IgnoreEls, _el);
 +      {<<"enable">>, <<>>, <<"urn:xmpp:sm:2">>} ->
 +        decode_sm_enable(<<"urn:xmpp:sm:2">>, IgnoreEls, _el);
 +      {<<"enable">>, <<"urn:xmpp:sm:3">>, _} ->
 +        decode_sm_enable(<<"urn:xmpp:sm:3">>, IgnoreEls, _el);
 +      {<<"enable">>, <<>>, <<"urn:xmpp:sm:3">>} ->
 +        decode_sm_enable(<<"urn:xmpp:sm:3">>, IgnoreEls, _el);
 +      {<<"sm">>, <<"urn:xmpp:sm:2">>, _} ->
 +        decode_feature_sm(<<"urn:xmpp:sm:2">>, IgnoreEls, _el);
 +      {<<"sm">>, <<>>, <<"urn:xmpp:sm:2">>} ->
 +        decode_feature_sm(<<"urn:xmpp:sm:2">>, IgnoreEls, _el);
 +      {<<"sm">>, <<"urn:xmpp:sm:3">>, _} ->
 +        decode_feature_sm(<<"urn:xmpp:sm:3">>, 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);
 +      {<<"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);
 +      {<<"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);
 +      {<<"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);
 +      {<<"sent">>, <<>>, <<"urn:xmpp:carbons:2">>} ->
 +        decode_carbons_sent(<<"urn:xmpp:carbons:2">>, IgnoreEls,
 +                            _el);
 +      {<<"received">>, <<"urn:xmpp:carbons:2">>, _} ->
 +        decode_carbons_received(<<"urn:xmpp:carbons:2">>,
 +                                IgnoreEls, _el);
 +      {<<"received">>, <<>>, <<"urn:xmpp:carbons:2">>} ->
 +        decode_carbons_received(<<"urn:xmpp:carbons:2">>,
 +                                IgnoreEls, _el);
 +      {<<"private">>, <<"urn:xmpp:carbons:2">>, _} ->
 +        decode_carbons_private(<<"urn:xmpp:carbons:2">>,
 +                               IgnoreEls, _el);
 +      {<<"private">>, <<>>, <<"urn:xmpp:carbons:2">>} ->
 +        decode_carbons_private(<<"urn:xmpp:carbons:2">>,
 +                               IgnoreEls, _el);
 +      {<<"enable">>, <<"urn:xmpp:carbons:2">>, _} ->
 +        decode_carbons_enable(<<"urn:xmpp:carbons:2">>,
 +                              IgnoreEls, _el);
 +      {<<"enable">>, <<>>, <<"urn:xmpp:carbons:2">>} ->
 +        decode_carbons_enable(<<"urn:xmpp:carbons:2">>,
 +                              IgnoreEls, _el);
 +      {<<"disable">>, <<"urn:xmpp:carbons:2">>, _} ->
 +        decode_carbons_disable(<<"urn:xmpp:carbons:2">>,
 +                               IgnoreEls, _el);
 +      {<<"disable">>, <<>>, <<"urn:xmpp:carbons:2">>} ->
 +        decode_carbons_disable(<<"urn:xmpp:carbons:2">>,
 +                               IgnoreEls, _el);
 +      {<<"forwarded">>, <<"urn:xmpp:forward:0">>, _} ->
 +        decode_forwarded(<<"urn:xmpp:forward:0">>, IgnoreEls,
 +                         _el);
 +      {<<"forwarded">>, <<>>, <<"urn:xmpp:forward:0">>} ->
 +        decode_forwarded(<<"urn:xmpp:forward:0">>, IgnoreEls,
 +                         _el);
 +      {<<"fin">>, <<"urn:xmpp:mam:0">>, _} ->
 +        decode_mam_fin(<<"urn:xmpp:mam:0">>, IgnoreEls, _el);
 +      {<<"fin">>, <<>>, <<"urn:xmpp:mam:0">>} ->
 +        decode_mam_fin(<<"urn:xmpp:mam:0">>, IgnoreEls, _el);
 +      {<<"fin">>, <<"urn:xmpp:mam:1">>, _} ->
 +        decode_mam_fin(<<"urn:xmpp:mam:1">>, IgnoreEls, _el);
 +      {<<"fin">>, <<>>, <<"urn:xmpp:mam:1">>} ->
 +        decode_mam_fin(<<"urn:xmpp:mam:1">>, IgnoreEls, _el);
 +      {<<"prefs">>, <<"urn:xmpp:mam:0">>, _} ->
 +        decode_mam_prefs(<<"urn:xmpp:mam:0">>, IgnoreEls, _el);
 +      {<<"prefs">>, <<>>, <<"urn:xmpp:mam:0">>} ->
 +        decode_mam_prefs(<<"urn:xmpp:mam:0">>, IgnoreEls, _el);
 +      {<<"prefs">>, <<"urn:xmpp:mam:1">>, _} ->
 +        decode_mam_prefs(<<"urn:xmpp:mam:1">>, IgnoreEls, _el);
 +      {<<"prefs">>, <<>>, <<"urn:xmpp:mam:1">>} ->
 +        decode_mam_prefs(<<"urn:xmpp:mam:1">>, IgnoreEls, _el);
 +      {<<"prefs">>, <<"urn:xmpp:mam:tmp">>, _} ->
 +        decode_mam_prefs(<<"urn:xmpp:mam:tmp">>, IgnoreEls,
 +                         _el);
 +      {<<"prefs">>, <<>>, <<"urn:xmpp:mam:tmp">>} ->
 +        decode_mam_prefs(<<"urn:xmpp:mam:tmp">>, IgnoreEls,
 +                         _el);
 +      {<<"always">>, <<"urn:xmpp:mam:0">>, _} ->
 +        decode_mam_always(<<"urn:xmpp:mam:0">>, IgnoreEls, _el);
 +      {<<"always">>, <<>>, <<"urn:xmpp:mam:0">>} ->
 +        decode_mam_always(<<"urn:xmpp:mam:0">>, IgnoreEls, _el);
 +      {<<"always">>, <<"urn:xmpp:mam:1">>, _} ->
 +        decode_mam_always(<<"urn:xmpp:mam:1">>, IgnoreEls, _el);
 +      {<<"always">>, <<>>, <<"urn:xmpp:mam:1">>} ->
 +        decode_mam_always(<<"urn:xmpp:mam:1">>, IgnoreEls, _el);
 +      {<<"always">>, <<"urn:xmpp:mam:tmp">>, _} ->
 +        decode_mam_always(<<"urn:xmpp:mam:tmp">>, IgnoreEls,
 +                          _el);
 +      {<<"always">>, <<>>, <<"urn:xmpp:mam:tmp">>} ->
 +        decode_mam_always(<<"urn:xmpp:mam:tmp">>, IgnoreEls,
 +                          _el);
 +      {<<"never">>, <<"urn:xmpp:mam:0">>, _} ->
 +        decode_mam_never(<<"urn:xmpp:mam:0">>, IgnoreEls, _el);
 +      {<<"never">>, <<>>, <<"urn:xmpp:mam:0">>} ->
 +        decode_mam_never(<<"urn:xmpp:mam:0">>, IgnoreEls, _el);
 +      {<<"never">>, <<"urn:xmpp:mam:1">>, _} ->
 +        decode_mam_never(<<"urn:xmpp:mam:1">>, IgnoreEls, _el);
 +      {<<"never">>, <<>>, <<"urn:xmpp:mam:1">>} ->
 +        decode_mam_never(<<"urn:xmpp:mam:1">>, IgnoreEls, _el);
 +      {<<"never">>, <<"urn:xmpp:mam:tmp">>, _} ->
 +        decode_mam_never(<<"urn:xmpp:mam:tmp">>, IgnoreEls,
 +                         _el);
 +      {<<"never">>, <<>>, <<"urn:xmpp:mam:tmp">>} ->
 +        decode_mam_never(<<"urn:xmpp:mam:tmp">>, IgnoreEls,
 +                         _el);
 +      {<<"jid">>, <<"urn:xmpp:mam:0">>, _} ->
 +        decode_mam_jid(<<"urn:xmpp:mam:0">>, IgnoreEls, _el);
 +      {<<"jid">>, <<>>, <<"urn:xmpp:mam:0">>} ->
 +        decode_mam_jid(<<"urn:xmpp:mam:0">>, IgnoreEls, _el);
 +      {<<"jid">>, <<"urn:xmpp:mam:1">>, _} ->
 +        decode_mam_jid(<<"urn:xmpp:mam:1">>, IgnoreEls, _el);
 +      {<<"jid">>, <<>>, <<"urn:xmpp:mam:1">>} ->
 +        decode_mam_jid(<<"urn:xmpp:mam:1">>, IgnoreEls, _el);
 +      {<<"jid">>, <<"urn:xmpp:mam:tmp">>, _} ->
 +        decode_mam_jid(<<"urn:xmpp:mam:tmp">>, IgnoreEls, _el);
 +      {<<"jid">>, <<>>, <<"urn:xmpp:mam:tmp">>} ->
 +        decode_mam_jid(<<"urn:xmpp:mam:tmp">>, IgnoreEls, _el);
 +      {<<"result">>, <<"urn:xmpp:mam:0">>, _} ->
 +        decode_mam_result(<<"urn:xmpp:mam:0">>, IgnoreEls, _el);
 +      {<<"result">>, <<>>, <<"urn:xmpp:mam:0">>} ->
 +        decode_mam_result(<<"urn:xmpp:mam:0">>, IgnoreEls, _el);
 +      {<<"result">>, <<"urn:xmpp:mam:1">>, _} ->
 +        decode_mam_result(<<"urn:xmpp:mam:1">>, IgnoreEls, _el);
 +      {<<"result">>, <<>>, <<"urn:xmpp:mam:1">>} ->
 +        decode_mam_result(<<"urn:xmpp:mam:1">>, IgnoreEls, _el);
 +      {<<"result">>, <<"urn:xmpp:mam:tmp">>, _} ->
 +        decode_mam_result(<<"urn:xmpp:mam:tmp">>, IgnoreEls,
 +                          _el);
 +      {<<"result">>, <<>>, <<"urn:xmpp:mam:tmp">>} ->
 +        decode_mam_result(<<"urn:xmpp:mam:tmp">>, IgnoreEls,
 +                          _el);
 +      {<<"archived">>, <<"urn:xmpp:mam:tmp">>, _} ->
 +        decode_mam_archived(<<"urn:xmpp:mam:tmp">>, IgnoreEls,
 +                            _el);
 +      {<<"archived">>, <<>>, <<"urn:xmpp:mam:tmp">>} ->
 +        decode_mam_archived(<<"urn:xmpp:mam:tmp">>, IgnoreEls,
 +                            _el);
 +      {<<"query">>, <<"urn:xmpp:mam:0">>, _} ->
 +        decode_mam_query(<<"urn:xmpp:mam:0">>, IgnoreEls, _el);
 +      {<<"query">>, <<>>, <<"urn:xmpp:mam:0">>} ->
 +        decode_mam_query(<<"urn:xmpp:mam:0">>, IgnoreEls, _el);
 +      {<<"query">>, <<"urn:xmpp:mam:1">>, _} ->
 +        decode_mam_query(<<"urn:xmpp:mam:1">>, IgnoreEls, _el);
 +      {<<"query">>, <<>>, <<"urn:xmpp:mam:1">>} ->
 +        decode_mam_query(<<"urn:xmpp:mam:1">>, IgnoreEls, _el);
 +      {<<"query">>, <<"urn:xmpp:mam:tmp">>, _} ->
 +        decode_mam_query(<<"urn:xmpp:mam:tmp">>, IgnoreEls,
 +                         _el);
 +      {<<"query">>, <<>>, <<"urn:xmpp:mam:tmp">>} ->
 +        decode_mam_query(<<"urn:xmpp:mam:tmp">>, IgnoreEls,
 +                         _el);
 +      {<<"withtext">>, <<"urn:xmpp:mam:tmp">>, _} ->
 +        decode_mam_withtext(<<"urn:xmpp:mam:tmp">>, IgnoreEls,
 +                            _el);
 +      {<<"withtext">>, <<>>, <<"urn:xmpp:mam:tmp">>} ->
 +        decode_mam_withtext(<<"urn:xmpp:mam:tmp">>, IgnoreEls,
 +                            _el);
 +      {<<"with">>, <<"urn:xmpp:mam:tmp">>, _} ->
 +        decode_mam_with(<<"urn:xmpp:mam:tmp">>, IgnoreEls, _el);
 +      {<<"with">>, <<>>, <<"urn:xmpp:mam:tmp">>} ->
 +        decode_mam_with(<<"urn:xmpp:mam:tmp">>, IgnoreEls, _el);
 +      {<<"end">>, <<"urn:xmpp:mam:tmp">>, _} ->
 +        decode_mam_end(<<"urn:xmpp:mam:tmp">>, IgnoreEls, _el);
 +      {<<"end">>, <<>>, <<"urn:xmpp:mam:tmp">>} ->
 +        decode_mam_end(<<"urn:xmpp:mam:tmp">>, IgnoreEls, _el);
 +      {<<"start">>, <<"urn:xmpp:mam:tmp">>, _} ->
 +        decode_mam_start(<<"urn:xmpp:mam:tmp">>, IgnoreEls,
 +                         _el);
 +      {<<"start">>, <<>>, <<"urn:xmpp:mam:tmp">>} ->
 +        decode_mam_start(<<"urn:xmpp:mam:tmp">>, IgnoreEls,
 +                         _el);
 +      {<<"set">>, <<"http://jabber.org/protocol/rsm">>, _} ->
 +        decode_rsm_set(<<"http://jabber.org/protocol/rsm">>,
 +                       IgnoreEls, _el);
 +      {<<"set">>, <<>>,
 +       <<"http://jabber.org/protocol/rsm">>} ->
 +        decode_rsm_set(<<"http://jabber.org/protocol/rsm">>,
 +                       IgnoreEls, _el);
 +      {<<"first">>, <<"http://jabber.org/protocol/rsm">>,
 +       _} ->
 +        decode_rsm_first(<<"http://jabber.org/protocol/rsm">>,
 +                         IgnoreEls, _el);
 +      {<<"first">>, <<>>,
 +       <<"http://jabber.org/protocol/rsm">>} ->
 +        decode_rsm_first(<<"http://jabber.org/protocol/rsm">>,
 +                         IgnoreEls, _el);
 +      {<<"max">>, <<"http://jabber.org/protocol/rsm">>, _} ->
 +        decode_rsm_max(<<"http://jabber.org/protocol/rsm">>,
 +                       IgnoreEls, _el);
 +      {<<"max">>, <<>>,
 +       <<"http://jabber.org/protocol/rsm">>} ->
 +        decode_rsm_max(<<"http://jabber.org/protocol/rsm">>,
 +                       IgnoreEls, _el);
 +      {<<"index">>, <<"http://jabber.org/protocol/rsm">>,
 +       _} ->
 +        decode_rsm_index(<<"http://jabber.org/protocol/rsm">>,
 +                         IgnoreEls, _el);
 +      {<<"index">>, <<>>,
 +       <<"http://jabber.org/protocol/rsm">>} ->
 +        decode_rsm_index(<<"http://jabber.org/protocol/rsm">>,
 +                         IgnoreEls, _el);
 +      {<<"count">>, <<"http://jabber.org/protocol/rsm">>,
 +       _} ->
 +        decode_rsm_count(<<"http://jabber.org/protocol/rsm">>,
 +                         IgnoreEls, _el);
 +      {<<"count">>, <<>>,
 +       <<"http://jabber.org/protocol/rsm">>} ->
 +        decode_rsm_count(<<"http://jabber.org/protocol/rsm">>,
 +                         IgnoreEls, _el);
 +      {<<"last">>, <<"http://jabber.org/protocol/rsm">>, _} ->
 +        decode_rsm_last(<<"http://jabber.org/protocol/rsm">>,
 +                        IgnoreEls, _el);
 +      {<<"last">>, <<>>,
 +       <<"http://jabber.org/protocol/rsm">>} ->
 +        decode_rsm_last(<<"http://jabber.org/protocol/rsm">>,
 +                        IgnoreEls, _el);
 +      {<<"before">>, <<"http://jabber.org/protocol/rsm">>,
 +       _} ->
 +        decode_rsm_before(<<"http://jabber.org/protocol/rsm">>,
 +                          IgnoreEls, _el);
 +      {<<"before">>, <<>>,
 +       <<"http://jabber.org/protocol/rsm">>} ->
 +        decode_rsm_before(<<"http://jabber.org/protocol/rsm">>,
 +                          IgnoreEls, _el);
 +      {<<"after">>, <<"http://jabber.org/protocol/rsm">>,
 +       _} ->
 +        decode_rsm_after(<<"http://jabber.org/protocol/rsm">>,
 +                         IgnoreEls, _el);
 +      {<<"after">>, <<>>,
 +       <<"http://jabber.org/protocol/rsm">>} ->
 +        decode_rsm_after(<<"http://jabber.org/protocol/rsm">>,
 +                         IgnoreEls, _el);
 +      {<<"unsubscribe">>, <<"urn:xmpp:mucsub:0">>, _} ->
 +        decode_muc_unsubscribe(<<"urn:xmpp:mucsub:0">>,
 +                               IgnoreEls, _el);
 +      {<<"unsubscribe">>, <<>>, <<"urn:xmpp:mucsub:0">>} ->
 +        decode_muc_unsubscribe(<<"urn:xmpp:mucsub:0">>,
 +                               IgnoreEls, _el);
 +      {<<"subscribe">>, <<"urn:xmpp:mucsub:0">>, _} ->
 +        decode_muc_subscribe(<<"urn:xmpp:mucsub:0">>, IgnoreEls,
 +                             _el);
 +      {<<"subscribe">>, <<>>, <<"urn:xmpp:mucsub:0">>} ->
 +        decode_muc_subscribe(<<"urn:xmpp:mucsub:0">>, IgnoreEls,
 +                             _el);
 +      {<<"event">>, <<"urn:xmpp:mucsub:0">>, _} ->
 +        decode_muc_subscribe_event(<<"urn:xmpp:mucsub:0">>,
 +                                   IgnoreEls, _el);
 +      {<<"event">>, <<>>, <<"urn:xmpp:mucsub:0">>} ->
 +        decode_muc_subscribe_event(<<"urn:xmpp:mucsub:0">>,
 +                                   IgnoreEls, _el);
 +      {<<"subscriptions">>, <<"urn:xmpp:mucsub:0">>, _} ->
 +        decode_muc_subscriptions(<<"urn:xmpp:mucsub:0">>,
 +                                 IgnoreEls, _el);
 +      {<<"subscriptions">>, <<>>, <<"urn:xmpp:mucsub:0">>} ->
 +        decode_muc_subscriptions(<<"urn:xmpp:mucsub:0">>,
 +                                 IgnoreEls, _el);
 +      {<<"subscription">>, <<"urn:xmpp:mucsub:0">>, _} ->
 +        decode_muc_subscription(<<"urn:xmpp:mucsub:0">>,
 +                                IgnoreEls, _el);
 +      {<<"subscription">>, <<>>, <<"urn:xmpp:mucsub:0">>} ->
 +        decode_muc_subscription(<<"urn:xmpp:mucsub:0">>,
 +                                IgnoreEls, _el);
 +      {<<"x">>, <<"jabber:x:conference">>, _} ->
 +        decode_x_conference(<<"jabber:x:conference">>,
 +                            IgnoreEls, _el);
 +      {<<"x">>, <<>>, <<"jabber:x:conference">>} ->
 +        decode_x_conference(<<"jabber:x:conference">>,
 +                            IgnoreEls, _el);
 +      {<<"unique">>,
 +       <<"http://jabber.org/protocol/muc#unique">>, _} ->
 +        decode_muc_unique(<<"http://jabber.org/protocol/muc#unique">>,
 +                          IgnoreEls, _el);
 +      {<<"unique">>, <<>>,
 +       <<"http://jabber.org/protocol/muc#unique">>} ->
 +        decode_muc_unique(<<"http://jabber.org/protocol/muc#unique">>,
 +                          IgnoreEls, _el);
 +      {<<"x">>, <<"http://jabber.org/protocol/muc">>, _} ->
 +        decode_muc(<<"http://jabber.org/protocol/muc">>,
 +                   IgnoreEls, _el);
 +      {<<"x">>, <<>>, <<"http://jabber.org/protocol/muc">>} ->
 +        decode_muc(<<"http://jabber.org/protocol/muc">>,
 +                   IgnoreEls, _el);
 +      {<<"query">>,
 +       <<"http://jabber.org/protocol/muc#admin">>, _} ->
 +        decode_muc_admin(<<"http://jabber.org/protocol/muc#admin">>,
 +                         IgnoreEls, _el);
 +      {<<"query">>, <<>>,
 +       <<"http://jabber.org/protocol/muc#admin">>} ->
 +        decode_muc_admin(<<"http://jabber.org/protocol/muc#admin">>,
 +                         IgnoreEls, _el);
 +      {<<"continue">>,
 +       <<"http://jabber.org/protocol/muc#admin">>, _} ->
 +        decode_muc_admin_continue(<<"http://jabber.org/protocol/muc#admin">>,
 +                                  IgnoreEls, _el);
 +      {<<"continue">>, <<>>,
 +       <<"http://jabber.org/protocol/muc#admin">>} ->
 +        decode_muc_admin_continue(<<"http://jabber.org/protocol/muc#admin">>,
 +                                  IgnoreEls, _el);
 +      {<<"actor">>,
 +       <<"http://jabber.org/protocol/muc#admin">>, _} ->
 +        decode_muc_admin_actor(<<"http://jabber.org/protocol/muc#admin">>,
 +                               IgnoreEls, _el);
 +      {<<"actor">>, <<>>,
 +       <<"http://jabber.org/protocol/muc#admin">>} ->
 +        decode_muc_admin_actor(<<"http://jabber.org/protocol/muc#admin">>,
 +                               IgnoreEls, _el);
 +      {<<"item">>, <<"http://jabber.org/protocol/muc#admin">>,
 +       _} ->
 +        decode_muc_admin_item(<<"http://jabber.org/protocol/muc#admin">>,
 +                              IgnoreEls, _el);
 +      {<<"item">>, <<>>,
 +       <<"http://jabber.org/protocol/muc#admin">>} ->
 +        decode_muc_admin_item(<<"http://jabber.org/protocol/muc#admin">>,
 +                              IgnoreEls, _el);
 +      {<<"item">>, <<"http://jabber.org/protocol/muc#owner">>,
 +       _} ->
 +        decode_muc_owner_item(<<"http://jabber.org/protocol/muc#owner">>,
 +                              IgnoreEls, _el);
 +      {<<"item">>, <<>>,
 +       <<"http://jabber.org/protocol/muc#owner">>} ->
 +        decode_muc_owner_item(<<"http://jabber.org/protocol/muc#owner">>,
 +                              IgnoreEls, _el);
 +      {<<"query">>,
 +       <<"http://jabber.org/protocol/muc#owner">>, _} ->
 +        decode_muc_owner(<<"http://jabber.org/protocol/muc#owner">>,
 +                         IgnoreEls, _el);
 +      {<<"query">>, <<>>,
 +       <<"http://jabber.org/protocol/muc#owner">>} ->
 +        decode_muc_owner(<<"http://jabber.org/protocol/muc#owner">>,
 +                         IgnoreEls, _el);
 +      {<<"password">>,
 +       <<"http://jabber.org/protocol/muc#owner">>, _} ->
 +        decode_muc_password(<<"http://jabber.org/protocol/muc#owner">>,
 +                            IgnoreEls, _el);
 +      {<<"password">>, <<>>,
 +       <<"http://jabber.org/protocol/muc#owner">>} ->
 +        decode_muc_password(<<"http://jabber.org/protocol/muc#owner">>,
 +                            IgnoreEls, _el);
 +      {<<"password">>,
 +       <<"http://jabber.org/protocol/muc#user">>, _} ->
 +        decode_muc_password(<<"http://jabber.org/protocol/muc#user">>,
 +                            IgnoreEls, _el);
 +      {<<"password">>, <<>>,
 +       <<"http://jabber.org/protocol/muc#user">>} ->
 +        decode_muc_password(<<"http://jabber.org/protocol/muc#user">>,
 +                            IgnoreEls, _el);
 +      {<<"password">>, <<"http://jabber.org/protocol/muc">>,
 +       _} ->
 +        decode_muc_password(<<"http://jabber.org/protocol/muc">>,
 +                            IgnoreEls, _el);
 +      {<<"password">>, <<>>,
 +       <<"http://jabber.org/protocol/muc">>} ->
 +        decode_muc_password(<<"http://jabber.org/protocol/muc">>,
 +                            IgnoreEls, _el);
 +      {<<"x">>, <<"http://jabber.org/protocol/muc#user">>,
 +       _} ->
 +        decode_muc_user(<<"http://jabber.org/protocol/muc#user">>,
 +                        IgnoreEls, _el);
 +      {<<"x">>, <<>>,
 +       <<"http://jabber.org/protocol/muc#user">>} ->
 +        decode_muc_user(<<"http://jabber.org/protocol/muc#user">>,
 +                        IgnoreEls, _el);
 +      {<<"item">>, <<"http://jabber.org/protocol/muc#user">>,
 +       _} ->
 +        decode_muc_user_item(<<"http://jabber.org/protocol/muc#user">>,
 +                             IgnoreEls, _el);
 +      {<<"item">>, <<>>,
 +       <<"http://jabber.org/protocol/muc#user">>} ->
 +        decode_muc_user_item(<<"http://jabber.org/protocol/muc#user">>,
 +                             IgnoreEls, _el);
 +      {<<"status">>,
 +       <<"http://jabber.org/protocol/muc#user">>, _} ->
 +        decode_muc_user_status(<<"http://jabber.org/protocol/muc#user">>,
 +                               IgnoreEls, _el);
 +      {<<"status">>, <<>>,
 +       <<"http://jabber.org/protocol/muc#user">>} ->
 +        decode_muc_user_status(<<"http://jabber.org/protocol/muc#user">>,
 +                               IgnoreEls, _el);
 +      {<<"continue">>,
 +       <<"http://jabber.org/protocol/muc#user">>, _} ->
 +        decode_muc_user_continue(<<"http://jabber.org/protocol/muc#user">>,
 +                                 IgnoreEls, _el);
 +      {<<"continue">>, <<>>,
 +       <<"http://jabber.org/protocol/muc#user">>} ->
 +        decode_muc_user_continue(<<"http://jabber.org/protocol/muc#user">>,
 +                                 IgnoreEls, _el);
 +      {<<"actor">>, <<"http://jabber.org/protocol/muc#user">>,
 +       _} ->
 +        decode_muc_user_actor(<<"http://jabber.org/protocol/muc#user">>,
 +                              IgnoreEls, _el);
 +      {<<"actor">>, <<>>,
 +       <<"http://jabber.org/protocol/muc#user">>} ->
 +        decode_muc_user_actor(<<"http://jabber.org/protocol/muc#user">>,
 +                              IgnoreEls, _el);
 +      {<<"invite">>,
 +       <<"http://jabber.org/protocol/muc#user">>, _} ->
 +        decode_muc_user_invite(<<"http://jabber.org/protocol/muc#user">>,
 +                               IgnoreEls, _el);
 +      {<<"invite">>, <<>>,
 +       <<"http://jabber.org/protocol/muc#user">>} ->
 +        decode_muc_user_invite(<<"http://jabber.org/protocol/muc#user">>,
 +                               IgnoreEls, _el);
 +      {<<"destroy">>,
 +       <<"http://jabber.org/protocol/muc#user">>, _} ->
 +        decode_muc_destroy(<<"http://jabber.org/protocol/muc#user">>,
 +                           IgnoreEls, _el);
 +      {<<"destroy">>, <<>>,
 +       <<"http://jabber.org/protocol/muc#user">>} ->
 +        decode_muc_destroy(<<"http://jabber.org/protocol/muc#user">>,
 +                           IgnoreEls, _el);
 +      {<<"destroy">>,
 +       <<"http://jabber.org/protocol/muc#owner">>, _} ->
 +        decode_muc_destroy(<<"http://jabber.org/protocol/muc#owner">>,
 +                           IgnoreEls, _el);
 +      {<<"destroy">>, <<>>,
 +       <<"http://jabber.org/protocol/muc#owner">>} ->
 +        decode_muc_destroy(<<"http://jabber.org/protocol/muc#owner">>,
 +                           IgnoreEls, _el);
 +      {<<"decline">>,
 +       <<"http://jabber.org/protocol/muc#user">>, _} ->
 +        decode_muc_user_decline(<<"http://jabber.org/protocol/muc#user">>,
 +                                IgnoreEls, _el);
 +      {<<"decline">>, <<>>,
 +       <<"http://jabber.org/protocol/muc#user">>} ->
 +        decode_muc_user_decline(<<"http://jabber.org/protocol/muc#user">>,
 +                                IgnoreEls, _el);
 +      {<<"reason">>,
 +       <<"http://jabber.org/protocol/muc#user">>, _} ->
 +        decode_muc_reason(<<"http://jabber.org/protocol/muc#user">>,
 +                          IgnoreEls, _el);
 +      {<<"reason">>, <<>>,
 +       <<"http://jabber.org/protocol/muc#user">>} ->
 +        decode_muc_reason(<<"http://jabber.org/protocol/muc#user">>,
 +                          IgnoreEls, _el);
 +      {<<"reason">>,
 +       <<"http://jabber.org/protocol/muc#admin">>, _} ->
 +        decode_muc_reason(<<"http://jabber.org/protocol/muc#admin">>,
 +                          IgnoreEls, _el);
 +      {<<"reason">>, <<>>,
 +       <<"http://jabber.org/protocol/muc#admin">>} ->
 +        decode_muc_reason(<<"http://jabber.org/protocol/muc#admin">>,
 +                          IgnoreEls, _el);
 +      {<<"reason">>,
 +       <<"http://jabber.org/protocol/muc#owner">>, _} ->
 +        decode_muc_reason(<<"http://jabber.org/protocol/muc#owner">>,
 +                          IgnoreEls, _el);
 +      {<<"reason">>, <<>>,
 +       <<"http://jabber.org/protocol/muc#owner">>} ->
 +        decode_muc_reason(<<"http://jabber.org/protocol/muc#owner">>,
 +                          IgnoreEls, _el);
 +      {<<"history">>, <<"http://jabber.org/protocol/muc">>,
 +       _} ->
 +        decode_muc_history(<<"http://jabber.org/protocol/muc">>,
 +                           IgnoreEls, _el);
 +      {<<"history">>, <<>>,
 +       <<"http://jabber.org/protocol/muc">>} ->
 +        decode_muc_history(<<"http://jabber.org/protocol/muc">>,
 +                           IgnoreEls, _el);
 +      {<<"query">>,
 +       <<"http://jabber.org/protocol/bytestreams">>, _} ->
 +        decode_bytestreams(<<"http://jabber.org/protocol/bytestreams">>,
 +                           IgnoreEls, _el);
 +      {<<"query">>, <<>>,
 +       <<"http://jabber.org/protocol/bytestreams">>} ->
 +        decode_bytestreams(<<"http://jabber.org/protocol/bytestreams">>,
 +                           IgnoreEls, _el);
 +      {<<"activate">>,
 +       <<"http://jabber.org/protocol/bytestreams">>, _} ->
 +        decode_bytestreams_activate(<<"http://jabber.org/protocol/bytestreams">>,
 +                                    IgnoreEls, _el);
 +      {<<"activate">>, <<>>,
 +       <<"http://jabber.org/protocol/bytestreams">>} ->
 +        decode_bytestreams_activate(<<"http://jabber.org/protocol/bytestreams">>,
 +                                    IgnoreEls, _el);
 +      {<<"streamhost-used">>,
 +       <<"http://jabber.org/protocol/bytestreams">>, _} ->
 +        decode_bytestreams_streamhost_used(<<"http://jabber.org/protocol/bytestreams">>,
 +                                           IgnoreEls, _el);
 +      {<<"streamhost-used">>, <<>>,
 +       <<"http://jabber.org/protocol/bytestreams">>} ->
 +        decode_bytestreams_streamhost_used(<<"http://jabber.org/protocol/bytestreams">>,
 +                                           IgnoreEls, _el);
 +      {<<"streamhost">>,
 +       <<"http://jabber.org/protocol/bytestreams">>, _} ->
 +        decode_bytestreams_streamhost(<<"http://jabber.org/protocol/bytestreams">>,
 +                                      IgnoreEls, _el);
 +      {<<"streamhost">>, <<>>,
 +       <<"http://jabber.org/protocol/bytestreams">>} ->
 +        decode_bytestreams_streamhost(<<"http://jabber.org/protocol/bytestreams">>,
 +                                      IgnoreEls, _el);
 +      {<<"delay">>, <<"urn:xmpp:delay">>, _} ->
 +        decode_delay(<<"urn:xmpp:delay">>, IgnoreEls, _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);
 +      {<<"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);
 +      {<<"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);
 +      {<<"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);
 +      {<<"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);
 +      {<<"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">>,
 +                            IgnoreEls, _el);
 +      {<<"headers">>, <<>>,
 +       <<"http://jabber.org/protocol/shim">>} ->
 +        decode_shim_headers(<<"http://jabber.org/protocol/shim">>,
 +                            IgnoreEls, _el);
 +      {<<"header">>, <<"http://jabber.org/protocol/shim">>,
 +       _} ->
 +        decode_shim_header(<<"http://jabber.org/protocol/shim">>,
 +                           IgnoreEls, _el);
 +      {<<"header">>, <<>>,
 +       <<"http://jabber.org/protocol/shim">>} ->
 +        decode_shim_header(<<"http://jabber.org/protocol/shim">>,
 +                           IgnoreEls, _el);
 +      {<<"unsupported-access-model">>,
 +       <<"http://jabber.org/protocol/pubsub#errors">>, _} ->
 +        decode_pubsub_error_unsupported_access_model(<<"http://jabber.org/protocol/pubsub#errors">>,
 +                                                     IgnoreEls, _el);
 +      {<<"unsupported-access-model">>, <<>>,
 +       <<"http://jabber.org/protocol/pubsub#errors">>} ->
 +        decode_pubsub_error_unsupported_access_model(<<"http://jabber.org/protocol/pubsub#errors">>,
 +                                                     IgnoreEls, _el);
 +      {<<"unsupported">>,
 +       <<"http://jabber.org/protocol/pubsub#errors">>, _} ->
 +        decode_pubsub_error_unsupported(<<"http://jabber.org/protocol/pubsub#errors">>,
 +                                        IgnoreEls, _el);
 +      {<<"unsupported">>, <<>>,
 +       <<"http://jabber.org/protocol/pubsub#errors">>} ->
 +        decode_pubsub_error_unsupported(<<"http://jabber.org/protocol/pubsub#errors">>,
 +                                        IgnoreEls, _el);
 +      {<<"too-many-subscriptions">>,
 +       <<"http://jabber.org/protocol/pubsub#errors">>, _} ->
 +        decode_pubsub_error_too_many_subscriptions(<<"http://jabber.org/protocol/pubsub#errors">>,
 +                                                   IgnoreEls, _el);
 +      {<<"too-many-subscriptions">>, <<>>,
 +       <<"http://jabber.org/protocol/pubsub#errors">>} ->
 +        decode_pubsub_error_too_many_subscriptions(<<"http://jabber.org/protocol/pubsub#errors">>,
 +                                                   IgnoreEls, _el);
 +      {<<"subid-required">>,
 +       <<"http://jabber.org/protocol/pubsub#errors">>, _} ->
 +        decode_pubsub_error_subid_required(<<"http://jabber.org/protocol/pubsub#errors">>,
 +                                           IgnoreEls, _el);
 +      {<<"subid-required">>, <<>>,
 +       <<"http://jabber.org/protocol/pubsub#errors">>} ->
 +        decode_pubsub_error_subid_required(<<"http://jabber.org/protocol/pubsub#errors">>,
 +                                           IgnoreEls, _el);
 +      {<<"presence-subscription-required">>,
 +       <<"http://jabber.org/protocol/pubsub#errors">>, _} ->
 +        decode_pubsub_error_presence_subscription_required(<<"http://jabber.org/protocol/pubsub#errors">>,
 +                                                           IgnoreEls, _el);
 +      {<<"presence-subscription-required">>, <<>>,
 +       <<"http://jabber.org/protocol/pubsub#errors">>} ->
 +        decode_pubsub_error_presence_subscription_required(<<"http://jabber.org/protocol/pubsub#errors">>,
 +                                                           IgnoreEls, _el);
 +      {<<"pending-subscription">>,
 +       <<"http://jabber.org/protocol/pubsub#errors">>, _} ->
 +        decode_pubsub_error_pending_subscription(<<"http://jabber.org/protocol/pubsub#errors">>,
 +                                                 IgnoreEls, _el);
 +      {<<"pending-subscription">>, <<>>,
 +       <<"http://jabber.org/protocol/pubsub#errors">>} ->
 +        decode_pubsub_error_pending_subscription(<<"http://jabber.org/protocol/pubsub#errors">>,
 +                                                 IgnoreEls, _el);
 +      {<<"payload-required">>,
 +       <<"http://jabber.org/protocol/pubsub#errors">>, _} ->
 +        decode_pubsub_error_payload_required(<<"http://jabber.org/protocol/pubsub#errors">>,
 +                                             IgnoreEls, _el);
 +      {<<"payload-required">>, <<>>,
 +       <<"http://jabber.org/protocol/pubsub#errors">>} ->
 +        decode_pubsub_error_payload_required(<<"http://jabber.org/protocol/pubsub#errors">>,
 +                                             IgnoreEls, _el);
 +      {<<"payload-too-big">>,
 +       <<"http://jabber.org/protocol/pubsub#errors">>, _} ->
 +        decode_pubsub_error_payload_too_big(<<"http://jabber.org/protocol/pubsub#errors">>,
 +                                            IgnoreEls, _el);
 +      {<<"payload-too-big">>, <<>>,
 +       <<"http://jabber.org/protocol/pubsub#errors">>} ->
 +        decode_pubsub_error_payload_too_big(<<"http://jabber.org/protocol/pubsub#errors">>,
 +                                            IgnoreEls, _el);
 +      {<<"not-subscribed">>,
 +       <<"http://jabber.org/protocol/pubsub#errors">>, _} ->
 +        decode_pubsub_error_not_subscribed(<<"http://jabber.org/protocol/pubsub#errors">>,
 +                                           IgnoreEls, _el);
 +      {<<"not-subscribed">>, <<>>,
 +       <<"http://jabber.org/protocol/pubsub#errors">>} ->
 +        decode_pubsub_error_not_subscribed(<<"http://jabber.org/protocol/pubsub#errors">>,
 +                                           IgnoreEls, _el);
 +      {<<"not-in-roster-group">>,
 +       <<"http://jabber.org/protocol/pubsub#errors">>, _} ->
 +        decode_pubsub_error_not_in_roster_group(<<"http://jabber.org/protocol/pubsub#errors">>,
 +                                                IgnoreEls, _el);
 +      {<<"not-in-roster-group">>, <<>>,
 +       <<"http://jabber.org/protocol/pubsub#errors">>} ->
 +        decode_pubsub_error_not_in_roster_group(<<"http://jabber.org/protocol/pubsub#errors">>,
 +                                                IgnoreEls, _el);
 +      {<<"nodeid-required">>,
 +       <<"http://jabber.org/protocol/pubsub#errors">>, _} ->
 +        decode_pubsub_error_nodeid_required(<<"http://jabber.org/protocol/pubsub#errors">>,
 +                                            IgnoreEls, _el);
 +      {<<"nodeid-required">>, <<>>,
 +       <<"http://jabber.org/protocol/pubsub#errors">>} ->
 +        decode_pubsub_error_nodeid_required(<<"http://jabber.org/protocol/pubsub#errors">>,
 +                                            IgnoreEls, _el);
 +      {<<"max-nodes-exceeded">>,
 +       <<"http://jabber.org/protocol/pubsub#errors">>, _} ->
 +        decode_pubsub_error_max_nodes_exceeded(<<"http://jabber.org/protocol/pubsub#errors">>,
 +                                               IgnoreEls, _el);
 +      {<<"max-nodes-exceeded">>, <<>>,
 +       <<"http://jabber.org/protocol/pubsub#errors">>} ->
 +        decode_pubsub_error_max_nodes_exceeded(<<"http://jabber.org/protocol/pubsub#errors">>,
 +                                               IgnoreEls, _el);
 +      {<<"max-items-exceeded">>,
 +       <<"http://jabber.org/protocol/pubsub#errors">>, _} ->
 +        decode_pubsub_error_max_items_exceeded(<<"http://jabber.org/protocol/pubsub#errors">>,
 +                                               IgnoreEls, _el);
 +      {<<"max-items-exceeded">>, <<>>,
 +       <<"http://jabber.org/protocol/pubsub#errors">>} ->
 +        decode_pubsub_error_max_items_exceeded(<<"http://jabber.org/protocol/pubsub#errors">>,
 +                                               IgnoreEls, _el);
 +      {<<"jid-required">>,
 +       <<"http://jabber.org/protocol/pubsub#errors">>, _} ->
 +        decode_pubsub_error_jid_required(<<"http://jabber.org/protocol/pubsub#errors">>,
 +                                         IgnoreEls, _el);
 +      {<<"jid-required">>, <<>>,
 +       <<"http://jabber.org/protocol/pubsub#errors">>} ->
 +        decode_pubsub_error_jid_required(<<"http://jabber.org/protocol/pubsub#errors">>,
 +                                         IgnoreEls, _el);
 +      {<<"item-required">>,
 +       <<"http://jabber.org/protocol/pubsub#errors">>, _} ->
 +        decode_pubsub_error_item_required(<<"http://jabber.org/protocol/pubsub#errors">>,
 +                                          IgnoreEls, _el);
 +      {<<"item-required">>, <<>>,
 +       <<"http://jabber.org/protocol/pubsub#errors">>} ->
 +        decode_pubsub_error_item_required(<<"http://jabber.org/protocol/pubsub#errors">>,
 +                                          IgnoreEls, _el);
 +      {<<"item-forbidden">>,
 +       <<"http://jabber.org/protocol/pubsub#errors">>, _} ->
 +        decode_pubsub_error_item_forbidden(<<"http://jabber.org/protocol/pubsub#errors">>,
 +                                           IgnoreEls, _el);
 +      {<<"item-forbidden">>, <<>>,
 +       <<"http://jabber.org/protocol/pubsub#errors">>} ->
 +        decode_pubsub_error_item_forbidden(<<"http://jabber.org/protocol/pubsub#errors">>,
 +                                           IgnoreEls, _el);
 +      {<<"invalid-subid">>,
 +       <<"http://jabber.org/protocol/pubsub#errors">>, _} ->
 +        decode_pubsub_error_invalid_subid(<<"http://jabber.org/protocol/pubsub#errors">>,
 +                                          IgnoreEls, _el);
 +      {<<"invalid-subid">>, <<>>,
 +       <<"http://jabber.org/protocol/pubsub#errors">>} ->
 +        decode_pubsub_error_invalid_subid(<<"http://jabber.org/protocol/pubsub#errors">>,
 +                                          IgnoreEls, _el);
 +      {<<"invalid-payload">>,
 +       <<"http://jabber.org/protocol/pubsub#errors">>, _} ->
 +        decode_pubsub_error_invalid_payload(<<"http://jabber.org/protocol/pubsub#errors">>,
 +                                            IgnoreEls, _el);
 +      {<<"invalid-payload">>, <<>>,
 +       <<"http://jabber.org/protocol/pubsub#errors">>} ->
 +        decode_pubsub_error_invalid_payload(<<"http://jabber.org/protocol/pubsub#errors">>,
 +                                            IgnoreEls, _el);
 +      {<<"invalid-options">>,
 +       <<"http://jabber.org/protocol/pubsub#errors">>, _} ->
 +        decode_pubsub_error_invalid_options(<<"http://jabber.org/protocol/pubsub#errors">>,
 +                                            IgnoreEls, _el);
 +      {<<"invalid-options">>, <<>>,
 +       <<"http://jabber.org/protocol/pubsub#errors">>} ->
 +        decode_pubsub_error_invalid_options(<<"http://jabber.org/protocol/pubsub#errors">>,
 +                                            IgnoreEls, _el);
 +      {<<"invalid-jid">>,
 +       <<"http://jabber.org/protocol/pubsub#errors">>, _} ->
 +        decode_pubsub_error_invalid_jid(<<"http://jabber.org/protocol/pubsub#errors">>,
 +                                        IgnoreEls, _el);
 +      {<<"invalid-jid">>, <<>>,
 +       <<"http://jabber.org/protocol/pubsub#errors">>} ->
 +        decode_pubsub_error_invalid_jid(<<"http://jabber.org/protocol/pubsub#errors">>,
 +                                        IgnoreEls, _el);
 +      {<<"configuration-required">>,
 +       <<"http://jabber.org/protocol/pubsub#errors">>, _} ->
 +        decode_pubsub_error_configuration_required(<<"http://jabber.org/protocol/pubsub#errors">>,
 +                                                   IgnoreEls, _el);
 +      {<<"configuration-required">>, <<>>,
 +       <<"http://jabber.org/protocol/pubsub#errors">>} ->
 +        decode_pubsub_error_configuration_required(<<"http://jabber.org/protocol/pubsub#errors">>,
 +                                                   IgnoreEls, _el);
 +      {<<"closed-node">>,
 +       <<"http://jabber.org/protocol/pubsub#errors">>, _} ->
 +        decode_pubsub_error_closed_node(<<"http://jabber.org/protocol/pubsub#errors">>,
 +                                        IgnoreEls, _el);
 +      {<<"closed-node">>, <<>>,
 +       <<"http://jabber.org/protocol/pubsub#errors">>} ->
 +        decode_pubsub_error_closed_node(<<"http://jabber.org/protocol/pubsub#errors">>,
 +                                        IgnoreEls, _el);
 +      {<<"pubsub">>,
 +       <<"http://jabber.org/protocol/pubsub#owner">>, _} ->
 +        decode_pubsub_owner(<<"http://jabber.org/protocol/pubsub#owner">>,
 +                            IgnoreEls, _el);
 +      {<<"pubsub">>, <<>>,
 +       <<"http://jabber.org/protocol/pubsub#owner">>} ->
 +        decode_pubsub_owner(<<"http://jabber.org/protocol/pubsub#owner">>,
 +                            IgnoreEls, _el);
 +      {<<"pubsub">>, <<"http://jabber.org/protocol/pubsub">>,
 +       _} ->
 +        decode_pubsub(<<"http://jabber.org/protocol/pubsub">>,
 +                      IgnoreEls, _el);
 +      {<<"pubsub">>, <<>>,
 +       <<"http://jabber.org/protocol/pubsub">>} ->
 +        decode_pubsub(<<"http://jabber.org/protocol/pubsub">>,
 +                      IgnoreEls, _el);
 +      {<<"purge">>, <<"http://jabber.org/protocol/pubsub">>,
 +       _} ->
 +        decode_pubsub_purge(<<"http://jabber.org/protocol/pubsub">>,
 +                            IgnoreEls, _el);
 +      {<<"purge">>, <<>>,
 +       <<"http://jabber.org/protocol/pubsub">>} ->
 +        decode_pubsub_purge(<<"http://jabber.org/protocol/pubsub">>,
 +                            IgnoreEls, _el);
 +      {<<"purge">>,
 +       <<"http://jabber.org/protocol/pubsub#owner">>, _} ->
 +        decode_pubsub_purge(<<"http://jabber.org/protocol/pubsub#owner">>,
 +                            IgnoreEls, _el);
 +      {<<"purge">>, <<>>,
 +       <<"http://jabber.org/protocol/pubsub#owner">>} ->
 +        decode_pubsub_purge(<<"http://jabber.org/protocol/pubsub#owner">>,
 +                            IgnoreEls, _el);
 +      {<<"purge">>,
 +       <<"http://jabber.org/protocol/pubsub#event">>, _} ->
 +        decode_pubsub_purge(<<"http://jabber.org/protocol/pubsub#event">>,
 +                            IgnoreEls, _el);
 +      {<<"purge">>, <<>>,
 +       <<"http://jabber.org/protocol/pubsub#event">>} ->
 +        decode_pubsub_purge(<<"http://jabber.org/protocol/pubsub#event">>,
 +                            IgnoreEls, _el);
 +      {<<"delete">>, <<"http://jabber.org/protocol/pubsub">>,
 +       _} ->
 +        decode_pubsub_delete(<<"http://jabber.org/protocol/pubsub">>,
 +                             IgnoreEls, _el);
 +      {<<"delete">>, <<>>,
 +       <<"http://jabber.org/protocol/pubsub">>} ->
 +        decode_pubsub_delete(<<"http://jabber.org/protocol/pubsub">>,
 +                             IgnoreEls, _el);
 +      {<<"delete">>,
 +       <<"http://jabber.org/protocol/pubsub#owner">>, _} ->
 +        decode_pubsub_delete(<<"http://jabber.org/protocol/pubsub#owner">>,
 +                             IgnoreEls, _el);
 +      {<<"delete">>, <<>>,
 +       <<"http://jabber.org/protocol/pubsub#owner">>} ->
 +        decode_pubsub_delete(<<"http://jabber.org/protocol/pubsub#owner">>,
 +                             IgnoreEls, _el);
 +      {<<"delete">>,
 +       <<"http://jabber.org/protocol/pubsub#event">>, _} ->
 +        decode_pubsub_delete(<<"http://jabber.org/protocol/pubsub#event">>,
 +                             IgnoreEls, _el);
 +      {<<"delete">>, <<>>,
 +       <<"http://jabber.org/protocol/pubsub#event">>} ->
 +        decode_pubsub_delete(<<"http://jabber.org/protocol/pubsub#event">>,
 +                             IgnoreEls, _el);
 +      {<<"redirect">>,
 +       <<"http://jabber.org/protocol/pubsub">>, _} ->
 +        decode_pubsub_redirect(<<"http://jabber.org/protocol/pubsub">>,
 +                               IgnoreEls, _el);
 +      {<<"redirect">>, <<>>,
 +       <<"http://jabber.org/protocol/pubsub">>} ->
 +        decode_pubsub_redirect(<<"http://jabber.org/protocol/pubsub">>,
 +                               IgnoreEls, _el);
 +      {<<"redirect">>,
 +       <<"http://jabber.org/protocol/pubsub#owner">>, _} ->
 +        decode_pubsub_redirect(<<"http://jabber.org/protocol/pubsub#owner">>,
 +                               IgnoreEls, _el);
 +      {<<"redirect">>, <<>>,
 +       <<"http://jabber.org/protocol/pubsub#owner">>} ->
 +        decode_pubsub_redirect(<<"http://jabber.org/protocol/pubsub#owner">>,
 +                               IgnoreEls, _el);
 +      {<<"redirect">>,
 +       <<"http://jabber.org/protocol/pubsub#event">>, _} ->
 +        decode_pubsub_redirect(<<"http://jabber.org/protocol/pubsub#event">>,
 +                               IgnoreEls, _el);
 +      {<<"redirect">>, <<>>,
 +       <<"http://jabber.org/protocol/pubsub#event">>} ->
 +        decode_pubsub_redirect(<<"http://jabber.org/protocol/pubsub#event">>,
 +                               IgnoreEls, _el);
 +      {<<"default">>, <<"http://jabber.org/protocol/pubsub">>,
 +       _} ->
 +        decode_pubsub_default(<<"http://jabber.org/protocol/pubsub">>,
 +                              IgnoreEls, _el);
 +      {<<"default">>, <<>>,
 +       <<"http://jabber.org/protocol/pubsub">>} ->
 +        decode_pubsub_default(<<"http://jabber.org/protocol/pubsub">>,
 +                              IgnoreEls, _el);
 +      {<<"default">>,
 +       <<"http://jabber.org/protocol/pubsub#owner">>, _} ->
 +        decode_pubsub_default(<<"http://jabber.org/protocol/pubsub#owner">>,
 +                              IgnoreEls, _el);
 +      {<<"default">>, <<>>,
 +       <<"http://jabber.org/protocol/pubsub#owner">>} ->
 +        decode_pubsub_default(<<"http://jabber.org/protocol/pubsub#owner">>,
 +                              IgnoreEls, _el);
 +      {<<"publish-options">>,
 +       <<"http://jabber.org/protocol/pubsub">>, _} ->
 +        decode_pubsub_publish_options(<<"http://jabber.org/protocol/pubsub">>,
 +                                      IgnoreEls, _el);
 +      {<<"publish-options">>, <<>>,
 +       <<"http://jabber.org/protocol/pubsub">>} ->
 +        decode_pubsub_publish_options(<<"http://jabber.org/protocol/pubsub">>,
 +                                      IgnoreEls, _el);
 +      {<<"configure">>,
 +       <<"http://jabber.org/protocol/pubsub">>, _} ->
 +        decode_pubsub_configure(<<"http://jabber.org/protocol/pubsub">>,
 +                                IgnoreEls, _el);
 +      {<<"configure">>, <<>>,
 +       <<"http://jabber.org/protocol/pubsub">>} ->
 +        decode_pubsub_configure(<<"http://jabber.org/protocol/pubsub">>,
 +                                IgnoreEls, _el);
 +      {<<"configure">>,
 +       <<"http://jabber.org/protocol/pubsub#owner">>, _} ->
 +        decode_pubsub_configure(<<"http://jabber.org/protocol/pubsub#owner">>,
 +                                IgnoreEls, _el);
 +      {<<"configure">>, <<>>,
 +       <<"http://jabber.org/protocol/pubsub#owner">>} ->
 +        decode_pubsub_configure(<<"http://jabber.org/protocol/pubsub#owner">>,
 +                                IgnoreEls, _el);
 +      {<<"create">>, <<"http://jabber.org/protocol/pubsub">>,
 +       _} ->
 +        decode_pubsub_create(<<"http://jabber.org/protocol/pubsub">>,
 +                             IgnoreEls, _el);
 +      {<<"create">>, <<>>,
 +       <<"http://jabber.org/protocol/pubsub">>} ->
 +        decode_pubsub_create(<<"http://jabber.org/protocol/pubsub">>,
 +                             IgnoreEls, _el);
 +      {<<"create">>,
 +       <<"http://jabber.org/protocol/pubsub#event">>, _} ->
 +        decode_pubsub_create(<<"http://jabber.org/protocol/pubsub#event">>,
 +                             IgnoreEls, _el);
 +      {<<"create">>, <<>>,
 +       <<"http://jabber.org/protocol/pubsub#event">>} ->
 +        decode_pubsub_create(<<"http://jabber.org/protocol/pubsub#event">>,
 +                             IgnoreEls, _el);
 +      {<<"retract">>, <<"http://jabber.org/protocol/pubsub">>,
 +       _} ->
 +        decode_pubsub_retract(<<"http://jabber.org/protocol/pubsub">>,
 +                              IgnoreEls, _el);
 +      {<<"retract">>, <<>>,
 +       <<"http://jabber.org/protocol/pubsub">>} ->
 +        decode_pubsub_retract(<<"http://jabber.org/protocol/pubsub">>,
 +                              IgnoreEls, _el);
 +      {<<"options">>, <<"http://jabber.org/protocol/pubsub">>,
 +       _} ->
 +        decode_pubsub_options(<<"http://jabber.org/protocol/pubsub">>,
 +                              IgnoreEls, _el);
 +      {<<"options">>, <<>>,
 +       <<"http://jabber.org/protocol/pubsub">>} ->
 +        decode_pubsub_options(<<"http://jabber.org/protocol/pubsub">>,
 +                              IgnoreEls, _el);
 +      {<<"publish">>, <<"http://jabber.org/protocol/pubsub">>,
 +       _} ->
 +        decode_pubsub_publish(<<"http://jabber.org/protocol/pubsub">>,
 +                              IgnoreEls, _el);
 +      {<<"publish">>, <<>>,
 +       <<"http://jabber.org/protocol/pubsub">>} ->
 +        decode_pubsub_publish(<<"http://jabber.org/protocol/pubsub">>,
 +                              IgnoreEls, _el);
 +      {<<"unsubscribe">>,
 +       <<"http://jabber.org/protocol/pubsub">>, _} ->
 +        decode_pubsub_unsubscribe(<<"http://jabber.org/protocol/pubsub">>,
 +                                  IgnoreEls, _el);
 +      {<<"unsubscribe">>, <<>>,
 +       <<"http://jabber.org/protocol/pubsub">>} ->
 +        decode_pubsub_unsubscribe(<<"http://jabber.org/protocol/pubsub">>,
 +                                  IgnoreEls, _el);
 +      {<<"subscribe">>,
 +       <<"http://jabber.org/protocol/pubsub">>, _} ->
 +        decode_pubsub_subscribe(<<"http://jabber.org/protocol/pubsub">>,
 +                                IgnoreEls, _el);
 +      {<<"subscribe">>, <<>>,
 +       <<"http://jabber.org/protocol/pubsub">>} ->
 +        decode_pubsub_subscribe(<<"http://jabber.org/protocol/pubsub">>,
 +                                IgnoreEls, _el);
 +      {<<"affiliations">>,
 +       <<"http://jabber.org/protocol/pubsub#owner">>, _} ->
 +        decode_pubsub_owner_affiliations(<<"http://jabber.org/protocol/pubsub#owner">>,
 +                                         IgnoreEls, _el);
 +      {<<"affiliations">>, <<>>,
 +       <<"http://jabber.org/protocol/pubsub#owner">>} ->
 +        decode_pubsub_owner_affiliations(<<"http://jabber.org/protocol/pubsub#owner">>,
 +                                         IgnoreEls, _el);
 +      {<<"affiliations">>,
 +       <<"http://jabber.org/protocol/pubsub">>, _} ->
 +        decode_pubsub_affiliations(<<"http://jabber.org/protocol/pubsub">>,
 +                                   IgnoreEls, _el);
 +      {<<"affiliations">>, <<>>,
 +       <<"http://jabber.org/protocol/pubsub">>} ->
 +        decode_pubsub_affiliations(<<"http://jabber.org/protocol/pubsub">>,
 +                                   IgnoreEls, _el);
 +      {<<"subscriptions">>,
 +       <<"http://jabber.org/protocol/pubsub">>, _} ->
 +        decode_pubsub_subscriptions(<<"http://jabber.org/protocol/pubsub">>,
 +                                    IgnoreEls, _el);
 +      {<<"subscriptions">>, <<>>,
 +       <<"http://jabber.org/protocol/pubsub">>} ->
 +        decode_pubsub_subscriptions(<<"http://jabber.org/protocol/pubsub">>,
 +                                    IgnoreEls, _el);
 +      {<<"subscriptions">>,
 +       <<"http://jabber.org/protocol/pubsub#owner">>, _} ->
 +        decode_pubsub_subscriptions(<<"http://jabber.org/protocol/pubsub#owner">>,
 +                                    IgnoreEls, _el);
 +      {<<"subscriptions">>, <<>>,
 +       <<"http://jabber.org/protocol/pubsub#owner">>} ->
 +        decode_pubsub_subscriptions(<<"http://jabber.org/protocol/pubsub#owner">>,
 +                                    IgnoreEls, _el);
 +      {<<"event">>,
 +       <<"http://jabber.org/protocol/pubsub#event">>, _} ->
 +        decode_pubsub_event(<<"http://jabber.org/protocol/pubsub#event">>,
 +                            IgnoreEls, _el);
 +      {<<"event">>, <<>>,
 +       <<"http://jabber.org/protocol/pubsub#event">>} ->
 +        decode_pubsub_event(<<"http://jabber.org/protocol/pubsub#event">>,
 +                            IgnoreEls, _el);
 +      {<<"items">>, <<"http://jabber.org/protocol/pubsub">>,
 +       _} ->
 +        decode_pubsub_items(<<"http://jabber.org/protocol/pubsub">>,
 +                            IgnoreEls, _el);
 +      {<<"items">>, <<>>,
 +       <<"http://jabber.org/protocol/pubsub">>} ->
 +        decode_pubsub_items(<<"http://jabber.org/protocol/pubsub">>,
 +                            IgnoreEls, _el);
 +      {<<"items">>,
 +       <<"http://jabber.org/protocol/pubsub#event">>, _} ->
 +        decode_pubsub_items(<<"http://jabber.org/protocol/pubsub#event">>,
 +                            IgnoreEls, _el);
 +      {<<"items">>, <<>>,
 +       <<"http://jabber.org/protocol/pubsub#event">>} ->
 +        decode_pubsub_items(<<"http://jabber.org/protocol/pubsub#event">>,
 +                            IgnoreEls, _el);
 +      {<<"item">>, <<"http://jabber.org/protocol/pubsub">>,
 +       _} ->
 +        decode_pubsub_item(<<"http://jabber.org/protocol/pubsub">>,
 +                           IgnoreEls, _el);
 +      {<<"item">>, <<>>,
 +       <<"http://jabber.org/protocol/pubsub">>} ->
 +        decode_pubsub_item(<<"http://jabber.org/protocol/pubsub">>,
 +                           IgnoreEls, _el);
 +      {<<"item">>,
 +       <<"http://jabber.org/protocol/pubsub#event">>, _} ->
 +        decode_pubsub_item(<<"http://jabber.org/protocol/pubsub#event">>,
 +                           IgnoreEls, _el);
 +      {<<"item">>, <<>>,
 +       <<"http://jabber.org/protocol/pubsub#event">>} ->
 +        decode_pubsub_item(<<"http://jabber.org/protocol/pubsub#event">>,
 +                           IgnoreEls, _el);
 +      {<<"retract">>,
 +       <<"http://jabber.org/protocol/pubsub#event">>, _} ->
 +        decode_pubsub_event_retract(<<"http://jabber.org/protocol/pubsub#event">>,
 +                                    IgnoreEls, _el);
 +      {<<"retract">>, <<>>,
 +       <<"http://jabber.org/protocol/pubsub#event">>} ->
 +        decode_pubsub_event_retract(<<"http://jabber.org/protocol/pubsub#event">>,
 +                                    IgnoreEls, _el);
 +      {<<"configuration">>,
 +       <<"http://jabber.org/protocol/pubsub#event">>, _} ->
 +        decode_pubsub_event_configuration(<<"http://jabber.org/protocol/pubsub#event">>,
 +                                          IgnoreEls, _el);
 +      {<<"configuration">>, <<>>,
 +       <<"http://jabber.org/protocol/pubsub#event">>} ->
 +        decode_pubsub_event_configuration(<<"http://jabber.org/protocol/pubsub#event">>,
 +                                          IgnoreEls, _el);
 +      {<<"affiliation">>,
 +       <<"http://jabber.org/protocol/pubsub#owner">>, _} ->
 +        decode_pubsub_owner_affiliation(<<"http://jabber.org/protocol/pubsub#owner">>,
 +                                        IgnoreEls, _el);
 +      {<<"affiliation">>, <<>>,
 +       <<"http://jabber.org/protocol/pubsub#owner">>} ->
 +        decode_pubsub_owner_affiliation(<<"http://jabber.org/protocol/pubsub#owner">>,
 +                                        IgnoreEls, _el);
 +      {<<"affiliation">>,
 +       <<"http://jabber.org/protocol/pubsub">>, _} ->
 +        decode_pubsub_affiliation(<<"http://jabber.org/protocol/pubsub">>,
 +                                  IgnoreEls, _el);
 +      {<<"affiliation">>, <<>>,
 +       <<"http://jabber.org/protocol/pubsub">>} ->
 +        decode_pubsub_affiliation(<<"http://jabber.org/protocol/pubsub">>,
 +                                  IgnoreEls, _el);
 +      {<<"subscription">>,
 +       <<"http://jabber.org/protocol/pubsub">>, _} ->
 +        decode_pubsub_subscription(<<"http://jabber.org/protocol/pubsub">>,
 +                                   IgnoreEls, _el);
 +      {<<"subscription">>, <<>>,
 +       <<"http://jabber.org/protocol/pubsub">>} ->
 +        decode_pubsub_subscription(<<"http://jabber.org/protocol/pubsub">>,
 +                                   IgnoreEls, _el);
 +      {<<"subscription">>,
 +       <<"http://jabber.org/protocol/pubsub#owner">>, _} ->
 +        decode_pubsub_subscription(<<"http://jabber.org/protocol/pubsub#owner">>,
 +                                   IgnoreEls, _el);
 +      {<<"subscription">>, <<>>,
 +       <<"http://jabber.org/protocol/pubsub#owner">>} ->
 +        decode_pubsub_subscription(<<"http://jabber.org/protocol/pubsub#owner">>,
 +                                   IgnoreEls, _el);
 +      {<<"subscription">>,
 +       <<"http://jabber.org/protocol/pubsub#event">>, _} ->
 +        decode_pubsub_subscription(<<"http://jabber.org/protocol/pubsub#event">>,
 +                                   IgnoreEls, _el);
 +      {<<"subscription">>, <<>>,
 +       <<"http://jabber.org/protocol/pubsub#event">>} ->
 +        decode_pubsub_subscription(<<"http://jabber.org/protocol/pubsub#event">>,
 +                                   IgnoreEls, _el);
 +      {<<"x">>, <<"jabber:x:data">>, _} ->
 +        decode_xdata(<<"jabber:x:data">>, IgnoreEls, _el);
 +      {<<"x">>, <<>>, <<"jabber:x:data">>} ->
 +        decode_xdata(<<"jabber:x:data">>, IgnoreEls, _el);
 +      {<<"item">>, <<"jabber:x:data">>, _} ->
 +        decode_xdata_item(<<"jabber:x:data">>, IgnoreEls, _el);
 +      {<<"item">>, <<>>, <<"jabber:x:data">>} ->
 +        decode_xdata_item(<<"jabber:x:data">>, IgnoreEls, _el);
 +      {<<"reported">>, <<"jabber:x:data">>, _} ->
 +        decode_xdata_reported(<<"jabber:x:data">>, IgnoreEls,
 +                              _el);
 +      {<<"reported">>, <<>>, <<"jabber:x:data">>} ->
 +        decode_xdata_reported(<<"jabber:x:data">>, IgnoreEls,
 +                              _el);
 +      {<<"title">>, <<"jabber:x:data">>, _} ->
 +        decode_xdata_title(<<"jabber:x:data">>, IgnoreEls, _el);
 +      {<<"title">>, <<>>, <<"jabber:x:data">>} ->
 +        decode_xdata_title(<<"jabber:x:data">>, IgnoreEls, _el);
 +      {<<"instructions">>, <<"jabber:x:data">>, _} ->
 +        decode_xdata_instructions(<<"jabber:x:data">>,
 +                                  IgnoreEls, _el);
 +      {<<"instructions">>, <<>>, <<"jabber:x:data">>} ->
 +        decode_xdata_instructions(<<"jabber:x:data">>,
 +                                  IgnoreEls, _el);
 +      {<<"field">>, <<"jabber:x:data">>, _} ->
 +        decode_xdata_field(<<"jabber:x:data">>, IgnoreEls, _el);
 +      {<<"field">>, <<>>, <<"jabber:x:data">>} ->
 +        decode_xdata_field(<<"jabber:x:data">>, IgnoreEls, _el);
 +      {<<"option">>, <<"jabber:x:data">>, _} ->
 +        decode_xdata_field_option(<<"jabber:x:data">>,
 +                                  IgnoreEls, _el);
 +      {<<"option">>, <<>>, <<"jabber:x:data">>} ->
 +        decode_xdata_field_option(<<"jabber:x:data">>,
 +                                  IgnoreEls, _el);
 +      {<<"value">>, <<"jabber:x:data">>, _} ->
 +        decode_xdata_field_value(<<"jabber:x:data">>, IgnoreEls,
 +                                 _el);
 +      {<<"value">>, <<>>, <<"jabber:x:data">>} ->
 +        decode_xdata_field_value(<<"jabber:x:data">>, IgnoreEls,
 +                                 _el);
 +      {<<"desc">>, <<"jabber:x:data">>, _} ->
 +        decode_xdata_field_desc(<<"jabber:x:data">>, IgnoreEls,
 +                                _el);
 +      {<<"desc">>, <<>>, <<"jabber:x:data">>} ->
 +        decode_xdata_field_desc(<<"jabber:x:data">>, IgnoreEls,
 +                                _el);
 +      {<<"required">>, <<"jabber:x:data">>, _} ->
 +        decode_xdata_field_required(<<"jabber:x:data">>,
 +                                    IgnoreEls, _el);
 +      {<<"required">>, <<>>, <<"jabber:x:data">>} ->
 +        decode_xdata_field_required(<<"jabber:x:data">>,
 +                                    IgnoreEls, _el);
 +      {<<"x">>, <<"vcard-temp:x:update">>, _} ->
 +        decode_vcard_xupdate(<<"vcard-temp:x:update">>,
 +                             IgnoreEls, _el);
 +      {<<"x">>, <<>>, <<"vcard-temp:x:update">>} ->
 +        decode_vcard_xupdate(<<"vcard-temp:x:update">>,
 +                             IgnoreEls, _el);
 +      {<<"photo">>, <<"vcard-temp:x:update">>, _} ->
 +        decode_vcard_xupdate_photo(<<"vcard-temp:x:update">>,
 +                                   IgnoreEls, _el);
 +      {<<"photo">>, <<>>, <<"vcard-temp:x:update">>} ->
 +        decode_vcard_xupdate_photo(<<"vcard-temp:x:update">>,
 +                                   IgnoreEls, _el);
 +      {<<"vCard">>, <<"vcard-temp">>, _} ->
 +        decode_vcard_temp(<<"vcard-temp">>, IgnoreEls, _el);
 +      {<<"vCard">>, <<>>, <<"vcard-temp">>} ->
 +        decode_vcard_temp(<<"vcard-temp">>, IgnoreEls, _el);
 +      {<<"CLASS">>, <<"vcard-temp">>, _} ->
 +        decode_vcard_CLASS(<<"vcard-temp">>, IgnoreEls, _el);
 +      {<<"CLASS">>, <<>>, <<"vcard-temp">>} ->
 +        decode_vcard_CLASS(<<"vcard-temp">>, IgnoreEls, _el);
 +      {<<"CATEGORIES">>, <<"vcard-temp">>, _} ->
 +        decode_vcard_CATEGORIES(<<"vcard-temp">>, IgnoreEls,
 +                                _el);
 +      {<<"CATEGORIES">>, <<>>, <<"vcard-temp">>} ->
 +        decode_vcard_CATEGORIES(<<"vcard-temp">>, IgnoreEls,
 +                                _el);
 +      {<<"KEY">>, <<"vcard-temp">>, _} ->
 +        decode_vcard_KEY(<<"vcard-temp">>, IgnoreEls, _el);
 +      {<<"KEY">>, <<>>, <<"vcard-temp">>} ->
 +        decode_vcard_KEY(<<"vcard-temp">>, IgnoreEls, _el);
 +      {<<"SOUND">>, <<"vcard-temp">>, _} ->
 +        decode_vcard_SOUND(<<"vcard-temp">>, IgnoreEls, _el);
 +      {<<"SOUND">>, <<>>, <<"vcard-temp">>} ->
 +        decode_vcard_SOUND(<<"vcard-temp">>, IgnoreEls, _el);
 +      {<<"ORG">>, <<"vcard-temp">>, _} ->
 +        decode_vcard_ORG(<<"vcard-temp">>, IgnoreEls, _el);
 +      {<<"ORG">>, <<>>, <<"vcard-temp">>} ->
 +        decode_vcard_ORG(<<"vcard-temp">>, IgnoreEls, _el);
 +      {<<"PHOTO">>, <<"vcard-temp">>, _} ->
 +        decode_vcard_PHOTO(<<"vcard-temp">>, IgnoreEls, _el);
 +      {<<"PHOTO">>, <<>>, <<"vcard-temp">>} ->
 +        decode_vcard_PHOTO(<<"vcard-temp">>, IgnoreEls, _el);
 +      {<<"LOGO">>, <<"vcard-temp">>, _} ->
 +        decode_vcard_LOGO(<<"vcard-temp">>, IgnoreEls, _el);
 +      {<<"LOGO">>, <<>>, <<"vcard-temp">>} ->
 +        decode_vcard_LOGO(<<"vcard-temp">>, IgnoreEls, _el);
 +      {<<"BINVAL">>, <<"vcard-temp">>, _} ->
 +        decode_vcard_BINVAL(<<"vcard-temp">>, IgnoreEls, _el);
 +      {<<"BINVAL">>, <<>>, <<"vcard-temp">>} ->
 +        decode_vcard_BINVAL(<<"vcard-temp">>, IgnoreEls, _el);
 +      {<<"GEO">>, <<"vcard-temp">>, _} ->
 +        decode_vcard_GEO(<<"vcard-temp">>, IgnoreEls, _el);
 +      {<<"GEO">>, <<>>, <<"vcard-temp">>} ->
 +        decode_vcard_GEO(<<"vcard-temp">>, IgnoreEls, _el);
 +      {<<"EMAIL">>, <<"vcard-temp">>, _} ->
 +        decode_vcard_EMAIL(<<"vcard-temp">>, IgnoreEls, _el);
 +      {<<"EMAIL">>, <<>>, <<"vcard-temp">>} ->
 +        decode_vcard_EMAIL(<<"vcard-temp">>, IgnoreEls, _el);
 +      {<<"TEL">>, <<"vcard-temp">>, _} ->
 +        decode_vcard_TEL(<<"vcard-temp">>, IgnoreEls, _el);
 +      {<<"TEL">>, <<>>, <<"vcard-temp">>} ->
 +        decode_vcard_TEL(<<"vcard-temp">>, IgnoreEls, _el);
 +      {<<"LABEL">>, <<"vcard-temp">>, _} ->
 +        decode_vcard_LABEL(<<"vcard-temp">>, IgnoreEls, _el);
 +      {<<"LABEL">>, <<>>, <<"vcard-temp">>} ->
 +        decode_vcard_LABEL(<<"vcard-temp">>, IgnoreEls, _el);
 +      {<<"ADR">>, <<"vcard-temp">>, _} ->
 +        decode_vcard_ADR(<<"vcard-temp">>, IgnoreEls, _el);
 +      {<<"ADR">>, <<>>, <<"vcard-temp">>} ->
 +        decode_vcard_ADR(<<"vcard-temp">>, IgnoreEls, _el);
 +      {<<"N">>, <<"vcard-temp">>, _} ->
 +        decode_vcard_N(<<"vcard-temp">>, IgnoreEls, _el);
 +      {<<"N">>, <<>>, <<"vcard-temp">>} ->
 +        decode_vcard_N(<<"vcard-temp">>, IgnoreEls, _el);
 +      {<<"CONFIDENTIAL">>, <<"vcard-temp">>, _} ->
 +        decode_vcard_CONFIDENTIAL(<<"vcard-temp">>, IgnoreEls,
 +                                  _el);
 +      {<<"CONFIDENTIAL">>, <<>>, <<"vcard-temp">>} ->
 +        decode_vcard_CONFIDENTIAL(<<"vcard-temp">>, IgnoreEls,
 +                                  _el);
 +      {<<"PRIVATE">>, <<"vcard-temp">>, _} ->
 +        decode_vcard_PRIVATE(<<"vcard-temp">>, IgnoreEls, _el);
 +      {<<"PRIVATE">>, <<>>, <<"vcard-temp">>} ->
 +        decode_vcard_PRIVATE(<<"vcard-temp">>, IgnoreEls, _el);
 +      {<<"PUBLIC">>, <<"vcard-temp">>, _} ->
 +        decode_vcard_PUBLIC(<<"vcard-temp">>, IgnoreEls, _el);
 +      {<<"PUBLIC">>, <<>>, <<"vcard-temp">>} ->
 +        decode_vcard_PUBLIC(<<"vcard-temp">>, IgnoreEls, _el);
 +      {<<"EXTVAL">>, <<"vcard-temp">>, _} ->
 +        decode_vcard_EXTVAL(<<"vcard-temp">>, IgnoreEls, _el);
 +      {<<"EXTVAL">>, <<>>, <<"vcard-temp">>} ->
 +        decode_vcard_EXTVAL(<<"vcard-temp">>, IgnoreEls, _el);
 +      {<<"TYPE">>, <<"vcard-temp">>, _} ->
 +        decode_vcard_TYPE(<<"vcard-temp">>, IgnoreEls, _el);
 +      {<<"TYPE">>, <<>>, <<"vcard-temp">>} ->
 +        decode_vcard_TYPE(<<"vcard-temp">>, IgnoreEls, _el);
 +      {<<"DESC">>, <<"vcard-temp">>, _} ->
 +        decode_vcard_DESC(<<"vcard-temp">>, IgnoreEls, _el);
 +      {<<"DESC">>, <<>>, <<"vcard-temp">>} ->
 +        decode_vcard_DESC(<<"vcard-temp">>, IgnoreEls, _el);
 +      {<<"URL">>, <<"vcard-temp">>, _} ->
 +        decode_vcard_URL(<<"vcard-temp">>, IgnoreEls, _el);
 +      {<<"URL">>, <<>>, <<"vcard-temp">>} ->
 +        decode_vcard_URL(<<"vcard-temp">>, IgnoreEls, _el);
 +      {<<"UID">>, <<"vcard-temp">>, _} ->
 +        decode_vcard_UID(<<"vcard-temp">>, IgnoreEls, _el);
 +      {<<"UID">>, <<>>, <<"vcard-temp">>} ->
 +        decode_vcard_UID(<<"vcard-temp">>, IgnoreEls, _el);
 +      {<<"SORT-STRING">>, <<"vcard-temp">>, _} ->
 +        decode_vcard_SORT_STRING(<<"vcard-temp">>, IgnoreEls,
 +                                 _el);
 +      {<<"SORT-STRING">>, <<>>, <<"vcard-temp">>} ->
 +        decode_vcard_SORT_STRING(<<"vcard-temp">>, IgnoreEls,
 +                                 _el);
 +      {<<"REV">>, <<"vcard-temp">>, _} ->
 +        decode_vcard_REV(<<"vcard-temp">>, IgnoreEls, _el);
 +      {<<"REV">>, <<>>, <<"vcard-temp">>} ->
 +        decode_vcard_REV(<<"vcard-temp">>, IgnoreEls, _el);
 +      {<<"PRODID">>, <<"vcard-temp">>, _} ->
 +        decode_vcard_PRODID(<<"vcard-temp">>, IgnoreEls, _el);
 +      {<<"PRODID">>, <<>>, <<"vcard-temp">>} ->
 +        decode_vcard_PRODID(<<"vcard-temp">>, IgnoreEls, _el);
 +      {<<"NOTE">>, <<"vcard-temp">>, _} ->
 +        decode_vcard_NOTE(<<"vcard-temp">>, IgnoreEls, _el);
 +      {<<"NOTE">>, <<>>, <<"vcard-temp">>} ->
 +        decode_vcard_NOTE(<<"vcard-temp">>, IgnoreEls, _el);
 +      {<<"KEYWORD">>, <<"vcard-temp">>, _} ->
 +        decode_vcard_KEYWORD(<<"vcard-temp">>, IgnoreEls, _el);
 +      {<<"KEYWORD">>, <<>>, <<"vcard-temp">>} ->
 +        decode_vcard_KEYWORD(<<"vcard-temp">>, IgnoreEls, _el);
 +      {<<"ROLE">>, <<"vcard-temp">>, _} ->
 +        decode_vcard_ROLE(<<"vcard-temp">>, IgnoreEls, _el);
 +      {<<"ROLE">>, <<>>, <<"vcard-temp">>} ->
 +        decode_vcard_ROLE(<<"vcard-temp">>, IgnoreEls, _el);
 +      {<<"TITLE">>, <<"vcard-temp">>, _} ->
 +        decode_vcard_TITLE(<<"vcard-temp">>, IgnoreEls, _el);
 +      {<<"TITLE">>, <<>>, <<"vcard-temp">>} ->
 +        decode_vcard_TITLE(<<"vcard-temp">>, IgnoreEls, _el);
 +      {<<"TZ">>, <<"vcard-temp">>, _} ->
 +        decode_vcard_TZ(<<"vcard-temp">>, IgnoreEls, _el);
 +      {<<"TZ">>, <<>>, <<"vcard-temp">>} ->
 +        decode_vcard_TZ(<<"vcard-temp">>, IgnoreEls, _el);
 +      {<<"MAILER">>, <<"vcard-temp">>, _} ->
 +        decode_vcard_MAILER(<<"vcard-temp">>, IgnoreEls, _el);
 +      {<<"MAILER">>, <<>>, <<"vcard-temp">>} ->
 +        decode_vcard_MAILER(<<"vcard-temp">>, IgnoreEls, _el);
 +      {<<"JABBERID">>, <<"vcard-temp">>, _} ->
 +        decode_vcard_JABBERID(<<"vcard-temp">>, IgnoreEls, _el);
 +      {<<"JABBERID">>, <<>>, <<"vcard-temp">>} ->
 +        decode_vcard_JABBERID(<<"vcard-temp">>, IgnoreEls, _el);
 +      {<<"BDAY">>, <<"vcard-temp">>, _} ->
 +        decode_vcard_BDAY(<<"vcard-temp">>, IgnoreEls, _el);
 +      {<<"BDAY">>, <<>>, <<"vcard-temp">>} ->
 +        decode_vcard_BDAY(<<"vcard-temp">>, IgnoreEls, _el);
 +      {<<"NICKNAME">>, <<"vcard-temp">>, _} ->
 +        decode_vcard_NICKNAME(<<"vcard-temp">>, IgnoreEls, _el);
 +      {<<"NICKNAME">>, <<>>, <<"vcard-temp">>} ->
 +        decode_vcard_NICKNAME(<<"vcard-temp">>, IgnoreEls, _el);
 +      {<<"FN">>, <<"vcard-temp">>, _} ->
 +        decode_vcard_FN(<<"vcard-temp">>, IgnoreEls, _el);
 +      {<<"FN">>, <<>>, <<"vcard-temp">>} ->
 +        decode_vcard_FN(<<"vcard-temp">>, IgnoreEls, _el);
 +      {<<"VERSION">>, <<"vcard-temp">>, _} ->
 +        decode_vcard_VERSION(<<"vcard-temp">>, IgnoreEls, _el);
 +      {<<"VERSION">>, <<>>, <<"vcard-temp">>} ->
 +        decode_vcard_VERSION(<<"vcard-temp">>, IgnoreEls, _el);
 +      {<<"CRED">>, <<"vcard-temp">>, _} ->
 +        decode_vcard_CRED(<<"vcard-temp">>, IgnoreEls, _el);
 +      {<<"CRED">>, <<>>, <<"vcard-temp">>} ->
 +        decode_vcard_CRED(<<"vcard-temp">>, IgnoreEls, _el);
 +      {<<"PHONETIC">>, <<"vcard-temp">>, _} ->
 +        decode_vcard_PHONETIC(<<"vcard-temp">>, IgnoreEls, _el);
 +      {<<"PHONETIC">>, <<>>, <<"vcard-temp">>} ->
 +        decode_vcard_PHONETIC(<<"vcard-temp">>, IgnoreEls, _el);
 +      {<<"ORGUNIT">>, <<"vcard-temp">>, _} ->
 +        decode_vcard_ORGUNIT(<<"vcard-temp">>, IgnoreEls, _el);
 +      {<<"ORGUNIT">>, <<>>, <<"vcard-temp">>} ->
 +        decode_vcard_ORGUNIT(<<"vcard-temp">>, IgnoreEls, _el);
 +      {<<"ORGNAME">>, <<"vcard-temp">>, _} ->
 +        decode_vcard_ORGNAME(<<"vcard-temp">>, IgnoreEls, _el);
 +      {<<"ORGNAME">>, <<>>, <<"vcard-temp">>} ->
 +        decode_vcard_ORGNAME(<<"vcard-temp">>, IgnoreEls, _el);
 +      {<<"LON">>, <<"vcard-temp">>, _} ->
 +        decode_vcard_LON(<<"vcard-temp">>, IgnoreEls, _el);
 +      {<<"LON">>, <<>>, <<"vcard-temp">>} ->
 +        decode_vcard_LON(<<"vcard-temp">>, IgnoreEls, _el);
 +      {<<"LAT">>, <<"vcard-temp">>, _} ->
 +        decode_vcard_LAT(<<"vcard-temp">>, IgnoreEls, _el);
 +      {<<"LAT">>, <<>>, <<"vcard-temp">>} ->
 +        decode_vcard_LAT(<<"vcard-temp">>, IgnoreEls, _el);
 +      {<<"USERID">>, <<"vcard-temp">>, _} ->
 +        decode_vcard_USERID(<<"vcard-temp">>, IgnoreEls, _el);
 +      {<<"USERID">>, <<>>, <<"vcard-temp">>} ->
 +        decode_vcard_USERID(<<"vcard-temp">>, IgnoreEls, _el);
 +      {<<"NUMBER">>, <<"vcard-temp">>, _} ->
 +        decode_vcard_NUMBER(<<"vcard-temp">>, IgnoreEls, _el);
 +      {<<"NUMBER">>, <<>>, <<"vcard-temp">>} ->
 +        decode_vcard_NUMBER(<<"vcard-temp">>, IgnoreEls, _el);
 +      {<<"LINE">>, <<"vcard-temp">>, _} ->
 +        decode_vcard_LINE(<<"vcard-temp">>, IgnoreEls, _el);
 +      {<<"LINE">>, <<>>, <<"vcard-temp">>} ->
 +        decode_vcard_LINE(<<"vcard-temp">>, IgnoreEls, _el);
 +      {<<"CTRY">>, <<"vcard-temp">>, _} ->
 +        decode_vcard_CTRY(<<"vcard-temp">>, IgnoreEls, _el);
 +      {<<"CTRY">>, <<>>, <<"vcard-temp">>} ->
 +        decode_vcard_CTRY(<<"vcard-temp">>, IgnoreEls, _el);
 +      {<<"PCODE">>, <<"vcard-temp">>, _} ->
 +        decode_vcard_PCODE(<<"vcard-temp">>, IgnoreEls, _el);
 +      {<<"PCODE">>, <<>>, <<"vcard-temp">>} ->
 +        decode_vcard_PCODE(<<"vcard-temp">>, IgnoreEls, _el);
 +      {<<"REGION">>, <<"vcard-temp">>, _} ->
 +        decode_vcard_REGION(<<"vcard-temp">>, IgnoreEls, _el);
 +      {<<"REGION">>, <<>>, <<"vcard-temp">>} ->
 +        decode_vcard_REGION(<<"vcard-temp">>, IgnoreEls, _el);
 +      {<<"LOCALITY">>, <<"vcard-temp">>, _} ->
 +        decode_vcard_LOCALITY(<<"vcard-temp">>, IgnoreEls, _el);
 +      {<<"LOCALITY">>, <<>>, <<"vcard-temp">>} ->
 +        decode_vcard_LOCALITY(<<"vcard-temp">>, IgnoreEls, _el);
 +      {<<"STREET">>, <<"vcard-temp">>, _} ->
 +        decode_vcard_STREET(<<"vcard-temp">>, IgnoreEls, _el);
 +      {<<"STREET">>, <<>>, <<"vcard-temp">>} ->
 +        decode_vcard_STREET(<<"vcard-temp">>, IgnoreEls, _el);
 +      {<<"EXTADD">>, <<"vcard-temp">>, _} ->
 +        decode_vcard_EXTADD(<<"vcard-temp">>, IgnoreEls, _el);
 +      {<<"EXTADD">>, <<>>, <<"vcard-temp">>} ->
 +        decode_vcard_EXTADD(<<"vcard-temp">>, IgnoreEls, _el);
 +      {<<"POBOX">>, <<"vcard-temp">>, _} ->
 +        decode_vcard_POBOX(<<"vcard-temp">>, IgnoreEls, _el);
 +      {<<"POBOX">>, <<>>, <<"vcard-temp">>} ->
 +        decode_vcard_POBOX(<<"vcard-temp">>, IgnoreEls, _el);
 +      {<<"SUFFIX">>, <<"vcard-temp">>, _} ->
 +        decode_vcard_SUFFIX(<<"vcard-temp">>, IgnoreEls, _el);
 +      {<<"SUFFIX">>, <<>>, <<"vcard-temp">>} ->
 +        decode_vcard_SUFFIX(<<"vcard-temp">>, IgnoreEls, _el);
 +      {<<"PREFIX">>, <<"vcard-temp">>, _} ->
 +        decode_vcard_PREFIX(<<"vcard-temp">>, IgnoreEls, _el);
 +      {<<"PREFIX">>, <<>>, <<"vcard-temp">>} ->
 +        decode_vcard_PREFIX(<<"vcard-temp">>, IgnoreEls, _el);
 +      {<<"MIDDLE">>, <<"vcard-temp">>, _} ->
 +        decode_vcard_MIDDLE(<<"vcard-temp">>, IgnoreEls, _el);
 +      {<<"MIDDLE">>, <<>>, <<"vcard-temp">>} ->
 +        decode_vcard_MIDDLE(<<"vcard-temp">>, IgnoreEls, _el);
 +      {<<"GIVEN">>, <<"vcard-temp">>, _} ->
 +        decode_vcard_GIVEN(<<"vcard-temp">>, IgnoreEls, _el);
 +      {<<"GIVEN">>, <<>>, <<"vcard-temp">>} ->
 +        decode_vcard_GIVEN(<<"vcard-temp">>, IgnoreEls, _el);
 +      {<<"FAMILY">>, <<"vcard-temp">>, _} ->
 +        decode_vcard_FAMILY(<<"vcard-temp">>, IgnoreEls, _el);
 +      {<<"FAMILY">>, <<>>, <<"vcard-temp">>} ->
 +        decode_vcard_FAMILY(<<"vcard-temp">>, IgnoreEls, _el);
 +      {<<"X400">>, <<"vcard-temp">>, _} ->
 +        decode_vcard_X400(<<"vcard-temp">>, IgnoreEls, _el);
 +      {<<"X400">>, <<>>, <<"vcard-temp">>} ->
 +        decode_vcard_X400(<<"vcard-temp">>, IgnoreEls, _el);
 +      {<<"INTERNET">>, <<"vcard-temp">>, _} ->
 +        decode_vcard_INTERNET(<<"vcard-temp">>, IgnoreEls, _el);
 +      {<<"INTERNET">>, <<>>, <<"vcard-temp">>} ->
 +        decode_vcard_INTERNET(<<"vcard-temp">>, IgnoreEls, _el);
 +      {<<"PREF">>, <<"vcard-temp">>, _} ->
 +        decode_vcard_PREF(<<"vcard-temp">>, IgnoreEls, _el);
 +      {<<"PREF">>, <<>>, <<"vcard-temp">>} ->
 +        decode_vcard_PREF(<<"vcard-temp">>, IgnoreEls, _el);
 +      {<<"INTL">>, <<"vcard-temp">>, _} ->
 +        decode_vcard_INTL(<<"vcard-temp">>, IgnoreEls, _el);
 +      {<<"INTL">>, <<>>, <<"vcard-temp">>} ->
 +        decode_vcard_INTL(<<"vcard-temp">>, IgnoreEls, _el);
 +      {<<"DOM">>, <<"vcard-temp">>, _} ->
 +        decode_vcard_DOM(<<"vcard-temp">>, IgnoreEls, _el);
 +      {<<"DOM">>, <<>>, <<"vcard-temp">>} ->
 +        decode_vcard_DOM(<<"vcard-temp">>, IgnoreEls, _el);
 +      {<<"PARCEL">>, <<"vcard-temp">>, _} ->
 +        decode_vcard_PARCEL(<<"vcard-temp">>, IgnoreEls, _el);
 +      {<<"PARCEL">>, <<>>, <<"vcard-temp">>} ->
 +        decode_vcard_PARCEL(<<"vcard-temp">>, IgnoreEls, _el);
 +      {<<"POSTAL">>, <<"vcard-temp">>, _} ->
 +        decode_vcard_POSTAL(<<"vcard-temp">>, IgnoreEls, _el);
 +      {<<"POSTAL">>, <<>>, <<"vcard-temp">>} ->
 +        decode_vcard_POSTAL(<<"vcard-temp">>, IgnoreEls, _el);
 +      {<<"PCS">>, <<"vcard-temp">>, _} ->
 +        decode_vcard_PCS(<<"vcard-temp">>, IgnoreEls, _el);
 +      {<<"PCS">>, <<>>, <<"vcard-temp">>} ->
 +        decode_vcard_PCS(<<"vcard-temp">>, IgnoreEls, _el);
 +      {<<"ISDN">>, <<"vcard-temp">>, _} ->
 +        decode_vcard_ISDN(<<"vcard-temp">>, IgnoreEls, _el);
 +      {<<"ISDN">>, <<>>, <<"vcard-temp">>} ->
 +        decode_vcard_ISDN(<<"vcard-temp">>, IgnoreEls, _el);
 +      {<<"MODEM">>, <<"vcard-temp">>, _} ->
 +        decode_vcard_MODEM(<<"vcard-temp">>, IgnoreEls, _el);
 +      {<<"MODEM">>, <<>>, <<"vcard-temp">>} ->
 +        decode_vcard_MODEM(<<"vcard-temp">>, IgnoreEls, _el);
 +      {<<"BBS">>, <<"vcard-temp">>, _} ->
 +        decode_vcard_BBS(<<"vcard-temp">>, IgnoreEls, _el);
 +      {<<"BBS">>, <<>>, <<"vcard-temp">>} ->
 +        decode_vcard_BBS(<<"vcard-temp">>, IgnoreEls, _el);
 +      {<<"VIDEO">>, <<"vcard-temp">>, _} ->
 +        decode_vcard_VIDEO(<<"vcard-temp">>, IgnoreEls, _el);
 +      {<<"VIDEO">>, <<>>, <<"vcard-temp">>} ->
 +        decode_vcard_VIDEO(<<"vcard-temp">>, IgnoreEls, _el);
 +      {<<"CELL">>, <<"vcard-temp">>, _} ->
 +        decode_vcard_CELL(<<"vcard-temp">>, IgnoreEls, _el);
 +      {<<"CELL">>, <<>>, <<"vcard-temp">>} ->
 +        decode_vcard_CELL(<<"vcard-temp">>, IgnoreEls, _el);
 +      {<<"MSG">>, <<"vcard-temp">>, _} ->
 +        decode_vcard_MSG(<<"vcard-temp">>, IgnoreEls, _el);
 +      {<<"MSG">>, <<>>, <<"vcard-temp">>} ->
 +        decode_vcard_MSG(<<"vcard-temp">>, IgnoreEls, _el);
 +      {<<"PAGER">>, <<"vcard-temp">>, _} ->
 +        decode_vcard_PAGER(<<"vcard-temp">>, IgnoreEls, _el);
 +      {<<"PAGER">>, <<>>, <<"vcard-temp">>} ->
 +        decode_vcard_PAGER(<<"vcard-temp">>, IgnoreEls, _el);
 +      {<<"FAX">>, <<"vcard-temp">>, _} ->
 +        decode_vcard_FAX(<<"vcard-temp">>, IgnoreEls, _el);
 +      {<<"FAX">>, <<>>, <<"vcard-temp">>} ->
 +        decode_vcard_FAX(<<"vcard-temp">>, IgnoreEls, _el);
 +      {<<"VOICE">>, <<"vcard-temp">>, _} ->
 +        decode_vcard_VOICE(<<"vcard-temp">>, IgnoreEls, _el);
 +      {<<"VOICE">>, <<>>, <<"vcard-temp">>} ->
 +        decode_vcard_VOICE(<<"vcard-temp">>, IgnoreEls, _el);
 +      {<<"WORK">>, <<"vcard-temp">>, _} ->
 +        decode_vcard_WORK(<<"vcard-temp">>, IgnoreEls, _el);
 +      {<<"WORK">>, <<>>, <<"vcard-temp">>} ->
 +        decode_vcard_WORK(<<"vcard-temp">>, IgnoreEls, _el);
 +      {<<"HOME">>, <<"vcard-temp">>, _} ->
 +        decode_vcard_HOME(<<"vcard-temp">>, IgnoreEls, _el);
 +      {<<"HOME">>, <<>>, <<"vcard-temp">>} ->
 +        decode_vcard_HOME(<<"vcard-temp">>, IgnoreEls, _el);
 +      {<<"stream:error">>, <<"jabber:client">>, _} ->
 +        decode_stream_error(<<"jabber:client">>, IgnoreEls,
 +                            _el);
 +      {<<"stream:error">>, <<>>, <<"jabber:client">>} ->
 +        decode_stream_error(<<"jabber:client">>, IgnoreEls,
 +                            _el);
 +      {<<"stream:error">>, <<"jabber:server">>, _} ->
 +        decode_stream_error(<<"jabber:server">>, IgnoreEls,
 +                            _el);
 +      {<<"stream:error">>, <<>>, <<"jabber:server">>} ->
 +        decode_stream_error(<<"jabber:server">>, IgnoreEls,
 +                            _el);
 +      {<<"stream:error">>, <<"jabber:component:accept">>,
 +       _} ->
 +        decode_stream_error(<<"jabber:component:accept">>,
 +                            IgnoreEls, _el);
 +      {<<"stream:error">>, <<>>,
 +       <<"jabber:component:accept">>} ->
 +        decode_stream_error(<<"jabber:component:accept">>,
 +                            IgnoreEls, _el);
 +      {<<"unsupported-version">>,
 +       <<"urn:ietf:params:xml:ns:xmpp-streams">>, _} ->
 +        decode_stream_error_unsupported_version(<<"urn:ietf:params:xml:ns:xmpp-streams">>,
 +                                                IgnoreEls, _el);
 +      {<<"unsupported-version">>, <<>>,
 +       <<"urn:ietf:params:xml:ns:xmpp-streams">>} ->
 +        decode_stream_error_unsupported_version(<<"urn:ietf:params:xml:ns:xmpp-streams">>,
 +                                                IgnoreEls, _el);
 +      {<<"unsupported-stanza-type">>,
 +       <<"urn:ietf:params:xml:ns:xmpp-streams">>, _} ->
 +        decode_stream_error_unsupported_stanza_type(<<"urn:ietf:params:xml:ns:xmpp-streams">>,
 +                                                    IgnoreEls, _el);
 +      {<<"unsupported-stanza-type">>, <<>>,
 +       <<"urn:ietf:params:xml:ns:xmpp-streams">>} ->
 +        decode_stream_error_unsupported_stanza_type(<<"urn:ietf:params:xml:ns:xmpp-streams">>,
 +                                                    IgnoreEls, _el);
 +      {<<"unsupported-encoding">>,
 +       <<"urn:ietf:params:xml:ns:xmpp-streams">>, _} ->
 +        decode_stream_error_unsupported_encoding(<<"urn:ietf:params:xml:ns:xmpp-streams">>,
 +                                                 IgnoreEls, _el);
 +      {<<"unsupported-encoding">>, <<>>,
 +       <<"urn:ietf:params:xml:ns:xmpp-streams">>} ->
 +        decode_stream_error_unsupported_encoding(<<"urn:ietf:params:xml:ns:xmpp-streams">>,
 +                                                 IgnoreEls, _el);
 +      {<<"undefined-condition">>,
 +       <<"urn:ietf:params:xml:ns:xmpp-streams">>, _} ->
 +        decode_stream_error_undefined_condition(<<"urn:ietf:params:xml:ns:xmpp-streams">>,
 +                                                IgnoreEls, _el);
 +      {<<"undefined-condition">>, <<>>,
 +       <<"urn:ietf:params:xml:ns:xmpp-streams">>} ->
 +        decode_stream_error_undefined_condition(<<"urn:ietf:params:xml:ns:xmpp-streams">>,
 +                                                IgnoreEls, _el);
 +      {<<"system-shutdown">>,
 +       <<"urn:ietf:params:xml:ns:xmpp-streams">>, _} ->
 +        decode_stream_error_system_shutdown(<<"urn:ietf:params:xml:ns:xmpp-streams">>,
 +                                            IgnoreEls, _el);
 +      {<<"system-shutdown">>, <<>>,
 +       <<"urn:ietf:params:xml:ns:xmpp-streams">>} ->
 +        decode_stream_error_system_shutdown(<<"urn:ietf:params:xml:ns:xmpp-streams">>,
 +                                            IgnoreEls, _el);
 +      {<<"see-other-host">>,
 +       <<"urn:ietf:params:xml:ns:xmpp-streams">>, _} ->
 +        decode_stream_error_see_other_host(<<"urn:ietf:params:xml:ns:xmpp-streams">>,
 +                                           IgnoreEls, _el);
 +      {<<"see-other-host">>, <<>>,
 +       <<"urn:ietf:params:xml:ns:xmpp-streams">>} ->
 +        decode_stream_error_see_other_host(<<"urn:ietf:params:xml:ns:xmpp-streams">>,
 +                                           IgnoreEls, _el);
 +      {<<"restricted-xml">>,
 +       <<"urn:ietf:params:xml:ns:xmpp-streams">>, _} ->
 +        decode_stream_error_restricted_xml(<<"urn:ietf:params:xml:ns:xmpp-streams">>,
 +                                           IgnoreEls, _el);
 +      {<<"restricted-xml">>, <<>>,
 +       <<"urn:ietf:params:xml:ns:xmpp-streams">>} ->
 +        decode_stream_error_restricted_xml(<<"urn:ietf:params:xml:ns:xmpp-streams">>,
 +                                           IgnoreEls, _el);
 +      {<<"resource-constraint">>,
 +       <<"urn:ietf:params:xml:ns:xmpp-streams">>, _} ->
 +        decode_stream_error_resource_constraint(<<"urn:ietf:params:xml:ns:xmpp-streams">>,
 +                                                IgnoreEls, _el);
 +      {<<"resource-constraint">>, <<>>,
 +       <<"urn:ietf:params:xml:ns:xmpp-streams">>} ->
 +        decode_stream_error_resource_constraint(<<"urn:ietf:params:xml:ns:xmpp-streams">>,
 +                                                IgnoreEls, _el);
 +      {<<"reset">>, <<"urn:ietf:params:xml:ns:xmpp-streams">>,
 +       _} ->
 +        decode_stream_error_reset(<<"urn:ietf:params:xml:ns:xmpp-streams">>,
 +                                  IgnoreEls, _el);
 +      {<<"reset">>, <<>>,
 +       <<"urn:ietf:params:xml:ns:xmpp-streams">>} ->
 +        decode_stream_error_reset(<<"urn:ietf:params:xml:ns:xmpp-streams">>,
 +                                  IgnoreEls, _el);
 +      {<<"remote-connection-failed">>,
 +       <<"urn:ietf:params:xml:ns:xmpp-streams">>, _} ->
 +        decode_stream_error_remote_connection_failed(<<"urn:ietf:params:xml:ns:xmpp-streams">>,
 +                                                     IgnoreEls, _el);
 +      {<<"remote-connection-failed">>, <<>>,
 +       <<"urn:ietf:params:xml:ns:xmpp-streams">>} ->
 +        decode_stream_error_remote_connection_failed(<<"urn:ietf:params:xml:ns:xmpp-streams">>,
 +                                                     IgnoreEls, _el);
 +      {<<"policy-violation">>,
 +       <<"urn:ietf:params:xml:ns:xmpp-streams">>, _} ->
 +        decode_stream_error_policy_violation(<<"urn:ietf:params:xml:ns:xmpp-streams">>,
 +                                             IgnoreEls, _el);
 +      {<<"policy-violation">>, <<>>,
 +       <<"urn:ietf:params:xml:ns:xmpp-streams">>} ->
 +        decode_stream_error_policy_violation(<<"urn:ietf:params:xml:ns:xmpp-streams">>,
 +                                             IgnoreEls, _el);
 +      {<<"not-well-formed">>,
 +       <<"urn:ietf:params:xml:ns:xmpp-streams">>, _} ->
 +        decode_stream_error_not_well_formed(<<"urn:ietf:params:xml:ns:xmpp-streams">>,
 +                                            IgnoreEls, _el);
 +      {<<"not-well-formed">>, <<>>,
 +       <<"urn:ietf:params:xml:ns:xmpp-streams">>} ->
 +        decode_stream_error_not_well_formed(<<"urn:ietf:params:xml:ns:xmpp-streams">>,
 +                                            IgnoreEls, _el);
 +      {<<"not-authorized">>,
 +       <<"urn:ietf:params:xml:ns:xmpp-streams">>, _} ->
 +        decode_stream_error_not_authorized(<<"urn:ietf:params:xml:ns:xmpp-streams">>,
 +                                           IgnoreEls, _el);
 +      {<<"not-authorized">>, <<>>,
 +       <<"urn:ietf:params:xml:ns:xmpp-streams">>} ->
 +        decode_stream_error_not_authorized(<<"urn:ietf:params:xml:ns:xmpp-streams">>,
 +                                           IgnoreEls, _el);
 +      {<<"invalid-xml">>,
 +       <<"urn:ietf:params:xml:ns:xmpp-streams">>, _} ->
 +        decode_stream_error_invalid_xml(<<"urn:ietf:params:xml:ns:xmpp-streams">>,
 +                                        IgnoreEls, _el);
 +      {<<"invalid-xml">>, <<>>,
 +       <<"urn:ietf:params:xml:ns:xmpp-streams">>} ->
 +        decode_stream_error_invalid_xml(<<"urn:ietf:params:xml:ns:xmpp-streams">>,
 +                                        IgnoreEls, _el);
 +      {<<"invalid-namespace">>,
 +       <<"urn:ietf:params:xml:ns:xmpp-streams">>, _} ->
 +        decode_stream_error_invalid_namespace(<<"urn:ietf:params:xml:ns:xmpp-streams">>,
 +                                              IgnoreEls, _el);
 +      {<<"invalid-namespace">>, <<>>,
 +       <<"urn:ietf:params:xml:ns:xmpp-streams">>} ->
 +        decode_stream_error_invalid_namespace(<<"urn:ietf:params:xml:ns:xmpp-streams">>,
 +                                              IgnoreEls, _el);
 +      {<<"invalid-id">>,
 +       <<"urn:ietf:params:xml:ns:xmpp-streams">>, _} ->
 +        decode_stream_error_invalid_id(<<"urn:ietf:params:xml:ns:xmpp-streams">>,
 +                                       IgnoreEls, _el);
 +      {<<"invalid-id">>, <<>>,
 +       <<"urn:ietf:params:xml:ns:xmpp-streams">>} ->
 +        decode_stream_error_invalid_id(<<"urn:ietf:params:xml:ns:xmpp-streams">>,
 +                                       IgnoreEls, _el);
 +      {<<"invalid-from">>,
 +       <<"urn:ietf:params:xml:ns:xmpp-streams">>, _} ->
 +        decode_stream_error_invalid_from(<<"urn:ietf:params:xml:ns:xmpp-streams">>,
 +                                         IgnoreEls, _el);
 +      {<<"invalid-from">>, <<>>,
 +       <<"urn:ietf:params:xml:ns:xmpp-streams">>} ->
 +        decode_stream_error_invalid_from(<<"urn:ietf:params:xml:ns:xmpp-streams">>,
 +                                         IgnoreEls, _el);
 +      {<<"internal-server-error">>,
 +       <<"urn:ietf:params:xml:ns:xmpp-streams">>, _} ->
 +        decode_stream_error_internal_server_error(<<"urn:ietf:params:xml:ns:xmpp-streams">>,
 +                                                  IgnoreEls, _el);
 +      {<<"internal-server-error">>, <<>>,
 +       <<"urn:ietf:params:xml:ns:xmpp-streams">>} ->
 +        decode_stream_error_internal_server_error(<<"urn:ietf:params:xml:ns:xmpp-streams">>,
 +                                                  IgnoreEls, _el);
 +      {<<"improper-addressing">>,
 +       <<"urn:ietf:params:xml:ns:xmpp-streams">>, _} ->
 +        decode_stream_error_improper_addressing(<<"urn:ietf:params:xml:ns:xmpp-streams">>,
 +                                                IgnoreEls, _el);
 +      {<<"improper-addressing">>, <<>>,
 +       <<"urn:ietf:params:xml:ns:xmpp-streams">>} ->
 +        decode_stream_error_improper_addressing(<<"urn:ietf:params:xml:ns:xmpp-streams">>,
 +                                                IgnoreEls, _el);
 +      {<<"host-unknown">>,
 +       <<"urn:ietf:params:xml:ns:xmpp-streams">>, _} ->
 +        decode_stream_error_host_unknown(<<"urn:ietf:params:xml:ns:xmpp-streams">>,
 +                                         IgnoreEls, _el);
 +      {<<"host-unknown">>, <<>>,
 +       <<"urn:ietf:params:xml:ns:xmpp-streams">>} ->
 +        decode_stream_error_host_unknown(<<"urn:ietf:params:xml:ns:xmpp-streams">>,
 +                                         IgnoreEls, _el);
 +      {<<"host-gone">>,
 +       <<"urn:ietf:params:xml:ns:xmpp-streams">>, _} ->
 +        decode_stream_error_host_gone(<<"urn:ietf:params:xml:ns:xmpp-streams">>,
 +                                      IgnoreEls, _el);
 +      {<<"host-gone">>, <<>>,
 +       <<"urn:ietf:params:xml:ns:xmpp-streams">>} ->
 +        decode_stream_error_host_gone(<<"urn:ietf:params:xml:ns:xmpp-streams">>,
 +                                      IgnoreEls, _el);
 +      {<<"connection-timeout">>,
 +       <<"urn:ietf:params:xml:ns:xmpp-streams">>, _} ->
 +        decode_stream_error_connection_timeout(<<"urn:ietf:params:xml:ns:xmpp-streams">>,
 +                                               IgnoreEls, _el);
 +      {<<"connection-timeout">>, <<>>,
 +       <<"urn:ietf:params:xml:ns:xmpp-streams">>} ->
 +        decode_stream_error_connection_timeout(<<"urn:ietf:params:xml:ns:xmpp-streams">>,
 +                                               IgnoreEls, _el);
 +      {<<"conflict">>,
 +       <<"urn:ietf:params:xml:ns:xmpp-streams">>, _} ->
 +        decode_stream_error_conflict(<<"urn:ietf:params:xml:ns:xmpp-streams">>,
 +                                     IgnoreEls, _el);
 +      {<<"conflict">>, <<>>,
 +       <<"urn:ietf:params:xml:ns:xmpp-streams">>} ->
 +        decode_stream_error_conflict(<<"urn:ietf:params:xml:ns:xmpp-streams">>,
 +                                     IgnoreEls, _el);
 +      {<<"bad-namespace-prefix">>,
 +       <<"urn:ietf:params:xml:ns:xmpp-streams">>, _} ->
 +        decode_stream_error_bad_namespace_prefix(<<"urn:ietf:params:xml:ns:xmpp-streams">>,
 +                                                 IgnoreEls, _el);
 +      {<<"bad-namespace-prefix">>, <<>>,
 +       <<"urn:ietf:params:xml:ns:xmpp-streams">>} ->
 +        decode_stream_error_bad_namespace_prefix(<<"urn:ietf:params:xml:ns:xmpp-streams">>,
 +                                                 IgnoreEls, _el);
 +      {<<"bad-format">>,
 +       <<"urn:ietf:params:xml:ns:xmpp-streams">>, _} ->
 +        decode_stream_error_bad_format(<<"urn:ietf:params:xml:ns:xmpp-streams">>,
 +                                       IgnoreEls, _el);
 +      {<<"bad-format">>, <<>>,
 +       <<"urn:ietf:params:xml:ns:xmpp-streams">>} ->
 +        decode_stream_error_bad_format(<<"urn:ietf:params:xml:ns:xmpp-streams">>,
 +                                       IgnoreEls, _el);
 +      {<<"text">>, <<"urn:ietf:params:xml:ns:xmpp-streams">>,
 +       _} ->
 +        decode_stream_error_text(<<"urn:ietf:params:xml:ns:xmpp-streams">>,
 +                                 IgnoreEls, _el);
 +      {<<"text">>, <<>>,
 +       <<"urn:ietf:params:xml:ns:xmpp-streams">>} ->
 +        decode_stream_error_text(<<"urn:ietf:params:xml:ns:xmpp-streams">>,
 +                                 IgnoreEls, _el);
 +      {<<"time">>, <<"urn:xmpp:time">>, _} ->
 +        decode_time(<<"urn:xmpp:time">>, IgnoreEls, _el);
 +      {<<"time">>, <<>>, <<"urn:xmpp:time">>} ->
 +        decode_time(<<"urn:xmpp:time">>, IgnoreEls, _el);
 +      {<<"tzo">>, <<"urn:xmpp:time">>, _} ->
 +        decode_time_tzo(<<"urn:xmpp:time">>, IgnoreEls, _el);
 +      {<<"tzo">>, <<>>, <<"urn:xmpp:time">>} ->
 +        decode_time_tzo(<<"urn:xmpp:time">>, IgnoreEls, _el);
 +      {<<"utc">>, <<"urn:xmpp:time">>, _} ->
 +        decode_time_utc(<<"urn:xmpp:time">>, IgnoreEls, _el);
 +      {<<"utc">>, <<>>, <<"urn:xmpp:time">>} ->
 +        decode_time_utc(<<"urn:xmpp:time">>, IgnoreEls, _el);
 +      {<<"ping">>, <<"urn:xmpp:ping">>, _} ->
 +        decode_ping(<<"urn:xmpp:ping">>, IgnoreEls, _el);
 +      {<<"ping">>, <<>>, <<"urn:xmpp:ping">>} ->
 +        decode_ping(<<"urn:xmpp:ping">>, IgnoreEls, _el);
 +      {<<"session">>,
 +       <<"urn:ietf:params:xml:ns:xmpp-session">>, _} ->
 +        decode_session(<<"urn:ietf:params:xml:ns:xmpp-session">>,
 +                       IgnoreEls, _el);
 +      {<<"session">>, <<>>,
 +       <<"urn:ietf:params:xml:ns:xmpp-session">>} ->
 +        decode_session(<<"urn:ietf:params:xml:ns:xmpp-session">>,
 +                       IgnoreEls, _el);
 +      {<<"optional">>,
 +       <<"urn:ietf:params:xml:ns:xmpp-session">>, _} ->
 +        decode_session_optional(<<"urn:ietf:params:xml:ns:xmpp-session">>,
 +                                IgnoreEls, _el);
 +      {<<"optional">>, <<>>,
 +       <<"urn:ietf:params:xml:ns:xmpp-session">>} ->
 +        decode_session_optional(<<"urn:ietf:params:xml:ns:xmpp-session">>,
 +                                IgnoreEls, _el);
 +      {<<"query">>, <<"jabber:iq:register">>, _} ->
 +        decode_register(<<"jabber:iq:register">>, IgnoreEls,
 +                        _el);
 +      {<<"query">>, <<>>, <<"jabber:iq:register">>} ->
 +        decode_register(<<"jabber:iq:register">>, IgnoreEls,
 +                        _el);
 +      {<<"key">>, <<"jabber:iq:register">>, _} ->
 +        decode_register_key(<<"jabber:iq:register">>, IgnoreEls,
 +                            _el);
 +      {<<"key">>, <<>>, <<"jabber:iq:register">>} ->
 +        decode_register_key(<<"jabber:iq:register">>, IgnoreEls,
 +                            _el);
 +      {<<"text">>, <<"jabber:iq:register">>, _} ->
 +        decode_register_text(<<"jabber:iq:register">>,
 +                             IgnoreEls, _el);
 +      {<<"text">>, <<>>, <<"jabber:iq:register">>} ->
 +        decode_register_text(<<"jabber:iq:register">>,
 +                             IgnoreEls, _el);
 +      {<<"misc">>, <<"jabber:iq:register">>, _} ->
 +        decode_register_misc(<<"jabber:iq:register">>,
 +                             IgnoreEls, _el);
 +      {<<"misc">>, <<>>, <<"jabber:iq:register">>} ->
 +        decode_register_misc(<<"jabber:iq:register">>,
 +                             IgnoreEls, _el);
 +      {<<"date">>, <<"jabber:iq:register">>, _} ->
 +        decode_register_date(<<"jabber:iq:register">>,
 +                             IgnoreEls, _el);
 +      {<<"date">>, <<>>, <<"jabber:iq:register">>} ->
 +        decode_register_date(<<"jabber:iq:register">>,
 +                             IgnoreEls, _el);
 +      {<<"url">>, <<"jabber:iq:register">>, _} ->
 +        decode_register_url(<<"jabber:iq:register">>, IgnoreEls,
 +                            _el);
 +      {<<"url">>, <<>>, <<"jabber:iq:register">>} ->
 +        decode_register_url(<<"jabber:iq:register">>, IgnoreEls,
 +                            _el);
 +      {<<"phone">>, <<"jabber:iq:register">>, _} ->
 +        decode_register_phone(<<"jabber:iq:register">>,
 +                              IgnoreEls, _el);
 +      {<<"phone">>, <<>>, <<"jabber:iq:register">>} ->
 +        decode_register_phone(<<"jabber:iq:register">>,
 +                              IgnoreEls, _el);
 +      {<<"zip">>, <<"jabber:iq:register">>, _} ->
 +        decode_register_zip(<<"jabber:iq:register">>, IgnoreEls,
 +                            _el);
 +      {<<"zip">>, <<>>, <<"jabber:iq:register">>} ->
 +        decode_register_zip(<<"jabber:iq:register">>, IgnoreEls,
 +                            _el);
 +      {<<"state">>, <<"jabber:iq:register">>, _} ->
 +        decode_register_state(<<"jabber:iq:register">>,
 +                              IgnoreEls, _el);
 +      {<<"state">>, <<>>, <<"jabber:iq:register">>} ->
 +        decode_register_state(<<"jabber:iq:register">>,
 +                              IgnoreEls, _el);
 +      {<<"city">>, <<"jabber:iq:register">>, _} ->
 +        decode_register_city(<<"jabber:iq:register">>,
 +                             IgnoreEls, _el);
 +      {<<"city">>, <<>>, <<"jabber:iq:register">>} ->
 +        decode_register_city(<<"jabber:iq:register">>,
 +                             IgnoreEls, _el);
 +      {<<"address">>, <<"jabber:iq:register">>, _} ->
 +        decode_register_address(<<"jabber:iq:register">>,
 +                                IgnoreEls, _el);
 +      {<<"address">>, <<>>, <<"jabber:iq:register">>} ->
 +        decode_register_address(<<"jabber:iq:register">>,
 +                                IgnoreEls, _el);
 +      {<<"email">>, <<"jabber:iq:register">>, _} ->
 +        decode_register_email(<<"jabber:iq:register">>,
 +                              IgnoreEls, _el);
 +      {<<"email">>, <<>>, <<"jabber:iq:register">>} ->
 +        decode_register_email(<<"jabber:iq:register">>,
 +                              IgnoreEls, _el);
 +      {<<"last">>, <<"jabber:iq:register">>, _} ->
 +        decode_register_last(<<"jabber:iq:register">>,
 +                             IgnoreEls, _el);
 +      {<<"last">>, <<>>, <<"jabber:iq:register">>} ->
 +        decode_register_last(<<"jabber:iq:register">>,
 +                             IgnoreEls, _el);
 +      {<<"first">>, <<"jabber:iq:register">>, _} ->
 +        decode_register_first(<<"jabber:iq:register">>,
 +                              IgnoreEls, _el);
 +      {<<"first">>, <<>>, <<"jabber:iq:register">>} ->
 +        decode_register_first(<<"jabber:iq:register">>,
 +                              IgnoreEls, _el);
 +      {<<"name">>, <<"jabber:iq:register">>, _} ->
 +        decode_register_name(<<"jabber:iq:register">>,
 +                             IgnoreEls, _el);
 +      {<<"name">>, <<>>, <<"jabber:iq:register">>} ->
 +        decode_register_name(<<"jabber:iq:register">>,
 +                             IgnoreEls, _el);
 +      {<<"password">>, <<"jabber:iq:register">>, _} ->
 +        decode_register_password(<<"jabber:iq:register">>,
 +                                 IgnoreEls, _el);
 +      {<<"password">>, <<>>, <<"jabber:iq:register">>} ->
 +        decode_register_password(<<"jabber:iq:register">>,
 +                                 IgnoreEls, _el);
 +      {<<"nick">>, <<"jabber:iq:register">>, _} ->
 +        decode_register_nick(<<"jabber:iq:register">>,
 +                             IgnoreEls, _el);
 +      {<<"nick">>, <<>>, <<"jabber:iq:register">>} ->
 +        decode_register_nick(<<"jabber:iq:register">>,
 +                             IgnoreEls, _el);
 +      {<<"username">>, <<"jabber:iq:register">>, _} ->
 +        decode_register_username(<<"jabber:iq:register">>,
 +                                 IgnoreEls, _el);
 +      {<<"username">>, <<>>, <<"jabber:iq:register">>} ->
 +        decode_register_username(<<"jabber:iq:register">>,
 +                                 IgnoreEls, _el);
 +      {<<"instructions">>, <<"jabber:iq:register">>, _} ->
 +        decode_register_instructions(<<"jabber:iq:register">>,
 +                                     IgnoreEls, _el);
 +      {<<"instructions">>, <<>>, <<"jabber:iq:register">>} ->
 +        decode_register_instructions(<<"jabber:iq:register">>,
 +                                     IgnoreEls, _el);
 +      {<<"remove">>, <<"jabber:iq:register">>, _} ->
 +        decode_register_remove(<<"jabber:iq:register">>,
 +                               IgnoreEls, _el);
 +      {<<"remove">>, <<>>, <<"jabber:iq:register">>} ->
 +        decode_register_remove(<<"jabber:iq:register">>,
 +                               IgnoreEls, _el);
 +      {<<"registered">>, <<"jabber:iq:register">>, _} ->
 +        decode_register_registered(<<"jabber:iq:register">>,
 +                                   IgnoreEls, _el);
 +      {<<"registered">>, <<>>, <<"jabber:iq:register">>} ->
 +        decode_register_registered(<<"jabber:iq:register">>,
 +                                   IgnoreEls, _el);
 +      {<<"register">>,
 +       <<"http://jabber.org/features/iq-register">>, _} ->
 +        decode_feature_register(<<"http://jabber.org/features/iq-register">>,
 +                                IgnoreEls, _el);
 +      {<<"register">>, <<>>,
 +       <<"http://jabber.org/features/iq-register">>} ->
 +        decode_feature_register(<<"http://jabber.org/features/iq-register">>,
 +                                IgnoreEls, _el);
 +      {<<"c">>, <<"http://jabber.org/protocol/caps">>, _} ->
 +        decode_caps(<<"http://jabber.org/protocol/caps">>,
 +                    IgnoreEls, _el);
 +      {<<"c">>, <<>>,
 +       <<"http://jabber.org/protocol/caps">>} ->
 +        decode_caps(<<"http://jabber.org/protocol/caps">>,
 +                    IgnoreEls, _el);
 +      {<<"ack">>, <<"p1:ack">>, _} ->
 +        decode_p1_ack(<<"p1:ack">>, IgnoreEls, _el);
 +      {<<"ack">>, <<>>, <<"p1:ack">>} ->
 +        decode_p1_ack(<<"p1:ack">>, IgnoreEls, _el);
 +      {<<"rebind">>, <<"p1:rebind">>, _} ->
 +        decode_p1_rebind(<<"p1:rebind">>, IgnoreEls, _el);
 +      {<<"rebind">>, <<>>, <<"p1:rebind">>} ->
 +        decode_p1_rebind(<<"p1:rebind">>, IgnoreEls, _el);
 +      {<<"push">>, <<"p1:push">>, _} ->
 +        decode_p1_push(<<"p1:push">>, IgnoreEls, _el);
 +      {<<"push">>, <<>>, <<"p1:push">>} ->
 +        decode_p1_push(<<"p1:push">>, IgnoreEls, _el);
 +      {<<"stream:features">>, <<"jabber:client">>, _} ->
 +        decode_stream_features(<<"jabber:client">>, IgnoreEls,
 +                               _el);
 +      {<<"stream:features">>, <<>>, <<"jabber:client">>} ->
 +        decode_stream_features(<<"jabber:client">>, IgnoreEls,
 +                               _el);
 +      {<<"stream:features">>, <<"jabber:server">>, _} ->
 +        decode_stream_features(<<"jabber:server">>, IgnoreEls,
 +                               _el);
 +      {<<"stream:features">>, <<>>, <<"jabber:server">>} ->
 +        decode_stream_features(<<"jabber:server">>, IgnoreEls,
 +                               _el);
 +      {<<"compression">>,
 +       <<"http://jabber.org/features/compress">>, _} ->
 +        decode_compression(<<"http://jabber.org/features/compress">>,
 +                           IgnoreEls, _el);
 +      {<<"compression">>, <<>>,
 +       <<"http://jabber.org/features/compress">>} ->
 +        decode_compression(<<"http://jabber.org/features/compress">>,
 +                           IgnoreEls, _el);
 +      {<<"method">>,
 +       <<"http://jabber.org/features/compress">>, _} ->
 +        decode_compression_method(<<"http://jabber.org/features/compress">>,
 +                                  IgnoreEls, _el);
 +      {<<"method">>, <<>>,
 +       <<"http://jabber.org/features/compress">>} ->
 +        decode_compression_method(<<"http://jabber.org/features/compress">>,
 +                                  IgnoreEls, _el);
 +      {<<"compressed">>,
 +       <<"http://jabber.org/protocol/compress">>, _} ->
 +        decode_compressed(<<"http://jabber.org/protocol/compress">>,
 +                          IgnoreEls, _el);
 +      {<<"compressed">>, <<>>,
 +       <<"http://jabber.org/protocol/compress">>} ->
 +        decode_compressed(<<"http://jabber.org/protocol/compress">>,
 +                          IgnoreEls, _el);
 +      {<<"compress">>,
 +       <<"http://jabber.org/protocol/compress">>, _} ->
 +        decode_compress(<<"http://jabber.org/protocol/compress">>,
 +                        IgnoreEls, _el);
 +      {<<"compress">>, <<>>,
 +       <<"http://jabber.org/protocol/compress">>} ->
 +        decode_compress(<<"http://jabber.org/protocol/compress">>,
 +                        IgnoreEls, _el);
 +      {<<"method">>,
 +       <<"http://jabber.org/protocol/compress">>, _} ->
 +        decode_compress_method(<<"http://jabber.org/protocol/compress">>,
 +                               IgnoreEls, _el);
 +      {<<"method">>, <<>>,
 +       <<"http://jabber.org/protocol/compress">>} ->
 +        decode_compress_method(<<"http://jabber.org/protocol/compress">>,
 +                               IgnoreEls, _el);
 +      {<<"failure">>,
 +       <<"http://jabber.org/protocol/compress">>, _} ->
 +        decode_compress_failure(<<"http://jabber.org/protocol/compress">>,
 +                                IgnoreEls, _el);
 +      {<<"failure">>, <<>>,
 +       <<"http://jabber.org/protocol/compress">>} ->
 +        decode_compress_failure(<<"http://jabber.org/protocol/compress">>,
 +                                IgnoreEls, _el);
 +      {<<"unsupported-method">>,
 +       <<"http://jabber.org/protocol/compress">>, _} ->
 +        decode_compress_failure_unsupported_method(<<"http://jabber.org/protocol/compress">>,
 +                                                   IgnoreEls, _el);
 +      {<<"unsupported-method">>, <<>>,
 +       <<"http://jabber.org/protocol/compress">>} ->
 +        decode_compress_failure_unsupported_method(<<"http://jabber.org/protocol/compress">>,
 +                                                   IgnoreEls, _el);
 +      {<<"processing-failed">>,
 +       <<"http://jabber.org/protocol/compress">>, _} ->
 +        decode_compress_failure_processing_failed(<<"http://jabber.org/protocol/compress">>,
 +                                                  IgnoreEls, _el);
 +      {<<"processing-failed">>, <<>>,
 +       <<"http://jabber.org/protocol/compress">>} ->
 +        decode_compress_failure_processing_failed(<<"http://jabber.org/protocol/compress">>,
 +                                                  IgnoreEls, _el);
 +      {<<"setup-failed">>,
 +       <<"http://jabber.org/protocol/compress">>, _} ->
 +        decode_compress_failure_setup_failed(<<"http://jabber.org/protocol/compress">>,
 +                                             IgnoreEls, _el);
 +      {<<"setup-failed">>, <<>>,
 +       <<"http://jabber.org/protocol/compress">>} ->
 +        decode_compress_failure_setup_failed(<<"http://jabber.org/protocol/compress">>,
 +                                             IgnoreEls, _el);
 +      {<<"failure">>, <<"urn:ietf:params:xml:ns:xmpp-tls">>,
 +       _} ->
 +        decode_starttls_failure(<<"urn:ietf:params:xml:ns:xmpp-tls">>,
 +                                IgnoreEls, _el);
 +      {<<"failure">>, <<>>,
 +       <<"urn:ietf:params:xml:ns:xmpp-tls">>} ->
 +        decode_starttls_failure(<<"urn:ietf:params:xml:ns:xmpp-tls">>,
 +                                IgnoreEls, _el);
 +      {<<"proceed">>, <<"urn:ietf:params:xml:ns:xmpp-tls">>,
 +       _} ->
 +        decode_starttls_proceed(<<"urn:ietf:params:xml:ns:xmpp-tls">>,
 +                                IgnoreEls, _el);
 +      {<<"proceed">>, <<>>,
 +       <<"urn:ietf:params:xml:ns:xmpp-tls">>} ->
 +        decode_starttls_proceed(<<"urn:ietf:params:xml:ns:xmpp-tls">>,
 +                                IgnoreEls, _el);
 +      {<<"starttls">>, <<"urn:ietf:params:xml:ns:xmpp-tls">>,
 +       _} ->
 +        decode_starttls(<<"urn:ietf:params:xml:ns:xmpp-tls">>,
 +                        IgnoreEls, _el);
 +      {<<"starttls">>, <<>>,
 +       <<"urn:ietf:params:xml:ns:xmpp-tls">>} ->
 +        decode_starttls(<<"urn:ietf:params:xml:ns:xmpp-tls">>,
 +                        IgnoreEls, _el);
 +      {<<"required">>, <<"urn:ietf:params:xml:ns:xmpp-tls">>,
 +       _} ->
 +        decode_starttls_required(<<"urn:ietf:params:xml:ns:xmpp-tls">>,
 +                                 IgnoreEls, _el);
 +      {<<"required">>, <<>>,
 +       <<"urn:ietf:params:xml:ns:xmpp-tls">>} ->
 +        decode_starttls_required(<<"urn:ietf:params:xml:ns:xmpp-tls">>,
 +                                 IgnoreEls, _el);
 +      {<<"mechanisms">>,
 +       <<"urn:ietf:params:xml:ns:xmpp-sasl">>, _} ->
 +        decode_sasl_mechanisms(<<"urn:ietf:params:xml:ns:xmpp-sasl">>,
 +                               IgnoreEls, _el);
 +      {<<"mechanisms">>, <<>>,
 +       <<"urn:ietf:params:xml:ns:xmpp-sasl">>} ->
 +        decode_sasl_mechanisms(<<"urn:ietf:params:xml:ns:xmpp-sasl">>,
 +                               IgnoreEls, _el);
 +      {<<"mechanism">>,
 +       <<"urn:ietf:params:xml:ns:xmpp-sasl">>, _} ->
 +        decode_sasl_mechanism(<<"urn:ietf:params:xml:ns:xmpp-sasl">>,
 +                              IgnoreEls, _el);
 +      {<<"mechanism">>, <<>>,
 +       <<"urn:ietf:params:xml:ns:xmpp-sasl">>} ->
 +        decode_sasl_mechanism(<<"urn:ietf:params:xml:ns:xmpp-sasl">>,
 +                              IgnoreEls, _el);
 +      {<<"failure">>, <<"urn:ietf:params:xml:ns:xmpp-sasl">>,
 +       _} ->
 +        decode_sasl_failure(<<"urn:ietf:params:xml:ns:xmpp-sasl">>,
 +                            IgnoreEls, _el);
 +      {<<"failure">>, <<>>,
 +       <<"urn:ietf:params:xml:ns:xmpp-sasl">>} ->
 +        decode_sasl_failure(<<"urn:ietf:params:xml:ns:xmpp-sasl">>,
 +                            IgnoreEls, _el);
 +      {<<"temporary-auth-failure">>,
 +       <<"urn:ietf:params:xml:ns:xmpp-sasl">>, _} ->
 +        decode_sasl_failure_temporary_auth_failure(<<"urn:ietf:params:xml:ns:xmpp-sasl">>,
 +                                                   IgnoreEls, _el);
 +      {<<"temporary-auth-failure">>, <<>>,
 +       <<"urn:ietf:params:xml:ns:xmpp-sasl">>} ->
 +        decode_sasl_failure_temporary_auth_failure(<<"urn:ietf:params:xml:ns:xmpp-sasl">>,
 +                                                   IgnoreEls, _el);
 +      {<<"bad-protocol">>,
 +       <<"urn:ietf:params:xml:ns:xmpp-sasl">>, _} ->
 +        decode_sasl_failure_bad_protocol(<<"urn:ietf:params:xml:ns:xmpp-sasl">>,
 +                                         IgnoreEls, _el);
 +      {<<"bad-protocol">>, <<>>,
 +       <<"urn:ietf:params:xml:ns:xmpp-sasl">>} ->
 +        decode_sasl_failure_bad_protocol(<<"urn:ietf:params:xml:ns:xmpp-sasl">>,
 +                                         IgnoreEls, _el);
 +      {<<"not-authorized">>,
 +       <<"urn:ietf:params:xml:ns:xmpp-sasl">>, _} ->
 +        decode_sasl_failure_not_authorized(<<"urn:ietf:params:xml:ns:xmpp-sasl">>,
 +                                           IgnoreEls, _el);
 +      {<<"not-authorized">>, <<>>,
 +       <<"urn:ietf:params:xml:ns:xmpp-sasl">>} ->
 +        decode_sasl_failure_not_authorized(<<"urn:ietf:params:xml:ns:xmpp-sasl">>,
 +                                           IgnoreEls, _el);
 +      {<<"mechanism-too-weak">>,
 +       <<"urn:ietf:params:xml:ns:xmpp-sasl">>, _} ->
 +        decode_sasl_failure_mechanism_too_weak(<<"urn:ietf:params:xml:ns:xmpp-sasl">>,
 +                                               IgnoreEls, _el);
 +      {<<"mechanism-too-weak">>, <<>>,
 +       <<"urn:ietf:params:xml:ns:xmpp-sasl">>} ->
 +        decode_sasl_failure_mechanism_too_weak(<<"urn:ietf:params:xml:ns:xmpp-sasl">>,
 +                                               IgnoreEls, _el);
 +      {<<"malformed-request">>,
 +       <<"urn:ietf:params:xml:ns:xmpp-sasl">>, _} ->
 +        decode_sasl_failure_malformed_request(<<"urn:ietf:params:xml:ns:xmpp-sasl">>,
 +                                              IgnoreEls, _el);
 +      {<<"malformed-request">>, <<>>,
 +       <<"urn:ietf:params:xml:ns:xmpp-sasl">>} ->
 +        decode_sasl_failure_malformed_request(<<"urn:ietf:params:xml:ns:xmpp-sasl">>,
 +                                              IgnoreEls, _el);
 +      {<<"invalid-mechanism">>,
 +       <<"urn:ietf:params:xml:ns:xmpp-sasl">>, _} ->
 +        decode_sasl_failure_invalid_mechanism(<<"urn:ietf:params:xml:ns:xmpp-sasl">>,
 +                                              IgnoreEls, _el);
 +      {<<"invalid-mechanism">>, <<>>,
 +       <<"urn:ietf:params:xml:ns:xmpp-sasl">>} ->
 +        decode_sasl_failure_invalid_mechanism(<<"urn:ietf:params:xml:ns:xmpp-sasl">>,
 +                                              IgnoreEls, _el);
 +      {<<"invalid-authzid">>,
 +       <<"urn:ietf:params:xml:ns:xmpp-sasl">>, _} ->
 +        decode_sasl_failure_invalid_authzid(<<"urn:ietf:params:xml:ns:xmpp-sasl">>,
 +                                            IgnoreEls, _el);
 +      {<<"invalid-authzid">>, <<>>,
 +       <<"urn:ietf:params:xml:ns:xmpp-sasl">>} ->
 +        decode_sasl_failure_invalid_authzid(<<"urn:ietf:params:xml:ns:xmpp-sasl">>,
 +                                            IgnoreEls, _el);
 +      {<<"incorrect-encoding">>,
 +       <<"urn:ietf:params:xml:ns:xmpp-sasl">>, _} ->
 +        decode_sasl_failure_incorrect_encoding(<<"urn:ietf:params:xml:ns:xmpp-sasl">>,
 +                                               IgnoreEls, _el);
 +      {<<"incorrect-encoding">>, <<>>,
 +       <<"urn:ietf:params:xml:ns:xmpp-sasl">>} ->
 +        decode_sasl_failure_incorrect_encoding(<<"urn:ietf:params:xml:ns:xmpp-sasl">>,
 +                                               IgnoreEls, _el);
 +      {<<"encryption-required">>,
 +       <<"urn:ietf:params:xml:ns:xmpp-sasl">>, _} ->
 +        decode_sasl_failure_encryption_required(<<"urn:ietf:params:xml:ns:xmpp-sasl">>,
 +                                                IgnoreEls, _el);
 +      {<<"encryption-required">>, <<>>,
 +       <<"urn:ietf:params:xml:ns:xmpp-sasl">>} ->
 +        decode_sasl_failure_encryption_required(<<"urn:ietf:params:xml:ns:xmpp-sasl">>,
 +                                                IgnoreEls, _el);
 +      {<<"credentials-expired">>,
 +       <<"urn:ietf:params:xml:ns:xmpp-sasl">>, _} ->
 +        decode_sasl_failure_credentials_expired(<<"urn:ietf:params:xml:ns:xmpp-sasl">>,
 +                                                IgnoreEls, _el);
 +      {<<"credentials-expired">>, <<>>,
 +       <<"urn:ietf:params:xml:ns:xmpp-sasl">>} ->
 +        decode_sasl_failure_credentials_expired(<<"urn:ietf:params:xml:ns:xmpp-sasl">>,
 +                                                IgnoreEls, _el);
 +      {<<"account-disabled">>,
 +       <<"urn:ietf:params:xml:ns:xmpp-sasl">>, _} ->
 +        decode_sasl_failure_account_disabled(<<"urn:ietf:params:xml:ns:xmpp-sasl">>,
 +                                             IgnoreEls, _el);
 +      {<<"account-disabled">>, <<>>,
 +       <<"urn:ietf:params:xml:ns:xmpp-sasl">>} ->
 +        decode_sasl_failure_account_disabled(<<"urn:ietf:params:xml:ns:xmpp-sasl">>,
 +                                             IgnoreEls, _el);
 +      {<<"aborted">>, <<"urn:ietf:params:xml:ns:xmpp-sasl">>,
 +       _} ->
 +        decode_sasl_failure_aborted(<<"urn:ietf:params:xml:ns:xmpp-sasl">>,
 +                                    IgnoreEls, _el);
 +      {<<"aborted">>, <<>>,
 +       <<"urn:ietf:params:xml:ns:xmpp-sasl">>} ->
 +        decode_sasl_failure_aborted(<<"urn:ietf:params:xml:ns:xmpp-sasl">>,
 +                                    IgnoreEls, _el);
 +      {<<"text">>, <<"urn:ietf:params:xml:ns:xmpp-sasl">>,
 +       _} ->
 +        decode_sasl_failure_text(<<"urn:ietf:params:xml:ns:xmpp-sasl">>,
 +                                 IgnoreEls, _el);
 +      {<<"text">>, <<>>,
 +       <<"urn:ietf:params:xml:ns:xmpp-sasl">>} ->
 +        decode_sasl_failure_text(<<"urn:ietf:params:xml:ns:xmpp-sasl">>,
 +                                 IgnoreEls, _el);
 +      {<<"success">>, <<"urn:ietf:params:xml:ns:xmpp-sasl">>,
 +       _} ->
 +        decode_sasl_success(<<"urn:ietf:params:xml:ns:xmpp-sasl">>,
 +                            IgnoreEls, _el);
 +      {<<"success">>, <<>>,
 +       <<"urn:ietf:params:xml:ns:xmpp-sasl">>} ->
 +        decode_sasl_success(<<"urn:ietf:params:xml:ns:xmpp-sasl">>,
 +                            IgnoreEls, _el);
 +      {<<"response">>, <<"urn:ietf:params:xml:ns:xmpp-sasl">>,
 +       _} ->
 +        decode_sasl_response(<<"urn:ietf:params:xml:ns:xmpp-sasl">>,
 +                             IgnoreEls, _el);
 +      {<<"response">>, <<>>,
 +       <<"urn:ietf:params:xml:ns:xmpp-sasl">>} ->
 +        decode_sasl_response(<<"urn:ietf:params:xml:ns:xmpp-sasl">>,
 +                             IgnoreEls, _el);
 +      {<<"challenge">>,
 +       <<"urn:ietf:params:xml:ns:xmpp-sasl">>, _} ->
 +        decode_sasl_challenge(<<"urn:ietf:params:xml:ns:xmpp-sasl">>,
 +                              IgnoreEls, _el);
 +      {<<"challenge">>, <<>>,
 +       <<"urn:ietf:params:xml:ns:xmpp-sasl">>} ->
 +        decode_sasl_challenge(<<"urn:ietf:params:xml:ns:xmpp-sasl">>,
 +                              IgnoreEls, _el);
 +      {<<"abort">>, <<"urn:ietf:params:xml:ns:xmpp-sasl">>,
 +       _} ->
 +        decode_sasl_abort(<<"urn:ietf:params:xml:ns:xmpp-sasl">>,
 +                          IgnoreEls, _el);
 +      {<<"abort">>, <<>>,
 +       <<"urn:ietf:params:xml:ns:xmpp-sasl">>} ->
 +        decode_sasl_abort(<<"urn:ietf:params:xml:ns:xmpp-sasl">>,
 +                          IgnoreEls, _el);
 +      {<<"auth">>, <<"urn:ietf:params:xml:ns:xmpp-sasl">>,
 +       _} ->
 +        decode_sasl_auth(<<"urn:ietf:params:xml:ns:xmpp-sasl">>,
 +                         IgnoreEls, _el);
 +      {<<"auth">>, <<>>,
 +       <<"urn:ietf:params:xml:ns:xmpp-sasl">>} ->
 +        decode_sasl_auth(<<"urn:ietf:params:xml:ns:xmpp-sasl">>,
 +                         IgnoreEls, _el);
 +      {<<"query">>, <<"jabber:iq:auth">>, _} ->
 +        decode_legacy_auth(<<"jabber:iq:auth">>, IgnoreEls,
 +                           _el);
 +      {<<"query">>, <<>>, <<"jabber:iq:auth">>} ->
 +        decode_legacy_auth(<<"jabber:iq:auth">>, IgnoreEls,
 +                           _el);
 +      {<<"resource">>, <<"jabber:iq:auth">>, _} ->
 +        decode_legacy_auth_resource(<<"jabber:iq:auth">>,
 +                                    IgnoreEls, _el);
 +      {<<"resource">>, <<>>, <<"jabber:iq:auth">>} ->
 +        decode_legacy_auth_resource(<<"jabber:iq:auth">>,
 +                                    IgnoreEls, _el);
 +      {<<"digest">>, <<"jabber:iq:auth">>, _} ->
 +        decode_legacy_auth_digest(<<"jabber:iq:auth">>,
 +                                  IgnoreEls, _el);
 +      {<<"digest">>, <<>>, <<"jabber:iq:auth">>} ->
 +        decode_legacy_auth_digest(<<"jabber:iq:auth">>,
 +                                  IgnoreEls, _el);
 +      {<<"password">>, <<"jabber:iq:auth">>, _} ->
 +        decode_legacy_auth_password(<<"jabber:iq:auth">>,
 +                                    IgnoreEls, _el);
 +      {<<"password">>, <<>>, <<"jabber:iq:auth">>} ->
 +        decode_legacy_auth_password(<<"jabber:iq:auth">>,
 +                                    IgnoreEls, _el);
 +      {<<"username">>, <<"jabber:iq:auth">>, _} ->
 +        decode_legacy_auth_username(<<"jabber:iq:auth">>,
 +                                    IgnoreEls, _el);
 +      {<<"username">>, <<>>, <<"jabber:iq:auth">>} ->
 +        decode_legacy_auth_username(<<"jabber:iq:auth">>,
 +                                    IgnoreEls, _el);
 +      {<<"bind">>, <<"urn:ietf:params:xml:ns:xmpp-bind">>,
 +       _} ->
 +        decode_bind(<<"urn:ietf:params:xml:ns:xmpp-bind">>,
 +                    IgnoreEls, _el);
 +      {<<"bind">>, <<>>,
 +       <<"urn:ietf:params:xml:ns:xmpp-bind">>} ->
 +        decode_bind(<<"urn:ietf:params:xml:ns:xmpp-bind">>,
 +                    IgnoreEls, _el);
 +      {<<"resource">>, <<"urn:ietf:params:xml:ns:xmpp-bind">>,
 +       _} ->
 +        decode_bind_resource(<<"urn:ietf:params:xml:ns:xmpp-bind">>,
 +                             IgnoreEls, _el);
 +      {<<"resource">>, <<>>,
 +       <<"urn:ietf:params:xml:ns:xmpp-bind">>} ->
 +        decode_bind_resource(<<"urn:ietf:params:xml:ns:xmpp-bind">>,
 +                             IgnoreEls, _el);
 +      {<<"jid">>, <<"urn:ietf:params:xml:ns:xmpp-bind">>,
 +       _} ->
 +        decode_bind_jid(<<"urn:ietf:params:xml:ns:xmpp-bind">>,
 +                        IgnoreEls, _el);
 +      {<<"jid">>, <<>>,
 +       <<"urn:ietf:params:xml:ns:xmpp-bind">>} ->
 +        decode_bind_jid(<<"urn:ietf:params:xml:ns:xmpp-bind">>,
 +                        IgnoreEls, _el);
 +      {<<"error">>, <<"jabber:client">>, _} ->
 +        decode_error(<<"jabber:client">>, IgnoreEls, _el);
 +      {<<"error">>, <<>>, <<"jabber:client">>} ->
 +        decode_error(<<"jabber:client">>, IgnoreEls, _el);
 +      {<<"error">>, <<"jabber:server">>, _} ->
 +        decode_error(<<"jabber:server">>, IgnoreEls, _el);
 +      {<<"error">>, <<>>, <<"jabber:server">>} ->
 +        decode_error(<<"jabber:server">>, IgnoreEls, _el);
 +      {<<"error">>, <<"jabber:component:accept">>, _} ->
 +        decode_error(<<"jabber:component:accept">>, IgnoreEls,
 +                     _el);
 +      {<<"error">>, <<>>, <<"jabber:component:accept">>} ->
 +        decode_error(<<"jabber:component:accept">>, IgnoreEls,
 +                     _el);
 +      {<<"text">>, <<"urn:ietf:params:xml:ns:xmpp-stanzas">>,
 +       _} ->
 +        decode_error_text(<<"urn:ietf:params:xml:ns:xmpp-stanzas">>,
 +                          IgnoreEls, _el);
 +      {<<"text">>, <<>>,
 +       <<"urn:ietf:params:xml:ns:xmpp-stanzas">>} ->
 +        decode_error_text(<<"urn:ietf:params:xml:ns:xmpp-stanzas">>,
 +                          IgnoreEls, _el);
 +      {<<"unexpected-request">>,
 +       <<"urn:ietf:params:xml:ns:xmpp-stanzas">>, _} ->
 +        decode_error_unexpected_request(<<"urn:ietf:params:xml:ns:xmpp-stanzas">>,
 +                                        IgnoreEls, _el);
 +      {<<"unexpected-request">>, <<>>,
 +       <<"urn:ietf:params:xml:ns:xmpp-stanzas">>} ->
 +        decode_error_unexpected_request(<<"urn:ietf:params:xml:ns:xmpp-stanzas">>,
 +                                        IgnoreEls, _el);
 +      {<<"undefined-condition">>,
 +       <<"urn:ietf:params:xml:ns:xmpp-stanzas">>, _} ->
 +        decode_error_undefined_condition(<<"urn:ietf:params:xml:ns:xmpp-stanzas">>,
 +                                         IgnoreEls, _el);
 +      {<<"undefined-condition">>, <<>>,
 +       <<"urn:ietf:params:xml:ns:xmpp-stanzas">>} ->
 +        decode_error_undefined_condition(<<"urn:ietf:params:xml:ns:xmpp-stanzas">>,
 +                                         IgnoreEls, _el);
 +      {<<"subscription-required">>,
 +       <<"urn:ietf:params:xml:ns:xmpp-stanzas">>, _} ->
 +        decode_error_subscription_required(<<"urn:ietf:params:xml:ns:xmpp-stanzas">>,
 +                                           IgnoreEls, _el);
 +      {<<"subscription-required">>, <<>>,
 +       <<"urn:ietf:params:xml:ns:xmpp-stanzas">>} ->
 +        decode_error_subscription_required(<<"urn:ietf:params:xml:ns:xmpp-stanzas">>,
 +                                           IgnoreEls, _el);
 +      {<<"service-unavailable">>,
 +       <<"urn:ietf:params:xml:ns:xmpp-stanzas">>, _} ->
 +        decode_error_service_unavailable(<<"urn:ietf:params:xml:ns:xmpp-stanzas">>,
 +                                         IgnoreEls, _el);
 +      {<<"service-unavailable">>, <<>>,
 +       <<"urn:ietf:params:xml:ns:xmpp-stanzas">>} ->
 +        decode_error_service_unavailable(<<"urn:ietf:params:xml:ns:xmpp-stanzas">>,
 +                                         IgnoreEls, _el);
 +      {<<"resource-constraint">>,
 +       <<"urn:ietf:params:xml:ns:xmpp-stanzas">>, _} ->
 +        decode_error_resource_constraint(<<"urn:ietf:params:xml:ns:xmpp-stanzas">>,
 +                                         IgnoreEls, _el);
 +      {<<"resource-constraint">>, <<>>,
 +       <<"urn:ietf:params:xml:ns:xmpp-stanzas">>} ->
 +        decode_error_resource_constraint(<<"urn:ietf:params:xml:ns:xmpp-stanzas">>,
 +                                         IgnoreEls, _el);
 +      {<<"remote-server-timeout">>,
 +       <<"urn:ietf:params:xml:ns:xmpp-stanzas">>, _} ->
 +        decode_error_remote_server_timeout(<<"urn:ietf:params:xml:ns:xmpp-stanzas">>,
 +                                           IgnoreEls, _el);
 +      {<<"remote-server-timeout">>, <<>>,
 +       <<"urn:ietf:params:xml:ns:xmpp-stanzas">>} ->
 +        decode_error_remote_server_timeout(<<"urn:ietf:params:xml:ns:xmpp-stanzas">>,
 +                                           IgnoreEls, _el);
 +      {<<"remote-server-not-found">>,
 +       <<"urn:ietf:params:xml:ns:xmpp-stanzas">>, _} ->
 +        decode_error_remote_server_not_found(<<"urn:ietf:params:xml:ns:xmpp-stanzas">>,
 +                                             IgnoreEls, _el);
 +      {<<"remote-server-not-found">>, <<>>,
 +       <<"urn:ietf:params:xml:ns:xmpp-stanzas">>} ->
 +        decode_error_remote_server_not_found(<<"urn:ietf:params:xml:ns:xmpp-stanzas">>,
 +                                             IgnoreEls, _el);
 +      {<<"registration-required">>,
 +       <<"urn:ietf:params:xml:ns:xmpp-stanzas">>, _} ->
 +        decode_error_registration_required(<<"urn:ietf:params:xml:ns:xmpp-stanzas">>,
 +                                           IgnoreEls, _el);
 +      {<<"registration-required">>, <<>>,
 +       <<"urn:ietf:params:xml:ns:xmpp-stanzas">>} ->
 +        decode_error_registration_required(<<"urn:ietf:params:xml:ns:xmpp-stanzas">>,
 +                                           IgnoreEls, _el);
 +      {<<"redirect">>,
 +       <<"urn:ietf:params:xml:ns:xmpp-stanzas">>, _} ->
 +        decode_error_redirect(<<"urn:ietf:params:xml:ns:xmpp-stanzas">>,
 +                              IgnoreEls, _el);
 +      {<<"redirect">>, <<>>,
 +       <<"urn:ietf:params:xml:ns:xmpp-stanzas">>} ->
 +        decode_error_redirect(<<"urn:ietf:params:xml:ns:xmpp-stanzas">>,
 +                              IgnoreEls, _el);
 +      {<<"recipient-unavailable">>,
 +       <<"urn:ietf:params:xml:ns:xmpp-stanzas">>, _} ->
 +        decode_error_recipient_unavailable(<<"urn:ietf:params:xml:ns:xmpp-stanzas">>,
 +                                           IgnoreEls, _el);
 +      {<<"recipient-unavailable">>, <<>>,
 +       <<"urn:ietf:params:xml:ns:xmpp-stanzas">>} ->
 +        decode_error_recipient_unavailable(<<"urn:ietf:params:xml:ns:xmpp-stanzas">>,
 +                                           IgnoreEls, _el);
 +      {<<"policy-violation">>,
 +       <<"urn:ietf:params:xml:ns:xmpp-stanzas">>, _} ->
 +        decode_error_policy_violation(<<"urn:ietf:params:xml:ns:xmpp-stanzas">>,
 +                                      IgnoreEls, _el);
 +      {<<"policy-violation">>, <<>>,
 +       <<"urn:ietf:params:xml:ns:xmpp-stanzas">>} ->
 +        decode_error_policy_violation(<<"urn:ietf:params:xml:ns:xmpp-stanzas">>,
 +                                      IgnoreEls, _el);
 +      {<<"payment-required">>,
 +       <<"urn:ietf:params:xml:ns:xmpp-stanzas">>, _} ->
 +        decode_error_payment_required(<<"urn:ietf:params:xml:ns:xmpp-stanzas">>,
 +                                      IgnoreEls, _el);
 +      {<<"payment-required">>, <<>>,
 +       <<"urn:ietf:params:xml:ns:xmpp-stanzas">>} ->
 +        decode_error_payment_required(<<"urn:ietf:params:xml:ns:xmpp-stanzas">>,
 +                                      IgnoreEls, _el);
 +      {<<"not-authorized">>,
 +       <<"urn:ietf:params:xml:ns:xmpp-stanzas">>, _} ->
 +        decode_error_not_authorized(<<"urn:ietf:params:xml:ns:xmpp-stanzas">>,
 +                                    IgnoreEls, _el);
 +      {<<"not-authorized">>, <<>>,
 +       <<"urn:ietf:params:xml:ns:xmpp-stanzas">>} ->
 +        decode_error_not_authorized(<<"urn:ietf:params:xml:ns:xmpp-stanzas">>,
 +                                    IgnoreEls, _el);
 +      {<<"not-allowed">>,
 +       <<"urn:ietf:params:xml:ns:xmpp-stanzas">>, _} ->
 +        decode_error_not_allowed(<<"urn:ietf:params:xml:ns:xmpp-stanzas">>,
 +                                 IgnoreEls, _el);
 +      {<<"not-allowed">>, <<>>,
 +       <<"urn:ietf:params:xml:ns:xmpp-stanzas">>} ->
 +        decode_error_not_allowed(<<"urn:ietf:params:xml:ns:xmpp-stanzas">>,
 +                                 IgnoreEls, _el);
 +      {<<"not-acceptable">>,
 +       <<"urn:ietf:params:xml:ns:xmpp-stanzas">>, _} ->
 +        decode_error_not_acceptable(<<"urn:ietf:params:xml:ns:xmpp-stanzas">>,
 +                                    IgnoreEls, _el);
 +      {<<"not-acceptable">>, <<>>,
 +       <<"urn:ietf:params:xml:ns:xmpp-stanzas">>} ->
 +        decode_error_not_acceptable(<<"urn:ietf:params:xml:ns:xmpp-stanzas">>,
 +                                    IgnoreEls, _el);
 +      {<<"jid-malformed">>,
 +       <<"urn:ietf:params:xml:ns:xmpp-stanzas">>, _} ->
 +        decode_error_jid_malformed(<<"urn:ietf:params:xml:ns:xmpp-stanzas">>,
 +                                   IgnoreEls, _el);
 +      {<<"jid-malformed">>, <<>>,
 +       <<"urn:ietf:params:xml:ns:xmpp-stanzas">>} ->
 +        decode_error_jid_malformed(<<"urn:ietf:params:xml:ns:xmpp-stanzas">>,
 +                                   IgnoreEls, _el);
 +      {<<"item-not-found">>,
 +       <<"urn:ietf:params:xml:ns:xmpp-stanzas">>, _} ->
 +        decode_error_item_not_found(<<"urn:ietf:params:xml:ns:xmpp-stanzas">>,
 +                                    IgnoreEls, _el);
 +      {<<"item-not-found">>, <<>>,
 +       <<"urn:ietf:params:xml:ns:xmpp-stanzas">>} ->
 +        decode_error_item_not_found(<<"urn:ietf:params:xml:ns:xmpp-stanzas">>,
 +                                    IgnoreEls, _el);
 +      {<<"internal-server-error">>,
 +       <<"urn:ietf:params:xml:ns:xmpp-stanzas">>, _} ->
 +        decode_error_internal_server_error(<<"urn:ietf:params:xml:ns:xmpp-stanzas">>,
 +                                           IgnoreEls, _el);
 +      {<<"internal-server-error">>, <<>>,
 +       <<"urn:ietf:params:xml:ns:xmpp-stanzas">>} ->
 +        decode_error_internal_server_error(<<"urn:ietf:params:xml:ns:xmpp-stanzas">>,
 +                                           IgnoreEls, _el);
 +      {<<"gone">>, <<"urn:ietf:params:xml:ns:xmpp-stanzas">>,
 +       _} ->
 +        decode_error_gone(<<"urn:ietf:params:xml:ns:xmpp-stanzas">>,
 +                          IgnoreEls, _el);
 +      {<<"gone">>, <<>>,
 +       <<"urn:ietf:params:xml:ns:xmpp-stanzas">>} ->
 +        decode_error_gone(<<"urn:ietf:params:xml:ns:xmpp-stanzas">>,
 +                          IgnoreEls, _el);
 +      {<<"forbidden">>,
 +       <<"urn:ietf:params:xml:ns:xmpp-stanzas">>, _} ->
 +        decode_error_forbidden(<<"urn:ietf:params:xml:ns:xmpp-stanzas">>,
 +                               IgnoreEls, _el);
 +      {<<"forbidden">>, <<>>,
 +       <<"urn:ietf:params:xml:ns:xmpp-stanzas">>} ->
 +        decode_error_forbidden(<<"urn:ietf:params:xml:ns:xmpp-stanzas">>,
 +                               IgnoreEls, _el);
 +      {<<"feature-not-implemented">>,
 +       <<"urn:ietf:params:xml:ns:xmpp-stanzas">>, _} ->
 +        decode_error_feature_not_implemented(<<"urn:ietf:params:xml:ns:xmpp-stanzas">>,
 +                                             IgnoreEls, _el);
 +      {<<"feature-not-implemented">>, <<>>,
 +       <<"urn:ietf:params:xml:ns:xmpp-stanzas">>} ->
 +        decode_error_feature_not_implemented(<<"urn:ietf:params:xml:ns:xmpp-stanzas">>,
 +                                             IgnoreEls, _el);
 +      {<<"conflict">>,
 +       <<"urn:ietf:params:xml:ns:xmpp-stanzas">>, _} ->
 +        decode_error_conflict(<<"urn:ietf:params:xml:ns:xmpp-stanzas">>,
 +                              IgnoreEls, _el);
 +      {<<"conflict">>, <<>>,
 +       <<"urn:ietf:params:xml:ns:xmpp-stanzas">>} ->
 +        decode_error_conflict(<<"urn:ietf:params:xml:ns:xmpp-stanzas">>,
 +                              IgnoreEls, _el);
 +      {<<"bad-request">>,
 +       <<"urn:ietf:params:xml:ns:xmpp-stanzas">>, _} ->
 +        decode_error_bad_request(<<"urn:ietf:params:xml:ns:xmpp-stanzas">>,
 +                                 IgnoreEls, _el);
 +      {<<"bad-request">>, <<>>,
 +       <<"urn:ietf:params:xml:ns:xmpp-stanzas">>} ->
 +        decode_error_bad_request(<<"urn:ietf:params:xml:ns:xmpp-stanzas">>,
 +                                 IgnoreEls, _el);
 +      {<<"presence">>, <<"jabber:client">>, _} ->
 +        decode_presence(<<"jabber:client">>, IgnoreEls, _el);
 +      {<<"presence">>, <<>>, <<"jabber:client">>} ->
 +        decode_presence(<<"jabber:client">>, IgnoreEls, _el);
 +      {<<"presence">>, <<"jabber:server">>, _} ->
 +        decode_presence(<<"jabber:server">>, IgnoreEls, _el);
 +      {<<"presence">>, <<>>, <<"jabber:server">>} ->
 +        decode_presence(<<"jabber:server">>, IgnoreEls, _el);
 +      {<<"presence">>, <<"jabber:component:accept">>, _} ->
 +        decode_presence(<<"jabber:component:accept">>,
 +                        IgnoreEls, _el);
 +      {<<"presence">>, <<>>, <<"jabber:component:accept">>} ->
 +        decode_presence(<<"jabber:component:accept">>,
 +                        IgnoreEls, _el);
 +      {<<"priority">>, <<"jabber:client">>, _} ->
 +        decode_presence_priority(<<"jabber:client">>, IgnoreEls,
 +                                 _el);
 +      {<<"priority">>, <<>>, <<"jabber:client">>} ->
 +        decode_presence_priority(<<"jabber:client">>, IgnoreEls,
 +                                 _el);
 +      {<<"priority">>, <<"jabber:server">>, _} ->
 +        decode_presence_priority(<<"jabber:server">>, IgnoreEls,
 +                                 _el);
 +      {<<"priority">>, <<>>, <<"jabber:server">>} ->
 +        decode_presence_priority(<<"jabber:server">>, IgnoreEls,
 +                                 _el);
 +      {<<"priority">>, <<"jabber:component:accept">>, _} ->
 +        decode_presence_priority(<<"jabber:component:accept">>,
 +                                 IgnoreEls, _el);
 +      {<<"priority">>, <<>>, <<"jabber:component:accept">>} ->
 +        decode_presence_priority(<<"jabber:component:accept">>,
 +                                 IgnoreEls, _el);
 +      {<<"status">>, <<"jabber:client">>, _} ->
 +        decode_presence_status(<<"jabber:client">>, IgnoreEls,
 +                               _el);
 +      {<<"status">>, <<>>, <<"jabber:client">>} ->
 +        decode_presence_status(<<"jabber:client">>, IgnoreEls,
 +                               _el);
 +      {<<"status">>, <<"jabber:server">>, _} ->
 +        decode_presence_status(<<"jabber:server">>, IgnoreEls,
 +                               _el);
 +      {<<"status">>, <<>>, <<"jabber:server">>} ->
 +        decode_presence_status(<<"jabber:server">>, IgnoreEls,
 +                               _el);
 +      {<<"status">>, <<"jabber:component:accept">>, _} ->
 +        decode_presence_status(<<"jabber:component:accept">>,
 +                               IgnoreEls, _el);
 +      {<<"status">>, <<>>, <<"jabber:component:accept">>} ->
 +        decode_presence_status(<<"jabber:component:accept">>,
 +                               IgnoreEls, _el);
 +      {<<"show">>, <<"jabber:client">>, _} ->
 +        decode_presence_show(<<"jabber:client">>, IgnoreEls,
 +                             _el);
 +      {<<"show">>, <<>>, <<"jabber:client">>} ->
 +        decode_presence_show(<<"jabber:client">>, IgnoreEls,
 +                             _el);
 +      {<<"show">>, <<"jabber:server">>, _} ->
 +        decode_presence_show(<<"jabber:server">>, IgnoreEls,
 +                             _el);
 +      {<<"show">>, <<>>, <<"jabber:server">>} ->
 +        decode_presence_show(<<"jabber:server">>, IgnoreEls,
 +                             _el);
 +      {<<"show">>, <<"jabber:component:accept">>, _} ->
 +        decode_presence_show(<<"jabber:component:accept">>,
 +                             IgnoreEls, _el);
 +      {<<"show">>, <<>>, <<"jabber:component:accept">>} ->
 +        decode_presence_show(<<"jabber:component:accept">>,
 +                             IgnoreEls, _el);
 +      {<<"message">>, <<"jabber:client">>, _} ->
 +        decode_message(<<"jabber:client">>, IgnoreEls, _el);
 +      {<<"message">>, <<>>, <<"jabber:client">>} ->
 +        decode_message(<<"jabber:client">>, IgnoreEls, _el);
 +      {<<"message">>, <<"jabber:server">>, _} ->
 +        decode_message(<<"jabber:server">>, IgnoreEls, _el);
 +      {<<"message">>, <<>>, <<"jabber:server">>} ->
 +        decode_message(<<"jabber:server">>, IgnoreEls, _el);
 +      {<<"message">>, <<"jabber:component:accept">>, _} ->
 +        decode_message(<<"jabber:component:accept">>, IgnoreEls,
 +                       _el);
 +      {<<"message">>, <<>>, <<"jabber:component:accept">>} ->
 +        decode_message(<<"jabber:component:accept">>, IgnoreEls,
 +                       _el);
 +      {<<"thread">>, <<"jabber:client">>, _} ->
 +        decode_message_thread(<<"jabber:client">>, IgnoreEls,
 +                              _el);
 +      {<<"thread">>, <<>>, <<"jabber:client">>} ->
 +        decode_message_thread(<<"jabber:client">>, IgnoreEls,
 +                              _el);
 +      {<<"thread">>, <<"jabber:server">>, _} ->
 +        decode_message_thread(<<"jabber:server">>, IgnoreEls,
 +                              _el);
 +      {<<"thread">>, <<>>, <<"jabber:server">>} ->
 +        decode_message_thread(<<"jabber:server">>, IgnoreEls,
 +                              _el);
 +      {<<"thread">>, <<"jabber:component:accept">>, _} ->
 +        decode_message_thread(<<"jabber:component:accept">>,
 +                              IgnoreEls, _el);
 +      {<<"thread">>, <<>>, <<"jabber:component:accept">>} ->
 +        decode_message_thread(<<"jabber:component:accept">>,
 +                              IgnoreEls, _el);
 +      {<<"body">>, <<"jabber:client">>, _} ->
 +        decode_message_body(<<"jabber:client">>, IgnoreEls,
 +                            _el);
 +      {<<"body">>, <<>>, <<"jabber:client">>} ->
 +        decode_message_body(<<"jabber:client">>, IgnoreEls,
 +                            _el);
 +      {<<"body">>, <<"jabber:server">>, _} ->
 +        decode_message_body(<<"jabber:server">>, IgnoreEls,
 +                            _el);
 +      {<<"body">>, <<>>, <<"jabber:server">>} ->
 +        decode_message_body(<<"jabber:server">>, IgnoreEls,
 +                            _el);
 +      {<<"body">>, <<"jabber:component:accept">>, _} ->
 +        decode_message_body(<<"jabber:component:accept">>,
 +                            IgnoreEls, _el);
 +      {<<"body">>, <<>>, <<"jabber:component:accept">>} ->
 +        decode_message_body(<<"jabber:component:accept">>,
 +                            IgnoreEls, _el);
 +      {<<"subject">>, <<"jabber:client">>, _} ->
 +        decode_message_subject(<<"jabber:client">>, IgnoreEls,
 +                               _el);
 +      {<<"subject">>, <<>>, <<"jabber:client">>} ->
 +        decode_message_subject(<<"jabber:client">>, IgnoreEls,
 +                               _el);
 +      {<<"subject">>, <<"jabber:server">>, _} ->
 +        decode_message_subject(<<"jabber:server">>, IgnoreEls,
 +                               _el);
 +      {<<"subject">>, <<>>, <<"jabber:server">>} ->
 +        decode_message_subject(<<"jabber:server">>, IgnoreEls,
 +                               _el);
 +      {<<"subject">>, <<"jabber:component:accept">>, _} ->
 +        decode_message_subject(<<"jabber:component:accept">>,
 +                               IgnoreEls, _el);
 +      {<<"subject">>, <<>>, <<"jabber:component:accept">>} ->
 +        decode_message_subject(<<"jabber:component:accept">>,
 +                               IgnoreEls, _el);
 +      {<<"iq">>, <<"jabber:client">>, _} ->
 +        decode_iq(<<"jabber:client">>, IgnoreEls, _el);
 +      {<<"iq">>, <<>>, <<"jabber:client">>} ->
 +        decode_iq(<<"jabber:client">>, IgnoreEls, _el);
 +      {<<"iq">>, <<"jabber:server">>, _} ->
 +        decode_iq(<<"jabber:server">>, IgnoreEls, _el);
 +      {<<"iq">>, <<>>, <<"jabber:server">>} ->
 +        decode_iq(<<"jabber:server">>, IgnoreEls, _el);
 +      {<<"iq">>, <<"jabber:component:accept">>, _} ->
 +        decode_iq(<<"jabber:component:accept">>, IgnoreEls,
 +                  _el);
 +      {<<"iq">>, <<>>, <<"jabber:component:accept">>} ->
 +        decode_iq(<<"jabber:component:accept">>, IgnoreEls,
 +                  _el);
 +      {<<"query">>, <<"http://jabber.org/protocol/stats">>,
 +       _} ->
 +        decode_stats(<<"http://jabber.org/protocol/stats">>,
 +                     IgnoreEls, _el);
 +      {<<"query">>, <<>>,
 +       <<"http://jabber.org/protocol/stats">>} ->
 +        decode_stats(<<"http://jabber.org/protocol/stats">>,
 +                     IgnoreEls, _el);
 +      {<<"stat">>, <<"http://jabber.org/protocol/stats">>,
 +       _} ->
 +        decode_stat(<<"http://jabber.org/protocol/stats">>,
 +                    IgnoreEls, _el);
 +      {<<"stat">>, <<>>,
 +       <<"http://jabber.org/protocol/stats">>} ->
 +        decode_stat(<<"http://jabber.org/protocol/stats">>,
 +                    IgnoreEls, _el);
 +      {<<"error">>, <<"http://jabber.org/protocol/stats">>,
 +       _} ->
 +        decode_stat_error(<<"http://jabber.org/protocol/stats">>,
 +                          IgnoreEls, _el);
 +      {<<"error">>, <<>>,
 +       <<"http://jabber.org/protocol/stats">>} ->
 +        decode_stat_error(<<"http://jabber.org/protocol/stats">>,
 +                          IgnoreEls, _el);
 +      {<<"storage">>, <<"storage:bookmarks">>, _} ->
 +        decode_bookmarks_storage(<<"storage:bookmarks">>,
 +                                 IgnoreEls, _el);
 +      {<<"storage">>, <<>>, <<"storage:bookmarks">>} ->
 +        decode_bookmarks_storage(<<"storage:bookmarks">>,
 +                                 IgnoreEls, _el);
 +      {<<"url">>, <<"storage:bookmarks">>, _} ->
 +        decode_bookmark_url(<<"storage:bookmarks">>, IgnoreEls,
 +                            _el);
 +      {<<"url">>, <<>>, <<"storage:bookmarks">>} ->
 +        decode_bookmark_url(<<"storage:bookmarks">>, IgnoreEls,
 +                            _el);
 +      {<<"conference">>, <<"storage:bookmarks">>, _} ->
 +        decode_bookmark_conference(<<"storage:bookmarks">>,
 +                                   IgnoreEls, _el);
 +      {<<"conference">>, <<>>, <<"storage:bookmarks">>} ->
 +        decode_bookmark_conference(<<"storage:bookmarks">>,
 +                                   IgnoreEls, _el);
 +      {<<"password">>, <<"storage:bookmarks">>, _} ->
 +        decode_conference_password(<<"storage:bookmarks">>,
 +                                   IgnoreEls, _el);
 +      {<<"password">>, <<>>, <<"storage:bookmarks">>} ->
 +        decode_conference_password(<<"storage:bookmarks">>,
 +                                   IgnoreEls, _el);
 +      {<<"nick">>, <<"storage:bookmarks">>, _} ->
 +        decode_conference_nick(<<"storage:bookmarks">>,
 +                               IgnoreEls, _el);
 +      {<<"nick">>, <<>>, <<"storage:bookmarks">>} ->
 +        decode_conference_nick(<<"storage:bookmarks">>,
 +                               IgnoreEls, _el);
 +      {<<"query">>, <<"jabber:iq:private">>, _} ->
 +        decode_private(<<"jabber:iq:private">>, IgnoreEls, _el);
 +      {<<"query">>, <<>>, <<"jabber:iq:private">>} ->
 +        decode_private(<<"jabber:iq:private">>, IgnoreEls, _el);
 +      {<<"query">>,
 +       <<"http://jabber.org/protocol/disco#items">>, _} ->
 +        decode_disco_items(<<"http://jabber.org/protocol/disco#items">>,
 +                           IgnoreEls, _el);
 +      {<<"query">>, <<>>,
 +       <<"http://jabber.org/protocol/disco#items">>} ->
 +        decode_disco_items(<<"http://jabber.org/protocol/disco#items">>,
 +                           IgnoreEls, _el);
 +      {<<"item">>,
 +       <<"http://jabber.org/protocol/disco#items">>, _} ->
 +        decode_disco_item(<<"http://jabber.org/protocol/disco#items">>,
 +                          IgnoreEls, _el);
 +      {<<"item">>, <<>>,
 +       <<"http://jabber.org/protocol/disco#items">>} ->
 +        decode_disco_item(<<"http://jabber.org/protocol/disco#items">>,
 +                          IgnoreEls, _el);
 +      {<<"query">>,
 +       <<"http://jabber.org/protocol/disco#info">>, _} ->
 +        decode_disco_info(<<"http://jabber.org/protocol/disco#info">>,
 +                          IgnoreEls, _el);
 +      {<<"query">>, <<>>,
 +       <<"http://jabber.org/protocol/disco#info">>} ->
 +        decode_disco_info(<<"http://jabber.org/protocol/disco#info">>,
 +                          IgnoreEls, _el);
 +      {<<"feature">>,
 +       <<"http://jabber.org/protocol/disco#info">>, _} ->
 +        decode_disco_feature(<<"http://jabber.org/protocol/disco#info">>,
 +                             IgnoreEls, _el);
 +      {<<"feature">>, <<>>,
 +       <<"http://jabber.org/protocol/disco#info">>} ->
 +        decode_disco_feature(<<"http://jabber.org/protocol/disco#info">>,
 +                             IgnoreEls, _el);
 +      {<<"identity">>,
 +       <<"http://jabber.org/protocol/disco#info">>, _} ->
 +        decode_disco_identity(<<"http://jabber.org/protocol/disco#info">>,
 +                              IgnoreEls, _el);
 +      {<<"identity">>, <<>>,
 +       <<"http://jabber.org/protocol/disco#info">>} ->
 +        decode_disco_identity(<<"http://jabber.org/protocol/disco#info">>,
 +                              IgnoreEls, _el);
 +      {<<"blocklist">>, <<"urn:xmpp:blocking">>, _} ->
 +        decode_block_list(<<"urn:xmpp:blocking">>, IgnoreEls,
 +                          _el);
 +      {<<"blocklist">>, <<>>, <<"urn:xmpp:blocking">>} ->
 +        decode_block_list(<<"urn:xmpp:blocking">>, IgnoreEls,
 +                          _el);
 +      {<<"unblock">>, <<"urn:xmpp:blocking">>, _} ->
 +        decode_unblock(<<"urn:xmpp:blocking">>, IgnoreEls, _el);
 +      {<<"unblock">>, <<>>, <<"urn:xmpp:blocking">>} ->
 +        decode_unblock(<<"urn:xmpp:blocking">>, IgnoreEls, _el);
 +      {<<"block">>, <<"urn:xmpp:blocking">>, _} ->
 +        decode_block(<<"urn:xmpp:blocking">>, IgnoreEls, _el);
 +      {<<"block">>, <<>>, <<"urn:xmpp:blocking">>} ->
 +        decode_block(<<"urn:xmpp:blocking">>, IgnoreEls, _el);
 +      {<<"item">>, <<"urn:xmpp:blocking">>, _} ->
 +        decode_block_item(<<"urn:xmpp:blocking">>, IgnoreEls,
 +                          _el);
 +      {<<"item">>, <<>>, <<"urn:xmpp:blocking">>} ->
 +        decode_block_item(<<"urn:xmpp:blocking">>, IgnoreEls,
 +                          _el);
 +      {<<"query">>, <<"jabber:iq:privacy">>, _} ->
 +        decode_privacy(<<"jabber:iq:privacy">>, IgnoreEls, _el);
 +      {<<"query">>, <<>>, <<"jabber:iq:privacy">>} ->
 +        decode_privacy(<<"jabber:iq:privacy">>, IgnoreEls, _el);
 +      {<<"active">>, <<"jabber:iq:privacy">>, _} ->
 +        decode_privacy_active_list(<<"jabber:iq:privacy">>,
 +                                   IgnoreEls, _el);
 +      {<<"active">>, <<>>, <<"jabber:iq:privacy">>} ->
 +        decode_privacy_active_list(<<"jabber:iq:privacy">>,
 +                                   IgnoreEls, _el);
 +      {<<"default">>, <<"jabber:iq:privacy">>, _} ->
 +        decode_privacy_default_list(<<"jabber:iq:privacy">>,
 +                                    IgnoreEls, _el);
 +      {<<"default">>, <<>>, <<"jabber:iq:privacy">>} ->
 +        decode_privacy_default_list(<<"jabber:iq:privacy">>,
 +                                    IgnoreEls, _el);
 +      {<<"list">>, <<"jabber:iq:privacy">>, _} ->
 +        decode_privacy_list(<<"jabber:iq:privacy">>, IgnoreEls,
 +                            _el);
 +      {<<"list">>, <<>>, <<"jabber:iq:privacy">>} ->
 +        decode_privacy_list(<<"jabber:iq:privacy">>, IgnoreEls,
 +                            _el);
 +      {<<"item">>, <<"jabber:iq:privacy">>, _} ->
 +        decode_privacy_item(<<"jabber:iq:privacy">>, IgnoreEls,
 +                            _el);
 +      {<<"item">>, <<>>, <<"jabber:iq:privacy">>} ->
 +        decode_privacy_item(<<"jabber:iq:privacy">>, IgnoreEls,
 +                            _el);
 +      {<<"presence-out">>, <<"jabber:iq:privacy">>, _} ->
 +        decode_privacy_presence_out(<<"jabber:iq:privacy">>,
 +                                    IgnoreEls, _el);
 +      {<<"presence-out">>, <<>>, <<"jabber:iq:privacy">>} ->
 +        decode_privacy_presence_out(<<"jabber:iq:privacy">>,
 +                                    IgnoreEls, _el);
 +      {<<"presence-in">>, <<"jabber:iq:privacy">>, _} ->
 +        decode_privacy_presence_in(<<"jabber:iq:privacy">>,
 +                                   IgnoreEls, _el);
 +      {<<"presence-in">>, <<>>, <<"jabber:iq:privacy">>} ->
 +        decode_privacy_presence_in(<<"jabber:iq:privacy">>,
 +                                   IgnoreEls, _el);
 +      {<<"iq">>, <<"jabber:iq:privacy">>, _} ->
 +        decode_privacy_iq(<<"jabber:iq:privacy">>, IgnoreEls,
 +                          _el);
 +      {<<"iq">>, <<>>, <<"jabber:iq:privacy">>} ->
 +        decode_privacy_iq(<<"jabber:iq:privacy">>, IgnoreEls,
 +                          _el);
 +      {<<"message">>, <<"jabber:iq:privacy">>, _} ->
 +        decode_privacy_message(<<"jabber:iq:privacy">>,
 +                               IgnoreEls, _el);
 +      {<<"message">>, <<>>, <<"jabber:iq:privacy">>} ->
 +        decode_privacy_message(<<"jabber:iq:privacy">>,
 +                               IgnoreEls, _el);
 +      {<<"ver">>, <<"urn:xmpp:features:rosterver">>, _} ->
 +        decode_rosterver_feature(<<"urn:xmpp:features:rosterver">>,
 +                                 IgnoreEls, _el);
 +      {<<"ver">>, <<>>, <<"urn:xmpp:features:rosterver">>} ->
 +        decode_rosterver_feature(<<"urn:xmpp:features:rosterver">>,
 +                                 IgnoreEls, _el);
 +      {<<"query">>, <<"jabber:iq:roster">>, _} ->
 +        decode_roster_query(<<"jabber:iq:roster">>, IgnoreEls,
 +                            _el);
 +      {<<"query">>, <<>>, <<"jabber:iq:roster">>} ->
 +        decode_roster_query(<<"jabber:iq:roster">>, IgnoreEls,
 +                            _el);
 +      {<<"item">>, <<"jabber:iq:roster">>, _} ->
 +        decode_roster_item(<<"jabber:iq:roster">>, IgnoreEls,
 +                           _el);
 +      {<<"item">>, <<>>, <<"jabber:iq:roster">>} ->
 +        decode_roster_item(<<"jabber:iq:roster">>, IgnoreEls,
 +                           _el);
 +      {<<"group">>, <<"jabber:iq:roster">>, _} ->
 +        decode_roster_group(<<"jabber:iq:roster">>, IgnoreEls,
 +                            _el);
 +      {<<"group">>, <<>>, <<"jabber:iq:roster">>} ->
 +        decode_roster_group(<<"jabber:iq:roster">>, IgnoreEls,
 +                            _el);
 +      {<<"query">>, <<"jabber:iq:version">>, _} ->
 +        decode_version(<<"jabber:iq:version">>, IgnoreEls, _el);
 +      {<<"query">>, <<>>, <<"jabber:iq:version">>} ->
 +        decode_version(<<"jabber:iq:version">>, IgnoreEls, _el);
 +      {<<"os">>, <<"jabber:iq:version">>, _} ->
 +        decode_version_os(<<"jabber:iq:version">>, IgnoreEls,
 +                          _el);
 +      {<<"os">>, <<>>, <<"jabber:iq:version">>} ->
 +        decode_version_os(<<"jabber:iq:version">>, IgnoreEls,
 +                          _el);
 +      {<<"version">>, <<"jabber:iq:version">>, _} ->
 +        decode_version_ver(<<"jabber:iq:version">>, IgnoreEls,
 +                           _el);
 +      {<<"version">>, <<>>, <<"jabber:iq:version">>} ->
 +        decode_version_ver(<<"jabber:iq:version">>, IgnoreEls,
 +                           _el);
 +      {<<"name">>, <<"jabber:iq:version">>, _} ->
 +        decode_version_name(<<"jabber:iq:version">>, IgnoreEls,
 +                            _el);
 +      {<<"name">>, <<>>, <<"jabber:iq:version">>} ->
 +        decode_version_name(<<"jabber:iq:version">>, IgnoreEls,
 +                            _el);
 +      {<<"query">>, <<"jabber:iq:last">>, _} ->
 +        decode_last(<<"jabber:iq:last">>, IgnoreEls, _el);
 +      {<<"query">>, <<>>, <<"jabber:iq:last">>} ->
 +        decode_last(<<"jabber:iq:last">>, IgnoreEls, _el);
 +      {_name, <<>>, <<>>} ->
 +        erlang:error({xmpp_codec, {missing_tag_xmlns, _name}});
 +      {_name, <<>>, _} ->
 +        erlang:error({xmpp_codec,
 +                      {unknown_tag, _name, TopXMLNS}});
 +      {_name, _xmlns, _} ->
 +        erlang:error({xmpp_codec, {unknown_tag, _name, _xmlns}})
 +    end.
 +
 +is_known_tag({xmlel, _name, _attrs, _} = _el,
 +           TopXMLNS) ->
 +    case {_name, get_attr(<<"xmlns">>, _attrs), TopXMLNS} of
++      {<<"query">>, <<"urn:xmpp:delegation:1">>, _} -> true;
++      {<<"query">>, <<>>, <<"urn:xmpp:delegation:1">>} ->
++        true;
++      {<<"delegate">>, <<"urn:xmpp:delegation:1">>, _} ->
++        true;
++      {<<"delegate">>, <<>>, <<"urn:xmpp:delegation:1">>} ->
++        true;
++      {<<"delegation">>, <<"urn:xmpp:delegation:1">>, _} ->
++        true;
++      {<<"delegation">>, <<>>, <<"urn:xmpp:delegation:1">>} ->
++        true;
++      {<<"delegated">>, <<"urn:xmpp:delegation:1">>, _} ->
++        true;
++      {<<"delegated">>, <<>>, <<"urn:xmpp:delegation:1">>} ->
++        true;
++      {<<"attribute">>, <<"urn:xmpp:delegation:1">>, _} ->
++        true;
++      {<<"attribute">>, <<>>, <<"urn:xmpp:delegation:1">>} ->
++        true;
++      {<<"privilege">>, <<"urn:xmpp:privilege:1">>, _} ->
++        true;
++      {<<"privilege">>, <<>>, <<"urn:xmpp:privilege:1">>} ->
++        true;
++      {<<"perm">>, <<"urn:xmpp:privilege:1">>, _} -> true;
++      {<<"perm">>, <<>>, <<"urn:xmpp:privilege:1">>} -> true;
 +      {<<"thumbnail">>, <<"urn:xmpp:thumbs:1">>, _} -> true;
 +      {<<"thumbnail">>, <<>>, <<"urn:xmpp:thumbs:1">>} ->
 +        true;
 +      {<<"slot">>, <<"urn:xmpp:http:upload">>, _} -> true;
 +      {<<"slot">>, <<>>, <<"urn:xmpp:http:upload">>} -> true;
 +      {<<"slot">>, <<"eu:siacs:conversations:http:upload">>,
 +       _} ->
 +        true;
 +      {<<"slot">>, <<>>,
 +       <<"eu:siacs:conversations:http:upload">>} ->
 +        true;
 +      {<<"put">>, <<"urn:xmpp:http:upload">>, _} -> true;
 +      {<<"put">>, <<>>, <<"urn:xmpp:http:upload">>} -> true;
 +      {<<"put">>, <<"eu:siacs:conversations:http:upload">>,
 +       _} ->
 +        true;
 +      {<<"put">>, <<>>,
 +       <<"eu:siacs:conversations:http:upload">>} ->
 +        true;
 +      {<<"get">>, <<"urn:xmpp:http:upload">>, _} -> true;
 +      {<<"get">>, <<>>, <<"urn:xmpp:http:upload">>} -> true;
 +      {<<"get">>, <<"eu:siacs:conversations:http:upload">>,
 +       _} ->
 +        true;
 +      {<<"get">>, <<>>,
 +       <<"eu:siacs:conversations:http:upload">>} ->
 +        true;
 +      {<<"request">>, <<"urn:xmpp:http:upload">>, _} -> true;
 +      {<<"request">>, <<>>, <<"urn:xmpp:http:upload">>} ->
 +        true;
 +      {<<"request">>,
 +       <<"eu:siacs:conversations:http:upload">>, _} ->
 +        true;
 +      {<<"request">>, <<>>,
 +       <<"eu:siacs:conversations:http:upload">>} ->
 +        true;
 +      {<<"content-type">>, <<"urn:xmpp:http:upload">>, _} ->
 +        true;
 +      {<<"content-type">>, <<>>,
 +       <<"urn:xmpp:http:upload">>} ->
 +        true;
 +      {<<"content-type">>,
 +       <<"eu:siacs:conversations:http:upload">>, _} ->
 +        true;
 +      {<<"content-type">>, <<>>,
 +       <<"eu:siacs:conversations:http:upload">>} ->
 +        true;
 +      {<<"size">>, <<"urn:xmpp:http:upload">>, _} -> true;
 +      {<<"size">>, <<>>, <<"urn:xmpp:http:upload">>} -> true;
 +      {<<"size">>, <<"eu:siacs:conversations:http:upload">>,
 +       _} ->
 +        true;
 +      {<<"size">>, <<>>,
 +       <<"eu:siacs:conversations:http:upload">>} ->
 +        true;
 +      {<<"filename">>, <<"urn:xmpp:http:upload">>, _} -> true;
 +      {<<"filename">>, <<>>, <<"urn:xmpp:http:upload">>} ->
 +        true;
 +      {<<"filename">>,
 +       <<"eu:siacs:conversations:http:upload">>, _} ->
 +        true;
 +      {<<"filename">>, <<>>,
 +       <<"eu:siacs:conversations:http:upload">>} ->
 +        true;
 +      {<<"address">>, <<"urn:xmpp:sic:0">>, _} -> true;
 +      {<<"address">>, <<>>, <<"urn:xmpp:sic:0">>} -> true;
 +      {<<"address">>, <<"urn:xmpp:sic:1">>, _} -> true;
 +      {<<"address">>, <<>>, <<"urn:xmpp:sic:1">>} -> true;
 +      {<<"port">>, <<"urn:xmpp:sic:1">>, _} -> true;
 +      {<<"port">>, <<>>, <<"urn:xmpp:sic:1">>} -> true;
 +      {<<"ip">>, <<"urn:xmpp:sic:0">>, _} -> true;
 +      {<<"ip">>, <<>>, <<"urn:xmpp:sic:0">>} -> true;
 +      {<<"ip">>, <<"urn:xmpp:sic:1">>, _} -> true;
 +      {<<"ip">>, <<>>, <<"urn:xmpp:sic:1">>} -> true;
 +      {<<"x">>, <<"jabber:x:oob">>, _} -> true;
 +      {<<"x">>, <<>>, <<"jabber:x:oob">>} -> true;
 +      {<<"desc">>, <<"jabber:x:oob">>, _} -> true;
 +      {<<"desc">>, <<>>, <<"jabber:x:oob">>} -> true;
 +      {<<"url">>, <<"jabber:x:oob">>, _} -> true;
 +      {<<"url">>, <<>>, <<"jabber:x:oob">>} -> true;
 +      {<<"media">>, <<"urn:xmpp:media-element">>, _} -> true;
 +      {<<"media">>, <<>>, <<"urn:xmpp:media-element">>} ->
 +        true;
 +      {<<"uri">>, <<"urn:xmpp:media-element">>, _} -> true;
 +      {<<"uri">>, <<>>, <<"urn:xmpp:media-element">>} -> true;
 +      {<<"captcha">>, <<"urn:xmpp:captcha">>, _} -> true;
 +      {<<"captcha">>, <<>>, <<"urn:xmpp:captcha">>} -> true;
 +      {<<"data">>, <<"urn:xmpp:bob">>, _} -> true;
 +      {<<"data">>, <<>>, <<"urn:xmpp:bob">>} -> true;
 +      {<<"stream:stream">>, <<"jabber:client">>, _} -> true;
 +      {<<"stream:stream">>, <<>>, <<"jabber:client">>} ->
 +        true;
 +      {<<"stream:stream">>, <<"jabber:server">>, _} -> true;
 +      {<<"stream:stream">>, <<>>, <<"jabber:server">>} ->
 +        true;
 +      {<<"stream:stream">>, <<"jabber:component:accept">>,
 +       _} ->
 +        true;
 +      {<<"stream:stream">>, <<>>,
 +       <<"jabber:component:accept">>} ->
 +        true;
 +      {<<"handshake">>, <<"jabber:component:accept">>, _} ->
 +        true;
 +      {<<"handshake">>, <<>>,
 +       <<"jabber:component:accept">>} ->
 +        true;
 +      {<<"db:verify">>, <<"jabber:server">>, _} -> true;
 +      {<<"db:verify">>, <<>>, <<"jabber:server">>} -> true;
 +      {<<"db:result">>, <<"jabber:server">>, _} -> true;
 +      {<<"db:result">>, <<>>, <<"jabber:server">>} -> true;
 +      {<<"command">>,
 +       <<"http://jabber.org/protocol/commands">>, _} ->
 +        true;
 +      {<<"command">>, <<>>,
 +       <<"http://jabber.org/protocol/commands">>} ->
 +        true;
 +      {<<"note">>, <<"http://jabber.org/protocol/commands">>,
 +       _} ->
 +        true;
 +      {<<"note">>, <<>>,
 +       <<"http://jabber.org/protocol/commands">>} ->
 +        true;
 +      {<<"actions">>,
 +       <<"http://jabber.org/protocol/commands">>, _} ->
 +        true;
 +      {<<"actions">>, <<>>,
 +       <<"http://jabber.org/protocol/commands">>} ->
 +        true;
 +      {<<"complete">>,
 +       <<"http://jabber.org/protocol/commands">>, _} ->
 +        true;
 +      {<<"complete">>, <<>>,
 +       <<"http://jabber.org/protocol/commands">>} ->
 +        true;
 +      {<<"next">>, <<"http://jabber.org/protocol/commands">>,
 +       _} ->
 +        true;
 +      {<<"next">>, <<>>,
 +       <<"http://jabber.org/protocol/commands">>} ->
 +        true;
 +      {<<"prev">>, <<"http://jabber.org/protocol/commands">>,
 +       _} ->
 +        true;
 +      {<<"prev">>, <<>>,
 +       <<"http://jabber.org/protocol/commands">>} ->
 +        true;
 +      {<<"client-id">>, <<"urn:xmpp:sid:0">>, _} -> true;
 +      {<<"client-id">>, <<>>, <<"urn:xmpp:sid:0">>} -> true;
 +      {<<"stanza-id">>, <<"urn:xmpp:sid:0">>, _} -> true;
 +      {<<"stanza-id">>, <<>>, <<"urn:xmpp:sid:0">>} -> true;
 +      {<<"addresses">>,
 +       <<"http://jabber.org/protocol/address">>, _} ->
 +        true;
 +      {<<"addresses">>, <<>>,
 +       <<"http://jabber.org/protocol/address">>} ->
 +        true;
 +      {<<"address">>,
 +       <<"http://jabber.org/protocol/address">>, _} ->
 +        true;
 +      {<<"address">>, <<>>,
 +       <<"http://jabber.org/protocol/address">>} ->
 +        true;
 +      {<<"nick">>, <<"http://jabber.org/protocol/nick">>,
 +       _} ->
 +        true;
 +      {<<"nick">>, <<>>,
 +       <<"http://jabber.org/protocol/nick">>} ->
 +        true;
 +      {<<"x">>, <<"jabber:x:expire">>, _} -> true;
 +      {<<"x">>, <<>>, <<"jabber:x:expire">>} -> true;
 +      {<<"x">>, <<"jabber:x:event">>, _} -> true;
 +      {<<"x">>, <<>>, <<"jabber:x:event">>} -> true;
 +      {<<"id">>, <<"jabber:x:event">>, _} -> true;
 +      {<<"id">>, <<>>, <<"jabber:x:event">>} -> true;
 +      {<<"composing">>, <<"jabber:x:event">>, _} -> true;
 +      {<<"composing">>, <<>>, <<"jabber:x:event">>} -> true;
 +      {<<"displayed">>, <<"jabber:x:event">>, _} -> true;
 +      {<<"displayed">>, <<>>, <<"jabber:x:event">>} -> true;
 +      {<<"delivered">>, <<"jabber:x:event">>, _} -> true;
 +      {<<"delivered">>, <<>>, <<"jabber:x:event">>} -> true;
 +      {<<"offline">>, <<"jabber:x:event">>, _} -> true;
 +      {<<"offline">>, <<>>, <<"jabber:x:event">>} -> true;
 +      {<<"query">>, <<"jabber:iq:search">>, _} -> true;
 +      {<<"query">>, <<>>, <<"jabber:iq:search">>} -> true;
 +      {<<"item">>, <<"jabber:iq:search">>, _} -> true;
 +      {<<"item">>, <<>>, <<"jabber:iq:search">>} -> true;
 +      {<<"email">>, <<"jabber:iq:search">>, _} -> true;
 +      {<<"email">>, <<>>, <<"jabber:iq:search">>} -> true;
 +      {<<"nick">>, <<"jabber:iq:search">>, _} -> true;
 +      {<<"nick">>, <<>>, <<"jabber:iq:search">>} -> true;
 +      {<<"last">>, <<"jabber:iq:search">>, _} -> true;
 +      {<<"last">>, <<>>, <<"jabber:iq:search">>} -> true;
 +      {<<"first">>, <<"jabber:iq:search">>, _} -> true;
 +      {<<"first">>, <<>>, <<"jabber:iq:search">>} -> true;
 +      {<<"instructions">>, <<"jabber:iq:search">>, _} -> true;
 +      {<<"instructions">>, <<>>, <<"jabber:iq:search">>} ->
 +        true;
 +      {<<"no-permanent-storage">>, <<"urn:xmpp:hints">>, _} ->
 +        true;
 +      {<<"no-permanent-storage">>, <<>>,
 +       <<"urn:xmpp:hints">>} ->
 +        true;
 +      {<<"no-permanent-store">>, <<"urn:xmpp:hints">>, _} ->
 +        true;
 +      {<<"no-permanent-store">>, <<>>,
 +       <<"urn:xmpp:hints">>} ->
 +        true;
 +      {<<"store">>, <<"urn:xmpp:hints">>, _} -> true;
 +      {<<"store">>, <<>>, <<"urn:xmpp:hints">>} -> true;
 +      {<<"no-storage">>, <<"urn:xmpp:hints">>, _} -> true;
 +      {<<"no-storage">>, <<>>, <<"urn:xmpp:hints">>} -> true;
 +      {<<"no-store">>, <<"urn:xmpp:hints">>, _} -> true;
 +      {<<"no-store">>, <<>>, <<"urn:xmpp:hints">>} -> true;
 +      {<<"no-copy">>, <<"urn:xmpp:hints">>, _} -> true;
 +      {<<"no-copy">>, <<>>, <<"urn:xmpp:hints">>} -> true;
 +      {<<"participant">>, <<"urn:xmpp:mix:0">>, _} -> true;
 +      {<<"participant">>, <<>>, <<"urn:xmpp:mix:0">>} -> true;
 +      {<<"leave">>, <<"urn:xmpp:mix:0">>, _} -> true;
 +      {<<"leave">>, <<>>, <<"urn:xmpp:mix:0">>} -> true;
 +      {<<"join">>, <<"urn:xmpp:mix:0">>, _} -> true;
 +      {<<"join">>, <<>>, <<"urn:xmpp:mix:0">>} -> true;
 +      {<<"subscribe">>, <<"urn:xmpp:mix:0">>, _} -> true;
 +      {<<"subscribe">>, <<>>, <<"urn:xmpp:mix:0">>} -> true;
 +      {<<"offline">>,
 +       <<"http://jabber.org/protocol/offline">>, _} ->
 +        true;
 +      {<<"offline">>, <<>>,
 +       <<"http://jabber.org/protocol/offline">>} ->
 +        true;
 +      {<<"item">>, <<"http://jabber.org/protocol/offline">>,
 +       _} ->
 +        true;
 +      {<<"item">>, <<>>,
 +       <<"http://jabber.org/protocol/offline">>} ->
 +        true;
 +      {<<"fetch">>, <<"http://jabber.org/protocol/offline">>,
 +       _} ->
 +        true;
 +      {<<"fetch">>, <<>>,
 +       <<"http://jabber.org/protocol/offline">>} ->
 +        true;
 +      {<<"purge">>, <<"http://jabber.org/protocol/offline">>,
 +       _} ->
 +        true;
 +      {<<"purge">>, <<>>,
 +       <<"http://jabber.org/protocol/offline">>} ->
 +        true;
 +      {<<"failed">>, <<"urn:xmpp:sm:2">>, _} -> true;
 +      {<<"failed">>, <<>>, <<"urn:xmpp:sm:2">>} -> true;
 +      {<<"failed">>, <<"urn:xmpp:sm:3">>, _} -> true;
 +      {<<"failed">>, <<>>, <<"urn:xmpp:sm:3">>} -> true;
 +      {<<"a">>, <<"urn:xmpp:sm:2">>, _} -> true;
 +      {<<"a">>, <<>>, <<"urn:xmpp:sm:2">>} -> true;
 +      {<<"a">>, <<"urn:xmpp:sm:3">>, _} -> true;
 +      {<<"a">>, <<>>, <<"urn:xmpp:sm:3">>} -> true;
 +      {<<"r">>, <<"urn:xmpp:sm:2">>, _} -> true;
 +      {<<"r">>, <<>>, <<"urn:xmpp:sm:2">>} -> true;
 +      {<<"r">>, <<"urn:xmpp:sm:3">>, _} -> true;
 +      {<<"r">>, <<>>, <<"urn:xmpp:sm:3">>} -> true;
 +      {<<"resumed">>, <<"urn:xmpp:sm:2">>, _} -> true;
 +      {<<"resumed">>, <<>>, <<"urn:xmpp:sm:2">>} -> true;
 +      {<<"resumed">>, <<"urn:xmpp:sm:3">>, _} -> true;
 +      {<<"resumed">>, <<>>, <<"urn:xmpp:sm:3">>} -> true;
 +      {<<"resume">>, <<"urn:xmpp:sm:2">>, _} -> true;
 +      {<<"resume">>, <<>>, <<"urn:xmpp:sm:2">>} -> true;
 +      {<<"resume">>, <<"urn:xmpp:sm:3">>, _} -> true;
 +      {<<"resume">>, <<>>, <<"urn:xmpp:sm:3">>} -> true;
 +      {<<"enabled">>, <<"urn:xmpp:sm:2">>, _} -> true;
 +      {<<"enabled">>, <<>>, <<"urn:xmpp:sm:2">>} -> true;
 +      {<<"enabled">>, <<"urn:xmpp:sm:3">>, _} -> true;
 +      {<<"enabled">>, <<>>, <<"urn:xmpp:sm:3">>} -> true;
 +      {<<"enable">>, <<"urn:xmpp:sm:2">>, _} -> true;
 +      {<<"enable">>, <<>>, <<"urn:xmpp:sm:2">>} -> true;
 +      {<<"enable">>, <<"urn:xmpp:sm:3">>, _} -> true;
 +      {<<"enable">>, <<>>, <<"urn:xmpp:sm:3">>} -> true;
 +      {<<"sm">>, <<"urn:xmpp:sm:2">>, _} -> true;
 +      {<<"sm">>, <<>>, <<"urn:xmpp:sm:2">>} -> true;
 +      {<<"sm">>, <<"urn:xmpp:sm:3">>, _} -> true;
 +      {<<"sm">>, <<>>, <<"urn:xmpp:sm:3">>} -> true;
 +      {<<"inactive">>, <<"urn:xmpp:csi:0">>, _} -> true;
 +      {<<"inactive">>, <<>>, <<"urn:xmpp:csi:0">>} -> true;
 +      {<<"active">>, <<"urn:xmpp:csi:0">>, _} -> true;
 +      {<<"active">>, <<>>, <<"urn:xmpp:csi:0">>} -> true;
 +      {<<"csi">>, <<"urn:xmpp:csi:0">>, _} -> true;
 +      {<<"csi">>, <<>>, <<"urn:xmpp:csi:0">>} -> true;
 +      {<<"sent">>, <<"urn:xmpp:carbons:2">>, _} -> true;
 +      {<<"sent">>, <<>>, <<"urn:xmpp:carbons:2">>} -> true;
 +      {<<"received">>, <<"urn:xmpp:carbons:2">>, _} -> true;
 +      {<<"received">>, <<>>, <<"urn:xmpp:carbons:2">>} ->
 +        true;
 +      {<<"private">>, <<"urn:xmpp:carbons:2">>, _} -> true;
 +      {<<"private">>, <<>>, <<"urn:xmpp:carbons:2">>} -> true;
 +      {<<"enable">>, <<"urn:xmpp:carbons:2">>, _} -> true;
 +      {<<"enable">>, <<>>, <<"urn:xmpp:carbons:2">>} -> true;
 +      {<<"disable">>, <<"urn:xmpp:carbons:2">>, _} -> true;
 +      {<<"disable">>, <<>>, <<"urn:xmpp:carbons:2">>} -> true;
 +      {<<"forwarded">>, <<"urn:xmpp:forward:0">>, _} -> true;
 +      {<<"forwarded">>, <<>>, <<"urn:xmpp:forward:0">>} ->
 +        true;
 +      {<<"fin">>, <<"urn:xmpp:mam:0">>, _} -> true;
 +      {<<"fin">>, <<>>, <<"urn:xmpp:mam:0">>} -> true;
 +      {<<"fin">>, <<"urn:xmpp:mam:1">>, _} -> true;
 +      {<<"fin">>, <<>>, <<"urn:xmpp:mam:1">>} -> true;
 +      {<<"prefs">>, <<"urn:xmpp:mam:0">>, _} -> true;
 +      {<<"prefs">>, <<>>, <<"urn:xmpp:mam:0">>} -> true;
 +      {<<"prefs">>, <<"urn:xmpp:mam:1">>, _} -> true;
 +      {<<"prefs">>, <<>>, <<"urn:xmpp:mam:1">>} -> true;
 +      {<<"prefs">>, <<"urn:xmpp:mam:tmp">>, _} -> true;
 +      {<<"prefs">>, <<>>, <<"urn:xmpp:mam:tmp">>} -> true;
 +      {<<"always">>, <<"urn:xmpp:mam:0">>, _} -> true;
 +      {<<"always">>, <<>>, <<"urn:xmpp:mam:0">>} -> true;
 +      {<<"always">>, <<"urn:xmpp:mam:1">>, _} -> true;
 +      {<<"always">>, <<>>, <<"urn:xmpp:mam:1">>} -> true;
 +      {<<"always">>, <<"urn:xmpp:mam:tmp">>, _} -> true;
 +      {<<"always">>, <<>>, <<"urn:xmpp:mam:tmp">>} -> true;
 +      {<<"never">>, <<"urn:xmpp:mam:0">>, _} -> true;
 +      {<<"never">>, <<>>, <<"urn:xmpp:mam:0">>} -> true;
 +      {<<"never">>, <<"urn:xmpp:mam:1">>, _} -> true;
 +      {<<"never">>, <<>>, <<"urn:xmpp:mam:1">>} -> true;
 +      {<<"never">>, <<"urn:xmpp:mam:tmp">>, _} -> true;
 +      {<<"never">>, <<>>, <<"urn:xmpp:mam:tmp">>} -> true;
 +      {<<"jid">>, <<"urn:xmpp:mam:0">>, _} -> true;
 +      {<<"jid">>, <<>>, <<"urn:xmpp:mam:0">>} -> true;
 +      {<<"jid">>, <<"urn:xmpp:mam:1">>, _} -> true;
 +      {<<"jid">>, <<>>, <<"urn:xmpp:mam:1">>} -> true;
 +      {<<"jid">>, <<"urn:xmpp:mam:tmp">>, _} -> true;
 +      {<<"jid">>, <<>>, <<"urn:xmpp:mam:tmp">>} -> true;
 +      {<<"result">>, <<"urn:xmpp:mam:0">>, _} -> true;
 +      {<<"result">>, <<>>, <<"urn:xmpp:mam:0">>} -> true;
 +      {<<"result">>, <<"urn:xmpp:mam:1">>, _} -> true;
 +      {<<"result">>, <<>>, <<"urn:xmpp:mam:1">>} -> true;
 +      {<<"result">>, <<"urn:xmpp:mam:tmp">>, _} -> true;
 +      {<<"result">>, <<>>, <<"urn:xmpp:mam:tmp">>} -> true;
 +      {<<"archived">>, <<"urn:xmpp:mam:tmp">>, _} -> true;
 +      {<<"archived">>, <<>>, <<"urn:xmpp:mam:tmp">>} -> true;
 +      {<<"query">>, <<"urn:xmpp:mam:0">>, _} -> true;
 +      {<<"query">>, <<>>, <<"urn:xmpp:mam:0">>} -> true;
 +      {<<"query">>, <<"urn:xmpp:mam:1">>, _} -> true;
 +      {<<"query">>, <<>>, <<"urn:xmpp:mam:1">>} -> true;
 +      {<<"query">>, <<"urn:xmpp:mam:tmp">>, _} -> true;
 +      {<<"query">>, <<>>, <<"urn:xmpp:mam:tmp">>} -> true;
 +      {<<"withtext">>, <<"urn:xmpp:mam:tmp">>, _} -> true;
 +      {<<"withtext">>, <<>>, <<"urn:xmpp:mam:tmp">>} -> true;
 +      {<<"with">>, <<"urn:xmpp:mam:tmp">>, _} -> true;
 +      {<<"with">>, <<>>, <<"urn:xmpp:mam:tmp">>} -> true;
 +      {<<"end">>, <<"urn:xmpp:mam:tmp">>, _} -> true;
 +      {<<"end">>, <<>>, <<"urn:xmpp:mam:tmp">>} -> true;
 +      {<<"start">>, <<"urn:xmpp:mam:tmp">>, _} -> true;
 +      {<<"start">>, <<>>, <<"urn:xmpp:mam:tmp">>} -> true;
 +      {<<"set">>, <<"http://jabber.org/protocol/rsm">>, _} ->
 +        true;
 +      {<<"set">>, <<>>,
 +       <<"http://jabber.org/protocol/rsm">>} ->
 +        true;
 +      {<<"first">>, <<"http://jabber.org/protocol/rsm">>,
 +       _} ->
 +        true;
 +      {<<"first">>, <<>>,
 +       <<"http://jabber.org/protocol/rsm">>} ->
 +        true;
 +      {<<"max">>, <<"http://jabber.org/protocol/rsm">>, _} ->
 +        true;
 +      {<<"max">>, <<>>,
 +       <<"http://jabber.org/protocol/rsm">>} ->
 +        true;
 +      {<<"index">>, <<"http://jabber.org/protocol/rsm">>,
 +       _} ->
 +        true;
 +      {<<"index">>, <<>>,
 +       <<"http://jabber.org/protocol/rsm">>} ->
 +        true;
 +      {<<"count">>, <<"http://jabber.org/protocol/rsm">>,
 +       _} ->
 +        true;
 +      {<<"count">>, <<>>,
 +       <<"http://jabber.org/protocol/rsm">>} ->
 +        true;
 +      {<<"last">>, <<"http://jabber.org/protocol/rsm">>, _} ->
 +        true;
 +      {<<"last">>, <<>>,
 +       <<"http://jabber.org/protocol/rsm">>} ->
 +        true;
 +      {<<"before">>, <<"http://jabber.org/protocol/rsm">>,
 +       _} ->
 +        true;
 +      {<<"before">>, <<>>,
 +       <<"http://jabber.org/protocol/rsm">>} ->
 +        true;
 +      {<<"after">>, <<"http://jabber.org/protocol/rsm">>,
 +       _} ->
 +        true;
 +      {<<"after">>, <<>>,
 +       <<"http://jabber.org/protocol/rsm">>} ->
 +        true;
 +      {<<"unsubscribe">>, <<"urn:xmpp:mucsub:0">>, _} -> true;
 +      {<<"unsubscribe">>, <<>>, <<"urn:xmpp:mucsub:0">>} ->
 +        true;
 +      {<<"subscribe">>, <<"urn:xmpp:mucsub:0">>, _} -> true;
 +      {<<"subscribe">>, <<>>, <<"urn:xmpp:mucsub:0">>} ->
 +        true;
 +      {<<"event">>, <<"urn:xmpp:mucsub:0">>, _} -> true;
 +      {<<"event">>, <<>>, <<"urn:xmpp:mucsub:0">>} -> true;
 +      {<<"subscriptions">>, <<"urn:xmpp:mucsub:0">>, _} ->
 +        true;
 +      {<<"subscriptions">>, <<>>, <<"urn:xmpp:mucsub:0">>} ->
 +        true;
 +      {<<"subscription">>, <<"urn:xmpp:mucsub:0">>, _} ->
 +        true;
 +      {<<"subscription">>, <<>>, <<"urn:xmpp:mucsub:0">>} ->
 +        true;
 +      {<<"x">>, <<"jabber:x:conference">>, _} -> true;
 +      {<<"x">>, <<>>, <<"jabber:x:conference">>} -> true;
 +      {<<"unique">>,
 +       <<"http://jabber.org/protocol/muc#unique">>, _} ->
 +        true;
 +      {<<"unique">>, <<>>,
 +       <<"http://jabber.org/protocol/muc#unique">>} ->
 +        true;
 +      {<<"x">>, <<"http://jabber.org/protocol/muc">>, _} ->
 +        true;
 +      {<<"x">>, <<>>, <<"http://jabber.org/protocol/muc">>} ->
 +        true;
 +      {<<"query">>,
 +       <<"http://jabber.org/protocol/muc#admin">>, _} ->
 +        true;
 +      {<<"query">>, <<>>,
 +       <<"http://jabber.org/protocol/muc#admin">>} ->
 +        true;
 +      {<<"continue">>,
 +       <<"http://jabber.org/protocol/muc#admin">>, _} ->
 +        true;
 +      {<<"continue">>, <<>>,
 +       <<"http://jabber.org/protocol/muc#admin">>} ->
 +        true;
 +      {<<"actor">>,
 +       <<"http://jabber.org/protocol/muc#admin">>, _} ->
 +        true;
 +      {<<"actor">>, <<>>,
 +       <<"http://jabber.org/protocol/muc#admin">>} ->
 +        true;
 +      {<<"item">>, <<"http://jabber.org/protocol/muc#admin">>,
 +       _} ->
 +        true;
 +      {<<"item">>, <<>>,
 +       <<"http://jabber.org/protocol/muc#admin">>} ->
 +        true;
 +      {<<"item">>, <<"http://jabber.org/protocol/muc#owner">>,
 +       _} ->
 +        true;
 +      {<<"item">>, <<>>,
 +       <<"http://jabber.org/protocol/muc#owner">>} ->
 +        true;
 +      {<<"query">>,
 +       <<"http://jabber.org/protocol/muc#owner">>, _} ->
 +        true;
 +      {<<"query">>, <<>>,
 +       <<"http://jabber.org/protocol/muc#owner">>} ->
 +        true;
 +      {<<"password">>,
 +       <<"http://jabber.org/protocol/muc#owner">>, _} ->
 +        true;
 +      {<<"password">>, <<>>,
 +       <<"http://jabber.org/protocol/muc#owner">>} ->
 +        true;
 +      {<<"password">>,
 +       <<"http://jabber.org/protocol/muc#user">>, _} ->
 +        true;
 +      {<<"password">>, <<>>,
 +       <<"http://jabber.org/protocol/muc#user">>} ->
 +        true;
 +      {<<"password">>, <<"http://jabber.org/protocol/muc">>,
 +       _} ->
 +        true;
 +      {<<"password">>, <<>>,
 +       <<"http://jabber.org/protocol/muc">>} ->
 +        true;
 +      {<<"x">>, <<"http://jabber.org/protocol/muc#user">>,
 +       _} ->
 +        true;
 +      {<<"x">>, <<>>,
 +       <<"http://jabber.org/protocol/muc#user">>} ->
 +        true;
 +      {<<"item">>, <<"http://jabber.org/protocol/muc#user">>,
 +       _} ->
 +        true;
 +      {<<"item">>, <<>>,
 +       <<"http://jabber.org/protocol/muc#user">>} ->
 +        true;
 +      {<<"status">>,
 +       <<"http://jabber.org/protocol/muc#user">>, _} ->
 +        true;
 +      {<<"status">>, <<>>,
 +       <<"http://jabber.org/protocol/muc#user">>} ->
 +        true;
 +      {<<"continue">>,
 +       <<"http://jabber.org/protocol/muc#user">>, _} ->
 +        true;
 +      {<<"continue">>, <<>>,
 +       <<"http://jabber.org/protocol/muc#user">>} ->
 +        true;
 +      {<<"actor">>, <<"http://jabber.org/protocol/muc#user">>,
 +       _} ->
 +        true;
 +      {<<"actor">>, <<>>,
 +       <<"http://jabber.org/protocol/muc#user">>} ->
 +        true;
 +      {<<"invite">>,
 +       <<"http://jabber.org/protocol/muc#user">>, _} ->
 +        true;
 +      {<<"invite">>, <<>>,
 +       <<"http://jabber.org/protocol/muc#user">>} ->
 +        true;
 +      {<<"destroy">>,
 +       <<"http://jabber.org/protocol/muc#user">>, _} ->
 +        true;
 +      {<<"destroy">>, <<>>,
 +       <<"http://jabber.org/protocol/muc#user">>} ->
 +        true;
 +      {<<"destroy">>,
 +       <<"http://jabber.org/protocol/muc#owner">>, _} ->
 +        true;
 +      {<<"destroy">>, <<>>,
 +       <<"http://jabber.org/protocol/muc#owner">>} ->
 +        true;
 +      {<<"decline">>,
 +       <<"http://jabber.org/protocol/muc#user">>, _} ->
 +        true;
 +      {<<"decline">>, <<>>,
 +       <<"http://jabber.org/protocol/muc#user">>} ->
 +        true;
 +      {<<"reason">>,
 +       <<"http://jabber.org/protocol/muc#user">>, _} ->
 +        true;
 +      {<<"reason">>, <<>>,
 +       <<"http://jabber.org/protocol/muc#user">>} ->
 +        true;
 +      {<<"reason">>,
 +       <<"http://jabber.org/protocol/muc#admin">>, _} ->
 +        true;
 +      {<<"reason">>, <<>>,
 +       <<"http://jabber.org/protocol/muc#admin">>} ->
 +        true;
 +      {<<"reason">>,
 +       <<"http://jabber.org/protocol/muc#owner">>, _} ->
 +        true;
 +      {<<"reason">>, <<>>,
 +       <<"http://jabber.org/protocol/muc#owner">>} ->
 +        true;
 +      {<<"history">>, <<"http://jabber.org/protocol/muc">>,
 +       _} ->
 +        true;
 +      {<<"history">>, <<>>,
 +       <<"http://jabber.org/protocol/muc">>} ->
 +        true;
 +      {<<"query">>,
 +       <<"http://jabber.org/protocol/bytestreams">>, _} ->
 +        true;
 +      {<<"query">>, <<>>,
 +       <<"http://jabber.org/protocol/bytestreams">>} ->
 +        true;
 +      {<<"activate">>,
 +       <<"http://jabber.org/protocol/bytestreams">>, _} ->
 +        true;
 +      {<<"activate">>, <<>>,
 +       <<"http://jabber.org/protocol/bytestreams">>} ->
 +        true;
 +      {<<"streamhost-used">>,
 +       <<"http://jabber.org/protocol/bytestreams">>, _} ->
 +        true;
 +      {<<"streamhost-used">>, <<>>,
 +       <<"http://jabber.org/protocol/bytestreams">>} ->
 +        true;
 +      {<<"streamhost">>,
 +       <<"http://jabber.org/protocol/bytestreams">>, _} ->
 +        true;
 +      {<<"streamhost">>, <<>>,
 +       <<"http://jabber.org/protocol/bytestreams">>} ->
 +        true;
 +      {<<"delay">>, <<"urn:xmpp:delay">>, _} -> true;
 +      {<<"delay">>, <<>>, <<"urn:xmpp:delay">>} -> true;
 +      {<<"paused">>,
 +       <<"http://jabber.org/protocol/chatstates">>, _} ->
 +        true;
 +      {<<"paused">>, <<>>,
 +       <<"http://jabber.org/protocol/chatstates">>} ->
 +        true;
 +      {<<"inactive">>,
 +       <<"http://jabber.org/protocol/chatstates">>, _} ->
 +        true;
 +      {<<"inactive">>, <<>>,
 +       <<"http://jabber.org/protocol/chatstates">>} ->
 +        true;
 +      {<<"gone">>,
 +       <<"http://jabber.org/protocol/chatstates">>, _} ->
 +        true;
 +      {<<"gone">>, <<>>,
 +       <<"http://jabber.org/protocol/chatstates">>} ->
 +        true;
 +      {<<"composing">>,
 +       <<"http://jabber.org/protocol/chatstates">>, _} ->
 +        true;
 +      {<<"composing">>, <<>>,
 +       <<"http://jabber.org/protocol/chatstates">>} ->
 +        true;
 +      {<<"active">>,
 +       <<"http://jabber.org/protocol/chatstates">>, _} ->
 +        true;
 +      {<<"active">>, <<>>,
 +       <<"http://jabber.org/protocol/chatstates">>} ->
 +        true;
 +      {<<"headers">>, <<"http://jabber.org/protocol/shim">>,
 +       _} ->
 +        true;
 +      {<<"headers">>, <<>>,
 +       <<"http://jabber.org/protocol/shim">>} ->
 +        true;
 +      {<<"header">>, <<"http://jabber.org/protocol/shim">>,
 +       _} ->
 +        true;
 +      {<<"header">>, <<>>,
 +       <<"http://jabber.org/protocol/shim">>} ->
 +        true;
 +      {<<"unsupported-access-model">>,
 +       <<"http://jabber.org/protocol/pubsub#errors">>, _} ->
 +        true;
 +      {<<"unsupported-access-model">>, <<>>,
 +       <<"http://jabber.org/protocol/pubsub#errors">>} ->
 +        true;
 +      {<<"unsupported">>,
 +       <<"http://jabber.org/protocol/pubsub#errors">>, _} ->
 +        true;
 +      {<<"unsupported">>, <<>>,
 +       <<"http://jabber.org/protocol/pubsub#errors">>} ->
 +        true;
 +      {<<"too-many-subscriptions">>,
 +       <<"http://jabber.org/protocol/pubsub#errors">>, _} ->
 +        true;
 +      {<<"too-many-subscriptions">>, <<>>,
 +       <<"http://jabber.org/protocol/pubsub#errors">>} ->
 +        true;
 +      {<<"subid-required">>,
 +       <<"http://jabber.org/protocol/pubsub#errors">>, _} ->
 +        true;
 +      {<<"subid-required">>, <<>>,
 +       <<"http://jabber.org/protocol/pubsub#errors">>} ->
 +        true;
 +      {<<"presence-subscription-required">>,
 +       <<"http://jabber.org/protocol/pubsub#errors">>, _} ->
 +        true;
 +      {<<"presence-subscription-required">>, <<>>,
 +       <<"http://jabber.org/protocol/pubsub#errors">>} ->
 +        true;
 +      {<<"pending-subscription">>,
 +       <<"http://jabber.org/protocol/pubsub#errors">>, _} ->
 +        true;
 +      {<<"pending-subscription">>, <<>>,
 +       <<"http://jabber.org/protocol/pubsub#errors">>} ->
 +        true;
 +      {<<"payload-required">>,
 +       <<"http://jabber.org/protocol/pubsub#errors">>, _} ->
 +        true;
 +      {<<"payload-required">>, <<>>,
 +       <<"http://jabber.org/protocol/pubsub#errors">>} ->
 +        true;
 +      {<<"payload-too-big">>,
 +       <<"http://jabber.org/protocol/pubsub#errors">>, _} ->
 +        true;
 +      {<<"payload-too-big">>, <<>>,
 +       <<"http://jabber.org/protocol/pubsub#errors">>} ->
 +        true;
 +      {<<"not-subscribed">>,
 +       <<"http://jabber.org/protocol/pubsub#errors">>, _} ->
 +        true;
 +      {<<"not-subscribed">>, <<>>,
 +       <<"http://jabber.org/protocol/pubsub#errors">>} ->
 +        true;
 +      {<<"not-in-roster-group">>,
 +       <<"http://jabber.org/protocol/pubsub#errors">>, _} ->
 +        true;
 +      {<<"not-in-roster-group">>, <<>>,
 +       <<"http://jabber.org/protocol/pubsub#errors">>} ->
 +        true;
 +      {<<"nodeid-required">>,
 +       <<"http://jabber.org/protocol/pubsub#errors">>, _} ->
 +        true;
 +      {<<"nodeid-required">>, <<>>,
 +       <<"http://jabber.org/protocol/pubsub#errors">>} ->
 +        true;
 +      {<<"max-nodes-exceeded">>,
 +       <<"http://jabber.org/protocol/pubsub#errors">>, _} ->
 +        true;
 +      {<<"max-nodes-exceeded">>, <<>>,
 +       <<"http://jabber.org/protocol/pubsub#errors">>} ->
 +        true;
 +      {<<"max-items-exceeded">>,
 +       <<"http://jabber.org/protocol/pubsub#errors">>, _} ->
 +        true;
 +      {<<"max-items-exceeded">>, <<>>,
 +       <<"http://jabber.org/protocol/pubsub#errors">>} ->
 +        true;
 +      {<<"jid-required">>,
 +       <<"http://jabber.org/protocol/pubsub#errors">>, _} ->
 +        true;
 +      {<<"jid-required">>, <<>>,
 +       <<"http://jabber.org/protocol/pubsub#errors">>} ->
 +        true;
 +      {<<"item-required">>,
 +       <<"http://jabber.org/protocol/pubsub#errors">>, _} ->
 +        true;
 +      {<<"item-required">>, <<>>,
 +       <<"http://jabber.org/protocol/pubsub#errors">>} ->
 +        true;
 +      {<<"item-forbidden">>,
 +       <<"http://jabber.org/protocol/pubsub#errors">>, _} ->
 +        true;
 +      {<<"item-forbidden">>, <<>>,
 +       <<"http://jabber.org/protocol/pubsub#errors">>} ->
 +        true;
 +      {<<"invalid-subid">>,
 +       <<"http://jabber.org/protocol/pubsub#errors">>, _} ->
 +        true;
 +      {<<"invalid-subid">>, <<>>,
 +       <<"http://jabber.org/protocol/pubsub#errors">>} ->
 +        true;
 +      {<<"invalid-payload">>,
 +       <<"http://jabber.org/protocol/pubsub#errors">>, _} ->
 +        true;
 +      {<<"invalid-payload">>, <<>>,
 +       <<"http://jabber.org/protocol/pubsub#errors">>} ->
 +        true;
 +      {<<"invalid-options">>,
 +       <<"http://jabber.org/protocol/pubsub#errors">>, _} ->
 +        true;
 +      {<<"invalid-options">>, <<>>,
 +       <<"http://jabber.org/protocol/pubsub#errors">>} ->
 +        true;
 +      {<<"invalid-jid">>,
 +       <<"http://jabber.org/protocol/pubsub#errors">>, _} ->
 +        true;
 +      {<<"invalid-jid">>, <<>>,
 +       <<"http://jabber.org/protocol/pubsub#errors">>} ->
 +        true;
 +      {<<"configuration-required">>,
 +       <<"http://jabber.org/protocol/pubsub#errors">>, _} ->
 +        true;
 +      {<<"configuration-required">>, <<>>,
 +       <<"http://jabber.org/protocol/pubsub#errors">>} ->
 +        true;
 +      {<<"closed-node">>,
 +       <<"http://jabber.org/protocol/pubsub#errors">>, _} ->
 +        true;
 +      {<<"closed-node">>, <<>>,
 +       <<"http://jabber.org/protocol/pubsub#errors">>} ->
 +        true;
 +      {<<"pubsub">>,
 +       <<"http://jabber.org/protocol/pubsub#owner">>, _} ->
 +        true;
 +      {<<"pubsub">>, <<>>,
 +       <<"http://jabber.org/protocol/pubsub#owner">>} ->
 +        true;
 +      {<<"pubsub">>, <<"http://jabber.org/protocol/pubsub">>,
 +       _} ->
 +        true;
 +      {<<"pubsub">>, <<>>,
 +       <<"http://jabber.org/protocol/pubsub">>} ->
 +        true;
 +      {<<"purge">>, <<"http://jabber.org/protocol/pubsub">>,
 +       _} ->
 +        true;
 +      {<<"purge">>, <<>>,
 +       <<"http://jabber.org/protocol/pubsub">>} ->
 +        true;
 +      {<<"purge">>,
 +       <<"http://jabber.org/protocol/pubsub#owner">>, _} ->
 +        true;
 +      {<<"purge">>, <<>>,
 +       <<"http://jabber.org/protocol/pubsub#owner">>} ->
 +        true;
 +      {<<"purge">>,
 +       <<"http://jabber.org/protocol/pubsub#event">>, _} ->
 +        true;
 +      {<<"purge">>, <<>>,
 +       <<"http://jabber.org/protocol/pubsub#event">>} ->
 +        true;
 +      {<<"delete">>, <<"http://jabber.org/protocol/pubsub">>,
 +       _} ->
 +        true;
 +      {<<"delete">>, <<>>,
 +       <<"http://jabber.org/protocol/pubsub">>} ->
 +        true;
 +      {<<"delete">>,
 +       <<"http://jabber.org/protocol/pubsub#owner">>, _} ->
 +        true;
 +      {<<"delete">>, <<>>,
 +       <<"http://jabber.org/protocol/pubsub#owner">>} ->
 +        true;
 +      {<<"delete">>,
 +       <<"http://jabber.org/protocol/pubsub#event">>, _} ->
 +        true;
 +      {<<"delete">>, <<>>,
 +       <<"http://jabber.org/protocol/pubsub#event">>} ->
 +        true;
 +      {<<"redirect">>,
 +       <<"http://jabber.org/protocol/pubsub">>, _} ->
 +        true;
 +      {<<"redirect">>, <<>>,
 +       <<"http://jabber.org/protocol/pubsub">>} ->
 +        true;
 +      {<<"redirect">>,
 +       <<"http://jabber.org/protocol/pubsub#owner">>, _} ->
 +        true;
 +      {<<"redirect">>, <<>>,
 +       <<"http://jabber.org/protocol/pubsub#owner">>} ->
 +        true;
 +      {<<"redirect">>,
 +       <<"http://jabber.org/protocol/pubsub#event">>, _} ->
 +        true;
 +      {<<"redirect">>, <<>>,
 +       <<"http://jabber.org/protocol/pubsub#event">>} ->
 +        true;
 +      {<<"default">>, <<"http://jabber.org/protocol/pubsub">>,
 +       _} ->
 +        true;
 +      {<<"default">>, <<>>,
 +       <<"http://jabber.org/protocol/pubsub">>} ->
 +        true;
 +      {<<"default">>,
 +       <<"http://jabber.org/protocol/pubsub#owner">>, _} ->
 +        true;
 +      {<<"default">>, <<>>,
 +       <<"http://jabber.org/protocol/pubsub#owner">>} ->
 +        true;
 +      {<<"publish-options">>,
 +       <<"http://jabber.org/protocol/pubsub">>, _} ->
 +        true;
 +      {<<"publish-options">>, <<>>,
 +       <<"http://jabber.org/protocol/pubsub">>} ->
 +        true;
 +      {<<"configure">>,
 +       <<"http://jabber.org/protocol/pubsub">>, _} ->
 +        true;
 +      {<<"configure">>, <<>>,
 +       <<"http://jabber.org/protocol/pubsub">>} ->
 +        true;
 +      {<<"configure">>,
 +       <<"http://jabber.org/protocol/pubsub#owner">>, _} ->
 +        true;
 +      {<<"configure">>, <<>>,
 +       <<"http://jabber.org/protocol/pubsub#owner">>} ->
 +        true;
 +      {<<"create">>, <<"http://jabber.org/protocol/pubsub">>,
 +       _} ->
 +        true;
 +      {<<"create">>, <<>>,
 +       <<"http://jabber.org/protocol/pubsub">>} ->
 +        true;
 +      {<<"create">>,
 +       <<"http://jabber.org/protocol/pubsub#event">>, _} ->
 +        true;
 +      {<<"create">>, <<>>,
 +       <<"http://jabber.org/protocol/pubsub#event">>} ->
 +        true;
 +      {<<"retract">>, <<"http://jabber.org/protocol/pubsub">>,
 +       _} ->
 +        true;
 +      {<<"retract">>, <<>>,
 +       <<"http://jabber.org/protocol/pubsub">>} ->
 +        true;
 +      {<<"options">>, <<"http://jabber.org/protocol/pubsub">>,
 +       _} ->
 +        true;
 +      {<<"options">>, <<>>,
 +       <<"http://jabber.org/protocol/pubsub">>} ->
 +        true;
 +      {<<"publish">>, <<"http://jabber.org/protocol/pubsub">>,
 +       _} ->
 +        true;
 +      {<<"publish">>, <<>>,
 +       <<"http://jabber.org/protocol/pubsub">>} ->
 +        true;
 +      {<<"unsubscribe">>,
 +       <<"http://jabber.org/protocol/pubsub">>, _} ->
 +        true;
 +      {<<"unsubscribe">>, <<>>,
 +       <<"http://jabber.org/protocol/pubsub">>} ->
 +        true;
 +      {<<"subscribe">>,
 +       <<"http://jabber.org/protocol/pubsub">>, _} ->
 +        true;
 +      {<<"subscribe">>, <<>>,
 +       <<"http://jabber.org/protocol/pubsub">>} ->
 +        true;
 +      {<<"affiliations">>,
 +       <<"http://jabber.org/protocol/pubsub#owner">>, _} ->
 +        true;
 +      {<<"affiliations">>, <<>>,
 +       <<"http://jabber.org/protocol/pubsub#owner">>} ->
 +        true;
 +      {<<"affiliations">>,
 +       <<"http://jabber.org/protocol/pubsub">>, _} ->
 +        true;
 +      {<<"affiliations">>, <<>>,
 +       <<"http://jabber.org/protocol/pubsub">>} ->
 +        true;
 +      {<<"subscriptions">>,
 +       <<"http://jabber.org/protocol/pubsub">>, _} ->
 +        true;
 +      {<<"subscriptions">>, <<>>,
 +       <<"http://jabber.org/protocol/pubsub">>} ->
 +        true;
 +      {<<"subscriptions">>,
 +       <<"http://jabber.org/protocol/pubsub#owner">>, _} ->
 +        true;
 +      {<<"subscriptions">>, <<>>,
 +       <<"http://jabber.org/protocol/pubsub#owner">>} ->
 +        true;
 +      {<<"event">>,
 +       <<"http://jabber.org/protocol/pubsub#event">>, _} ->
 +        true;
 +      {<<"event">>, <<>>,
 +       <<"http://jabber.org/protocol/pubsub#event">>} ->
 +        true;
 +      {<<"items">>, <<"http://jabber.org/protocol/pubsub">>,
 +       _} ->
 +        true;
 +      {<<"items">>, <<>>,
 +       <<"http://jabber.org/protocol/pubsub">>} ->
 +        true;
 +      {<<"items">>,
 +       <<"http://jabber.org/protocol/pubsub#event">>, _} ->
 +        true;
 +      {<<"items">>, <<>>,
 +       <<"http://jabber.org/protocol/pubsub#event">>} ->
 +        true;
 +      {<<"item">>, <<"http://jabber.org/protocol/pubsub">>,
 +       _} ->
 +        true;
 +      {<<"item">>, <<>>,
 +       <<"http://jabber.org/protocol/pubsub">>} ->
 +        true;
 +      {<<"item">>,
 +       <<"http://jabber.org/protocol/pubsub#event">>, _} ->
 +        true;
 +      {<<"item">>, <<>>,
 +       <<"http://jabber.org/protocol/pubsub#event">>} ->
 +        true;
 +      {<<"retract">>,
 +       <<"http://jabber.org/protocol/pubsub#event">>, _} ->
 +        true;
 +      {<<"retract">>, <<>>,
 +       <<"http://jabber.org/protocol/pubsub#event">>} ->
 +        true;
 +      {<<"configuration">>,
 +       <<"http://jabber.org/protocol/pubsub#event">>, _} ->
 +        true;
 +      {<<"configuration">>, <<>>,
 +       <<"http://jabber.org/protocol/pubsub#event">>} ->
 +        true;
 +      {<<"affiliation">>,
 +       <<"http://jabber.org/protocol/pubsub#owner">>, _} ->
 +        true;
 +      {<<"affiliation">>, <<>>,
 +       <<"http://jabber.org/protocol/pubsub#owner">>} ->
 +        true;
 +      {<<"affiliation">>,
 +       <<"http://jabber.org/protocol/pubsub">>, _} ->
 +        true;
 +      {<<"affiliation">>, <<>>,
 +       <<"http://jabber.org/protocol/pubsub">>} ->
 +        true;
 +      {<<"subscription">>,
 +       <<"http://jabber.org/protocol/pubsub">>, _} ->
 +        true;
 +      {<<"subscription">>, <<>>,
 +       <<"http://jabber.org/protocol/pubsub">>} ->
 +        true;
 +      {<<"subscription">>,
 +       <<"http://jabber.org/protocol/pubsub#owner">>, _} ->
 +        true;
 +      {<<"subscription">>, <<>>,
 +       <<"http://jabber.org/protocol/pubsub#owner">>} ->
 +        true;
 +      {<<"subscription">>,
 +       <<"http://jabber.org/protocol/pubsub#event">>, _} ->
 +        true;
 +      {<<"subscription">>, <<>>,
 +       <<"http://jabber.org/protocol/pubsub#event">>} ->
 +        true;
 +      {<<"x">>, <<"jabber:x:data">>, _} -> true;
 +      {<<"x">>, <<>>, <<"jabber:x:data">>} -> true;
 +      {<<"item">>, <<"jabber:x:data">>, _} -> true;
 +      {<<"item">>, <<>>, <<"jabber:x:data">>} -> true;
 +      {<<"reported">>, <<"jabber:x:data">>, _} -> true;
 +      {<<"reported">>, <<>>, <<"jabber:x:data">>} -> true;
 +      {<<"title">>, <<"jabber:x:data">>, _} -> true;
 +      {<<"title">>, <<>>, <<"jabber:x:data">>} -> true;
 +      {<<"instructions">>, <<"jabber:x:data">>, _} -> true;
 +      {<<"instructions">>, <<>>, <<"jabber:x:data">>} -> true;
 +      {<<"field">>, <<"jabber:x:data">>, _} -> true;
 +      {<<"field">>, <<>>, <<"jabber:x:data">>} -> true;
 +      {<<"option">>, <<"jabber:x:data">>, _} -> true;
 +      {<<"option">>, <<>>, <<"jabber:x:data">>} -> true;
 +      {<<"value">>, <<"jabber:x:data">>, _} -> true;
 +      {<<"value">>, <<>>, <<"jabber:x:data">>} -> true;
 +      {<<"desc">>, <<"jabber:x:data">>, _} -> true;
 +      {<<"desc">>, <<>>, <<"jabber:x:data">>} -> true;
 +      {<<"required">>, <<"jabber:x:data">>, _} -> true;
 +      {<<"required">>, <<>>, <<"jabber:x:data">>} -> true;
 +      {<<"x">>, <<"vcard-temp:x:update">>, _} -> true;
 +      {<<"x">>, <<>>, <<"vcard-temp:x:update">>} -> true;
 +      {<<"photo">>, <<"vcard-temp:x:update">>, _} -> true;
 +      {<<"photo">>, <<>>, <<"vcard-temp:x:update">>} -> true;
 +      {<<"vCard">>, <<"vcard-temp">>, _} -> true;
 +      {<<"vCard">>, <<>>, <<"vcard-temp">>} -> true;
 +      {<<"CLASS">>, <<"vcard-temp">>, _} -> true;
 +      {<<"CLASS">>, <<>>, <<"vcard-temp">>} -> true;
 +      {<<"CATEGORIES">>, <<"vcard-temp">>, _} -> true;
 +      {<<"CATEGORIES">>, <<>>, <<"vcard-temp">>} -> true;
 +      {<<"KEY">>, <<"vcard-temp">>, _} -> true;
 +      {<<"KEY">>, <<>>, <<"vcard-temp">>} -> true;
 +      {<<"SOUND">>, <<"vcard-temp">>, _} -> true;
 +      {<<"SOUND">>, <<>>, <<"vcard-temp">>} -> true;
 +      {<<"ORG">>, <<"vcard-temp">>, _} -> true;
 +      {<<"ORG">>, <<>>, <<"vcard-temp">>} -> true;
 +      {<<"PHOTO">>, <<"vcard-temp">>, _} -> true;
 +      {<<"PHOTO">>, <<>>, <<"vcard-temp">>} -> true;
 +      {<<"LOGO">>, <<"vcard-temp">>, _} -> true;
 +      {<<"LOGO">>, <<>>, <<"vcard-temp">>} -> true;
 +      {<<"BINVAL">>, <<"vcard-temp">>, _} -> true;
 +      {<<"BINVAL">>, <<>>, <<"vcard-temp">>} -> true;
 +      {<<"GEO">>, <<"vcard-temp">>, _} -> true;
 +      {<<"GEO">>, <<>>, <<"vcard-temp">>} -> true;
 +      {<<"EMAIL">>, <<"vcard-temp">>, _} -> true;
 +      {<<"EMAIL">>, <<>>, <<"vcard-temp">>} -> true;
 +      {<<"TEL">>, <<"vcard-temp">>, _} -> true;
 +      {<<"TEL">>, <<>>, <<"vcard-temp">>} -> true;
 +      {<<"LABEL">>, <<"vcard-temp">>, _} -> true;
 +      {<<"LABEL">>, <<>>, <<"vcard-temp">>} -> true;
 +      {<<"ADR">>, <<"vcard-temp">>, _} -> true;
 +      {<<"ADR">>, <<>>, <<"vcard-temp">>} -> true;
 +      {<<"N">>, <<"vcard-temp">>, _} -> true;
 +      {<<"N">>, <<>>, <<"vcard-temp">>} -> true;
 +      {<<"CONFIDENTIAL">>, <<"vcard-temp">>, _} -> true;
 +      {<<"CONFIDENTIAL">>, <<>>, <<"vcard-temp">>} -> true;
 +      {<<"PRIVATE">>, <<"vcard-temp">>, _} -> true;
 +      {<<"PRIVATE">>, <<>>, <<"vcard-temp">>} -> true;
 +      {<<"PUBLIC">>, <<"vcard-temp">>, _} -> true;
 +      {<<"PUBLIC">>, <<>>, <<"vcard-temp">>} -> true;
 +      {<<"EXTVAL">>, <<"vcard-temp">>, _} -> true;
 +      {<<"EXTVAL">>, <<>>, <<"vcard-temp">>} -> true;
 +      {<<"TYPE">>, <<"vcard-temp">>, _} -> true;
 +      {<<"TYPE">>, <<>>, <<"vcard-temp">>} -> true;
 +      {<<"DESC">>, <<"vcard-temp">>, _} -> true;
 +      {<<"DESC">>, <<>>, <<"vcard-temp">>} -> true;
 +      {<<"URL">>, <<"vcard-temp">>, _} -> true;
 +      {<<"URL">>, <<>>, <<"vcard-temp">>} -> true;
 +      {<<"UID">>, <<"vcard-temp">>, _} -> true;
 +      {<<"UID">>, <<>>, <<"vcard-temp">>} -> true;
 +      {<<"SORT-STRING">>, <<"vcard-temp">>, _} -> true;
 +      {<<"SORT-STRING">>, <<>>, <<"vcard-temp">>} -> true;
 +      {<<"REV">>, <<"vcard-temp">>, _} -> true;
 +      {<<"REV">>, <<>>, <<"vcard-temp">>} -> true;
 +      {<<"PRODID">>, <<"vcard-temp">>, _} -> true;
 +      {<<"PRODID">>, <<>>, <<"vcard-temp">>} -> true;
 +      {<<"NOTE">>, <<"vcard-temp">>, _} -> true;
 +      {<<"NOTE">>, <<>>, <<"vcard-temp">>} -> true;
 +      {<<"KEYWORD">>, <<"vcard-temp">>, _} -> true;
 +      {<<"KEYWORD">>, <<>>, <<"vcard-temp">>} -> true;
 +      {<<"ROLE">>, <<"vcard-temp">>, _} -> true;
 +      {<<"ROLE">>, <<>>, <<"vcard-temp">>} -> true;
 +      {<<"TITLE">>, <<"vcard-temp">>, _} -> true;
 +      {<<"TITLE">>, <<>>, <<"vcard-temp">>} -> true;
 +      {<<"TZ">>, <<"vcard-temp">>, _} -> true;
 +      {<<"TZ">>, <<>>, <<"vcard-temp">>} -> true;
 +      {<<"MAILER">>, <<"vcard-temp">>, _} -> true;
 +      {<<"MAILER">>, <<>>, <<"vcard-temp">>} -> true;
 +      {<<"JABBERID">>, <<"vcard-temp">>, _} -> true;
 +      {<<"JABBERID">>, <<>>, <<"vcard-temp">>} -> true;
 +      {<<"BDAY">>, <<"vcard-temp">>, _} -> true;
 +      {<<"BDAY">>, <<>>, <<"vcard-temp">>} -> true;
 +      {<<"NICKNAME">>, <<"vcard-temp">>, _} -> true;
 +      {<<"NICKNAME">>, <<>>, <<"vcard-temp">>} -> true;
 +      {<<"FN">>, <<"vcard-temp">>, _} -> true;
 +      {<<"FN">>, <<>>, <<"vcard-temp">>} -> true;
 +      {<<"VERSION">>, <<"vcard-temp">>, _} -> true;
 +      {<<"VERSION">>, <<>>, <<"vcard-temp">>} -> true;
 +      {<<"CRED">>, <<"vcard-temp">>, _} -> true;
 +      {<<"CRED">>, <<>>, <<"vcard-temp">>} -> true;
 +      {<<"PHONETIC">>, <<"vcard-temp">>, _} -> true;
 +      {<<"PHONETIC">>, <<>>, <<"vcard-temp">>} -> true;
 +      {<<"ORGUNIT">>, <<"vcard-temp">>, _} -> true;
 +      {<<"ORGUNIT">>, <<>>, <<"vcard-temp">>} -> true;
 +      {<<"ORGNAME">>, <<"vcard-temp">>, _} -> true;
 +      {<<"ORGNAME">>, <<>>, <<"vcard-temp">>} -> true;
 +      {<<"LON">>, <<"vcard-temp">>, _} -> true;
 +      {<<"LON">>, <<>>, <<"vcard-temp">>} -> true;
 +      {<<"LAT">>, <<"vcard-temp">>, _} -> true;
 +      {<<"LAT">>, <<>>, <<"vcard-temp">>} -> true;
 +      {<<"USERID">>, <<"vcard-temp">>, _} -> true;
 +      {<<"USERID">>, <<>>, <<"vcard-temp">>} -> true;
 +      {<<"NUMBER">>, <<"vcard-temp">>, _} -> true;
 +      {<<"NUMBER">>, <<>>, <<"vcard-temp">>} -> true;
 +      {<<"LINE">>, <<"vcard-temp">>, _} -> true;
 +      {<<"LINE">>, <<>>, <<"vcard-temp">>} -> true;
 +      {<<"CTRY">>, <<"vcard-temp">>, _} -> true;
 +      {<<"CTRY">>, <<>>, <<"vcard-temp">>} -> true;
 +      {<<"PCODE">>, <<"vcard-temp">>, _} -> true;
 +      {<<"PCODE">>, <<>>, <<"vcard-temp">>} -> true;
 +      {<<"REGION">>, <<"vcard-temp">>, _} -> true;
 +      {<<"REGION">>, <<>>, <<"vcard-temp">>} -> true;
 +      {<<"LOCALITY">>, <<"vcard-temp">>, _} -> true;
 +      {<<"LOCALITY">>, <<>>, <<"vcard-temp">>} -> true;
 +      {<<"STREET">>, <<"vcard-temp">>, _} -> true;
 +      {<<"STREET">>, <<>>, <<"vcard-temp">>} -> true;
 +      {<<"EXTADD">>, <<"vcard-temp">>, _} -> true;
 +      {<<"EXTADD">>, <<>>, <<"vcard-temp">>} -> true;
 +      {<<"POBOX">>, <<"vcard-temp">>, _} -> true;
 +      {<<"POBOX">>, <<>>, <<"vcard-temp">>} -> true;
 +      {<<"SUFFIX">>, <<"vcard-temp">>, _} -> true;
 +      {<<"SUFFIX">>, <<>>, <<"vcard-temp">>} -> true;
 +      {<<"PREFIX">>, <<"vcard-temp">>, _} -> true;
 +      {<<"PREFIX">>, <<>>, <<"vcard-temp">>} -> true;
 +      {<<"MIDDLE">>, <<"vcard-temp">>, _} -> true;
 +      {<<"MIDDLE">>, <<>>, <<"vcard-temp">>} -> true;
 +      {<<"GIVEN">>, <<"vcard-temp">>, _} -> true;
 +      {<<"GIVEN">>, <<>>, <<"vcard-temp">>} -> true;
 +      {<<"FAMILY">>, <<"vcard-temp">>, _} -> true;
 +      {<<"FAMILY">>, <<>>, <<"vcard-temp">>} -> true;
 +      {<<"X400">>, <<"vcard-temp">>, _} -> true;
 +      {<<"X400">>, <<>>, <<"vcard-temp">>} -> true;
 +      {<<"INTERNET">>, <<"vcard-temp">>, _} -> true;
 +      {<<"INTERNET">>, <<>>, <<"vcard-temp">>} -> true;
 +      {<<"PREF">>, <<"vcard-temp">>, _} -> true;
 +      {<<"PREF">>, <<>>, <<"vcard-temp">>} -> true;
 +      {<<"INTL">>, <<"vcard-temp">>, _} -> true;
 +      {<<"INTL">>, <<>>, <<"vcard-temp">>} -> true;
 +      {<<"DOM">>, <<"vcard-temp">>, _} -> true;
 +      {<<"DOM">>, <<>>, <<"vcard-temp">>} -> true;
 +      {<<"PARCEL">>, <<"vcard-temp">>, _} -> true;
 +      {<<"PARCEL">>, <<>>, <<"vcard-temp">>} -> true;
 +      {<<"POSTAL">>, <<"vcard-temp">>, _} -> true;
 +      {<<"POSTAL">>, <<>>, <<"vcard-temp">>} -> true;
 +      {<<"PCS">>, <<"vcard-temp">>, _} -> true;
 +      {<<"PCS">>, <<>>, <<"vcard-temp">>} -> true;
 +      {<<"ISDN">>, <<"vcard-temp">>, _} -> true;
 +      {<<"ISDN">>, <<>>, <<"vcard-temp">>} -> true;
 +      {<<"MODEM">>, <<"vcard-temp">>, _} -> true;
 +      {<<"MODEM">>, <<>>, <<"vcard-temp">>} -> true;
 +      {<<"BBS">>, <<"vcard-temp">>, _} -> true;
 +      {<<"BBS">>, <<>>, <<"vcard-temp">>} -> true;
 +      {<<"VIDEO">>, <<"vcard-temp">>, _} -> true;
 +      {<<"VIDEO">>, <<>>, <<"vcard-temp">>} -> true;
 +      {<<"CELL">>, <<"vcard-temp">>, _} -> true;
 +      {<<"CELL">>, <<>>, <<"vcard-temp">>} -> true;
 +      {<<"MSG">>, <<"vcard-temp">>, _} -> true;
 +      {<<"MSG">>, <<>>, <<"vcard-temp">>} -> true;
 +      {<<"PAGER">>, <<"vcard-temp">>, _} -> true;
 +      {<<"PAGER">>, <<>>, <<"vcard-temp">>} -> true;
 +      {<<"FAX">>, <<"vcard-temp">>, _} -> true;
 +      {<<"FAX">>, <<>>, <<"vcard-temp">>} -> true;
 +      {<<"VOICE">>, <<"vcard-temp">>, _} -> true;
 +      {<<"VOICE">>, <<>>, <<"vcard-temp">>} -> true;
 +      {<<"WORK">>, <<"vcard-temp">>, _} -> true;
 +      {<<"WORK">>, <<>>, <<"vcard-temp">>} -> true;
 +      {<<"HOME">>, <<"vcard-temp">>, _} -> true;
 +      {<<"HOME">>, <<>>, <<"vcard-temp">>} -> true;
 +      {<<"stream:error">>, <<"jabber:client">>, _} -> true;
 +      {<<"stream:error">>, <<>>, <<"jabber:client">>} -> true;
 +      {<<"stream:error">>, <<"jabber:server">>, _} -> true;
 +      {<<"stream:error">>, <<>>, <<"jabber:server">>} -> true;
 +      {<<"stream:error">>, <<"jabber:component:accept">>,
 +       _} ->
 +        true;
 +      {<<"stream:error">>, <<>>,
 +       <<"jabber:component:accept">>} ->
 +        true;
 +      {<<"unsupported-version">>,
 +       <<"urn:ietf:params:xml:ns:xmpp-streams">>, _} ->
 +        true;
 +      {<<"unsupported-version">>, <<>>,
 +       <<"urn:ietf:params:xml:ns:xmpp-streams">>} ->
 +        true;
 +      {<<"unsupported-stanza-type">>,
 +       <<"urn:ietf:params:xml:ns:xmpp-streams">>, _} ->
 +        true;
 +      {<<"unsupported-stanza-type">>, <<>>,
 +       <<"urn:ietf:params:xml:ns:xmpp-streams">>} ->
 +        true;
 +      {<<"unsupported-encoding">>,
 +       <<"urn:ietf:params:xml:ns:xmpp-streams">>, _} ->
 +        true;
 +      {<<"unsupported-encoding">>, <<>>,
 +       <<"urn:ietf:params:xml:ns:xmpp-streams">>} ->
 +        true;
 +      {<<"undefined-condition">>,
 +       <<"urn:ietf:params:xml:ns:xmpp-streams">>, _} ->
 +        true;
 +      {<<"undefined-condition">>, <<>>,
 +       <<"urn:ietf:params:xml:ns:xmpp-streams">>} ->
 +        true;
 +      {<<"system-shutdown">>,
 +       <<"urn:ietf:params:xml:ns:xmpp-streams">>, _} ->
 +        true;
 +      {<<"system-shutdown">>, <<>>,
 +       <<"urn:ietf:params:xml:ns:xmpp-streams">>} ->
 +        true;
 +      {<<"see-other-host">>,
 +       <<"urn:ietf:params:xml:ns:xmpp-streams">>, _} ->
 +        true;
 +      {<<"see-other-host">>, <<>>,
 +       <<"urn:ietf:params:xml:ns:xmpp-streams">>} ->
 +        true;
 +      {<<"restricted-xml">>,
 +       <<"urn:ietf:params:xml:ns:xmpp-streams">>, _} ->
 +        true;
 +      {<<"restricted-xml">>, <<>>,
 +       <<"urn:ietf:params:xml:ns:xmpp-streams">>} ->
 +        true;
 +      {<<"resource-constraint">>,
 +       <<"urn:ietf:params:xml:ns:xmpp-streams">>, _} ->
 +        true;
 +      {<<"resource-constraint">>, <<>>,
 +       <<"urn:ietf:params:xml:ns:xmpp-streams">>} ->
 +        true;
 +      {<<"reset">>, <<"urn:ietf:params:xml:ns:xmpp-streams">>,
 +       _} ->
 +        true;
 +      {<<"reset">>, <<>>,
 +       <<"urn:ietf:params:xml:ns:xmpp-streams">>} ->
 +        true;
 +      {<<"remote-connection-failed">>,
 +       <<"urn:ietf:params:xml:ns:xmpp-streams">>, _} ->
 +        true;
 +      {<<"remote-connection-failed">>, <<>>,
 +       <<"urn:ietf:params:xml:ns:xmpp-streams">>} ->
 +        true;
 +      {<<"policy-violation">>,
 +       <<"urn:ietf:params:xml:ns:xmpp-streams">>, _} ->
 +        true;
 +      {<<"policy-violation">>, <<>>,
 +       <<"urn:ietf:params:xml:ns:xmpp-streams">>} ->
 +        true;
 +      {<<"not-well-formed">>,
 +       <<"urn:ietf:params:xml:ns:xmpp-streams">>, _} ->
 +        true;
 +      {<<"not-well-formed">>, <<>>,
 +       <<"urn:ietf:params:xml:ns:xmpp-streams">>} ->
 +        true;
 +      {<<"not-authorized">>,
 +       <<"urn:ietf:params:xml:ns:xmpp-streams">>, _} ->
 +        true;
 +      {<<"not-authorized">>, <<>>,
 +       <<"urn:ietf:params:xml:ns:xmpp-streams">>} ->
 +        true;
 +      {<<"invalid-xml">>,
 +       <<"urn:ietf:params:xml:ns:xmpp-streams">>, _} ->
 +        true;
 +      {<<"invalid-xml">>, <<>>,
 +       <<"urn:ietf:params:xml:ns:xmpp-streams">>} ->
 +        true;
 +      {<<"invalid-namespace">>,
 +       <<"urn:ietf:params:xml:ns:xmpp-streams">>, _} ->
 +        true;
 +      {<<"invalid-namespace">>, <<>>,
 +       <<"urn:ietf:params:xml:ns:xmpp-streams">>} ->
 +        true;
 +      {<<"invalid-id">>,
 +       <<"urn:ietf:params:xml:ns:xmpp-streams">>, _} ->
 +        true;
 +      {<<"invalid-id">>, <<>>,
 +       <<"urn:ietf:params:xml:ns:xmpp-streams">>} ->
 +        true;
 +      {<<"invalid-from">>,
 +       <<"urn:ietf:params:xml:ns:xmpp-streams">>, _} ->
 +        true;
 +      {<<"invalid-from">>, <<>>,
 +       <<"urn:ietf:params:xml:ns:xmpp-streams">>} ->
 +        true;
 +      {<<"internal-server-error">>,
 +       <<"urn:ietf:params:xml:ns:xmpp-streams">>, _} ->
 +        true;
 +      {<<"internal-server-error">>, <<>>,
 +       <<"urn:ietf:params:xml:ns:xmpp-streams">>} ->
 +        true;
 +      {<<"improper-addressing">>,
 +       <<"urn:ietf:params:xml:ns:xmpp-streams">>, _} ->
 +        true;
 +      {<<"improper-addressing">>, <<>>,
 +       <<"urn:ietf:params:xml:ns:xmpp-streams">>} ->
 +        true;
 +      {<<"host-unknown">>,
 +       <<"urn:ietf:params:xml:ns:xmpp-streams">>, _} ->
 +        true;
 +      {<<"host-unknown">>, <<>>,
 +       <<"urn:ietf:params:xml:ns:xmpp-streams">>} ->
 +        true;
 +      {<<"host-gone">>,
 +       <<"urn:ietf:params:xml:ns:xmpp-streams">>, _} ->
 +        true;
 +      {<<"host-gone">>, <<>>,
 +       <<"urn:ietf:params:xml:ns:xmpp-streams">>} ->
 +        true;
 +      {<<"connection-timeout">>,
 +       <<"urn:ietf:params:xml:ns:xmpp-streams">>, _} ->
 +        true;
 +      {<<"connection-timeout">>, <<>>,
 +       <<"urn:ietf:params:xml:ns:xmpp-streams">>} ->
 +        true;
 +      {<<"conflict">>,
 +       <<"urn:ietf:params:xml:ns:xmpp-streams">>, _} ->
 +        true;
 +      {<<"conflict">>, <<>>,
 +       <<"urn:ietf:params:xml:ns:xmpp-streams">>} ->
 +        true;
 +      {<<"bad-namespace-prefix">>,
 +       <<"urn:ietf:params:xml:ns:xmpp-streams">>, _} ->
 +        true;
 +      {<<"bad-namespace-prefix">>, <<>>,
 +       <<"urn:ietf:params:xml:ns:xmpp-streams">>} ->
 +        true;
 +      {<<"bad-format">>,
 +       <<"urn:ietf:params:xml:ns:xmpp-streams">>, _} ->
 +        true;
 +      {<<"bad-format">>, <<>>,
 +       <<"urn:ietf:params:xml:ns:xmpp-streams">>} ->
 +        true;
 +      {<<"text">>, <<"urn:ietf:params:xml:ns:xmpp-streams">>,
 +       _} ->
 +        true;
 +      {<<"text">>, <<>>,
 +       <<"urn:ietf:params:xml:ns:xmpp-streams">>} ->
 +        true;
 +      {<<"time">>, <<"urn:xmpp:time">>, _} -> true;
 +      {<<"time">>, <<>>, <<"urn:xmpp:time">>} -> true;
 +      {<<"tzo">>, <<"urn:xmpp:time">>, _} -> true;
 +      {<<"tzo">>, <<>>, <<"urn:xmpp:time">>} -> true;
 +      {<<"utc">>, <<"urn:xmpp:time">>, _} -> true;
 +      {<<"utc">>, <<>>, <<"urn:xmpp:time">>} -> true;
 +      {<<"ping">>, <<"urn:xmpp:ping">>, _} -> true;
 +      {<<"ping">>, <<>>, <<"urn:xmpp:ping">>} -> true;
 +      {<<"session">>,
 +       <<"urn:ietf:params:xml:ns:xmpp-session">>, _} ->
 +        true;
 +      {<<"session">>, <<>>,
 +       <<"urn:ietf:params:xml:ns:xmpp-session">>} ->
 +        true;
 +      {<<"optional">>,
 +       <<"urn:ietf:params:xml:ns:xmpp-session">>, _} ->
 +        true;
 +      {<<"optional">>, <<>>,
 +       <<"urn:ietf:params:xml:ns:xmpp-session">>} ->
 +        true;
 +      {<<"query">>, <<"jabber:iq:register">>, _} -> true;
 +      {<<"query">>, <<>>, <<"jabber:iq:register">>} -> true;
 +      {<<"key">>, <<"jabber:iq:register">>, _} -> true;
 +      {<<"key">>, <<>>, <<"jabber:iq:register">>} -> true;
 +      {<<"text">>, <<"jabber:iq:register">>, _} -> true;
 +      {<<"text">>, <<>>, <<"jabber:iq:register">>} -> true;
 +      {<<"misc">>, <<"jabber:iq:register">>, _} -> true;
 +      {<<"misc">>, <<>>, <<"jabber:iq:register">>} -> true;
 +      {<<"date">>, <<"jabber:iq:register">>, _} -> true;
 +      {<<"date">>, <<>>, <<"jabber:iq:register">>} -> true;
 +      {<<"url">>, <<"jabber:iq:register">>, _} -> true;
 +      {<<"url">>, <<>>, <<"jabber:iq:register">>} -> true;
 +      {<<"phone">>, <<"jabber:iq:register">>, _} -> true;
 +      {<<"phone">>, <<>>, <<"jabber:iq:register">>} -> true;
 +      {<<"zip">>, <<"jabber:iq:register">>, _} -> true;
 +      {<<"zip">>, <<>>, <<"jabber:iq:register">>} -> true;
 +      {<<"state">>, <<"jabber:iq:register">>, _} -> true;
 +      {<<"state">>, <<>>, <<"jabber:iq:register">>} -> true;
 +      {<<"city">>, <<"jabber:iq:register">>, _} -> true;
 +      {<<"city">>, <<>>, <<"jabber:iq:register">>} -> true;
 +      {<<"address">>, <<"jabber:iq:register">>, _} -> true;
 +      {<<"address">>, <<>>, <<"jabber:iq:register">>} -> true;
 +      {<<"email">>, <<"jabber:iq:register">>, _} -> true;
 +      {<<"email">>, <<>>, <<"jabber:iq:register">>} -> true;
 +      {<<"last">>, <<"jabber:iq:register">>, _} -> true;
 +      {<<"last">>, <<>>, <<"jabber:iq:register">>} -> true;
 +      {<<"first">>, <<"jabber:iq:register">>, _} -> true;
 +      {<<"first">>, <<>>, <<"jabber:iq:register">>} -> true;
 +      {<<"name">>, <<"jabber:iq:register">>, _} -> true;
 +      {<<"name">>, <<>>, <<"jabber:iq:register">>} -> true;
 +      {<<"password">>, <<"jabber:iq:register">>, _} -> true;
 +      {<<"password">>, <<>>, <<"jabber:iq:register">>} ->
 +        true;
 +      {<<"nick">>, <<"jabber:iq:register">>, _} -> true;
 +      {<<"nick">>, <<>>, <<"jabber:iq:register">>} -> true;
 +      {<<"username">>, <<"jabber:iq:register">>, _} -> true;
 +      {<<"username">>, <<>>, <<"jabber:iq:register">>} ->
 +        true;
 +      {<<"instructions">>, <<"jabber:iq:register">>, _} ->
 +        true;
 +      {<<"instructions">>, <<>>, <<"jabber:iq:register">>} ->
 +        true;
 +      {<<"remove">>, <<"jabber:iq:register">>, _} -> true;
 +      {<<"remove">>, <<>>, <<"jabber:iq:register">>} -> true;
 +      {<<"registered">>, <<"jabber:iq:register">>, _} -> true;
 +      {<<"registered">>, <<>>, <<"jabber:iq:register">>} ->
 +        true;
 +      {<<"register">>,
 +       <<"http://jabber.org/features/iq-register">>, _} ->
 +        true;
 +      {<<"register">>, <<>>,
 +       <<"http://jabber.org/features/iq-register">>} ->
 +        true;
 +      {<<"c">>, <<"http://jabber.org/protocol/caps">>, _} ->
 +        true;
 +      {<<"c">>, <<>>,
 +       <<"http://jabber.org/protocol/caps">>} ->
 +        true;
 +      {<<"ack">>, <<"p1:ack">>, _} -> true;
 +      {<<"ack">>, <<>>, <<"p1:ack">>} -> true;
 +      {<<"rebind">>, <<"p1:rebind">>, _} -> true;
 +      {<<"rebind">>, <<>>, <<"p1:rebind">>} -> true;
 +      {<<"push">>, <<"p1:push">>, _} -> true;
 +      {<<"push">>, <<>>, <<"p1:push">>} -> true;
 +      {<<"stream:features">>, <<"jabber:client">>, _} -> true;
 +      {<<"stream:features">>, <<>>, <<"jabber:client">>} ->
 +        true;
 +      {<<"stream:features">>, <<"jabber:server">>, _} -> true;
 +      {<<"stream:features">>, <<>>, <<"jabber:server">>} ->
 +        true;
 +      {<<"compression">>,
 +       <<"http://jabber.org/features/compress">>, _} ->
 +        true;
 +      {<<"compression">>, <<>>,
 +       <<"http://jabber.org/features/compress">>} ->
 +        true;
 +      {<<"method">>,
 +       <<"http://jabber.org/features/compress">>, _} ->
 +        true;
 +      {<<"method">>, <<>>,
 +       <<"http://jabber.org/features/compress">>} ->
 +        true;
 +      {<<"compressed">>,
 +       <<"http://jabber.org/protocol/compress">>, _} ->
 +        true;
 +      {<<"compressed">>, <<>>,
 +       <<"http://jabber.org/protocol/compress">>} ->
 +        true;
 +      {<<"compress">>,
 +       <<"http://jabber.org/protocol/compress">>, _} ->
 +        true;
 +      {<<"compress">>, <<>>,
 +       <<"http://jabber.org/protocol/compress">>} ->
 +        true;
 +      {<<"method">>,
 +       <<"http://jabber.org/protocol/compress">>, _} ->
 +        true;
 +      {<<"method">>, <<>>,
 +       <<"http://jabber.org/protocol/compress">>} ->
 +        true;
 +      {<<"failure">>,
 +       <<"http://jabber.org/protocol/compress">>, _} ->
 +        true;
 +      {<<"failure">>, <<>>,
 +       <<"http://jabber.org/protocol/compress">>} ->
 +        true;
 +      {<<"unsupported-method">>,
 +       <<"http://jabber.org/protocol/compress">>, _} ->
 +        true;
 +      {<<"unsupported-method">>, <<>>,
 +       <<"http://jabber.org/protocol/compress">>} ->
 +        true;
 +      {<<"processing-failed">>,
 +       <<"http://jabber.org/protocol/compress">>, _} ->
 +        true;
 +      {<<"processing-failed">>, <<>>,
 +       <<"http://jabber.org/protocol/compress">>} ->
 +        true;
 +      {<<"setup-failed">>,
 +       <<"http://jabber.org/protocol/compress">>, _} ->
 +        true;
 +      {<<"setup-failed">>, <<>>,
 +       <<"http://jabber.org/protocol/compress">>} ->
 +        true;
 +      {<<"failure">>, <<"urn:ietf:params:xml:ns:xmpp-tls">>,
 +       _} ->
 +        true;
 +      {<<"failure">>, <<>>,
 +       <<"urn:ietf:params:xml:ns:xmpp-tls">>} ->
 +        true;
 +      {<<"proceed">>, <<"urn:ietf:params:xml:ns:xmpp-tls">>,
 +       _} ->
 +        true;
 +      {<<"proceed">>, <<>>,
 +       <<"urn:ietf:params:xml:ns:xmpp-tls">>} ->
 +        true;
 +      {<<"starttls">>, <<"urn:ietf:params:xml:ns:xmpp-tls">>,
 +       _} ->
 +        true;
 +      {<<"starttls">>, <<>>,
 +       <<"urn:ietf:params:xml:ns:xmpp-tls">>} ->
 +        true;
 +      {<<"required">>, <<"urn:ietf:params:xml:ns:xmpp-tls">>,
 +       _} ->
 +        true;
 +      {<<"required">>, <<>>,
 +       <<"urn:ietf:params:xml:ns:xmpp-tls">>} ->
 +        true;
 +      {<<"mechanisms">>,
 +       <<"urn:ietf:params:xml:ns:xmpp-sasl">>, _} ->
 +        true;
 +      {<<"mechanisms">>, <<>>,
 +       <<"urn:ietf:params:xml:ns:xmpp-sasl">>} ->
 +        true;
 +      {<<"mechanism">>,
 +       <<"urn:ietf:params:xml:ns:xmpp-sasl">>, _} ->
 +        true;
 +      {<<"mechanism">>, <<>>,
 +       <<"urn:ietf:params:xml:ns:xmpp-sasl">>} ->
 +        true;
 +      {<<"failure">>, <<"urn:ietf:params:xml:ns:xmpp-sasl">>,
 +       _} ->
 +        true;
 +      {<<"failure">>, <<>>,
 +       <<"urn:ietf:params:xml:ns:xmpp-sasl">>} ->
 +        true;
 +      {<<"temporary-auth-failure">>,
 +       <<"urn:ietf:params:xml:ns:xmpp-sasl">>, _} ->
 +        true;
 +      {<<"temporary-auth-failure">>, <<>>,
 +       <<"urn:ietf:params:xml:ns:xmpp-sasl">>} ->
 +        true;
 +      {<<"bad-protocol">>,
 +       <<"urn:ietf:params:xml:ns:xmpp-sasl">>, _} ->
 +        true;
 +      {<<"bad-protocol">>, <<>>,
 +       <<"urn:ietf:params:xml:ns:xmpp-sasl">>} ->
 +        true;
 +      {<<"not-authorized">>,
 +       <<"urn:ietf:params:xml:ns:xmpp-sasl">>, _} ->
 +        true;
 +      {<<"not-authorized">>, <<>>,
 +       <<"urn:ietf:params:xml:ns:xmpp-sasl">>} ->
 +        true;
 +      {<<"mechanism-too-weak">>,
 +       <<"urn:ietf:params:xml:ns:xmpp-sasl">>, _} ->
 +        true;
 +      {<<"mechanism-too-weak">>, <<>>,
 +       <<"urn:ietf:params:xml:ns:xmpp-sasl">>} ->
 +        true;
 +      {<<"malformed-request">>,
 +       <<"urn:ietf:params:xml:ns:xmpp-sasl">>, _} ->
 +        true;
 +      {<<"malformed-request">>, <<>>,
 +       <<"urn:ietf:params:xml:ns:xmpp-sasl">>} ->
 +        true;
 +      {<<"invalid-mechanism">>,
 +       <<"urn:ietf:params:xml:ns:xmpp-sasl">>, _} ->
 +        true;
 +      {<<"invalid-mechanism">>, <<>>,
 +       <<"urn:ietf:params:xml:ns:xmpp-sasl">>} ->
 +        true;
 +      {<<"invalid-authzid">>,
 +       <<"urn:ietf:params:xml:ns:xmpp-sasl">>, _} ->
 +        true;
 +      {<<"invalid-authzid">>, <<>>,
 +       <<"urn:ietf:params:xml:ns:xmpp-sasl">>} ->
 +        true;
 +      {<<"incorrect-encoding">>,
 +       <<"urn:ietf:params:xml:ns:xmpp-sasl">>, _} ->
 +        true;
 +      {<<"incorrect-encoding">>, <<>>,
 +       <<"urn:ietf:params:xml:ns:xmpp-sasl">>} ->
 +        true;
 +      {<<"encryption-required">>,
 +       <<"urn:ietf:params:xml:ns:xmpp-sasl">>, _} ->
 +        true;
 +      {<<"encryption-required">>, <<>>,
 +       <<"urn:ietf:params:xml:ns:xmpp-sasl">>} ->
 +        true;
 +      {<<"credentials-expired">>,
 +       <<"urn:ietf:params:xml:ns:xmpp-sasl">>, _} ->
 +        true;
 +      {<<"credentials-expired">>, <<>>,
 +       <<"urn:ietf:params:xml:ns:xmpp-sasl">>} ->
 +        true;
 +      {<<"account-disabled">>,
 +       <<"urn:ietf:params:xml:ns:xmpp-sasl">>, _} ->
 +        true;
 +      {<<"account-disabled">>, <<>>,
 +       <<"urn:ietf:params:xml:ns:xmpp-sasl">>} ->
 +        true;
 +      {<<"aborted">>, <<"urn:ietf:params:xml:ns:xmpp-sasl">>,
 +       _} ->
 +        true;
 +      {<<"aborted">>, <<>>,
 +       <<"urn:ietf:params:xml:ns:xmpp-sasl">>} ->
 +        true;
 +      {<<"text">>, <<"urn:ietf:params:xml:ns:xmpp-sasl">>,
 +       _} ->
 +        true;
 +      {<<"text">>, <<>>,
 +       <<"urn:ietf:params:xml:ns:xmpp-sasl">>} ->
 +        true;
 +      {<<"success">>, <<"urn:ietf:params:xml:ns:xmpp-sasl">>,
 +       _} ->
 +        true;
 +      {<<"success">>, <<>>,
 +       <<"urn:ietf:params:xml:ns:xmpp-sasl">>} ->
 +        true;
 +      {<<"response">>, <<"urn:ietf:params:xml:ns:xmpp-sasl">>,
 +       _} ->
 +        true;
 +      {<<"response">>, <<>>,
 +       <<"urn:ietf:params:xml:ns:xmpp-sasl">>} ->
 +        true;
 +      {<<"challenge">>,
 +       <<"urn:ietf:params:xml:ns:xmpp-sasl">>, _} ->
 +        true;
 +      {<<"challenge">>, <<>>,
 +       <<"urn:ietf:params:xml:ns:xmpp-sasl">>} ->
 +        true;
 +      {<<"abort">>, <<"urn:ietf:params:xml:ns:xmpp-sasl">>,
 +       _} ->
 +        true;
 +      {<<"abort">>, <<>>,
 +       <<"urn:ietf:params:xml:ns:xmpp-sasl">>} ->
 +        true;
 +      {<<"auth">>, <<"urn:ietf:params:xml:ns:xmpp-sasl">>,
 +       _} ->
 +        true;
 +      {<<"auth">>, <<>>,
 +       <<"urn:ietf:params:xml:ns:xmpp-sasl">>} ->
 +        true;
 +      {<<"query">>, <<"jabber:iq:auth">>, _} -> true;
 +      {<<"query">>, <<>>, <<"jabber:iq:auth">>} -> true;
 +      {<<"resource">>, <<"jabber:iq:auth">>, _} -> true;
 +      {<<"resource">>, <<>>, <<"jabber:iq:auth">>} -> true;
 +      {<<"digest">>, <<"jabber:iq:auth">>, _} -> true;
 +      {<<"digest">>, <<>>, <<"jabber:iq:auth">>} -> true;
 +      {<<"password">>, <<"jabber:iq:auth">>, _} -> true;
 +      {<<"password">>, <<>>, <<"jabber:iq:auth">>} -> true;
 +      {<<"username">>, <<"jabber:iq:auth">>, _} -> true;
 +      {<<"username">>, <<>>, <<"jabber:iq:auth">>} -> true;
 +      {<<"bind">>, <<"urn:ietf:params:xml:ns:xmpp-bind">>,
 +       _} ->
 +        true;
 +      {<<"bind">>, <<>>,
 +       <<"urn:ietf:params:xml:ns:xmpp-bind">>} ->
 +        true;
 +      {<<"resource">>, <<"urn:ietf:params:xml:ns:xmpp-bind">>,
 +       _} ->
 +        true;
 +      {<<"resource">>, <<>>,
 +       <<"urn:ietf:params:xml:ns:xmpp-bind">>} ->
 +        true;
 +      {<<"jid">>, <<"urn:ietf:params:xml:ns:xmpp-bind">>,
 +       _} ->
 +        true;
 +      {<<"jid">>, <<>>,
 +       <<"urn:ietf:params:xml:ns:xmpp-bind">>} ->
 +        true;
 +      {<<"error">>, <<"jabber:client">>, _} -> true;
 +      {<<"error">>, <<>>, <<"jabber:client">>} -> true;
 +      {<<"error">>, <<"jabber:server">>, _} -> true;
 +      {<<"error">>, <<>>, <<"jabber:server">>} -> true;
 +      {<<"error">>, <<"jabber:component:accept">>, _} -> true;
 +      {<<"error">>, <<>>, <<"jabber:component:accept">>} ->
 +        true;
 +      {<<"text">>, <<"urn:ietf:params:xml:ns:xmpp-stanzas">>,
 +       _} ->
 +        true;
 +      {<<"text">>, <<>>,
 +       <<"urn:ietf:params:xml:ns:xmpp-stanzas">>} ->
 +        true;
 +      {<<"unexpected-request">>,
 +       <<"urn:ietf:params:xml:ns:xmpp-stanzas">>, _} ->
 +        true;
 +      {<<"unexpected-request">>, <<>>,
 +       <<"urn:ietf:params:xml:ns:xmpp-stanzas">>} ->
 +        true;
 +      {<<"undefined-condition">>,
 +       <<"urn:ietf:params:xml:ns:xmpp-stanzas">>, _} ->
 +        true;
 +      {<<"undefined-condition">>, <<>>,
 +       <<"urn:ietf:params:xml:ns:xmpp-stanzas">>} ->
 +        true;
 +      {<<"subscription-required">>,
 +       <<"urn:ietf:params:xml:ns:xmpp-stanzas">>, _} ->
 +        true;
 +      {<<"subscription-required">>, <<>>,
 +       <<"urn:ietf:params:xml:ns:xmpp-stanzas">>} ->
 +        true;
 +      {<<"service-unavailable">>,
 +       <<"urn:ietf:params:xml:ns:xmpp-stanzas">>, _} ->
 +        true;
 +      {<<"service-unavailable">>, <<>>,
 +       <<"urn:ietf:params:xml:ns:xmpp-stanzas">>} ->
 +        true;
 +      {<<"resource-constraint">>,
 +       <<"urn:ietf:params:xml:ns:xmpp-stanzas">>, _} ->
 +        true;
 +      {<<"resource-constraint">>, <<>>,
 +       <<"urn:ietf:params:xml:ns:xmpp-stanzas">>} ->
 +        true;
 +      {<<"remote-server-timeout">>,
 +       <<"urn:ietf:params:xml:ns:xmpp-stanzas">>, _} ->
 +        true;
 +      {<<"remote-server-timeout">>, <<>>,
 +       <<"urn:ietf:params:xml:ns:xmpp-stanzas">>} ->
 +        true;
 +      {<<"remote-server-not-found">>,
 +       <<"urn:ietf:params:xml:ns:xmpp-stanzas">>, _} ->
 +        true;
 +      {<<"remote-server-not-found">>, <<>>,
 +       <<"urn:ietf:params:xml:ns:xmpp-stanzas">>} ->
 +        true;
 +      {<<"registration-required">>,
 +       <<"urn:ietf:params:xml:ns:xmpp-stanzas">>, _} ->
 +        true;
 +      {<<"registration-required">>, <<>>,
 +       <<"urn:ietf:params:xml:ns:xmpp-stanzas">>} ->
 +        true;
 +      {<<"redirect">>,
 +       <<"urn:ietf:params:xml:ns:xmpp-stanzas">>, _} ->
 +        true;
 +      {<<"redirect">>, <<>>,
 +       <<"urn:ietf:params:xml:ns:xmpp-stanzas">>} ->
 +        true;
 +      {<<"recipient-unavailable">>,
 +       <<"urn:ietf:params:xml:ns:xmpp-stanzas">>, _} ->
 +        true;
 +      {<<"recipient-unavailable">>, <<>>,
 +       <<"urn:ietf:params:xml:ns:xmpp-stanzas">>} ->
 +        true;
 +      {<<"policy-violation">>,
 +       <<"urn:ietf:params:xml:ns:xmpp-stanzas">>, _} ->
 +        true;
 +      {<<"policy-violation">>, <<>>,
 +       <<"urn:ietf:params:xml:ns:xmpp-stanzas">>} ->
 +        true;
 +      {<<"payment-required">>,
 +       <<"urn:ietf:params:xml:ns:xmpp-stanzas">>, _} ->
 +        true;
 +      {<<"payment-required">>, <<>>,
 +       <<"urn:ietf:params:xml:ns:xmpp-stanzas">>} ->
 +        true;
 +      {<<"not-authorized">>,
 +       <<"urn:ietf:params:xml:ns:xmpp-stanzas">>, _} ->
 +        true;
 +      {<<"not-authorized">>, <<>>,
 +       <<"urn:ietf:params:xml:ns:xmpp-stanzas">>} ->
 +        true;
 +      {<<"not-allowed">>,
 +       <<"urn:ietf:params:xml:ns:xmpp-stanzas">>, _} ->
 +        true;
 +      {<<"not-allowed">>, <<>>,
 +       <<"urn:ietf:params:xml:ns:xmpp-stanzas">>} ->
 +        true;
 +      {<<"not-acceptable">>,
 +       <<"urn:ietf:params:xml:ns:xmpp-stanzas">>, _} ->
 +        true;
 +      {<<"not-acceptable">>, <<>>,
 +       <<"urn:ietf:params:xml:ns:xmpp-stanzas">>} ->
 +        true;
 +      {<<"jid-malformed">>,
 +       <<"urn:ietf:params:xml:ns:xmpp-stanzas">>, _} ->
 +        true;
 +      {<<"jid-malformed">>, <<>>,
 +       <<"urn:ietf:params:xml:ns:xmpp-stanzas">>} ->
 +        true;
 +      {<<"item-not-found">>,
 +       <<"urn:ietf:params:xml:ns:xmpp-stanzas">>, _} ->
 +        true;
 +      {<<"item-not-found">>, <<>>,
 +       <<"urn:ietf:params:xml:ns:xmpp-stanzas">>} ->
 +        true;
 +      {<<"internal-server-error">>,
 +       <<"urn:ietf:params:xml:ns:xmpp-stanzas">>, _} ->
 +        true;
 +      {<<"internal-server-error">>, <<>>,
 +       <<"urn:ietf:params:xml:ns:xmpp-stanzas">>} ->
 +        true;
 +      {<<"gone">>, <<"urn:ietf:params:xml:ns:xmpp-stanzas">>,
 +       _} ->
 +        true;
 +      {<<"gone">>, <<>>,
 +       <<"urn:ietf:params:xml:ns:xmpp-stanzas">>} ->
 +        true;
 +      {<<"forbidden">>,
 +       <<"urn:ietf:params:xml:ns:xmpp-stanzas">>, _} ->
 +        true;
 +      {<<"forbidden">>, <<>>,
 +       <<"urn:ietf:params:xml:ns:xmpp-stanzas">>} ->
 +        true;
 +      {<<"feature-not-implemented">>,
 +       <<"urn:ietf:params:xml:ns:xmpp-stanzas">>, _} ->
 +        true;
 +      {<<"feature-not-implemented">>, <<>>,
 +       <<"urn:ietf:params:xml:ns:xmpp-stanzas">>} ->
 +        true;
 +      {<<"conflict">>,
 +       <<"urn:ietf:params:xml:ns:xmpp-stanzas">>, _} ->
 +        true;
 +      {<<"conflict">>, <<>>,
 +       <<"urn:ietf:params:xml:ns:xmpp-stanzas">>} ->
 +        true;
 +      {<<"bad-request">>,
 +       <<"urn:ietf:params:xml:ns:xmpp-stanzas">>, _} ->
 +        true;
 +      {<<"bad-request">>, <<>>,
 +       <<"urn:ietf:params:xml:ns:xmpp-stanzas">>} ->
 +        true;
 +      {<<"presence">>, <<"jabber:client">>, _} -> true;
 +      {<<"presence">>, <<>>, <<"jabber:client">>} -> true;
 +      {<<"presence">>, <<"jabber:server">>, _} -> true;
 +      {<<"presence">>, <<>>, <<"jabber:server">>} -> true;
 +      {<<"presence">>, <<"jabber:component:accept">>, _} ->
 +        true;
 +      {<<"presence">>, <<>>, <<"jabber:component:accept">>} ->
 +        true;
 +      {<<"priority">>, <<"jabber:client">>, _} -> true;
 +      {<<"priority">>, <<>>, <<"jabber:client">>} -> true;
 +      {<<"priority">>, <<"jabber:server">>, _} -> true;
 +      {<<"priority">>, <<>>, <<"jabber:server">>} -> true;
 +      {<<"priority">>, <<"jabber:component:accept">>, _} ->
 +        true;
 +      {<<"priority">>, <<>>, <<"jabber:component:accept">>} ->
 +        true;
 +      {<<"status">>, <<"jabber:client">>, _} -> true;
 +      {<<"status">>, <<>>, <<"jabber:client">>} -> true;
 +      {<<"status">>, <<"jabber:server">>, _} -> true;
 +      {<<"status">>, <<>>, <<"jabber:server">>} -> true;
 +      {<<"status">>, <<"jabber:component:accept">>, _} ->
 +        true;
 +      {<<"status">>, <<>>, <<"jabber:component:accept">>} ->
 +        true;
 +      {<<"show">>, <<"jabber:client">>, _} -> true;
 +      {<<"show">>, <<>>, <<"jabber:client">>} -> true;
 +      {<<"show">>, <<"jabber:server">>, _} -> true;
 +      {<<"show">>, <<>>, <<"jabber:server">>} -> true;
 +      {<<"show">>, <<"jabber:component:accept">>, _} -> true;
 +      {<<"show">>, <<>>, <<"jabber:component:accept">>} ->
 +        true;
 +      {<<"message">>, <<"jabber:client">>, _} -> true;
 +      {<<"message">>, <<>>, <<"jabber:client">>} -> true;
 +      {<<"message">>, <<"jabber:server">>, _} -> true;
 +      {<<"message">>, <<>>, <<"jabber:server">>} -> true;
 +      {<<"message">>, <<"jabber:component:accept">>, _} ->
 +        true;
 +      {<<"message">>, <<>>, <<"jabber:component:accept">>} ->
 +        true;
 +      {<<"thread">>, <<"jabber:client">>, _} -> true;
 +      {<<"thread">>, <<>>, <<"jabber:client">>} -> true;
 +      {<<"thread">>, <<"jabber:server">>, _} -> true;
 +      {<<"thread">>, <<>>, <<"jabber:server">>} -> true;
 +      {<<"thread">>, <<"jabber:component:accept">>, _} ->
 +        true;
 +      {<<"thread">>, <<>>, <<"jabber:component:accept">>} ->
 +        true;
 +      {<<"body">>, <<"jabber:client">>, _} -> true;
 +      {<<"body">>, <<>>, <<"jabber:client">>} -> true;
 +      {<<"body">>, <<"jabber:server">>, _} -> true;
 +      {<<"body">>, <<>>, <<"jabber:server">>} -> true;
 +      {<<"body">>, <<"jabber:component:accept">>, _} -> true;
 +      {<<"body">>, <<>>, <<"jabber:component:accept">>} ->
 +        true;
 +      {<<"subject">>, <<"jabber:client">>, _} -> true;
 +      {<<"subject">>, <<>>, <<"jabber:client">>} -> true;
 +      {<<"subject">>, <<"jabber:server">>, _} -> true;
 +      {<<"subject">>, <<>>, <<"jabber:server">>} -> true;
 +      {<<"subject">>, <<"jabber:component:accept">>, _} ->
 +        true;
 +      {<<"subject">>, <<>>, <<"jabber:component:accept">>} ->
 +        true;
 +      {<<"iq">>, <<"jabber:client">>, _} -> true;
 +      {<<"iq">>, <<>>, <<"jabber:client">>} -> true;
 +      {<<"iq">>, <<"jabber:server">>, _} -> true;
 +      {<<"iq">>, <<>>, <<"jabber:server">>} -> true;
 +      {<<"iq">>, <<"jabber:component:accept">>, _} -> true;
 +      {<<"iq">>, <<>>, <<"jabber:component:accept">>} -> true;
 +      {<<"query">>, <<"http://jabber.org/protocol/stats">>,
 +       _} ->
 +        true;
 +      {<<"query">>, <<>>,
 +       <<"http://jabber.org/protocol/stats">>} ->
 +        true;
 +      {<<"stat">>, <<"http://jabber.org/protocol/stats">>,
 +       _} ->
 +        true;
 +      {<<"stat">>, <<>>,
 +       <<"http://jabber.org/protocol/stats">>} ->
 +        true;
 +      {<<"error">>, <<"http://jabber.org/protocol/stats">>,
 +       _} ->
 +        true;
 +      {<<"error">>, <<>>,
 +       <<"http://jabber.org/protocol/stats">>} ->
 +        true;
 +      {<<"storage">>, <<"storage:bookmarks">>, _} -> true;
 +      {<<"storage">>, <<>>, <<"storage:bookmarks">>} -> true;
 +      {<<"url">>, <<"storage:bookmarks">>, _} -> true;
 +      {<<"url">>, <<>>, <<"storage:bookmarks">>} -> true;
 +      {<<"conference">>, <<"storage:bookmarks">>, _} -> true;
 +      {<<"conference">>, <<>>, <<"storage:bookmarks">>} ->
 +        true;
 +      {<<"password">>, <<"storage:bookmarks">>, _} -> true;
 +      {<<"password">>, <<>>, <<"storage:bookmarks">>} -> true;
 +      {<<"nick">>, <<"storage:bookmarks">>, _} -> true;
 +      {<<"nick">>, <<>>, <<"storage:bookmarks">>} -> true;
 +      {<<"query">>, <<"jabber:iq:private">>, _} -> true;
 +      {<<"query">>, <<>>, <<"jabber:iq:private">>} -> true;
 +      {<<"query">>,
 +       <<"http://jabber.org/protocol/disco#items">>, _} ->
 +        true;
 +      {<<"query">>, <<>>,
 +       <<"http://jabber.org/protocol/disco#items">>} ->
 +        true;
 +      {<<"item">>,
 +       <<"http://jabber.org/protocol/disco#items">>, _} ->
 +        true;
 +      {<<"item">>, <<>>,
 +       <<"http://jabber.org/protocol/disco#items">>} ->
 +        true;
 +      {<<"query">>,
 +       <<"http://jabber.org/protocol/disco#info">>, _} ->
 +        true;
 +      {<<"query">>, <<>>,
 +       <<"http://jabber.org/protocol/disco#info">>} ->
 +        true;
 +      {<<"feature">>,
 +       <<"http://jabber.org/protocol/disco#info">>, _} ->
 +        true;
 +      {<<"feature">>, <<>>,
 +       <<"http://jabber.org/protocol/disco#info">>} ->
 +        true;
 +      {<<"identity">>,
 +       <<"http://jabber.org/protocol/disco#info">>, _} ->
 +        true;
 +      {<<"identity">>, <<>>,
 +       <<"http://jabber.org/protocol/disco#info">>} ->
 +        true;
 +      {<<"blocklist">>, <<"urn:xmpp:blocking">>, _} -> true;
 +      {<<"blocklist">>, <<>>, <<"urn:xmpp:blocking">>} ->
 +        true;
 +      {<<"unblock">>, <<"urn:xmpp:blocking">>, _} -> true;
 +      {<<"unblock">>, <<>>, <<"urn:xmpp:blocking">>} -> true;
 +      {<<"block">>, <<"urn:xmpp:blocking">>, _} -> true;
 +      {<<"block">>, <<>>, <<"urn:xmpp:blocking">>} -> true;
 +      {<<"item">>, <<"urn:xmpp:blocking">>, _} -> true;
 +      {<<"item">>, <<>>, <<"urn:xmpp:blocking">>} -> true;
 +      {<<"query">>, <<"jabber:iq:privacy">>, _} -> true;
 +      {<<"query">>, <<>>, <<"jabber:iq:privacy">>} -> true;
 +      {<<"active">>, <<"jabber:iq:privacy">>, _} -> true;
 +      {<<"active">>, <<>>, <<"jabber:iq:privacy">>} -> true;
 +      {<<"default">>, <<"jabber:iq:privacy">>, _} -> true;
 +      {<<"default">>, <<>>, <<"jabber:iq:privacy">>} -> true;
 +      {<<"list">>, <<"jabber:iq:privacy">>, _} -> true;
 +      {<<"list">>, <<>>, <<"jabber:iq:privacy">>} -> true;
 +      {<<"item">>, <<"jabber:iq:privacy">>, _} -> true;
 +      {<<"item">>, <<>>, <<"jabber:iq:privacy">>} -> true;
 +      {<<"presence-out">>, <<"jabber:iq:privacy">>, _} ->
 +        true;
 +      {<<"presence-out">>, <<>>, <<"jabber:iq:privacy">>} ->
 +        true;
 +      {<<"presence-in">>, <<"jabber:iq:privacy">>, _} -> true;
 +      {<<"presence-in">>, <<>>, <<"jabber:iq:privacy">>} ->
 +        true;
 +      {<<"iq">>, <<"jabber:iq:privacy">>, _} -> true;
 +      {<<"iq">>, <<>>, <<"jabber:iq:privacy">>} -> true;
 +      {<<"message">>, <<"jabber:iq:privacy">>, _} -> true;
 +      {<<"message">>, <<>>, <<"jabber:iq:privacy">>} -> true;
 +      {<<"ver">>, <<"urn:xmpp:features:rosterver">>, _} ->
 +        true;
 +      {<<"ver">>, <<>>, <<"urn:xmpp:features:rosterver">>} ->
 +        true;
 +      {<<"query">>, <<"jabber:iq:roster">>, _} -> true;
 +      {<<"query">>, <<>>, <<"jabber:iq:roster">>} -> true;
 +      {<<"item">>, <<"jabber:iq:roster">>, _} -> true;
 +      {<<"item">>, <<>>, <<"jabber:iq:roster">>} -> true;
 +      {<<"group">>, <<"jabber:iq:roster">>, _} -> true;
 +      {<<"group">>, <<>>, <<"jabber:iq:roster">>} -> true;
 +      {<<"query">>, <<"jabber:iq:version">>, _} -> true;
 +      {<<"query">>, <<>>, <<"jabber:iq:version">>} -> true;
 +      {<<"os">>, <<"jabber:iq:version">>, _} -> true;
 +      {<<"os">>, <<>>, <<"jabber:iq:version">>} -> true;
 +      {<<"version">>, <<"jabber:iq:version">>, _} -> true;
 +      {<<"version">>, <<>>, <<"jabber:iq:version">>} -> true;
 +      {<<"name">>, <<"jabber:iq:version">>, _} -> true;
 +      {<<"name">>, <<>>, <<"jabber:iq:version">>} -> true;
 +      {<<"query">>, <<"jabber:iq:last">>, _} -> true;
 +      {<<"query">>, <<>>, <<"jabber:iq:last">>} -> true;
 +      _ -> false
 +    end.
 +
 +encode(_el) -> encode(_el, <<>>).
 +
 +encode({xmlel, _, _, _} = El, _) -> El;
 +encode({last, _, _} = Query, TopXMLNS) ->
 +    encode_last(Query, TopXMLNS);
 +encode({version, _, _, _} = Query, TopXMLNS) ->
 +    encode_version(Query, TopXMLNS);
 +encode({roster_item, _, _, _, _, _} = Item, TopXMLNS) ->
 +    encode_roster_item(Item, TopXMLNS);
 +encode({roster_query, _, _} = Query, TopXMLNS) ->
 +    encode_roster_query(Query, TopXMLNS);
 +encode({rosterver_feature} = Ver, TopXMLNS) ->
 +    encode_rosterver_feature(Ver, TopXMLNS);
 +encode({privacy_item, _, _, _, _, _, _, _, _} = Item,
 +       TopXMLNS) ->
 +    encode_privacy_item(Item, TopXMLNS);
 +encode({privacy_list, _, _} = List, TopXMLNS) ->
 +    encode_privacy_list(List, TopXMLNS);
 +encode({privacy_query, _, _, _} = Query, TopXMLNS) ->
 +    encode_privacy(Query, TopXMLNS);
 +encode({block, _} = Block, TopXMLNS) ->
 +    encode_block(Block, TopXMLNS);
 +encode({unblock, _} = Unblock, TopXMLNS) ->
 +    encode_unblock(Unblock, TopXMLNS);
 +encode({block_list, _} = Blocklist, TopXMLNS) ->
 +    encode_block_list(Blocklist, TopXMLNS);
 +encode({identity, _, _, _, _} = Identity, TopXMLNS) ->
 +    encode_disco_identity(Identity, TopXMLNS);
 +encode({disco_info, _, _, _, _} = Query, TopXMLNS) ->
 +    encode_disco_info(Query, TopXMLNS);
 +encode({disco_item, _, _, _} = Item, TopXMLNS) ->
 +    encode_disco_item(Item, TopXMLNS);
 +encode({disco_items, _, _, _} = Query, TopXMLNS) ->
 +    encode_disco_items(Query, TopXMLNS);
 +encode({private, _} = Query, TopXMLNS) ->
 +    encode_private(Query, TopXMLNS);
 +encode({bookmark_conference, _, _, _, _, _} =
 +         Conference,
 +       TopXMLNS) ->
 +    encode_bookmark_conference(Conference, TopXMLNS);
 +encode({bookmark_url, _, _} = Url, TopXMLNS) ->
 +    encode_bookmark_url(Url, TopXMLNS);
 +encode({bookmark_storage, _, _} = Storage, TopXMLNS) ->
 +    encode_bookmarks_storage(Storage, TopXMLNS);
 +encode({stat_error, _, _} = Error, TopXMLNS) ->
 +    encode_stat_error(Error, TopXMLNS);
 +encode({stat, _, _, _, _} = Stat, TopXMLNS) ->
 +    encode_stat(Stat, TopXMLNS);
 +encode({stats, _, _} = Query, TopXMLNS) ->
 +    encode_stats(Query, TopXMLNS);
 +encode({iq, _, _, _, _, _, _} = Iq, TopXMLNS) ->
 +    encode_iq(Iq, TopXMLNS);
 +encode({message, _, _, _, _, _, _, _, _, _} = Message,
 +       TopXMLNS) ->
 +    encode_message(Message, TopXMLNS);
 +encode({presence, _, _, _, _, _, _, _, _, _} = Presence,
 +       TopXMLNS) ->
 +    encode_presence(Presence, TopXMLNS);
 +encode({gone, _} = Gone, TopXMLNS) ->
 +    encode_error_gone(Gone, TopXMLNS);
 +encode({redirect, _} = Redirect, TopXMLNS) ->
 +    encode_error_redirect(Redirect, TopXMLNS);
 +encode({stanza_error, _, _, _, _, _, _} = Error,
 +       TopXMLNS) ->
 +    encode_error(Error, TopXMLNS);
 +encode({bind, _, _} = Bind, TopXMLNS) ->
 +    encode_bind(Bind, TopXMLNS);
 +encode({legacy_auth, _, _, _, _} = Query, TopXMLNS) ->
 +    encode_legacy_auth(Query, TopXMLNS);
 +encode({sasl_auth, _, _} = Auth, TopXMLNS) ->
 +    encode_sasl_auth(Auth, TopXMLNS);
 +encode({sasl_abort} = Abort, TopXMLNS) ->
 +    encode_sasl_abort(Abort, TopXMLNS);
 +encode({sasl_challenge, _} = Challenge, TopXMLNS) ->
 +    encode_sasl_challenge(Challenge, TopXMLNS);
 +encode({sasl_response, _} = Response, TopXMLNS) ->
 +    encode_sasl_response(Response, TopXMLNS);
 +encode({sasl_success, _} = Success, TopXMLNS) ->
 +    encode_sasl_success(Success, TopXMLNS);
 +encode({sasl_failure, _, _} = Failure, TopXMLNS) ->
 +    encode_sasl_failure(Failure, TopXMLNS);
 +encode({sasl_mechanisms, _} = Mechanisms, TopXMLNS) ->
 +    encode_sasl_mechanisms(Mechanisms, TopXMLNS);
 +encode({starttls, _} = Starttls, TopXMLNS) ->
 +    encode_starttls(Starttls, TopXMLNS);
 +encode({starttls_proceed} = Proceed, TopXMLNS) ->
 +    encode_starttls_proceed(Proceed, TopXMLNS);
 +encode({starttls_failure} = Failure, TopXMLNS) ->
 +    encode_starttls_failure(Failure, TopXMLNS);
 +encode({compress_failure, _} = Failure, TopXMLNS) ->
 +    encode_compress_failure(Failure, TopXMLNS);
 +encode({compress, _} = Compress, TopXMLNS) ->
 +    encode_compress(Compress, TopXMLNS);
 +encode({compressed} = Compressed, TopXMLNS) ->
 +    encode_compressed(Compressed, TopXMLNS);
 +encode({compression, _} = Compression, TopXMLNS) ->
 +    encode_compression(Compression, TopXMLNS);
 +encode({stream_features, _} = Stream_features,
 +       TopXMLNS) ->
 +    encode_stream_features(Stream_features, TopXMLNS);
 +encode({p1_push} = Push, TopXMLNS) ->
 +    encode_p1_push(Push, TopXMLNS);
 +encode({p1_rebind} = Rebind, TopXMLNS) ->
 +    encode_p1_rebind(Rebind, TopXMLNS);
 +encode({p1_ack} = Ack, TopXMLNS) ->
 +    encode_p1_ack(Ack, TopXMLNS);
 +encode({caps, _, _, _, _} = C, TopXMLNS) ->
 +    encode_caps(C, TopXMLNS);
 +encode({feature_register} = Register, TopXMLNS) ->
 +    encode_feature_register(Register, TopXMLNS);
 +encode({register, _, _, _, _, _, _, _, _, _, _, _, _, _,
 +      _, _, _, _, _, _, _, _, _} =
 +         Query,
 +       TopXMLNS) ->
 +    encode_register(Query, TopXMLNS);
 +encode({xmpp_session, _} = Session, TopXMLNS) ->
 +    encode_session(Session, TopXMLNS);
 +encode({ping} = Ping, TopXMLNS) ->
 +    encode_ping(Ping, TopXMLNS);
 +encode({time, _, _} = Time, TopXMLNS) ->
 +    encode_time(Time, TopXMLNS);
 +encode({text, _, _} = Text, TopXMLNS) ->
 +    encode_stream_error_text(Text, TopXMLNS);
 +encode({'see-other-host', _} = See_other_host,
 +       TopXMLNS) ->
 +    encode_stream_error_see_other_host(See_other_host,
 +                                     TopXMLNS);
 +encode({stream_error, _, _} = Stream_error, TopXMLNS) ->
 +    encode_stream_error(Stream_error, TopXMLNS);
 +encode({vcard_name, _, _, _, _, _} = N, TopXMLNS) ->
 +    encode_vcard_N(N, TopXMLNS);
 +encode({vcard_adr, _, _, _, _, _, _, _, _, _, _, _, _,
 +      _, _} =
 +         Adr,
 +       TopXMLNS) ->
 +    encode_vcard_ADR(Adr, TopXMLNS);
 +encode({vcard_label, _, _, _, _, _, _, _, _} = Label,
 +       TopXMLNS) ->
 +    encode_vcard_LABEL(Label, TopXMLNS);
 +encode({vcard_tel, _, _, _, _, _, _, _, _, _, _, _, _,
 +      _, _} =
 +         Tel,
 +       TopXMLNS) ->
 +    encode_vcard_TEL(Tel, TopXMLNS);
 +encode({vcard_email, _, _, _, _, _, _} = Email,
 +       TopXMLNS) ->
 +    encode_vcard_EMAIL(Email, TopXMLNS);
 +encode({vcard_geo, _, _} = Geo, TopXMLNS) ->
 +    encode_vcard_GEO(Geo, TopXMLNS);
 +encode({vcard_logo, _, _, _} = Logo, TopXMLNS) ->
 +    encode_vcard_LOGO(Logo, TopXMLNS);
 +encode({vcard_photo, _, _, _} = Photo, TopXMLNS) ->
 +    encode_vcard_PHOTO(Photo, TopXMLNS);
 +encode({vcard_org, _, _} = Org, TopXMLNS) ->
 +    encode_vcard_ORG(Org, TopXMLNS);
 +encode({vcard_sound, _, _, _} = Sound, TopXMLNS) ->
 +    encode_vcard_SOUND(Sound, TopXMLNS);
 +encode({vcard_key, _, _} = Key, TopXMLNS) ->
 +    encode_vcard_KEY(Key, TopXMLNS);
 +encode({vcard_temp, _, _, _, _, _, _, _, _, _, _, _, _,
 +      _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _} =
 +         Vcard,
 +       TopXMLNS) ->
 +    encode_vcard_temp(Vcard, TopXMLNS);
 +encode({vcard_xupdate, _, _} = X, TopXMLNS) ->
 +    encode_vcard_xupdate(X, TopXMLNS);
 +encode({xdata_option, _, _} = Option, TopXMLNS) ->
 +    encode_xdata_field_option(Option, TopXMLNS);
 +encode({xdata_field, _, _, _, _, _, _, _, _} = Field,
 +       TopXMLNS) ->
 +    encode_xdata_field(Field, TopXMLNS);
 +encode({xdata, _, _, _, _, _, _} = X, TopXMLNS) ->
 +    encode_xdata(X, TopXMLNS);
 +encode({ps_subscription, _, _, _, _, _, _} =
 +         Subscription,
 +       TopXMLNS) ->
 +    encode_pubsub_subscription(Subscription, TopXMLNS);
 +encode({ps_affiliation,
 +      <<"http://jabber.org/protocol/pubsub">>, _, _, _} =
 +         Affiliation,
 +       TopXMLNS) ->
 +    encode_pubsub_affiliation(Affiliation, TopXMLNS);
 +encode({ps_affiliation, <<>>, _, _, _} = Affiliation,
 +       TopXMLNS = <<"http://jabber.org/protocol/pubsub">>) ->
 +    encode_pubsub_affiliation(Affiliation, TopXMLNS);
 +encode({ps_affiliation,
 +      <<"http://jabber.org/protocol/pubsub#owner">>, _, _,
 +      _} =
 +         Affiliation,
 +       TopXMLNS) ->
 +    encode_pubsub_owner_affiliation(Affiliation, TopXMLNS);
 +encode({ps_affiliation, <<>>, _, _, _} = Affiliation,
 +       TopXMLNS =
 +         <<"http://jabber.org/protocol/pubsub#owner">>) ->
 +    encode_pubsub_owner_affiliation(Affiliation, TopXMLNS);
 +encode({ps_item, _, _, _, _, _} = Item, TopXMLNS) ->
 +    encode_pubsub_item(Item, TopXMLNS);
 +encode({ps_items, _, _, _, _, _, _} = Items,
 +       TopXMLNS) ->
 +    encode_pubsub_items(Items, TopXMLNS);
 +encode({ps_event, _, _, _, _, _, _} = Event,
 +       TopXMLNS) ->
 +    encode_pubsub_event(Event, TopXMLNS);
 +encode({ps_subscribe, _, _} = Subscribe, TopXMLNS) ->
 +    encode_pubsub_subscribe(Subscribe, TopXMLNS);
 +encode({ps_unsubscribe, _, _, _} = Unsubscribe,
 +       TopXMLNS) ->
 +    encode_pubsub_unsubscribe(Unsubscribe, TopXMLNS);
 +encode({ps_publish, _, _} = Publish, TopXMLNS) ->
 +    encode_pubsub_publish(Publish, TopXMLNS);
 +encode({ps_options, _, _, _, _} = Options, TopXMLNS) ->
 +    encode_pubsub_options(Options, TopXMLNS);
 +encode({ps_retract, _, _, _} = Retract, TopXMLNS) ->
 +    encode_pubsub_retract(Retract, TopXMLNS);
 +encode({pubsub, _, _, _, _, _, _, _, _, _, _, _, _, _,
 +      _, _, _} =
 +         Pubsub,
 +       TopXMLNS) ->
 +    encode_pubsub(Pubsub, TopXMLNS);
 +encode({pubsub_owner, _, _, _, _, _, _} = Pubsub,
 +       TopXMLNS) ->
 +    encode_pubsub_owner(Pubsub, TopXMLNS);
 +encode({ps_error, 'closed-node', _} = Closed_node,
 +       TopXMLNS) ->
 +    encode_pubsub_error_closed_node(Closed_node, TopXMLNS);
 +encode({ps_error, 'configuration-required', _} =
 +         Configuration_required,
 +       TopXMLNS) ->
 +    encode_pubsub_error_configuration_required(Configuration_required,
 +                                             TopXMLNS);
 +encode({ps_error, 'invalid-jid', _} = Invalid_jid,
 +       TopXMLNS) ->
 +    encode_pubsub_error_invalid_jid(Invalid_jid, TopXMLNS);
 +encode({ps_error, 'invalid-options', _} =
 +         Invalid_options,
 +       TopXMLNS) ->
 +    encode_pubsub_error_invalid_options(Invalid_options,
 +                                      TopXMLNS);
 +encode({ps_error, 'invalid-payload', _} =
 +         Invalid_payload,
 +       TopXMLNS) ->
 +    encode_pubsub_error_invalid_payload(Invalid_payload,
 +                                      TopXMLNS);
 +encode({ps_error, 'invalid-subid', _} = Invalid_subid,
 +       TopXMLNS) ->
 +    encode_pubsub_error_invalid_subid(Invalid_subid,
 +                                    TopXMLNS);
 +encode({ps_error, 'item-forbidden', _} = Item_forbidden,
 +       TopXMLNS) ->
 +    encode_pubsub_error_item_forbidden(Item_forbidden,
 +                                     TopXMLNS);
 +encode({ps_error, 'item-required', _} = Item_required,
 +       TopXMLNS) ->
 +    encode_pubsub_error_item_required(Item_required,
 +                                    TopXMLNS);
 +encode({ps_error, 'jid-required', _} = Jid_required,
 +       TopXMLNS) ->
 +    encode_pubsub_error_jid_required(Jid_required,
 +                                   TopXMLNS);
 +encode({ps_error, 'max-items-exceeded', _} =
 +         Max_items_exceeded,
 +       TopXMLNS) ->
 +    encode_pubsub_error_max_items_exceeded(Max_items_exceeded,
 +                                         TopXMLNS);
 +encode({ps_error, 'max-nodes-exceeded', _} =
 +         Max_nodes_exceeded,
 +       TopXMLNS) ->
 +    encode_pubsub_error_max_nodes_exceeded(Max_nodes_exceeded,
 +                                         TopXMLNS);
 +encode({ps_error, 'nodeid-required', _} =
 +         Nodeid_required,
 +       TopXMLNS) ->
 +    encode_pubsub_error_nodeid_required(Nodeid_required,
 +                                      TopXMLNS);
 +encode({ps_error, 'not-in-roster-group', _} =
 +         Not_in_roster_group,
 +       TopXMLNS) ->
 +    encode_pubsub_error_not_in_roster_group(Not_in_roster_group,
 +                                          TopXMLNS);
 +encode({ps_error, 'not-subscribed', _} = Not_subscribed,
 +       TopXMLNS) ->
 +    encode_pubsub_error_not_subscribed(Not_subscribed,
 +                                     TopXMLNS);
 +encode({ps_error, 'payload-too-big', _} =
 +         Payload_too_big,
 +       TopXMLNS) ->
 +    encode_pubsub_error_payload_too_big(Payload_too_big,
 +                                      TopXMLNS);
 +encode({ps_error, 'payload-required', _} =
 +         Payload_required,
 +       TopXMLNS) ->
 +    encode_pubsub_error_payload_required(Payload_required,
 +                                       TopXMLNS);
 +encode({ps_error, 'pending-subscription', _} =
 +         Pending_subscription,
 +       TopXMLNS) ->
 +    encode_pubsub_error_pending_subscription(Pending_subscription,
 +                                           TopXMLNS);
 +encode({ps_error, 'presence-subscription-required', _} =
 +         Presence_subscription_required,
 +       TopXMLNS) ->
 +    encode_pubsub_error_presence_subscription_required(Presence_subscription_required,
 +                                                     TopXMLNS);
 +encode({ps_error, 'subid-required', _} = Subid_required,
 +       TopXMLNS) ->
 +    encode_pubsub_error_subid_required(Subid_required,
 +                                     TopXMLNS);
 +encode({ps_error, 'too-many-subscriptions', _} =
 +         Too_many_subscriptions,
 +       TopXMLNS) ->
 +    encode_pubsub_error_too_many_subscriptions(Too_many_subscriptions,
 +                                             TopXMLNS);
 +encode({ps_error, unsupported, _} = Unsupported,
 +       TopXMLNS) ->
 +    encode_pubsub_error_unsupported(Unsupported, TopXMLNS);
 +encode({ps_error, 'unsupported-access-model', _} =
 +         Unsupported_access_model,
 +       TopXMLNS) ->
 +    encode_pubsub_error_unsupported_access_model(Unsupported_access_model,
 +                                               TopXMLNS);
 +encode({shim, _} = Headers, TopXMLNS) ->
 +    encode_shim_headers(Headers, TopXMLNS);
 +encode({chatstate, active} = Active, TopXMLNS) ->
 +    encode_chatstate_active(Active, TopXMLNS);
 +encode({chatstate, composing} = Composing, TopXMLNS) ->
 +    encode_chatstate_composing(Composing, TopXMLNS);
 +encode({chatstate, gone} = Gone, TopXMLNS) ->
 +    encode_chatstate_gone(Gone, TopXMLNS);
 +encode({chatstate, inactive} = Inactive, TopXMLNS) ->
 +    encode_chatstate_inactive(Inactive, TopXMLNS);
 +encode({chatstate, paused} = Paused, TopXMLNS) ->
 +    encode_chatstate_paused(Paused, TopXMLNS);
 +encode({delay, _, _, _} = Delay, TopXMLNS) ->
 +    encode_delay(Delay, TopXMLNS);
 +encode({streamhost, _, _, _} = Streamhost, TopXMLNS) ->
 +    encode_bytestreams_streamhost(Streamhost, TopXMLNS);
 +encode({bytestreams, _, _, _, _, _, _} = Query,
 +       TopXMLNS) ->
 +    encode_bytestreams(Query, TopXMLNS);
 +encode({muc_history, _, _, _, _} = History, TopXMLNS) ->
 +    encode_muc_history(History, TopXMLNS);
 +encode({muc_decline, _, _, _} = Decline, TopXMLNS) ->
 +    encode_muc_user_decline(Decline, TopXMLNS);
 +encode({muc_destroy, _, _, _, _} = Destroy, TopXMLNS) ->
 +    encode_muc_destroy(Destroy, TopXMLNS);
 +encode({muc_invite, _, _, _, _} = Invite, TopXMLNS) ->
 +    encode_muc_user_invite(Invite, TopXMLNS);
 +encode({muc_user, _, _, _, _, _, _} = X, TopXMLNS) ->
 +    encode_muc_user(X, TopXMLNS);
 +encode({muc_owner, _, _, _} = Query, TopXMLNS) ->
 +    encode_muc_owner(Query, TopXMLNS);
 +encode({muc_item, _, _, _, _, _, _, _} = Item,
 +       TopXMLNS) ->
 +    encode_muc_admin_item(Item, TopXMLNS);
 +encode({muc_actor, _, _} = Actor, TopXMLNS) ->
 +    encode_muc_admin_actor(Actor, TopXMLNS);
 +encode({muc_admin, _} = Query, TopXMLNS) ->
 +    encode_muc_admin(Query, TopXMLNS);
 +encode({muc, _, _} = X, TopXMLNS) ->
 +    encode_muc(X, TopXMLNS);
 +encode({muc_unique, _} = Unique, TopXMLNS) ->
 +    encode_muc_unique(Unique, TopXMLNS);
 +encode({x_conference, _, _, _, _, _} = X, TopXMLNS) ->
 +    encode_x_conference(X, TopXMLNS);
 +encode({muc_subscriptions, _} = Subscriptions,
 +       TopXMLNS) ->
 +    encode_muc_subscriptions(Subscriptions, TopXMLNS);
 +encode({muc_subscribe, _, _} = Subscribe, TopXMLNS) ->
 +    encode_muc_subscribe(Subscribe, TopXMLNS);
 +encode({muc_unsubscribe} = Unsubscribe, TopXMLNS) ->
 +    encode_muc_unsubscribe(Unsubscribe, TopXMLNS);
 +encode({rsm_first, _, _} = First, TopXMLNS) ->
 +    encode_rsm_first(First, TopXMLNS);
 +encode({rsm_set, _, _, _, _, _, _, _} = Set,
 +       TopXMLNS) ->
 +    encode_rsm_set(Set, TopXMLNS);
 +encode({mam_query, _, _, _, _, _, _, _, _} = Query,
 +       TopXMLNS) ->
 +    encode_mam_query(Query, TopXMLNS);
 +encode({mam_archived, _, _} = Archived, TopXMLNS) ->
 +    encode_mam_archived(Archived, TopXMLNS);
 +encode({mam_result, _, _, _, _} = Result, TopXMLNS) ->
 +    encode_mam_result(Result, TopXMLNS);
 +encode({mam_prefs, _, _, _, _} = Prefs, TopXMLNS) ->
 +    encode_mam_prefs(Prefs, TopXMLNS);
 +encode({mam_fin, _, _, _, _, _} = Fin, TopXMLNS) ->
 +    encode_mam_fin(Fin, TopXMLNS);
 +encode({forwarded, _, _} = Forwarded, TopXMLNS) ->
 +    encode_forwarded(Forwarded, TopXMLNS);
 +encode({carbons_disable} = Disable, TopXMLNS) ->
 +    encode_carbons_disable(Disable, TopXMLNS);
 +encode({carbons_enable} = Enable, TopXMLNS) ->
 +    encode_carbons_enable(Enable, TopXMLNS);
 +encode({carbons_private} = Private, TopXMLNS) ->
 +    encode_carbons_private(Private, TopXMLNS);
 +encode({carbons_received, _} = Received, TopXMLNS) ->
 +    encode_carbons_received(Received, TopXMLNS);
 +encode({carbons_sent, _} = Sent, TopXMLNS) ->
 +    encode_carbons_sent(Sent, TopXMLNS);
 +encode({feature_csi, <<"urn:xmpp:csi:0">>} = Csi,
 +       TopXMLNS) ->
 +    encode_feature_csi(Csi, TopXMLNS);
 +encode({feature_csi, <<>>} = Csi,
 +       TopXMLNS = <<"urn:xmpp:csi:0">>) ->
 +    encode_feature_csi(Csi, TopXMLNS);
 +encode({csi, active} = Active, TopXMLNS) ->
 +    encode_csi_active(Active, TopXMLNS);
 +encode({csi, inactive} = Inactive, TopXMLNS) ->
 +    encode_csi_inactive(Inactive, TopXMLNS);
 +encode({feature_sm, _} = Sm, TopXMLNS) ->
 +    encode_feature_sm(Sm, TopXMLNS);
 +encode({sm_enable, _, _, _} = Enable, TopXMLNS) ->
 +    encode_sm_enable(Enable, TopXMLNS);
 +encode({sm_enabled, _, _, _, _, _} = Enabled,
 +       TopXMLNS) ->
 +    encode_sm_enabled(Enabled, TopXMLNS);
 +encode({sm_resume, _, _, _} = Resume, TopXMLNS) ->
 +    encode_sm_resume(Resume, TopXMLNS);
 +encode({sm_resumed, _, _, _} = Resumed, TopXMLNS) ->
 +    encode_sm_resumed(Resumed, TopXMLNS);
 +encode({sm_r, _} = R, TopXMLNS) ->
 +    encode_sm_r(R, TopXMLNS);
 +encode({sm_a, _, _} = A, TopXMLNS) ->
 +    encode_sm_a(A, TopXMLNS);
 +encode({sm_failed, _, _, _} = Failed, TopXMLNS) ->
 +    encode_sm_failed(Failed, TopXMLNS);
 +encode({offline_item, _, _} = Item, TopXMLNS) ->
 +    encode_offline_item(Item, TopXMLNS);
 +encode({offline, _, _, _} = Offline, TopXMLNS) ->
 +    encode_offline(Offline, TopXMLNS);
 +encode({mix_join, _, _} = Join, TopXMLNS) ->
 +    encode_mix_join(Join, TopXMLNS);
 +encode({mix_leave} = Leave, TopXMLNS) ->
 +    encode_mix_leave(Leave, TopXMLNS);
 +encode({mix_participant, _, _} = Participant,
 +       TopXMLNS) ->
 +    encode_mix_participant(Participant, TopXMLNS);
 +encode({hint, 'no-copy'} = No_copy, TopXMLNS) ->
 +    encode_hint_no_copy(No_copy, TopXMLNS);
 +encode({hint, 'no-store'} = No_store, TopXMLNS) ->
 +    encode_hint_no_store(No_store, TopXMLNS);
 +encode({hint, 'no-storage'} = No_storage, TopXMLNS) ->
 +    encode_hint_no_storage(No_storage, TopXMLNS);
 +encode({hint, store} = Store, TopXMLNS) ->
 +    encode_hint_store(Store, TopXMLNS);
 +encode({hint, 'no-permanent-store'} =
 +         No_permanent_store,
 +       TopXMLNS) ->
 +    encode_hint_no_permanent_store(No_permanent_store,
 +                                 TopXMLNS);
 +encode({hint, 'no-permanent-storage'} =
 +         No_permanent_storage,
 +       TopXMLNS) ->
 +    encode_hint_no_permanent_storage(No_permanent_storage,
 +                                   TopXMLNS);
 +encode({search_item, _, _, _, _, _} = Item, TopXMLNS) ->
 +    encode_search_item(Item, TopXMLNS);
 +encode({search, _, _, _, _, _, _, _} = Query,
 +       TopXMLNS) ->
 +    encode_search(Query, TopXMLNS);
 +encode({xevent, _, _, _, _, _} = X, TopXMLNS) ->
 +    encode_xevent(X, TopXMLNS);
 +encode({expire, _, _} = X, TopXMLNS) ->
 +    encode_expire(X, TopXMLNS);
 +encode({nick, _} = Nick, TopXMLNS) ->
 +    encode_nick(Nick, TopXMLNS);
 +encode({address, _, _, _, _, _} = Address, TopXMLNS) ->
 +    encode_address(Address, TopXMLNS);
 +encode({addresses, _} = Addresses, TopXMLNS) ->
 +    encode_addresses(Addresses, TopXMLNS);
 +encode({stanza_id, _, _} = Stanza_id, TopXMLNS) ->
 +    encode_stanza_id(Stanza_id, TopXMLNS);
 +encode({client_id, _} = Client_id, TopXMLNS) ->
 +    encode_client_id(Client_id, TopXMLNS);
 +encode({adhoc_actions, _, _, _, _} = Actions,
 +       TopXMLNS) ->
 +    encode_adhoc_command_actions(Actions, TopXMLNS);
 +encode({adhoc_note, _, _} = Note, TopXMLNS) ->
 +    encode_adhoc_command_notes(Note, TopXMLNS);
 +encode({adhoc_command, _, _, _, _, _, _, _, _} =
 +         Command,
 +       TopXMLNS) ->
 +    encode_adhoc_command(Command, TopXMLNS);
 +encode({db_result, _, _, _, _, _} = Db_result,
 +       TopXMLNS) ->
 +    encode_db_result(Db_result, TopXMLNS);
 +encode({db_verify, _, _, _, _, _, _} = Db_verify,
 +       TopXMLNS) ->
 +    encode_db_verify(Db_verify, TopXMLNS);
 +encode({handshake, _} = Handshake, TopXMLNS) ->
 +    encode_handshake(Handshake, TopXMLNS);
 +encode({stream_start, _, _, _, _, _, _, _, _} =
 +         Stream_stream,
 +       TopXMLNS) ->
 +    encode_stream_start(Stream_stream, TopXMLNS);
 +encode({bob_data, _, _, _, _} = Data, TopXMLNS) ->
 +    encode_bob_data(Data, TopXMLNS);
 +encode({xcaptcha, _} = Captcha, TopXMLNS) ->
 +    encode_captcha(Captcha, TopXMLNS);
 +encode({media_uri, _, _} = Uri, TopXMLNS) ->
 +    encode_media_uri(Uri, TopXMLNS);
 +encode({media, _, _, _} = Media, TopXMLNS) ->
 +    encode_media(Media, TopXMLNS);
 +encode({oob_x, _, _, _} = X, TopXMLNS) ->
 +    encode_oob_x(X, TopXMLNS);
 +encode({sic, _, _, _} = Address, TopXMLNS) ->
 +    encode_sic(Address, TopXMLNS);
 +encode({upload_request, _, _, _, _} = Request,
 +       TopXMLNS) ->
 +    encode_upload_request(Request, TopXMLNS);
 +encode({upload_slot, _, _, _} = Slot, TopXMLNS) ->
 +    encode_upload_slot(Slot, TopXMLNS);
 +encode({thumbnail, _, _, _, _} = Thumbnail, TopXMLNS) ->
++    encode_thumbnail(Thumbnail, TopXMLNS);
++encode({privilege_perm, _, _} = Perm, TopXMLNS) ->
++    encode_privilege_perm(Perm, TopXMLNS);
++encode({privilege, _, _} = Privilege, TopXMLNS) ->
++    encode_privilege(Privilege, TopXMLNS);
++encode({delegated, _, _} = Delegated, TopXMLNS) ->
++    encode_delegated(Delegated, TopXMLNS);
++encode({delegation, _, _} = Delegation, TopXMLNS) ->
++    encode_delegation(Delegation, TopXMLNS);
++encode({delegation_query, _, _} = Query, TopXMLNS) ->
++    encode_delegation_query(Query, TopXMLNS).
 +
 +get_name({address, _, _, _, _, _}) -> <<"address">>;
 +get_name({addresses, _}) -> <<"addresses">>;
 +get_name({adhoc_actions, _, _, _, _}) -> <<"actions">>;
 +get_name({adhoc_command, _, _, _, _, _, _, _, _}) ->
 +    <<"command">>;
 +get_name({adhoc_note, _, _}) -> <<"note">>;
 +get_name({bind, _, _}) -> <<"bind">>;
 +get_name({block, _}) -> <<"block">>;
 +get_name({block_list, _}) -> <<"blocklist">>;
 +get_name({bob_data, _, _, _, _}) -> <<"data">>;
 +get_name({bookmark_conference, _, _, _, _, _}) ->
 +    <<"conference">>;
 +get_name({bookmark_storage, _, _}) -> <<"storage">>;
 +get_name({bookmark_url, _, _}) -> <<"url">>;
 +get_name({bytestreams, _, _, _, _, _, _}) ->
 +    <<"query">>;
 +get_name({caps, _, _, _, _}) -> <<"c">>;
 +get_name({carbons_disable}) -> <<"disable">>;
 +get_name({carbons_enable}) -> <<"enable">>;
 +get_name({carbons_private}) -> <<"private">>;
 +get_name({carbons_received, _}) -> <<"received">>;
 +get_name({carbons_sent, _}) -> <<"sent">>;
 +get_name({chatstate, active}) -> <<"active">>;
 +get_name({chatstate, composing}) -> <<"composing">>;
 +get_name({chatstate, gone}) -> <<"gone">>;
 +get_name({chatstate, inactive}) -> <<"inactive">>;
 +get_name({chatstate, paused}) -> <<"paused">>;
 +get_name({client_id, _}) -> <<"client-id">>;
 +get_name({compress, _}) -> <<"compress">>;
 +get_name({compress_failure, _}) -> <<"failure">>;
 +get_name({compressed}) -> <<"compressed">>;
 +get_name({compression, _}) -> <<"compression">>;
 +get_name({csi, active}) -> <<"active">>;
 +get_name({csi, inactive}) -> <<"inactive">>;
 +get_name({db_result, _, _, _, _, _}) -> <<"db:result">>;
 +get_name({db_verify, _, _, _, _, _, _}) ->
 +    <<"db:verify">>;
 +get_name({delay, _, _, _}) -> <<"delay">>;
++get_name({delegated, _, _}) -> <<"delegated">>;
++get_name({delegation, _, _}) -> <<"delegation">>;
++get_name({delegation_query, _, _}) -> <<"query">>;
 +get_name({disco_info, _, _, _, _}) -> <<"query">>;
 +get_name({disco_item, _, _, _}) -> <<"item">>;
 +get_name({disco_items, _, _, _}) -> <<"query">>;
 +get_name({expire, _, _}) -> <<"x">>;
 +get_name({feature_csi, _}) -> <<"csi">>;
 +get_name({feature_register}) -> <<"register">>;
 +get_name({feature_sm, _}) -> <<"sm">>;
 +get_name({forwarded, _, _}) -> <<"forwarded">>;
 +get_name({gone, _}) -> <<"gone">>;
 +get_name({handshake, _}) -> <<"handshake">>;
 +get_name({hint, 'no-copy'}) -> <<"no-copy">>;
 +get_name({hint, 'no-permanent-storage'}) ->
 +    <<"no-permanent-storage">>;
 +get_name({hint, 'no-permanent-store'}) ->
 +    <<"no-permanent-store">>;
 +get_name({hint, 'no-storage'}) -> <<"no-storage">>;
 +get_name({hint, 'no-store'}) -> <<"no-store">>;
 +get_name({hint, store}) -> <<"store">>;
 +get_name({identity, _, _, _, _}) -> <<"identity">>;
 +get_name({iq, _, _, _, _, _, _}) -> <<"iq">>;
 +get_name({last, _, _}) -> <<"query">>;
 +get_name({legacy_auth, _, _, _, _}) -> <<"query">>;
 +get_name({mam_archived, _, _}) -> <<"archived">>;
 +get_name({mam_fin, _, _, _, _, _}) -> <<"fin">>;
 +get_name({mam_prefs, _, _, _, _}) -> <<"prefs">>;
 +get_name({mam_query, _, _, _, _, _, _, _, _}) ->
 +    <<"query">>;
 +get_name({mam_result, _, _, _, _}) -> <<"result">>;
 +get_name({media, _, _, _}) -> <<"media">>;
 +get_name({media_uri, _, _}) -> <<"uri">>;
 +get_name({message, _, _, _, _, _, _, _, _, _}) ->
 +    <<"message">>;
 +get_name({mix_join, _, _}) -> <<"join">>;
 +get_name({mix_leave}) -> <<"leave">>;
 +get_name({mix_participant, _, _}) -> <<"participant">>;
 +get_name({muc, _, _}) -> <<"x">>;
 +get_name({muc_actor, _, _}) -> <<"actor">>;
 +get_name({muc_admin, _}) -> <<"query">>;
 +get_name({muc_decline, _, _, _}) -> <<"decline">>;
 +get_name({muc_destroy, _, _, _, _}) -> <<"destroy">>;
 +get_name({muc_history, _, _, _, _}) -> <<"history">>;
 +get_name({muc_invite, _, _, _, _}) -> <<"invite">>;
 +get_name({muc_item, _, _, _, _, _, _, _}) -> <<"item">>;
 +get_name({muc_owner, _, _, _}) -> <<"query">>;
 +get_name({muc_subscribe, _, _}) -> <<"subscribe">>;
 +get_name({muc_subscriptions, _}) -> <<"subscriptions">>;
 +get_name({muc_unique, _}) -> <<"unique">>;
 +get_name({muc_unsubscribe}) -> <<"unsubscribe">>;
 +get_name({muc_user, _, _, _, _, _, _}) -> <<"x">>;
 +get_name({nick, _}) -> <<"nick">>;
 +get_name({offline, _, _, _}) -> <<"offline">>;
 +get_name({offline_item, _, _}) -> <<"item">>;
 +get_name({oob_x, _, _, _}) -> <<"x">>;
 +get_name({p1_ack}) -> <<"ack">>;
 +get_name({p1_push}) -> <<"push">>;
 +get_name({p1_rebind}) -> <<"rebind">>;
 +get_name({ping}) -> <<"ping">>;
 +get_name({presence, _, _, _, _, _, _, _, _, _}) ->
 +    <<"presence">>;
 +get_name({privacy_item, _, _, _, _, _, _, _, _}) ->
 +    <<"item">>;
 +get_name({privacy_list, _, _}) -> <<"list">>;
 +get_name({privacy_query, _, _, _}) -> <<"query">>;
 +get_name({private, _}) -> <<"query">>;
++get_name({privilege, _, _}) -> <<"privilege">>;
++get_name({privilege_perm, _, _}) -> <<"perm">>;
 +get_name({ps_affiliation, _, _, _, _}) ->
 +    <<"affiliation">>;
 +get_name({ps_error, 'closed-node', _}) ->
 +    <<"closed-node">>;
 +get_name({ps_error, 'configuration-required', _}) ->
 +    <<"configuration-required">>;
 +get_name({ps_error, 'invalid-jid', _}) ->
 +    <<"invalid-jid">>;
 +get_name({ps_error, 'invalid-options', _}) ->
 +    <<"invalid-options">>;
 +get_name({ps_error, 'invalid-payload', _}) ->
 +    <<"invalid-payload">>;
 +get_name({ps_error, 'invalid-subid', _}) ->
 +    <<"invalid-subid">>;
 +get_name({ps_error, 'item-forbidden', _}) ->
 +    <<"item-forbidden">>;
 +get_name({ps_error, 'item-required', _}) ->
 +    <<"item-required">>;
 +get_name({ps_error, 'jid-required', _}) ->
 +    <<"jid-required">>;
 +get_name({ps_error, 'max-items-exceeded', _}) ->
 +    <<"max-items-exceeded">>;
 +get_name({ps_error, 'max-nodes-exceeded', _}) ->
 +    <<"max-nodes-exceeded">>;
 +get_name({ps_error, 'nodeid-required', _}) ->
 +    <<"nodeid-required">>;
 +get_name({ps_error, 'not-in-roster-group', _}) ->
 +    <<"not-in-roster-group">>;
 +get_name({ps_error, 'not-subscribed', _}) ->
 +    <<"not-subscribed">>;
 +get_name({ps_error, 'payload-required', _}) ->
 +    <<"payload-required">>;
 +get_name({ps_error, 'payload-too-big', _}) ->
 +    <<"payload-too-big">>;
 +get_name({ps_error, 'pending-subscription', _}) ->
 +    <<"pending-subscription">>;
 +get_name({ps_error, 'presence-subscription-required',
 +        _}) ->
 +    <<"presence-subscription-required">>;
 +get_name({ps_error, 'subid-required', _}) ->
 +    <<"subid-required">>;
 +get_name({ps_error, 'too-many-subscriptions', _}) ->
 +    <<"too-many-subscriptions">>;
 +get_name({ps_error, unsupported, _}) ->
 +    <<"unsupported">>;
 +get_name({ps_error, 'unsupported-access-model', _}) ->
 +    <<"unsupported-access-model">>;
 +get_name({ps_event, _, _, _, _, _, _}) -> <<"event">>;
 +get_name({ps_item, _, _, _, _, _}) -> <<"item">>;
 +get_name({ps_items, _, _, _, _, _, _}) -> <<"items">>;
 +get_name({ps_options, _, _, _, _}) -> <<"options">>;
 +get_name({ps_publish, _, _}) -> <<"publish">>;
 +get_name({ps_retract, _, _, _}) -> <<"retract">>;
 +get_name({ps_subscribe, _, _}) -> <<"subscribe">>;
 +get_name({ps_subscription, _, _, _, _, _, _}) ->
 +    <<"subscription">>;
 +get_name({ps_unsubscribe, _, _, _}) ->
 +    <<"unsubscribe">>;
 +get_name({pubsub, _, _, _, _, _, _, _, _, _, _, _, _, _,
 +        _, _, _}) ->
 +    <<"pubsub">>;
 +get_name({pubsub_owner, _, _, _, _, _, _}) ->
 +    <<"pubsub">>;
 +get_name({redirect, _}) -> <<"redirect">>;
 +get_name({register, _, _, _, _, _, _, _, _, _, _, _, _,
 +        _, _, _, _, _, _, _, _, _, _}) ->
 +    <<"query">>;
 +get_name({roster_item, _, _, _, _, _}) -> <<"item">>;
 +get_name({roster_query, _, _}) -> <<"query">>;
 +get_name({rosterver_feature}) -> <<"ver">>;
 +get_name({rsm_first, _, _}) -> <<"first">>;
 +get_name({rsm_set, _, _, _, _, _, _, _}) -> <<"set">>;
 +get_name({sasl_abort}) -> <<"abort">>;
 +get_name({sasl_auth, _, _}) -> <<"auth">>;
 +get_name({sasl_challenge, _}) -> <<"challenge">>;
 +get_name({sasl_failure, _, _}) -> <<"failure">>;
 +get_name({sasl_mechanisms, _}) -> <<"mechanisms">>;
 +get_name({sasl_response, _}) -> <<"response">>;
 +get_name({sasl_success, _}) -> <<"success">>;
 +get_name({search, _, _, _, _, _, _, _}) -> <<"query">>;
 +get_name({search_item, _, _, _, _, _}) -> <<"item">>;
 +get_name({'see-other-host', _}) -> <<"see-other-host">>;
 +get_name({shim, _}) -> <<"headers">>;
 +get_name({sic, _, _, _}) -> <<"address">>;
 +get_name({sm_a, _, _}) -> <<"a">>;
 +get_name({sm_enable, _, _, _}) -> <<"enable">>;
 +get_name({sm_enabled, _, _, _, _, _}) -> <<"enabled">>;
 +get_name({sm_failed, _, _, _}) -> <<"failed">>;
 +get_name({sm_r, _}) -> <<"r">>;
 +get_name({sm_resume, _, _, _}) -> <<"resume">>;
 +get_name({sm_resumed, _, _, _}) -> <<"resumed">>;
 +get_name({stanza_error, _, _, _, _, _, _}) ->
 +    <<"error">>;
 +get_name({stanza_id, _, _}) -> <<"stanza-id">>;
 +get_name({starttls, _}) -> <<"starttls">>;
 +get_name({starttls_failure}) -> <<"failure">>;
 +get_name({starttls_proceed}) -> <<"proceed">>;
 +get_name({stat, _, _, _, _}) -> <<"stat">>;
 +get_name({stat_error, _, _}) -> <<"error">>;
 +get_name({stats, _, _}) -> <<"query">>;
 +get_name({stream_error, _, _}) -> <<"stream:error">>;
 +get_name({stream_features, _}) -> <<"stream:features">>;
 +get_name({stream_start, _, _, _, _, _, _, _, _}) ->
 +    <<"stream:stream">>;
 +get_name({streamhost, _, _, _}) -> <<"streamhost">>;
 +get_name({text, _, _}) -> <<"text">>;
 +get_name({thumbnail, _, _, _, _}) -> <<"thumbnail">>;
 +get_name({time, _, _}) -> <<"time">>;
 +get_name({unblock, _}) -> <<"unblock">>;
 +get_name({upload_request, _, _, _, _}) -> <<"request">>;
 +get_name({upload_slot, _, _, _}) -> <<"slot">>;
 +get_name({vcard_adr, _, _, _, _, _, _, _, _, _, _, _, _,
 +        _, _}) ->
 +    <<"ADR">>;
 +get_name({vcard_email, _, _, _, _, _, _}) ->
 +    <<"EMAIL">>;
 +get_name({vcard_geo, _, _}) -> <<"GEO">>;
 +get_name({vcard_key, _, _}) -> <<"KEY">>;
 +get_name({vcard_label, _, _, _, _, _, _, _, _}) ->
 +    <<"LABEL">>;
 +get_name({vcard_logo, _, _, _}) -> <<"LOGO">>;
 +get_name({vcard_name, _, _, _, _, _}) -> <<"N">>;
 +get_name({vcard_org, _, _}) -> <<"ORG">>;
 +get_name({vcard_photo, _, _, _}) -> <<"PHOTO">>;
 +get_name({vcard_sound, _, _, _}) -> <<"SOUND">>;
 +get_name({vcard_tel, _, _, _, _, _, _, _, _, _, _, _, _,
 +        _, _}) ->
 +    <<"TEL">>;
 +get_name({vcard_temp, _, _, _, _, _, _, _, _, _, _, _,
 +        _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _,
 +        _}) ->
 +    <<"vCard">>;
 +get_name({vcard_xupdate, _, _}) -> <<"x">>;
 +get_name({version, _, _, _}) -> <<"query">>;
 +get_name({x_conference, _, _, _, _, _}) -> <<"x">>;
 +get_name({xcaptcha, _}) -> <<"captcha">>;
 +get_name({xdata, _, _, _, _, _, _}) -> <<"x">>;
 +get_name({xdata_field, _, _, _, _, _, _, _, _}) ->
 +    <<"field">>;
 +get_name({xdata_option, _, _}) -> <<"option">>;
 +get_name({xevent, _, _, _, _, _}) -> <<"x">>;
 +get_name({xmpp_session, _}) -> <<"session">>.
 +
 +get_ns({address, _, _, _, _, _}) ->
 +    <<"http://jabber.org/protocol/address">>;
 +get_ns({addresses, _}) ->
 +    <<"http://jabber.org/protocol/address">>;
 +get_ns({adhoc_actions, _, _, _, _}) ->
 +    <<"http://jabber.org/protocol/commands">>;
 +get_ns({adhoc_command, _, _, _, _, _, _, _, _}) ->
 +    <<"http://jabber.org/protocol/commands">>;
 +get_ns({adhoc_note, _, _}) ->
 +    <<"http://jabber.org/protocol/commands">>;
 +get_ns({bind, _, _}) ->
 +    <<"urn:ietf:params:xml:ns:xmpp-bind">>;
 +get_ns({block, _}) -> <<"urn:xmpp:blocking">>;
 +get_ns({block_list, _}) -> <<"urn:xmpp:blocking">>;
 +get_ns({bob_data, _, _, _, _}) -> <<"urn:xmpp:bob">>;
 +get_ns({bookmark_conference, _, _, _, _, _}) ->
 +    <<"storage:bookmarks">>;
 +get_ns({bookmark_storage, _, _}) ->
 +    <<"storage:bookmarks">>;
 +get_ns({bookmark_url, _, _}) -> <<"storage:bookmarks">>;
 +get_ns({bytestreams, _, _, _, _, _, _}) ->
 +    <<"http://jabber.org/protocol/bytestreams">>;
 +get_ns({caps, _, _, _, _}) ->
 +    <<"http://jabber.org/protocol/caps">>;
 +get_ns({carbons_disable}) -> <<"urn:xmpp:carbons:2">>;
 +get_ns({carbons_enable}) -> <<"urn:xmpp:carbons:2">>;
 +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({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({client_id, _}) -> <<"urn:xmpp:sid:0">>;
 +get_ns({compress, _}) ->
 +    <<"http://jabber.org/protocol/compress">>;
 +get_ns({compress_failure, _}) ->
 +    <<"http://jabber.org/protocol/compress">>;
 +get_ns({compressed}) ->
 +    <<"http://jabber.org/protocol/compress">>;
 +get_ns({compression, _}) ->
 +    <<"http://jabber.org/features/compress">>;
 +get_ns({csi, active}) -> <<"urn:xmpp:csi:0">>;
 +get_ns({csi, inactive}) -> <<"urn:xmpp:csi:0">>;
 +get_ns({db_result, _, _, _, _, _}) ->
 +    <<"jabber:server">>;
 +get_ns({db_verify, _, _, _, _, _, _}) ->
 +    <<"jabber:server">>;
 +get_ns({delay, _, _, _}) -> <<"urn:xmpp:delay">>;
++get_ns({delegated, _, _}) ->
++    <<"urn:xmpp:delegation:1">>;
++get_ns({delegation, _, _}) ->
++    <<"urn:xmpp:delegation:1">>;
++get_ns({delegation_query, _, _}) ->
++    <<"urn:xmpp:delegation:1">>;
 +get_ns({disco_info, _, _, _, _}) ->
 +    <<"http://jabber.org/protocol/disco#info">>;
 +get_ns({disco_item, _, _, _}) ->
 +    <<"http://jabber.org/protocol/disco#items">>;
 +get_ns({disco_items, _, _, _}) ->
 +    <<"http://jabber.org/protocol/disco#items">>;
 +get_ns({expire, _, _}) -> <<"jabber:x:expire">>;
 +get_ns({feature_csi, Xmlns}) -> Xmlns;
 +get_ns({feature_register}) ->
 +    <<"http://jabber.org/features/iq-register">>;
 +get_ns({feature_sm, Xmlns}) -> Xmlns;
 +get_ns({forwarded, _, _}) -> <<"urn:xmpp:forward:0">>;
 +get_ns({gone, _}) ->
 +    <<"urn:ietf:params:xml:ns:xmpp-stanzas">>;
 +get_ns({handshake, _}) -> <<"jabber:component:accept">>;
 +get_ns({hint, 'no-copy'}) -> <<"urn:xmpp:hints">>;
 +get_ns({hint, 'no-permanent-storage'}) ->
 +    <<"urn:xmpp:hints">>;
 +get_ns({hint, 'no-permanent-store'}) ->
 +    <<"urn:xmpp:hints">>;
 +get_ns({hint, 'no-storage'}) -> <<"urn:xmpp:hints">>;
 +get_ns({hint, 'no-store'}) -> <<"urn:xmpp:hints">>;
 +get_ns({hint, store}) -> <<"urn:xmpp:hints">>;
 +get_ns({identity, _, _, _, _}) ->
 +    <<"http://jabber.org/protocol/disco#info">>;
 +get_ns({iq, _, _, _, _, _, _}) -> <<"jabber:client">>;
 +get_ns({last, _, _}) -> <<"jabber:iq:last">>;
 +get_ns({legacy_auth, _, _, _, _}) ->
 +    <<"jabber:iq:auth">>;
 +get_ns({mam_archived, _, _}) -> <<"urn:xmpp:mam:tmp">>;
 +get_ns({mam_fin, Xmlns, _, _, _, _}) -> Xmlns;
 +get_ns({mam_prefs, Xmlns, _, _, _}) -> Xmlns;
 +get_ns({mam_query, Xmlns, _, _, _, _, _, _, _}) ->
 +    Xmlns;
 +get_ns({mam_result, Xmlns, _, _, _}) -> Xmlns;
 +get_ns({media, _, _, _}) ->
 +    <<"urn:xmpp:media-element">>;
 +get_ns({media_uri, _, _}) ->
 +    <<"urn:xmpp:media-element">>;
 +get_ns({message, _, _, _, _, _, _, _, _, _}) ->
 +    <<"jabber:client">>;
 +get_ns({mix_join, _, _}) -> <<"urn:xmpp:mix:0">>;
 +get_ns({mix_leave}) -> <<"urn:xmpp:mix:0">>;
 +get_ns({mix_participant, _, _}) -> <<"urn:xmpp:mix:0">>;
 +get_ns({muc, _, _}) ->
 +    <<"http://jabber.org/protocol/muc">>;
 +get_ns({muc_admin, _}) ->
 +    <<"http://jabber.org/protocol/muc#admin">>;
 +get_ns({muc_decline, _, _, _}) ->
 +    <<"http://jabber.org/protocol/muc#user">>;
 +get_ns({muc_destroy, Xmlns, _, _, _}) -> Xmlns;
 +get_ns({muc_history, _, _, _, _}) ->
 +    <<"http://jabber.org/protocol/muc">>;
 +get_ns({muc_invite, _, _, _, _}) ->
 +    <<"http://jabber.org/protocol/muc#user">>;
 +get_ns({muc_owner, _, _, _}) ->
 +    <<"http://jabber.org/protocol/muc#owner">>;
 +get_ns({muc_subscribe, _, _}) ->
 +    <<"urn:xmpp:mucsub:0">>;
 +get_ns({muc_subscriptions, _}) ->
 +    <<"urn:xmpp:mucsub:0">>;
 +get_ns({muc_unique, _}) ->
 +    <<"http://jabber.org/protocol/muc#unique">>;
 +get_ns({muc_unsubscribe}) -> <<"urn:xmpp:mucsub:0">>;
 +get_ns({muc_user, _, _, _, _, _, _}) ->
 +    <<"http://jabber.org/protocol/muc#user">>;
 +get_ns({nick, _}) ->
 +    <<"http://jabber.org/protocol/nick">>;
 +get_ns({offline, _, _, _}) ->
 +    <<"http://jabber.org/protocol/offline">>;
 +get_ns({offline_item, _, _}) ->
 +    <<"http://jabber.org/protocol/offline">>;
 +get_ns({oob_x, _, _, _}) -> <<"jabber:x:oob">>;
 +get_ns({p1_ack}) -> <<"p1:ack">>;
 +get_ns({p1_push}) -> <<"p1:push">>;
 +get_ns({p1_rebind}) -> <<"p1:rebind">>;
 +get_ns({ping}) -> <<"urn:xmpp:ping">>;
 +get_ns({presence, _, _, _, _, _, _, _, _, _}) ->
 +    <<"jabber:client">>;
 +get_ns({privacy_item, _, _, _, _, _, _, _, _}) ->
 +    <<"jabber:iq:privacy">>;
 +get_ns({privacy_list, _, _}) -> <<"jabber:iq:privacy">>;
 +get_ns({privacy_query, _, _, _}) ->
 +    <<"jabber:iq:privacy">>;
 +get_ns({private, _}) -> <<"jabber:iq:private">>;
++get_ns({privilege, _, _}) -> <<"urn:xmpp:privilege:1">>;
++get_ns({privilege_perm, _, _}) ->
++    <<"urn:xmpp:privilege:1">>;
 +get_ns({ps_affiliation, Xmlns, _, _, _}) -> Xmlns;
 +get_ns({ps_error, 'closed-node', _}) ->
 +    <<"http://jabber.org/protocol/pubsub#errors">>;
 +get_ns({ps_error, 'configuration-required', _}) ->
 +    <<"http://jabber.org/protocol/pubsub#errors">>;
 +get_ns({ps_error, 'invalid-jid', _}) ->
 +    <<"http://jabber.org/protocol/pubsub#errors">>;
 +get_ns({ps_error, 'invalid-options', _}) ->
 +    <<"http://jabber.org/protocol/pubsub#errors">>;
 +get_ns({ps_error, 'invalid-payload', _}) ->
 +    <<"http://jabber.org/protocol/pubsub#errors">>;
 +get_ns({ps_error, 'invalid-subid', _}) ->
 +    <<"http://jabber.org/protocol/pubsub#errors">>;
 +get_ns({ps_error, 'item-forbidden', _}) ->
 +    <<"http://jabber.org/protocol/pubsub#errors">>;
 +get_ns({ps_error, 'item-required', _}) ->
 +    <<"http://jabber.org/protocol/pubsub#errors">>;
 +get_ns({ps_error, 'jid-required', _}) ->
 +    <<"http://jabber.org/protocol/pubsub#errors">>;
 +get_ns({ps_error, 'max-items-exceeded', _}) ->
 +    <<"http://jabber.org/protocol/pubsub#errors">>;
 +get_ns({ps_error, 'max-nodes-exceeded', _}) ->
 +    <<"http://jabber.org/protocol/pubsub#errors">>;
 +get_ns({ps_error, 'nodeid-required', _}) ->
 +    <<"http://jabber.org/protocol/pubsub#errors">>;
 +get_ns({ps_error, 'not-in-roster-group', _}) ->
 +    <<"http://jabber.org/protocol/pubsub#errors">>;
 +get_ns({ps_error, 'not-subscribed', _}) ->
 +    <<"http://jabber.org/protocol/pubsub#errors">>;
 +get_ns({ps_error, 'payload-required', _}) ->
 +    <<"http://jabber.org/protocol/pubsub#errors">>;
 +get_ns({ps_error, 'payload-too-big', _}) ->
 +    <<"http://jabber.org/protocol/pubsub#errors">>;
 +get_ns({ps_error, 'pending-subscription', _}) ->
 +    <<"http://jabber.org/protocol/pubsub#errors">>;
 +get_ns({ps_error, 'presence-subscription-required',
 +      _}) ->
 +    <<"http://jabber.org/protocol/pubsub#errors">>;
 +get_ns({ps_error, 'subid-required', _}) ->
 +    <<"http://jabber.org/protocol/pubsub#errors">>;
 +get_ns({ps_error, 'too-many-subscriptions', _}) ->
 +    <<"http://jabber.org/protocol/pubsub#errors">>;
 +get_ns({ps_error, unsupported, _}) ->
 +    <<"http://jabber.org/protocol/pubsub#errors">>;
 +get_ns({ps_error, 'unsupported-access-model', _}) ->
 +    <<"http://jabber.org/protocol/pubsub#errors">>;
 +get_ns({ps_event, _, _, _, _, _, _}) ->
 +    <<"http://jabber.org/protocol/pubsub#event">>;
 +get_ns({ps_item, Xmlns, _, _, _, _}) -> Xmlns;
 +get_ns({ps_items, Xmlns, _, _, _, _, _}) -> Xmlns;
 +get_ns({ps_options, _, _, _, _}) ->
 +    <<"http://jabber.org/protocol/pubsub">>;
 +get_ns({ps_publish, _, _}) ->
 +    <<"http://jabber.org/protocol/pubsub">>;
 +get_ns({ps_retract, _, _, _}) ->
 +    <<"http://jabber.org/protocol/pubsub">>;
 +get_ns({ps_subscribe, _, _}) ->
 +    <<"http://jabber.org/protocol/pubsub">>;
 +get_ns({ps_subscription, Xmlns, _, _, _, _, _}) ->
 +    Xmlns;
 +get_ns({ps_unsubscribe, _, _, _}) ->
 +    <<"http://jabber.org/protocol/pubsub">>;
 +get_ns({pubsub, _, _, _, _, _, _, _, _, _, _, _, _, _,
 +      _, _, _}) ->
 +    <<"http://jabber.org/protocol/pubsub">>;
 +get_ns({pubsub_owner, _, _, _, _, _, _}) ->
 +    <<"http://jabber.org/protocol/pubsub#owner">>;
 +get_ns({redirect, _}) ->
 +    <<"urn:ietf:params:xml:ns:xmpp-stanzas">>;
 +get_ns({register, _, _, _, _, _, _, _, _, _, _, _, _, _,
 +      _, _, _, _, _, _, _, _, _}) ->
 +    <<"jabber:iq:register">>;
 +get_ns({roster_item, _, _, _, _, _}) ->
 +    <<"jabber:iq:roster">>;
 +get_ns({roster_query, _, _}) -> <<"jabber:iq:roster">>;
 +get_ns({rosterver_feature}) ->
 +    <<"urn:xmpp:features:rosterver">>;
 +get_ns({rsm_first, _, _}) ->
 +    <<"http://jabber.org/protocol/rsm">>;
 +get_ns({rsm_set, _, _, _, _, _, _, _}) ->
 +    <<"http://jabber.org/protocol/rsm">>;
 +get_ns({sasl_abort}) ->
 +    <<"urn:ietf:params:xml:ns:xmpp-sasl">>;
 +get_ns({sasl_auth, _, _}) ->
 +    <<"urn:ietf:params:xml:ns:xmpp-sasl">>;
 +get_ns({sasl_challenge, _}) ->
 +    <<"urn:ietf:params:xml:ns:xmpp-sasl">>;
 +get_ns({sasl_failure, _, _}) ->
 +    <<"urn:ietf:params:xml:ns:xmpp-sasl">>;
 +get_ns({sasl_mechanisms, _}) ->
 +    <<"urn:ietf:params:xml:ns:xmpp-sasl">>;
 +get_ns({sasl_response, _}) ->
 +    <<"urn:ietf:params:xml:ns:xmpp-sasl">>;
 +get_ns({sasl_success, _}) ->
 +    <<"urn:ietf:params:xml:ns:xmpp-sasl">>;
 +get_ns({search, _, _, _, _, _, _, _}) ->
 +    <<"jabber:iq:search">>;
 +get_ns({search_item, _, _, _, _, _}) ->
 +    <<"jabber:iq:search">>;
 +get_ns({'see-other-host', _}) ->
 +    <<"urn:ietf:params:xml:ns:xmpp-streams">>;
 +get_ns({shim, _}) ->
 +    <<"http://jabber.org/protocol/shim">>;
 +get_ns({sic, _, _, Xmlns}) -> Xmlns;
 +get_ns({sm_a, _, Xmlns}) -> Xmlns;
 +get_ns({sm_enable, _, _, Xmlns}) -> Xmlns;
 +get_ns({sm_enabled, _, _, _, _, Xmlns}) -> Xmlns;
 +get_ns({sm_failed, _, _, Xmlns}) -> Xmlns;
 +get_ns({sm_r, Xmlns}) -> Xmlns;
 +get_ns({sm_resume, _, _, Xmlns}) -> Xmlns;
 +get_ns({sm_resumed, _, _, Xmlns}) -> Xmlns;
 +get_ns({stanza_error, _, _, _, _, _, _}) ->
 +    <<"jabber:client">>;
 +get_ns({stanza_id, _, _}) -> <<"urn:xmpp:sid:0">>;
 +get_ns({starttls, _}) ->
 +    <<"urn:ietf:params:xml:ns:xmpp-tls">>;
 +get_ns({starttls_failure}) ->
 +    <<"urn:ietf:params:xml:ns:xmpp-tls">>;
 +get_ns({starttls_proceed}) ->
 +    <<"urn:ietf:params:xml:ns:xmpp-tls">>;
 +get_ns({stat, _, _, _, _}) ->
 +    <<"http://jabber.org/protocol/stats">>;
 +get_ns({stat_error, _, _}) ->
 +    <<"http://jabber.org/protocol/stats">>;
 +get_ns({stats, _, _}) ->
 +    <<"http://jabber.org/protocol/stats">>;
 +get_ns({stream_error, _, _}) -> <<"jabber:client">>;
 +get_ns({stream_features, _}) -> <<"jabber:client">>;
 +get_ns({stream_start, _, _, _, _, Xmlns, _, _, _}) ->
 +    Xmlns;
 +get_ns({streamhost, _, _, _}) ->
 +    <<"http://jabber.org/protocol/bytestreams">>;
 +get_ns({thumbnail, _, _, _, _}) ->
 +    <<"urn:xmpp:thumbs:1">>;
 +get_ns({time, _, _}) -> <<"urn:xmpp:time">>;
 +get_ns({unblock, _}) -> <<"urn:xmpp:blocking">>;
 +get_ns({upload_request, _, _, _, Xmlns}) -> Xmlns;
 +get_ns({upload_slot, _, _, Xmlns}) -> Xmlns;
 +get_ns({vcard_adr, _, _, _, _, _, _, _, _, _, _, _, _,
 +      _, _}) ->
 +    <<"vcard-temp">>;
 +get_ns({vcard_email, _, _, _, _, _, _}) ->
 +    <<"vcard-temp">>;
 +get_ns({vcard_geo, _, _}) -> <<"vcard-temp">>;
 +get_ns({vcard_key, _, _}) -> <<"vcard-temp">>;
 +get_ns({vcard_label, _, _, _, _, _, _, _, _}) ->
 +    <<"vcard-temp">>;
 +get_ns({vcard_logo, _, _, _}) -> <<"vcard-temp">>;
 +get_ns({vcard_name, _, _, _, _, _}) -> <<"vcard-temp">>;
 +get_ns({vcard_org, _, _}) -> <<"vcard-temp">>;
 +get_ns({vcard_photo, _, _, _}) -> <<"vcard-temp">>;
 +get_ns({vcard_sound, _, _, _}) -> <<"vcard-temp">>;
 +get_ns({vcard_tel, _, _, _, _, _, _, _, _, _, _, _, _,
 +      _, _}) ->
 +    <<"vcard-temp">>;
 +get_ns({vcard_temp, _, _, _, _, _, _, _, _, _, _, _, _,
 +      _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _}) ->
 +    <<"vcard-temp">>;
 +get_ns({vcard_xupdate, _, _}) ->
 +    <<"vcard-temp:x:update">>;
 +get_ns({version, _, _, _}) -> <<"jabber:iq:version">>;
 +get_ns({x_conference, _, _, _, _, _}) ->
 +    <<"jabber:x:conference">>;
 +get_ns({xcaptcha, _}) -> <<"urn:xmpp:captcha">>;
 +get_ns({xdata, _, _, _, _, _, _}) ->
 +    <<"jabber:x:data">>;
 +get_ns({xdata_field, _, _, _, _, _, _, _, _}) ->
 +    <<"jabber:x:data">>;
 +get_ns({xdata_option, _, _}) -> <<"jabber:x:data">>;
 +get_ns({xevent, _, _, _, _, _}) -> <<"jabber:x:event">>;
 +get_ns({xmpp_session, _}) ->
 +    <<"urn:ietf:params:xml:ns:xmpp-session">>.
 +
 +dec_int(Val) -> dec_int(Val, infinity, infinity).
 +
 +dec_int(Val, Min, Max) ->
 +    case list_to_integer(binary_to_list(Val)) of
 +      Int when Int =< Max, Min == infinity -> Int;
 +      Int when Int =< Max, Int >= Min -> Int
 +    end.
 +
 +enc_int(Int) -> list_to_binary(integer_to_list(Int)).
 +
 +dec_enum(Val, Enums) ->
 +    AtomVal = erlang:binary_to_existing_atom(Val, utf8),
 +    case lists:member(AtomVal, Enums) of
 +      true -> AtomVal
 +    end.
 +
 +enc_enum(Atom) -> erlang:atom_to_binary(Atom, utf8).
 +
 +format_error({bad_attr_value, Attr, Tag, XMLNS}) ->
 +    <<"Bad value of attribute '", Attr/binary, "' in tag <",
 +      Tag/binary, "/> qualified by namespace '", XMLNS/binary,
 +      "'">>;
 +format_error({bad_cdata_value, <<>>, Tag, XMLNS}) ->
 +    <<"Bad value of cdata in tag <", Tag/binary,
 +      "/> qualified by namespace '", XMLNS/binary, "'">>;
 +format_error({missing_tag, Tag, XMLNS}) ->
 +    <<"Missing tag <", Tag/binary,
 +      "/> qualified by namespace '", XMLNS/binary, "'">>;
 +format_error({missing_attr, Attr, Tag, XMLNS}) ->
 +    <<"Missing attribute '", Attr/binary, "' in tag <",
 +      Tag/binary, "/> qualified by namespace '", XMLNS/binary,
 +      "'">>;
 +format_error({missing_cdata, <<>>, Tag, XMLNS}) ->
 +    <<"Missing cdata in tag <", Tag/binary,
 +      "/> qualified by namespace '", XMLNS/binary, "'">>;
 +format_error({unknown_tag, Tag, XMLNS}) ->
 +    <<"Unknown tag <", Tag/binary,
 +      "/> qualified by namespace '", XMLNS/binary, "'">>;
 +format_error({missing_tag_xmlns, Tag}) ->
 +    <<"Missing namespace for tag <", Tag/binary, "/>">>.
 +
 +get_attr(Attr, Attrs) ->
 +    case lists:keyfind(Attr, 1, Attrs) of
 +      {_, Val} -> Val;
 +      false -> <<>>
 +    end.
 +
 +enc_xmlns_attrs(XMLNS, XMLNS) -> [];
 +enc_xmlns_attrs(XMLNS, _) -> [{<<"xmlns">>, XMLNS}].
 +
 +choose_top_xmlns(<<>>, NSList, TopXMLNS) ->
 +    case lists:member(TopXMLNS, NSList) of
 +      true -> TopXMLNS;
 +      false -> hd(NSList)
 +    end;
 +choose_top_xmlns(XMLNS, _, _) -> XMLNS.
 +
 +pp(Term) -> io_lib_pretty:print(Term, fun pp/2).
 +
 +pp(last, 2) -> [seconds, status];
 +pp(version, 3) -> [name, ver, os];
 +pp(roster_item, 5) ->
 +    [jid, name, groups, subscription, ask];
 +pp(roster_query, 2) -> [items, ver];
 +pp(rosterver_feature, 0) -> [];
 +pp(privacy_item, 8) ->
 +    [order, action, type, value, message, iq, presence_in,
 +     presence_out];
 +pp(privacy_list, 2) -> [name, items];
 +pp(privacy_query, 3) -> [lists, default, active];
 +pp(block, 1) -> [items];
 +pp(unblock, 1) -> [items];
 +pp(block_list, 1) -> [items];
 +pp(identity, 4) -> [category, type, lang, name];
 +pp(disco_info, 4) ->
 +    [node, identities, features, xdata];
 +pp(disco_item, 3) -> [jid, name, node];
 +pp(disco_items, 3) -> [node, items, rsm];
 +pp(private, 1) -> [xml_els];
 +pp(bookmark_conference, 5) ->
 +    [name, jid, autojoin, nick, password];
 +pp(bookmark_url, 2) -> [name, url];
 +pp(bookmark_storage, 2) -> [conference, url];
 +pp(stat_error, 2) -> [code, reason];
 +pp(stat, 4) -> [name, units, value, error];
 +pp(stats, 2) -> [list, node];
 +pp(iq, 6) -> [id, type, lang, from, to, sub_els];
 +pp(message, 9) ->
 +    [id, type, lang, from, to, subject, body, thread,
 +     sub_els];
 +pp(presence, 9) ->
 +    [id, type, lang, from, to, show, status, priority,
 +     sub_els];
 +pp(gone, 1) -> [uri];
 +pp(redirect, 1) -> [uri];
 +pp(stanza_error, 6) ->
 +    [type, code, by, reason, text, sub_els];
 +pp(bind, 2) -> [jid, resource];
 +pp(legacy_auth, 4) ->
 +    [username, password, digest, resource];
 +pp(sasl_auth, 2) -> [mechanism, text];
 +pp(sasl_abort, 0) -> [];
 +pp(sasl_challenge, 1) -> [text];
 +pp(sasl_response, 1) -> [text];
 +pp(sasl_success, 1) -> [text];
 +pp(sasl_failure, 2) -> [reason, text];
 +pp(sasl_mechanisms, 1) -> [list];
 +pp(starttls, 1) -> [required];
 +pp(starttls_proceed, 0) -> [];
 +pp(starttls_failure, 0) -> [];
 +pp(compress_failure, 1) -> [reason];
 +pp(compress, 1) -> [methods];
 +pp(compressed, 0) -> [];
 +pp(compression, 1) -> [methods];
 +pp(stream_features, 1) -> [sub_els];
 +pp(p1_push, 0) -> [];
 +pp(p1_rebind, 0) -> [];
 +pp(p1_ack, 0) -> [];
 +pp(caps, 4) -> [node, version, hash, exts];
 +pp(feature_register, 0) -> [];
 +pp(register, 22) ->
 +    [registered, remove, instructions, username, nick,
 +     password, name, first, last, email, address, city,
 +     state, zip, phone, url, date, misc, text, key, xdata,
 +     sub_els];
 +pp(xmpp_session, 1) -> [optional];
 +pp(ping, 0) -> [];
 +pp(time, 2) -> [tzo, utc];
 +pp(text, 2) -> [lang, data];
 +pp('see-other-host', 1) -> [host];
 +pp(stream_error, 2) -> [reason, text];
 +pp(vcard_name, 5) ->
 +    [family, given, middle, prefix, suffix];
 +pp(vcard_adr, 14) ->
 +    [home, work, postal, parcel, dom, intl, pref, pobox,
 +     extadd, street, locality, region, pcode, ctry];
 +pp(vcard_label, 8) ->
 +    [home, work, postal, parcel, dom, intl, pref, line];
 +pp(vcard_tel, 14) ->
 +    [home, work, voice, fax, pager, msg, cell, video, bbs,
 +     modem, isdn, pcs, pref, number];
 +pp(vcard_email, 6) ->
 +    [home, work, internet, pref, x400, userid];
 +pp(vcard_geo, 2) -> [lat, lon];
 +pp(vcard_logo, 3) -> [type, binval, extval];
 +pp(vcard_photo, 3) -> [type, binval, extval];
 +pp(vcard_org, 2) -> [name, units];
 +pp(vcard_sound, 3) -> [phonetic, binval, extval];
 +pp(vcard_key, 2) -> [type, cred];
 +pp(vcard_temp, 29) ->
 +    [version, fn, n, nickname, photo, bday, adr, label, tel,
 +     email, jabberid, mailer, tz, geo, title, role, logo,
 +     org, categories, note, prodid, rev, sort_string, sound,
 +     uid, url, class, key, desc];
 +pp(xdata_option, 2) -> [label, value];
 +pp(xdata_field, 8) ->
 +    [label, type, var, required, desc, values, options,
 +     sub_els];
 +pp(xdata, 6) ->
 +    [type, instructions, title, reported, items, fields];
 +pp(ps_subscription, 6) ->
 +    [xmlns, jid, type, node, subid, expiry];
 +pp(ps_item, 5) -> [xmlns, id, xml_els, node, publisher];
 +pp(ps_items, 6) ->
 +    [xmlns, node, items, max_items, subid, retract];
 +pp(ps_event, 6) ->
 +    [items, purge, subscription, delete, create,
 +     configuration];
 +pp(ps_subscribe, 2) -> [node, jid];
 +pp(ps_unsubscribe, 3) -> [node, jid, subid];
 +pp(ps_publish, 2) -> [node, items];
 +pp(ps_options, 4) -> [node, jid, subid, xdata];
 +pp(ps_retract, 3) -> [node, notify, items];
 +pp(pubsub, 16) ->
 +    [subscriptions, subscription, affiliations, publish,
 +     publish_options, subscribe, unsubscribe, options, items,
 +     retract, create, configure, default, delete, purge,
 +     rsm];
 +pp(pubsub_owner, 6) ->
 +    [affiliations, configure, default, delete, purge,
 +     subscriptions];
 +pp(shim, 1) -> [headers];
 +pp(delay, 3) -> [stamp, from, desc];
 +pp(streamhost, 3) -> [jid, host, port];
 +pp(bytestreams, 6) ->
 +    [hosts, used, activate, dstaddr, mode, sid];
 +pp(muc_history, 4) ->
 +    [maxchars, maxstanzas, seconds, since];
 +pp(muc_decline, 3) -> [reason, from, to];
 +pp(muc_destroy, 4) -> [xmlns, jid, reason, password];
 +pp(muc_invite, 4) -> [reason, from, to, continue];
 +pp(muc_user, 6) ->
 +    [decline, destroy, invites, items, status_codes,
 +     password];
 +pp(muc_owner, 3) -> [destroy, config, items];
 +pp(muc_item, 7) ->
 +    [actor, continue, reason, affiliation, role, jid, nick];
 +pp(muc_actor, 2) -> [jid, nick];
 +pp(muc_admin, 1) -> [items];
 +pp(muc, 2) -> [history, password];
 +pp(muc_unique, 1) -> [name];
 +pp(x_conference, 5) ->
 +    [jid, password, reason, continue, thread];
 +pp(muc_subscriptions, 1) -> [list];
 +pp(muc_subscribe, 2) -> [nick, events];
 +pp(muc_unsubscribe, 0) -> [];
 +pp(rsm_first, 2) -> [index, data];
 +pp(rsm_set, 7) ->
 +    ['after', before, count, first, index, last, max];
 +pp(mam_query, 8) ->
 +    [xmlns, id, start, 'end', with, withtext, rsm, xdata];
 +pp(mam_archived, 2) -> [by, id];
 +pp(mam_result, 4) -> [xmlns, queryid, id, sub_els];
 +pp(mam_prefs, 4) -> [xmlns, default, always, never];
 +pp(mam_fin, 5) -> [xmlns, id, rsm, stable, complete];
 +pp(forwarded, 2) -> [delay, sub_els];
 +pp(carbons_disable, 0) -> [];
 +pp(carbons_enable, 0) -> [];
 +pp(carbons_private, 0) -> [];
 +pp(carbons_received, 1) -> [forwarded];
 +pp(carbons_sent, 1) -> [forwarded];
 +pp(feature_csi, 1) -> [xmlns];
 +pp(feature_sm, 1) -> [xmlns];
 +pp(sm_enable, 3) -> [max, resume, xmlns];
 +pp(sm_enabled, 5) -> [id, location, max, resume, xmlns];
 +pp(sm_resume, 3) -> [h, previd, xmlns];
 +pp(sm_resumed, 3) -> [h, previd, xmlns];
 +pp(sm_r, 1) -> [xmlns];
 +pp(sm_a, 2) -> [h, xmlns];
 +pp(sm_failed, 3) -> [reason, h, xmlns];
 +pp(offline_item, 2) -> [node, action];
 +pp(offline, 3) -> [items, purge, fetch];
 +pp(mix_join, 2) -> [jid, subscribe];
 +pp(mix_leave, 0) -> [];
 +pp(mix_participant, 2) -> [jid, nick];
 +pp(search_item, 5) -> [jid, first, last, nick, email];
 +pp(search, 7) ->
 +    [instructions, first, last, nick, email, items, xdata];
 +pp(xevent, 5) ->
 +    [offline, delivered, displayed, composing, id];
 +pp(expire, 2) -> [seconds, stored];
 +pp(nick, 1) -> [name];
 +pp(address, 5) -> [type, jid, desc, node, delivered];
 +pp(addresses, 1) -> [list];
 +pp(stanza_id, 2) -> [by, id];
 +pp(client_id, 1) -> [id];
 +pp(adhoc_actions, 4) -> [execute, prev, next, complete];
 +pp(adhoc_note, 2) -> [type, data];
 +pp(adhoc_command, 8) ->
 +    [node, action, sid, status, lang, actions, notes,
 +     xdata];
 +pp(db_result, 5) -> [from, to, type, key, sub_els];
 +pp(db_verify, 6) -> [from, to, id, type, key, sub_els];
 +pp(handshake, 1) -> [data];
 +pp(stream_start, 8) ->
 +    [from, to, id, version, xmlns, stream_xmlns, db_xmlns,
 +     lang];
 +pp(bob_data, 4) -> [cid, 'max-age', type, data];
 +pp(xcaptcha, 1) -> [xdata];
 +pp(media_uri, 2) -> [type, uri];
 +pp(media, 3) -> [height, width, uri];
 +pp(oob_x, 3) -> [url, desc, sid];
 +pp(sic, 3) -> [ip, port, xmlns];
 +pp(upload_request, 4) ->
 +    [filename, size, 'content-type', xmlns];
 +pp(upload_slot, 3) -> [get, put, xmlns];
 +pp(thumbnail, 4) -> [uri, 'media-type', width, height];
++pp(privilege_perm, 2) -> [access, type];
++pp(privilege, 2) -> [perms, forwarded];
++pp(delegated, 2) -> [ns, attrs];
++pp(delegation, 2) -> [delegated, forwarded];
++pp(delegation_query, 2) -> [to, delegate];
 +pp(_, _) -> no.
 +
 +enc_ps_aff(member) -> <<"member">>;
 +enc_ps_aff(none) -> <<"none">>;
 +enc_ps_aff(outcast) -> <<"outcast">>;
 +enc_ps_aff(owner) -> <<"owner">>;
 +enc_ps_aff(publisher) -> <<"publisher">>;
 +enc_ps_aff(publish_only) -> <<"publish-only">>.
 +
 +dec_ps_aff(<<"member">>) -> member;
 +dec_ps_aff(<<"none">>) -> none;
 +dec_ps_aff(<<"outcast">>) -> outcast;
 +dec_ps_aff(<<"owner">>) -> owner;
 +dec_ps_aff(<<"publisher">>) -> publisher;
 +dec_ps_aff(<<"publish-only">>) -> publish_only.
 +
 +enc_version({Maj, Min}) ->
 +    <<(integer_to_binary(Maj))/binary, $.,
 +      (integer_to_binary(Min))/binary>>.
 +
 +dec_version(S) ->
 +    [Major, Minor] = binary:split(S, <<$.>>),
 +    {binary_to_integer(Major), binary_to_integer(Minor)}.
 +
 +enc_host_port(Host) when is_binary(Host) -> Host;
 +enc_host_port({{_, _, _, _, _, _, _, _} = IPv6,
 +             Port}) ->
 +    enc_host_port({<<$[, (enc_ip(IPv6))/binary, $]>>,
 +                 Port});
 +enc_host_port({{_, _, _, _} = IPv4, Port}) ->
 +    enc_host_port({enc_ip(IPv4), Port});
 +enc_host_port({Host, Port}) ->
 +    <<Host/binary, $:, (integer_to_binary(Port))/binary>>;
 +enc_host_port(Addr) -> enc_ip(Addr).
 +
 +dec_host_port(<<$[, T/binary>>) ->
 +    [IP, <<$:, Port/binary>>] = binary:split(T, <<$]>>),
 +    {dec_ip(IP), dec_int(Port, 0, 65535)};
 +dec_host_port(S) ->
 +    case binary:split(S, <<$:>>) of
 +      [S] -> try dec_ip(S) catch _:_ -> S end;
 +      [S, P] ->
 +        {try dec_ip(S) catch _:_ -> S end, dec_int(P, 0, 65535)}
 +    end.
 +
 +enc_ip({0, 0, 0, 0, 0, 65535, A, B}) ->
 +    enc_ip({(A bsr 8) band 255, A band 255,
 +          (B bsr 8) band 255, B band 255});
 +enc_ip(Addr) -> list_to_binary(inet_parse:ntoa(Addr)).
 +
 +dec_ip(S) ->
 +    {ok, Addr} = inet_parse:address(binary_to_list(S)),
 +    Addr.
 +
 +join([], _Sep) -> <<>>;
 +join([H | T], Sep) ->
 +    <<H/binary, << <<Sep, X/binary>>  || X <- T >>/binary>>.
 +
 +enc_bool(false) -> <<"false">>;
 +enc_bool(true) -> <<"true">>.
 +
 +dec_bool(<<"false">>) -> false;
 +dec_bool(<<"0">>) -> false;
 +dec_bool(<<"true">>) -> true;
 +dec_bool(<<"1">>) -> true.
 +
 +nameprep(S) ->
 +    case jid:nameprep(S) of
 +      error -> erlang:error(badarg);
 +      S1 -> S1
 +    end.
 +
 +resourceprep(R) ->
 +    case jid:resourceprep(R) of
 +      error -> erlang:error(badarg);
 +      R1 -> R1
 +    end.
 +
 +enc_jid(J) -> jid:to_string(J).
 +
 +dec_jid(Val) ->
 +    case jid:from_string(Val) of
 +      error -> erlang:error(badarg);
 +      J -> J
 +    end.
 +
 +enc_utc(Val) -> jlib:now_to_utc_string(Val).
 +
 +dec_utc(Val) ->
 +    {_, _, _} = jlib:datetime_string_to_timestamp(Val).
 +
 +enc_tzo({H, M}) ->
 +    Sign = if H >= 0 -> <<>>;
 +            true -> <<"-">>
 +         end,
 +    list_to_binary([Sign,
 +                  io_lib:format("~2..0w:~2..0w", [H, M])]).
 +
 +dec_tzo(Val) ->
 +    [H1, M1] = str:tokens(Val, <<":">>),
 +    H = binary_to_integer(H1),
 +    M = binary_to_integer(M1),
 +    if H >= -12, H =< 12, M >= 0, M < 60 -> {H, M} end.
 +
++decode_delegation_query(__TopXMLNS, __IgnoreEls,
++                      {xmlel, <<"query">>, _attrs, _els}) ->
++    Delegate = decode_delegation_query_els(__TopXMLNS,
++                                         __IgnoreEls, _els, []),
++    To = decode_delegation_query_attrs(__TopXMLNS, _attrs,
++                                     undefined),
++    {delegation_query, To, Delegate}.
++
++decode_delegation_query_els(__TopXMLNS, __IgnoreEls, [],
++                          Delegate) ->
++    lists:reverse(Delegate);
++decode_delegation_query_els(__TopXMLNS, __IgnoreEls,
++                          [{xmlel, <<"delegate">>, _attrs, _} = _el | _els],
++                          Delegate) ->
++    case get_attr(<<"xmlns">>, _attrs) of
++      <<"">> when __TopXMLNS == <<"urn:xmpp:delegation:1">> ->
++        decode_delegation_query_els(__TopXMLNS, __IgnoreEls,
++                                    _els,
++                                    [decode_delegate(__TopXMLNS, __IgnoreEls,
++                                                     _el)
++                                     | Delegate]);
++      <<"urn:xmpp:delegation:1">> ->
++        decode_delegation_query_els(__TopXMLNS, __IgnoreEls,
++                                    _els,
++                                    [decode_delegate(<<"urn:xmpp:delegation:1">>,
++                                                     __IgnoreEls, _el)
++                                     | Delegate]);
++      _ ->
++        decode_delegation_query_els(__TopXMLNS, __IgnoreEls,
++                                    _els, Delegate)
++    end;
++decode_delegation_query_els(__TopXMLNS, __IgnoreEls,
++                          [_ | _els], Delegate) ->
++    decode_delegation_query_els(__TopXMLNS, __IgnoreEls,
++                              _els, Delegate).
++
++decode_delegation_query_attrs(__TopXMLNS,
++                            [{<<"to">>, _val} | _attrs], _To) ->
++    decode_delegation_query_attrs(__TopXMLNS, _attrs, _val);
++decode_delegation_query_attrs(__TopXMLNS, [_ | _attrs],
++                            To) ->
++    decode_delegation_query_attrs(__TopXMLNS, _attrs, To);
++decode_delegation_query_attrs(__TopXMLNS, [], To) ->
++    decode_delegation_query_attr_to(__TopXMLNS, To).
++
++encode_delegation_query({delegation_query, To,
++                       Delegate},
++                      __TopXMLNS) ->
++    __NewTopXMLNS =
++      choose_top_xmlns(<<"urn:xmpp:delegation:1">>, [],
++                       __TopXMLNS),
++    _els =
++      lists:reverse('encode_delegation_query_$delegate'(Delegate,
++                                                        __NewTopXMLNS, [])),
++    _attrs = encode_delegation_query_attr_to(To,
++                                           enc_xmlns_attrs(__NewTopXMLNS,
++                                                           __TopXMLNS)),
++    {xmlel, <<"query">>, _attrs, _els}.
++
++'encode_delegation_query_$delegate'([], __TopXMLNS,
++                                  _acc) ->
++    _acc;
++'encode_delegation_query_$delegate'([Delegate | _els],
++                                  __TopXMLNS, _acc) ->
++    'encode_delegation_query_$delegate'(_els, __TopXMLNS,
++                                      [encode_delegate(Delegate, __TopXMLNS)
++                                       | _acc]).
++
++decode_delegation_query_attr_to(__TopXMLNS,
++                              undefined) ->
++    erlang:error({xmpp_codec,
++                {missing_attr, <<"to">>, <<"query">>, __TopXMLNS}});
++decode_delegation_query_attr_to(__TopXMLNS, _val) ->
++    case catch dec_jid(_val) of
++      {'EXIT', _} ->
++        erlang:error({xmpp_codec,
++                      {bad_attr_value, <<"to">>, <<"query">>, __TopXMLNS}});
++      _res -> _res
++    end.
++
++encode_delegation_query_attr_to(_val, _acc) ->
++    [{<<"to">>, enc_jid(_val)} | _acc].
++
++decode_delegate(__TopXMLNS, __IgnoreEls,
++              {xmlel, <<"delegate">>, _attrs, _els}) ->
++    Namespace = decode_delegate_attrs(__TopXMLNS, _attrs,
++                                    undefined),
++    Namespace.
++
++decode_delegate_attrs(__TopXMLNS,
++                    [{<<"namespace">>, _val} | _attrs], _Namespace) ->
++    decode_delegate_attrs(__TopXMLNS, _attrs, _val);
++decode_delegate_attrs(__TopXMLNS, [_ | _attrs],
++                    Namespace) ->
++    decode_delegate_attrs(__TopXMLNS, _attrs, Namespace);
++decode_delegate_attrs(__TopXMLNS, [], Namespace) ->
++    decode_delegate_attr_namespace(__TopXMLNS, Namespace).
++
++encode_delegate(Namespace, __TopXMLNS) ->
++    __NewTopXMLNS =
++      choose_top_xmlns(<<"urn:xmpp:delegation:1">>, [],
++                       __TopXMLNS),
++    _els = [],
++    _attrs = encode_delegate_attr_namespace(Namespace,
++                                          enc_xmlns_attrs(__NewTopXMLNS,
++                                                          __TopXMLNS)),
++    {xmlel, <<"delegate">>, _attrs, _els}.
++
++decode_delegate_attr_namespace(__TopXMLNS, undefined) ->
++    erlang:error({xmpp_codec,
++                {missing_attr, <<"namespace">>, <<"delegate">>,
++                 __TopXMLNS}});
++decode_delegate_attr_namespace(__TopXMLNS, _val) ->
++    _val.
++
++encode_delegate_attr_namespace(_val, _acc) ->
++    [{<<"namespace">>, _val} | _acc].
++
++decode_delegation(__TopXMLNS, __IgnoreEls,
++                {xmlel, <<"delegation">>, _attrs, _els}) ->
++    {Forwarded, Delegated} =
++      decode_delegation_els(__TopXMLNS, __IgnoreEls, _els,
++                            undefined, []),
++    {delegation, Delegated, Forwarded}.
++
++decode_delegation_els(__TopXMLNS, __IgnoreEls, [],
++                    Forwarded, Delegated) ->
++    {Forwarded, lists:reverse(Delegated)};
++decode_delegation_els(__TopXMLNS, __IgnoreEls,
++                    [{xmlel, <<"delegated">>, _attrs, _} = _el | _els],
++                    Forwarded, Delegated) ->
++    case get_attr(<<"xmlns">>, _attrs) of
++      <<"">> when __TopXMLNS == <<"urn:xmpp:delegation:1">> ->
++        decode_delegation_els(__TopXMLNS, __IgnoreEls, _els,
++                              Forwarded,
++                              [decode_delegated(__TopXMLNS, __IgnoreEls, _el)
++                               | Delegated]);
++      <<"urn:xmpp:delegation:1">> ->
++        decode_delegation_els(__TopXMLNS, __IgnoreEls, _els,
++                              Forwarded,
++                              [decode_delegated(<<"urn:xmpp:delegation:1">>,
++                                                __IgnoreEls, _el)
++                               | Delegated]);
++      _ ->
++        decode_delegation_els(__TopXMLNS, __IgnoreEls, _els,
++                              Forwarded, Delegated)
++    end;
++decode_delegation_els(__TopXMLNS, __IgnoreEls,
++                    [{xmlel, <<"forwarded">>, _attrs, _} = _el | _els],
++                    Forwarded, Delegated) ->
++    case get_attr(<<"xmlns">>, _attrs) of
++      <<"urn:xmpp:forward:0">> ->
++        decode_delegation_els(__TopXMLNS, __IgnoreEls, _els,
++                              decode_forwarded(<<"urn:xmpp:forward:0">>,
++                                               __IgnoreEls, _el),
++                              Delegated);
++      _ ->
++        decode_delegation_els(__TopXMLNS, __IgnoreEls, _els,
++                              Forwarded, Delegated)
++    end;
++decode_delegation_els(__TopXMLNS, __IgnoreEls,
++                    [_ | _els], Forwarded, Delegated) ->
++    decode_delegation_els(__TopXMLNS, __IgnoreEls, _els,
++                        Forwarded, Delegated).
++
++encode_delegation({delegation, Delegated, Forwarded},
++                __TopXMLNS) ->
++    __NewTopXMLNS =
++      choose_top_xmlns(<<"urn:xmpp:delegation:1">>, [],
++                       __TopXMLNS),
++    _els =
++      lists:reverse('encode_delegation_$forwarded'(Forwarded,
++                                                   __NewTopXMLNS,
++                                                   'encode_delegation_$delegated'(Delegated,
++                                                                                  __NewTopXMLNS,
++                                                                                  []))),
++    _attrs = enc_xmlns_attrs(__NewTopXMLNS, __TopXMLNS),
++    {xmlel, <<"delegation">>, _attrs, _els}.
++
++'encode_delegation_$forwarded'(undefined, __TopXMLNS,
++                             _acc) ->
++    _acc;
++'encode_delegation_$forwarded'(Forwarded, __TopXMLNS,
++                             _acc) ->
++    [encode_forwarded(Forwarded, __TopXMLNS) | _acc].
++
++'encode_delegation_$delegated'([], __TopXMLNS, _acc) ->
++    _acc;
++'encode_delegation_$delegated'([Delegated | _els],
++                             __TopXMLNS, _acc) ->
++    'encode_delegation_$delegated'(_els, __TopXMLNS,
++                                 [encode_delegated(Delegated, __TopXMLNS)
++                                  | _acc]).
++
++decode_delegated(__TopXMLNS, __IgnoreEls,
++               {xmlel, <<"delegated">>, _attrs, _els}) ->
++    Attrs = decode_delegated_els(__TopXMLNS, __IgnoreEls,
++                               _els, []),
++    Ns = decode_delegated_attrs(__TopXMLNS, _attrs,
++                              undefined),
++    {delegated, Ns, Attrs}.
++
++decode_delegated_els(__TopXMLNS, __IgnoreEls, [],
++                   Attrs) ->
++    lists:reverse(Attrs);
++decode_delegated_els(__TopXMLNS, __IgnoreEls,
++                   [{xmlel, <<"attribute">>, _attrs, _} = _el | _els],
++                   Attrs) ->
++    case get_attr(<<"xmlns">>, _attrs) of
++      <<"">> when __TopXMLNS == <<"urn:xmpp:delegation:1">> ->
++        decode_delegated_els(__TopXMLNS, __IgnoreEls, _els,
++                             [decode_delegated_attribute(__TopXMLNS,
++                                                         __IgnoreEls, _el)
++                              | Attrs]);
++      <<"urn:xmpp:delegation:1">> ->
++        decode_delegated_els(__TopXMLNS, __IgnoreEls, _els,
++                             [decode_delegated_attribute(<<"urn:xmpp:delegation:1">>,
++                                                         __IgnoreEls, _el)
++                              | Attrs]);
++      _ ->
++        decode_delegated_els(__TopXMLNS, __IgnoreEls, _els,
++                             Attrs)
++    end;
++decode_delegated_els(__TopXMLNS, __IgnoreEls,
++                   [_ | _els], Attrs) ->
++    decode_delegated_els(__TopXMLNS, __IgnoreEls, _els,
++                       Attrs).
++
++decode_delegated_attrs(__TopXMLNS,
++                     [{<<"namespace">>, _val} | _attrs], _Ns) ->
++    decode_delegated_attrs(__TopXMLNS, _attrs, _val);
++decode_delegated_attrs(__TopXMLNS, [_ | _attrs], Ns) ->
++    decode_delegated_attrs(__TopXMLNS, _attrs, Ns);
++decode_delegated_attrs(__TopXMLNS, [], Ns) ->
++    decode_delegated_attr_namespace(__TopXMLNS, Ns).
++
++encode_delegated({delegated, Ns, Attrs}, __TopXMLNS) ->
++    __NewTopXMLNS =
++      choose_top_xmlns(<<"urn:xmpp:delegation:1">>, [],
++                       __TopXMLNS),
++    _els = lists:reverse('encode_delegated_$attrs'(Attrs,
++                                                 __NewTopXMLNS, [])),
++    _attrs = encode_delegated_attr_namespace(Ns,
++                                           enc_xmlns_attrs(__NewTopXMLNS,
++                                                           __TopXMLNS)),
++    {xmlel, <<"delegated">>, _attrs, _els}.
++
++'encode_delegated_$attrs'([], __TopXMLNS, _acc) -> _acc;
++'encode_delegated_$attrs'([Attrs | _els], __TopXMLNS,
++                        _acc) ->
++    'encode_delegated_$attrs'(_els, __TopXMLNS,
++                            [encode_delegated_attribute(Attrs, __TopXMLNS)
++                             | _acc]).
++
++decode_delegated_attr_namespace(__TopXMLNS,
++                              undefined) ->
++    erlang:error({xmpp_codec,
++                {missing_attr, <<"namespace">>, <<"delegated">>,
++                 __TopXMLNS}});
++decode_delegated_attr_namespace(__TopXMLNS, _val) ->
++    _val.
++
++encode_delegated_attr_namespace(_val, _acc) ->
++    [{<<"namespace">>, _val} | _acc].
++
++decode_delegated_attribute(__TopXMLNS, __IgnoreEls,
++                         {xmlel, <<"attribute">>, _attrs, _els}) ->
++    Name = decode_delegated_attribute_attrs(__TopXMLNS,
++                                          _attrs, undefined),
++    Name.
++
++decode_delegated_attribute_attrs(__TopXMLNS,
++                               [{<<"name">>, _val} | _attrs], _Name) ->
++    decode_delegated_attribute_attrs(__TopXMLNS, _attrs,
++                                   _val);
++decode_delegated_attribute_attrs(__TopXMLNS,
++                               [_ | _attrs], Name) ->
++    decode_delegated_attribute_attrs(__TopXMLNS, _attrs,
++                                   Name);
++decode_delegated_attribute_attrs(__TopXMLNS, [],
++                               Name) ->
++    decode_delegated_attribute_attr_name(__TopXMLNS, Name).
++
++encode_delegated_attribute(Name, __TopXMLNS) ->
++    __NewTopXMLNS =
++      choose_top_xmlns(<<"urn:xmpp:delegation:1">>, [],
++                       __TopXMLNS),
++    _els = [],
++    _attrs = encode_delegated_attribute_attr_name(Name,
++                                                enc_xmlns_attrs(__NewTopXMLNS,
++                                                                __TopXMLNS)),
++    {xmlel, <<"attribute">>, _attrs, _els}.
++
++decode_delegated_attribute_attr_name(__TopXMLNS,
++                                   undefined) ->
++    erlang:error({xmpp_codec,
++                {missing_attr, <<"name">>, <<"attribute">>,
++                 __TopXMLNS}});
++decode_delegated_attribute_attr_name(__TopXMLNS,
++                                   _val) ->
++    _val.
++
++encode_delegated_attribute_attr_name(_val, _acc) ->
++    [{<<"name">>, _val} | _acc].
++
++decode_privilege(__TopXMLNS, __IgnoreEls,
++               {xmlel, <<"privilege">>, _attrs, _els}) ->
++    {Perms, Forwarded} = decode_privilege_els(__TopXMLNS,
++                                            __IgnoreEls, _els, [], undefined),
++    {privilege, Perms, Forwarded}.
++
++decode_privilege_els(__TopXMLNS, __IgnoreEls, [], Perms,
++                   Forwarded) ->
++    {lists:reverse(Perms), Forwarded};
++decode_privilege_els(__TopXMLNS, __IgnoreEls,
++                   [{xmlel, <<"perm">>, _attrs, _} = _el | _els], Perms,
++                   Forwarded) ->
++    case get_attr(<<"xmlns">>, _attrs) of
++      <<"">> when __TopXMLNS == <<"urn:xmpp:privilege:1">> ->
++        decode_privilege_els(__TopXMLNS, __IgnoreEls, _els,
++                             [decode_privilege_perm(__TopXMLNS, __IgnoreEls,
++                                                    _el)
++                              | Perms],
++                             Forwarded);
++      <<"urn:xmpp:privilege:1">> ->
++        decode_privilege_els(__TopXMLNS, __IgnoreEls, _els,
++                             [decode_privilege_perm(<<"urn:xmpp:privilege:1">>,
++                                                    __IgnoreEls, _el)
++                              | Perms],
++                             Forwarded);
++      _ ->
++        decode_privilege_els(__TopXMLNS, __IgnoreEls, _els,
++                             Perms, Forwarded)
++    end;
++decode_privilege_els(__TopXMLNS, __IgnoreEls,
++                   [{xmlel, <<"forwarded">>, _attrs, _} = _el | _els],
++                   Perms, Forwarded) ->
++    case get_attr(<<"xmlns">>, _attrs) of
++      <<"urn:xmpp:forward:0">> ->
++        decode_privilege_els(__TopXMLNS, __IgnoreEls, _els,
++                             Perms,
++                             decode_forwarded(<<"urn:xmpp:forward:0">>,
++                                              __IgnoreEls, _el));
++      _ ->
++        decode_privilege_els(__TopXMLNS, __IgnoreEls, _els,
++                             Perms, Forwarded)
++    end;
++decode_privilege_els(__TopXMLNS, __IgnoreEls,
++                   [_ | _els], Perms, Forwarded) ->
++    decode_privilege_els(__TopXMLNS, __IgnoreEls, _els,
++                       Perms, Forwarded).
++
++encode_privilege({privilege, Perms, Forwarded},
++               __TopXMLNS) ->
++    __NewTopXMLNS =
++      choose_top_xmlns(<<"urn:xmpp:privilege:1">>, [],
++                       __TopXMLNS),
++    _els = lists:reverse('encode_privilege_$perms'(Perms,
++                                                 __NewTopXMLNS,
++                                                 'encode_privilege_$forwarded'(Forwarded,
++                                                                               __NewTopXMLNS,
++                                                                               []))),
++    _attrs = enc_xmlns_attrs(__NewTopXMLNS, __TopXMLNS),
++    {xmlel, <<"privilege">>, _attrs, _els}.
++
++'encode_privilege_$perms'([], __TopXMLNS, _acc) -> _acc;
++'encode_privilege_$perms'([Perms | _els], __TopXMLNS,
++                        _acc) ->
++    'encode_privilege_$perms'(_els, __TopXMLNS,
++                            [encode_privilege_perm(Perms, __TopXMLNS)
++                             | _acc]).
++
++'encode_privilege_$forwarded'(undefined, __TopXMLNS,
++                            _acc) ->
++    _acc;
++'encode_privilege_$forwarded'(Forwarded, __TopXMLNS,
++                            _acc) ->
++    [encode_forwarded(Forwarded, __TopXMLNS) | _acc].
++
++decode_privilege_perm(__TopXMLNS, __IgnoreEls,
++                    {xmlel, <<"perm">>, _attrs, _els}) ->
++    {Access, Type} = decode_privilege_perm_attrs(__TopXMLNS,
++                                               _attrs, undefined, undefined),
++    {privilege_perm, Access, Type}.
++
++decode_privilege_perm_attrs(__TopXMLNS,
++                          [{<<"access">>, _val} | _attrs], _Access, Type) ->
++    decode_privilege_perm_attrs(__TopXMLNS, _attrs, _val,
++                              Type);
++decode_privilege_perm_attrs(__TopXMLNS,
++                          [{<<"type">>, _val} | _attrs], Access, _Type) ->
++    decode_privilege_perm_attrs(__TopXMLNS, _attrs, Access,
++                              _val);
++decode_privilege_perm_attrs(__TopXMLNS, [_ | _attrs],
++                          Access, Type) ->
++    decode_privilege_perm_attrs(__TopXMLNS, _attrs, Access,
++                              Type);
++decode_privilege_perm_attrs(__TopXMLNS, [], Access,
++                          Type) ->
++    {decode_privilege_perm_attr_access(__TopXMLNS, Access),
++     decode_privilege_perm_attr_type(__TopXMLNS, Type)}.
++
++encode_privilege_perm({privilege_perm, Access, Type},
++                    __TopXMLNS) ->
++    __NewTopXMLNS =
++      choose_top_xmlns(<<"urn:xmpp:privilege:1">>, [],
++                       __TopXMLNS),
++    _els = [],
++    _attrs = encode_privilege_perm_attr_type(Type,
++                                           encode_privilege_perm_attr_access(Access,
++                                                                             enc_xmlns_attrs(__NewTopXMLNS,
++                                                                                             __TopXMLNS))),
++    {xmlel, <<"perm">>, _attrs, _els}.
++
++decode_privilege_perm_attr_access(__TopXMLNS,
++                                undefined) ->
++    erlang:error({xmpp_codec,
++                {missing_attr, <<"access">>, <<"perm">>, __TopXMLNS}});
++decode_privilege_perm_attr_access(__TopXMLNS, _val) ->
++    case catch dec_enum(_val, [roster, message, presence])
++      of
++      {'EXIT', _} ->
++        erlang:error({xmpp_codec,
++                      {bad_attr_value, <<"access">>, <<"perm">>,
++                       __TopXMLNS}});
++      _res -> _res
++    end.
++
++encode_privilege_perm_attr_access(_val, _acc) ->
++    [{<<"access">>, enc_enum(_val)} | _acc].
++
++decode_privilege_perm_attr_type(__TopXMLNS,
++                              undefined) ->
++    erlang:error({xmpp_codec,
++                {missing_attr, <<"type">>, <<"perm">>, __TopXMLNS}});
++decode_privilege_perm_attr_type(__TopXMLNS, _val) ->
++    case catch dec_enum(_val,
++                      [none, get, set, both, outgoing, roster,
++                       managed_entity])
++      of
++      {'EXIT', _} ->
++        erlang:error({xmpp_codec,
++                      {bad_attr_value, <<"type">>, <<"perm">>, __TopXMLNS}});
++      _res -> _res
++    end.
++
++encode_privilege_perm_attr_type(_val, _acc) ->
++    [{<<"type">>, enc_enum(_val)} | _acc].
++
 +decode_thumbnail(__TopXMLNS, __IgnoreEls,
 +               {xmlel, <<"thumbnail">>, _attrs, _els}) ->
 +    {Uri, Media_type, Width, Height} =
 +      decode_thumbnail_attrs(__TopXMLNS, _attrs, undefined,
 +                             undefined, undefined, undefined),
 +    {thumbnail, Uri, Media_type, Width, Height}.
 +
 +decode_thumbnail_attrs(__TopXMLNS,
 +                     [{<<"uri">>, _val} | _attrs], _Uri, Media_type, Width,
 +                     Height) ->
 +    decode_thumbnail_attrs(__TopXMLNS, _attrs, _val,
 +                         Media_type, Width, Height);
 +decode_thumbnail_attrs(__TopXMLNS,
 +                     [{<<"media-type">>, _val} | _attrs], Uri, _Media_type,
 +                     Width, Height) ->
 +    decode_thumbnail_attrs(__TopXMLNS, _attrs, Uri, _val,
 +                         Width, Height);
 +decode_thumbnail_attrs(__TopXMLNS,
 +                     [{<<"width">>, _val} | _attrs], Uri, Media_type, _Width,
 +                     Height) ->
 +    decode_thumbnail_attrs(__TopXMLNS, _attrs, Uri,
 +                         Media_type, _val, Height);
 +decode_thumbnail_attrs(__TopXMLNS,
 +                     [{<<"height">>, _val} | _attrs], Uri, Media_type, Width,
 +                     _Height) ->
 +    decode_thumbnail_attrs(__TopXMLNS, _attrs, Uri,
 +                         Media_type, Width, _val);
 +decode_thumbnail_attrs(__TopXMLNS, [_ | _attrs], Uri,
 +                     Media_type, Width, Height) ->
 +    decode_thumbnail_attrs(__TopXMLNS, _attrs, Uri,
 +                         Media_type, Width, Height);
 +decode_thumbnail_attrs(__TopXMLNS, [], Uri, Media_type,
 +                     Width, Height) ->
 +    {decode_thumbnail_attr_uri(__TopXMLNS, Uri),
 +     'decode_thumbnail_attr_media-type'(__TopXMLNS,
 +                                      Media_type),
 +     decode_thumbnail_attr_width(__TopXMLNS, Width),
 +     decode_thumbnail_attr_height(__TopXMLNS, Height)}.
 +
 +encode_thumbnail({thumbnail, Uri, Media_type, Width,
 +                Height},
 +               __TopXMLNS) ->
 +    __NewTopXMLNS =
 +      choose_top_xmlns(<<"urn:xmpp:thumbs:1">>, [],
 +                       __TopXMLNS),
 +    _els = [],
 +    _attrs = encode_thumbnail_attr_height(Height,
 +                                        encode_thumbnail_attr_width(Width,
 +                                                                    'encode_thumbnail_attr_media-type'(Media_type,
 +                                                                                                       encode_thumbnail_attr_uri(Uri,
 +                                                                                                                                 enc_xmlns_attrs(__NewTopXMLNS,
 +                                                                                                                                                 __TopXMLNS))))),
 +    {xmlel, <<"thumbnail">>, _attrs, _els}.
 +
 +decode_thumbnail_attr_uri(__TopXMLNS, undefined) ->
 +    erlang:error({xmpp_codec,
 +                {missing_attr, <<"uri">>, <<"thumbnail">>,
 +                 __TopXMLNS}});
 +decode_thumbnail_attr_uri(__TopXMLNS, _val) -> _val.
 +
 +encode_thumbnail_attr_uri(_val, _acc) ->
 +    [{<<"uri">>, _val} | _acc].
 +
 +'decode_thumbnail_attr_media-type'(__TopXMLNS,
 +                                 undefined) ->
 +    <<>>;
 +'decode_thumbnail_attr_media-type'(__TopXMLNS, _val) ->
 +    _val.
 +
 +'encode_thumbnail_attr_media-type'(<<>>, _acc) -> _acc;
 +'encode_thumbnail_attr_media-type'(_val, _acc) ->
 +    [{<<"media-type">>, _val} | _acc].
 +
 +decode_thumbnail_attr_width(__TopXMLNS, undefined) ->
 +    undefined;
 +decode_thumbnail_attr_width(__TopXMLNS, _val) ->
 +    case catch dec_int(_val, 0, infinity) of
 +      {'EXIT', _} ->
 +        erlang:error({xmpp_codec,
 +                      {bad_attr_value, <<"width">>, <<"thumbnail">>,
 +                       __TopXMLNS}});
 +      _res -> _res
 +    end.
 +
 +encode_thumbnail_attr_width(undefined, _acc) -> _acc;
 +encode_thumbnail_attr_width(_val, _acc) ->
 +    [{<<"width">>, enc_int(_val)} | _acc].
 +
 +decode_thumbnail_attr_height(__TopXMLNS, undefined) ->
 +    undefined;
 +decode_thumbnail_attr_height(__TopXMLNS, _val) ->
 +    case catch dec_int(_val, 0, infinity) of
 +      {'EXIT', _} ->
 +        erlang:error({xmpp_codec,
 +                      {bad_attr_value, <<"height">>, <<"thumbnail">>,
 +                       __TopXMLNS}});
 +      _res -> _res
 +    end.
 +
 +encode_thumbnail_attr_height(undefined, _acc) -> _acc;
 +encode_thumbnail_attr_height(_val, _acc) ->
 +    [{<<"height">>, enc_int(_val)} | _acc].
 +
 +decode_upload_slot(__TopXMLNS, __IgnoreEls,
 +                 {xmlel, <<"slot">>, _attrs, _els}) ->
 +    {Put, Get} = decode_upload_slot_els(__TopXMLNS,
 +                                      __IgnoreEls, _els, undefined,
 +                                      undefined),
 +    Xmlns = decode_upload_slot_attrs(__TopXMLNS, _attrs,
 +                                   undefined),
 +    {upload_slot, Get, Put, Xmlns}.
 +
 +decode_upload_slot_els(__TopXMLNS, __IgnoreEls, [], Put,
 +                     Get) ->
 +    {Put, Get};
 +decode_upload_slot_els(__TopXMLNS, __IgnoreEls,
 +                     [{xmlel, <<"get">>, _attrs, _} = _el | _els], Put,
 +                     Get) ->
 +    case get_attr(<<"xmlns">>, _attrs) of
 +      <<"">>
 +        when __TopXMLNS ==
 +               <<"eu:siacs:conversations:http:upload">>;
 +             __TopXMLNS == <<"urn:xmpp:http:upload">> ->
 +        decode_upload_slot_els(__TopXMLNS, __IgnoreEls, _els,
 +                               Put,
 +                               decode_upload_get(__TopXMLNS, __IgnoreEls,
 +                                                 _el));
 +      <<"urn:xmpp:http:upload">> ->
 +        decode_upload_slot_els(__TopXMLNS, __IgnoreEls, _els,
 +                               Put,
 +                               decode_upload_get(<<"urn:xmpp:http:upload">>,
 +                                                 __IgnoreEls, _el));
 +      <<"eu:siacs:conversations:http:upload">> ->
 +        decode_upload_slot_els(__TopXMLNS, __IgnoreEls, _els,
 +                               Put,
 +                               decode_upload_get(<<"eu:siacs:conversations:http:upload">>,
 +                                                 __IgnoreEls, _el));
 +      _ ->
 +        decode_upload_slot_els(__TopXMLNS, __IgnoreEls, _els,
 +                               Put, Get)
 +    end;
 +decode_upload_slot_els(__TopXMLNS, __IgnoreEls,
 +                     [{xmlel, <<"put">>, _attrs, _} = _el | _els], Put,
 +                     Get) ->
 +    case get_attr(<<"xmlns">>, _attrs) of
 +      <<"">>
 +        when __TopXMLNS ==
 +               <<"eu:siacs:conversations:http:upload">>;
 +             __TopXMLNS == <<"urn:xmpp:http:upload">> ->
 +        decode_upload_slot_els(__TopXMLNS, __IgnoreEls, _els,
 +                               decode_upload_put(__TopXMLNS, __IgnoreEls,
 +                                                 _el),
 +                               Get);
 +      <<"urn:xmpp:http:upload">> ->
 +        decode_upload_slot_els(__TopXMLNS, __IgnoreEls, _els,
 +                               decode_upload_put(<<"urn:xmpp:http:upload">>,
 +                                                 __IgnoreEls, _el),
 +                               Get);
 +      <<"eu:siacs:conversations:http:upload">> ->
 +        decode_upload_slot_els(__TopXMLNS, __IgnoreEls, _els,
 +                               decode_upload_put(<<"eu:siacs:conversations:http:upload">>,
 +                                                 __IgnoreEls, _el),
 +                               Get);
 +      _ ->
 +        decode_upload_slot_els(__TopXMLNS, __IgnoreEls, _els,
 +                               Put, Get)
 +    end;
 +decode_upload_slot_els(__TopXMLNS, __IgnoreEls,
 +                     [_ | _els], Put, Get) ->
 +    decode_upload_slot_els(__TopXMLNS, __IgnoreEls, _els,
 +                         Put, Get).
 +
 +decode_upload_slot_attrs(__TopXMLNS,
 +                       [{<<"xmlns">>, _val} | _attrs], _Xmlns) ->
 +    decode_upload_slot_attrs(__TopXMLNS, _attrs, _val);
 +decode_upload_slot_attrs(__TopXMLNS, [_ | _attrs],
 +                       Xmlns) ->
 +    decode_upload_slot_attrs(__TopXMLNS, _attrs, Xmlns);
 +decode_upload_slot_attrs(__TopXMLNS, [], Xmlns) ->
 +    decode_upload_slot_attr_xmlns(__TopXMLNS, Xmlns).
 +
 +encode_upload_slot({upload_slot, Get, Put, Xmlns},
 +                 __TopXMLNS) ->
 +    __NewTopXMLNS = choose_top_xmlns(Xmlns,
 +                                   [<<"urn:xmpp:http:upload">>,
 +                                    <<"eu:siacs:conversations:http:upload">>],
 +                                   __TopXMLNS),
 +    _els = lists:reverse('encode_upload_slot_$put'(Put,
 +                                                 __NewTopXMLNS,
 +                                                 'encode_upload_slot_$get'(Get,
 +                                                                           __NewTopXMLNS,
 +                                                                           []))),
 +    _attrs = enc_xmlns_attrs(__NewTopXMLNS, __TopXMLNS),
 +    {xmlel, <<"slot">>, _attrs, _els}.
 +
 +'encode_upload_slot_$put'(undefined, __TopXMLNS,
 +                        _acc) ->
 +    _acc;
 +'encode_upload_slot_$put'(Put, __TopXMLNS, _acc) ->
 +    [encode_upload_put(Put, __TopXMLNS) | _acc].
 +
 +'encode_upload_slot_$get'(undefined, __TopXMLNS,
 +                        _acc) ->
 +    _acc;
 +'encode_upload_slot_$get'(Get, __TopXMLNS, _acc) ->
 +    [encode_upload_get(Get, __TopXMLNS) | _acc].
 +
 +decode_upload_slot_attr_xmlns(__TopXMLNS, undefined) ->
 +    <<>>;
 +decode_upload_slot_attr_xmlns(__TopXMLNS, _val) -> _val.
 +
 +decode_upload_put(__TopXMLNS, __IgnoreEls,
 +                {xmlel, <<"put">>, _attrs, _els}) ->
 +    Cdata = decode_upload_put_els(__TopXMLNS, __IgnoreEls,
 +                                _els, <<>>),
 +    Cdata.
 +
 +decode_upload_put_els(__TopXMLNS, __IgnoreEls, [],
 +                    Cdata) ->
 +    decode_upload_put_cdata(__TopXMLNS, Cdata);
 +decode_upload_put_els(__TopXMLNS, __IgnoreEls,
 +                    [{xmlcdata, _data} | _els], Cdata) ->
 +    decode_upload_put_els(__TopXMLNS, __IgnoreEls, _els,
 +                        <<Cdata/binary, _data/binary>>);
 +decode_upload_put_els(__TopXMLNS, __IgnoreEls,
 +                    [_ | _els], Cdata) ->
 +    decode_upload_put_els(__TopXMLNS, __IgnoreEls, _els,
 +                        Cdata).
 +
 +encode_upload_put(Cdata, __TopXMLNS) ->
 +    __NewTopXMLNS = choose_top_xmlns(<<>>,
 +                                   [<<"urn:xmpp:http:upload">>,
 +                                    <<"eu:siacs:conversations:http:upload">>],
 +                                   __TopXMLNS),
 +    _els = encode_upload_put_cdata(Cdata, []),
 +    _attrs = enc_xmlns_attrs(__NewTopXMLNS, __TopXMLNS),
 +    {xmlel, <<"put">>, _attrs, _els}.
 +
 +decode_upload_put_cdata(__TopXMLNS, <<>>) ->
 +    erlang:error({xmpp_codec,
 +                {missing_cdata, <<>>, <<"put">>, __TopXMLNS}});
 +decode_upload_put_cdata(__TopXMLNS, _val) -> _val.
 +
 +encode_upload_put_cdata(_val, _acc) ->
 +    [{xmlcdata, _val} | _acc].
 +
 +decode_upload_get(__TopXMLNS, __IgnoreEls,
 +                {xmlel, <<"get">>, _attrs, _els}) ->
 +    Cdata = decode_upload_get_els(__TopXMLNS, __IgnoreEls,
 +                                _els, <<>>),
 +    Cdata.
 +
 +decode_upload_get_els(__TopXMLNS, __IgnoreEls, [],
 +                    Cdata) ->
 +    decode_upload_get_cdata(__TopXMLNS, Cdata);
 +decode_upload_get_els(__TopXMLNS, __IgnoreEls,
 +                    [{xmlcdata, _data} | _els], Cdata) ->
 +    decode_upload_get_els(__TopXMLNS, __IgnoreEls, _els,
 +                        <<Cdata/binary, _data/binary>>);
 +decode_upload_get_els(__TopXMLNS, __IgnoreEls,
 +                    [_ | _els], Cdata) ->
 +    decode_upload_get_els(__TopXMLNS, __IgnoreEls, _els,
 +                        Cdata).
 +
 +encode_upload_get(Cdata, __TopXMLNS) ->
 +    __NewTopXMLNS = choose_top_xmlns(<<>>,
 +                                   [<<"urn:xmpp:http:upload">>,
 +                                    <<"eu:siacs:conversations:http:upload">>],
 +                                   __TopXMLNS),
 +    _els = encode_upload_get_cdata(Cdata, []),
 +    _attrs = enc_xmlns_attrs(__NewTopXMLNS, __TopXMLNS),
 +    {xmlel, <<"get">>, _attrs, _els}.
 +
 +decode_upload_get_cdata(__TopXMLNS, <<>>) ->
 +    erlang:error({xmpp_codec,
 +                {missing_cdata, <<>>, <<"get">>, __TopXMLNS}});
 +decode_upload_get_cdata(__TopXMLNS, _val) -> _val.
 +
 +encode_upload_get_cdata(_val, _acc) ->
 +    [{xmlcdata, _val} | _acc].
 +
 +decode_upload_request(__TopXMLNS, __IgnoreEls,
 +                    {xmlel, <<"request">>, _attrs, _els}) ->
 +    {Content_type, Size, Filename} =
 +      decode_upload_request_els(__TopXMLNS, __IgnoreEls, _els,
 +                                <<>>, error, error),
 +    Xmlns = decode_upload_request_attrs(__TopXMLNS, _attrs,
 +                                      undefined),
 +    {upload_request, Filename, Size, Content_type, Xmlns}.
 +
 +decode_upload_request_els(__TopXMLNS, __IgnoreEls, [],
 +                        Content_type, Size, Filename) ->
 +    {Content_type,
 +     case Size of
 +       error ->
 +         erlang:error({xmpp_codec,
 +                       {missing_tag, <<"size">>, __TopXMLNS}});
 +       {value, Size1} -> Size1
 +     end,
 +     case Filename of
 +       error ->
 +         erlang:error({xmpp_codec,
 +                       {missing_tag, <<"filename">>, __TopXMLNS}});
 +       {value, Filename1} -> Filename1
 +     end};
 +decode_upload_request_els(__TopXMLNS, __IgnoreEls,
 +                        [{xmlel, <<"filename">>, _attrs, _} = _el | _els],
 +                        Content_type, Size, Filename) ->
 +    case get_attr(<<"xmlns">>, _attrs) of
 +      <<"">>
 +        when __TopXMLNS ==
 +               <<"eu:siacs:conversations:http:upload">>;
 +             __TopXMLNS == <<"urn:xmpp:http:upload">> ->
 +        decode_upload_request_els(__TopXMLNS, __IgnoreEls, _els,
 +                                  Content_type, Size,
 +                                  {value,
 +                                   decode_upload_filename(__TopXMLNS,
 +                                                          __IgnoreEls, _el)});
 +      <<"urn:xmpp:http:upload">> ->
 +        decode_upload_request_els(__TopXMLNS, __IgnoreEls, _els,
 +                                  Content_type, Size,
 +                                  {value,
 +                                   decode_upload_filename(<<"urn:xmpp:http:upload">>,
 +                                                          __IgnoreEls, _el)});
 +      <<"eu:siacs:conversations:http:upload">> ->
 +        decode_upload_request_els(__TopXMLNS, __IgnoreEls, _els,
 +                                  Content_type, Size,
 +                                  {value,
 +                                   decode_upload_filename(<<"eu:siacs:conversations:http:upload">>,
 +                                                          __IgnoreEls, _el)});
 +      _ ->
 +        decode_upload_request_els(__TopXMLNS, __IgnoreEls, _els,
 +                                  Content_type, Size, Filename)
 +    end;
 +decode_upload_request_els(__TopXMLNS, __IgnoreEls,
 +                        [{xmlel, <<"size">>, _attrs, _} = _el | _els],
 +                        Content_type, Size, Filename) ->
 +    case get_attr(<<"xmlns">>, _attrs) of
 +      <<"">>
 +        when __TopXMLNS ==
 +               <<"eu:siacs:conversations:http:upload">>;
 +             __TopXMLNS == <<"urn:xmpp:http:upload">> ->
 +        decode_upload_request_els(__TopXMLNS, __IgnoreEls, _els,
 +                                  Content_type,
 +                                  {value,
 +                                   decode_upload_size(__TopXMLNS, __IgnoreEls,
 +                                                      _el)},
 +                                  Filename);
 +      <<"urn:xmpp:http:upload">> ->
 +        decode_upload_request_els(__TopXMLNS, __IgnoreEls, _els,
 +                                  Content_type,
 +                                  {value,
 +                                   decode_upload_size(<<"urn:xmpp:http:upload">>,
 +                                                      __IgnoreEls, _el)},
 +                                  Filename);
 +      <<"eu:siacs:conversations:http:upload">> ->
 +        decode_upload_request_els(__TopXMLNS, __IgnoreEls, _els,
 +                                  Content_type,
 +                                  {value,
 +                                   decode_upload_size(<<"eu:siacs:conversations:http:upload">>,
 +                                                      __IgnoreEls, _el)},
 +                                  Filename);
 +      _ ->
 +        decode_upload_request_els(__TopXMLNS, __IgnoreEls, _els,
 +                                  Content_type, Size, Filename)
 +    end;
 +decode_upload_request_els(__TopXMLNS, __IgnoreEls,
 +                        [{xmlel, <<"content-type">>, _attrs, _} = _el | _els],
 +                        Content_type, Size, Filename) ->
 +    case get_attr(<<"xmlns">>, _attrs) of
 +      <<"">>
 +        when __TopXMLNS ==
 +               <<"eu:siacs:conversations:http:upload">>;
 +             __TopXMLNS == <<"urn:xmpp:http:upload">> ->
 +        decode_upload_request_els(__TopXMLNS, __IgnoreEls, _els,
 +                                  decode_upload_content_type(__TopXMLNS,
 +                                                             __IgnoreEls,
 +                                                             _el),
 +                                  Size, Filename);
 +      <<"urn:xmpp:http:upload">> ->
 +        decode_upload_request_els(__TopXMLNS, __IgnoreEls, _els,
 +                                  decode_upload_content_type(<<"urn:xmpp:http:upload">>,
 +                                                             __IgnoreEls,
 +                                                             _el),
 +                                  Size, Filename);
 +      <<"eu:siacs:conversations:http:upload">> ->
 +        decode_upload_request_els(__TopXMLNS, __IgnoreEls, _els,
 +                                  decode_upload_content_type(<<"eu:siacs:conversations:http:upload">>,
 +                                                             __IgnoreEls,
 +                                                             _el),
 +                                  Size, Filename);
 +      _ ->
 +        decode_upload_request_els(__TopXMLNS, __IgnoreEls, _els,
 +                                  Content_type, Size, Filename)
 +    end;
 +decode_upload_request_els(__TopXMLNS, __IgnoreEls,
 +                        [_ | _els], Content_type, Size, Filename) ->
 +    decode_upload_request_els(__TopXMLNS, __IgnoreEls, _els,
 +                            Content_type, Size, Filename).
 +
 +decode_upload_request_attrs(__TopXMLNS,
 +                          [{<<"xmlns">>, _val} | _attrs], _Xmlns) ->
 +    decode_upload_request_attrs(__TopXMLNS, _attrs, _val);
 +decode_upload_request_attrs(__TopXMLNS, [_ | _attrs],
 +                          Xmlns) ->
 +    decode_upload_request_attrs(__TopXMLNS, _attrs, Xmlns);
 +decode_upload_request_attrs(__TopXMLNS, [], Xmlns) ->
 +    decode_upload_request_attr_xmlns(__TopXMLNS, Xmlns).
 +
 +encode_upload_request({upload_request, Filename, Size,
 +                     Content_type, Xmlns},
 +                    __TopXMLNS) ->
 +    __NewTopXMLNS = choose_top_xmlns(Xmlns,
 +                                   [<<"urn:xmpp:http:upload">>,
 +                                    <<"eu:siacs:conversations:http:upload">>],
 +                                   __TopXMLNS),
 +    _els =
 +      lists:reverse('encode_upload_request_$content-type'(Content_type,
 +                                                          __NewTopXMLNS,
 +                                                          'encode_upload_request_$size'(Size,
 +                                                                                        __NewTopXMLNS,
 +                                                                                        'encode_upload_request_$filename'(Filename,
 +                                                                                                                          __NewTopXMLNS,
 +                                                                                                                          [])))),
 +    _attrs = enc_xmlns_attrs(__NewTopXMLNS, __TopXMLNS),
 +    {xmlel, <<"request">>, _attrs, _els}.
 +
 +'encode_upload_request_$content-type'(<<>>, __TopXMLNS,
 +                                    _acc) ->
 +    _acc;
 +'encode_upload_request_$content-type'(Content_type,
 +                                    __TopXMLNS, _acc) ->
 +    [encode_upload_content_type(Content_type, __TopXMLNS)
 +     | _acc].
 +
 +'encode_upload_request_$size'(Size, __TopXMLNS, _acc) ->
 +    [encode_upload_size(Size, __TopXMLNS) | _acc].
 +
 +'encode_upload_request_$filename'(Filename, __TopXMLNS,
 +                                _acc) ->
 +    [encode_upload_filename(Filename, __TopXMLNS) | _acc].
 +
 +decode_upload_request_attr_xmlns(__TopXMLNS,
 +                               undefined) ->
 +    <<>>;
 +decode_upload_request_attr_xmlns(__TopXMLNS, _val) ->
 +    _val.
 +
 +decode_upload_content_type(__TopXMLNS, __IgnoreEls,
 +                         {xmlel, <<"content-type">>, _attrs, _els}) ->
 +    Cdata = decode_upload_content_type_els(__TopXMLNS,
 +                                         __IgnoreEls, _els, <<>>),
 +    Cdata.
 +
 +decode_upload_content_type_els(__TopXMLNS, __IgnoreEls,
 +                             [], Cdata) ->
 +    decode_upload_content_type_cdata(__TopXMLNS, Cdata);
 +decode_upload_content_type_els(__TopXMLNS, __IgnoreEls,
 +                             [{xmlcdata, _data} | _els], Cdata) ->
 +    decode_upload_content_type_els(__TopXMLNS, __IgnoreEls,
 +                                 _els, <<Cdata/binary, _data/binary>>);
 +decode_upload_content_type_els(__TopXMLNS, __IgnoreEls,
 +                             [_ | _els], Cdata) ->
 +    decode_upload_content_type_els(__TopXMLNS, __IgnoreEls,
 +                                 _els, Cdata).
 +
 +encode_upload_content_type(Cdata, __TopXMLNS) ->
 +    __NewTopXMLNS = choose_top_xmlns(<<>>,
 +                                   [<<"urn:xmpp:http:upload">>,
 +                                    <<"eu:siacs:conversations:http:upload">>],
 +                                   __TopXMLNS),
 +    _els = encode_upload_content_type_cdata(Cdata, []),
 +    _attrs = enc_xmlns_attrs(__NewTopXMLNS, __TopXMLNS),
 +    {xmlel, <<"content-type">>, _attrs, _els}.
 +
 +decode_upload_content_type_cdata(__TopXMLNS, <<>>) ->
 +    <<>>;
 +decode_upload_content_type_cdata(__TopXMLNS, _val) ->
 +    _val.
 +
 +encode_upload_content_type_cdata(<<>>, _acc) -> _acc;
 +encode_upload_content_type_cdata(_val, _acc) ->
 +    [{xmlcdata, _val} | _acc].
 +
 +decode_upload_size(__TopXMLNS, __IgnoreEls,
 +                 {xmlel, <<"size">>, _attrs, _els}) ->
 +    Cdata = decode_upload_size_els(__TopXMLNS, __IgnoreEls,
 +                                 _els, <<>>),
 +    Cdata.
 +
 +decode_upload_size_els(__TopXMLNS, __IgnoreEls, [],
 +                     Cdata) ->
 +    decode_upload_size_cdata(__TopXMLNS, Cdata);
 +decode_upload_size_els(__TopXMLNS, __IgnoreEls,
 +                     [{xmlcdata, _data} | _els], Cdata) ->
 +    decode_upload_size_els(__TopXMLNS, __IgnoreEls, _els,
 +                         <<Cdata/binary, _data/binary>>);
 +decode_upload_size_els(__TopXMLNS, __IgnoreEls,
 +                     [_ | _els], Cdata) ->
 +    decode_upload_size_els(__TopXMLNS, __IgnoreEls, _els,
 +                         Cdata).
 +
 +encode_upload_size(Cdata, __TopXMLNS) ->
 +    __NewTopXMLNS = choose_top_xmlns(<<>>,
 +                                   [<<"urn:xmpp:http:upload">>,
 +                                    <<"eu:siacs:conversations:http:upload">>],
 +                                   __TopXMLNS),
 +    _els = encode_upload_size_cdata(Cdata, []),
 +    _attrs = enc_xmlns_attrs(__NewTopXMLNS, __TopXMLNS),
 +    {xmlel, <<"size">>, _attrs, _els}.
 +
 +decode_upload_size_cdata(__TopXMLNS, <<>>) ->
 +    erlang:error({xmpp_codec,
 +                {missing_cdata, <<>>, <<"size">>, __TopXMLNS}});
 +decode_upload_size_cdata(__TopXMLNS, _val) ->
 +    case catch dec_int(_val, 0, infinity) of
 +      {'EXIT', _} ->
 +        erlang:error({xmpp_codec,
 +                      {bad_cdata_value, <<>>, <<"size">>, __TopXMLNS}});
 +      _res -> _res
 +    end.
 +
 +encode_upload_size_cdata(_val, _acc) ->
 +    [{xmlcdata, enc_int(_val)} | _acc].
 +
 +decode_upload_filename(__TopXMLNS, __IgnoreEls,
 +                     {xmlel, <<"filename">>, _attrs, _els}) ->
 +    Cdata = decode_upload_filename_els(__TopXMLNS,
 +                                     __IgnoreEls, _els, <<>>),
 +    Cdata.
 +
 +decode_upload_filename_els(__TopXMLNS, __IgnoreEls, [],
 +                         Cdata) ->
 +    decode_upload_filename_cdata(__TopXMLNS, Cdata);
 +decode_upload_filename_els(__TopXMLNS, __IgnoreEls,
 +                         [{xmlcdata, _data} | _els], Cdata) ->
 +    decode_upload_filename_els(__TopXMLNS, __IgnoreEls,
 +                             _els, <<Cdata/binary, _data/binary>>);
 +decode_upload_filename_els(__TopXMLNS, __IgnoreEls,
 +                         [_ | _els], Cdata) ->
 +    decode_upload_filename_els(__TopXMLNS, __IgnoreEls,
 +                             _els, Cdata).
 +
 +encode_upload_filename(Cdata, __TopXMLNS) ->
 +    __NewTopXMLNS = choose_top_xmlns(<<>>,
 +                                   [<<"urn:xmpp:http:upload">>,
 +                                    <<"eu:siacs:conversations:http:upload">>],
 +                                   __TopXMLNS),
 +    _els = encode_upload_filename_cdata(Cdata, []),
 +    _attrs = enc_xmlns_attrs(__NewTopXMLNS, __TopXMLNS),
 +    {xmlel, <<"filename">>, _attrs, _els}.
 +
 +decode_upload_filename_cdata(__TopXMLNS, <<>>) ->
 +    erlang:error({xmpp_codec,
 +                {missing_cdata, <<>>, <<"filename">>, __TopXMLNS}});
 +decode_upload_filename_cdata(__TopXMLNS, _val) -> _val.
 +
 +encode_upload_filename_cdata(_val, _acc) ->
 +    [{xmlcdata, _val} | _acc].
 +
 +decode_sic(__TopXMLNS, __IgnoreEls,
 +         {xmlel, <<"address">>, _attrs, _els}) ->
 +    {Ip, Port} = decode_sic_els(__TopXMLNS, __IgnoreEls,
 +                              _els, undefined, undefined),
 +    Xmlns = decode_sic_attrs(__TopXMLNS, _attrs, undefined),
 +    {sic, Ip, Port, Xmlns}.
 +
 +decode_sic_els(__TopXMLNS, __IgnoreEls, [], Ip, Port) ->
 +    {Ip, Port};
 +decode_sic_els(__TopXMLNS, __IgnoreEls,
 +             [{xmlel, <<"ip">>, _attrs, _} = _el | _els], Ip,
 +             Port) ->
 +    case get_attr(<<"xmlns">>, _attrs) of
 +      <<"">>
 +        when __TopXMLNS == <<"urn:xmpp:sic:1">>;
 +             __TopXMLNS == <<"urn:xmpp:sic:0">> ->
 +        decode_sic_els(__TopXMLNS, __IgnoreEls, _els,
 +                       decode_sic_ip(__TopXMLNS, __IgnoreEls, _el), Port);
 +      <<"urn:xmpp:sic:0">> ->
 +        decode_sic_els(__TopXMLNS, __IgnoreEls, _els,
 +                       decode_sic_ip(<<"urn:xmpp:sic:0">>, __IgnoreEls, _el),
 +                       Port);
 +      <<"urn:xmpp:sic:1">> ->
 +        decode_sic_els(__TopXMLNS, __IgnoreEls, _els,
 +                       decode_sic_ip(<<"urn:xmpp:sic:1">>, __IgnoreEls, _el),
 +                       Port);
 +      _ ->
 +        decode_sic_els(__TopXMLNS, __IgnoreEls, _els, Ip, Port)
 +    end;
 +decode_sic_els(__TopXMLNS, __IgnoreEls,
 +             [{xmlel, <<"port">>, _attrs, _} = _el | _els], Ip,
 +             Port) ->
 +    case get_attr(<<"xmlns">>, _attrs) of
 +      <<"">> when __TopXMLNS == <<"urn:xmpp:sic:1">> ->
 +        decode_sic_els(__TopXMLNS, __IgnoreEls, _els, Ip,
 +                       decode_sip_port(__TopXMLNS, __IgnoreEls, _el));
 +      <<"urn:xmpp:sic:1">> ->
 +        decode_sic_els(__TopXMLNS, __IgnoreEls, _els, Ip,
 +                       decode_sip_port(<<"urn:xmpp:sic:1">>, __IgnoreEls,
 +                                       _el));
 +      _ ->
 +        decode_sic_els(__TopXMLNS, __IgnoreEls, _els, Ip, Port)
 +    end;
 +decode_sic_els(__TopXMLNS, __IgnoreEls, [_ | _els], Ip,
 +             Port) ->
 +    decode_sic_els(__TopXMLNS, __IgnoreEls, _els, Ip, Port).
 +
 +decode_sic_attrs(__TopXMLNS,
 +               [{<<"xmlns">>, _val} | _attrs], _Xmlns) ->
 +    decode_sic_attrs(__TopXMLNS, _attrs, _val);
 +decode_sic_attrs(__TopXMLNS, [_ | _attrs], Xmlns) ->
 +    decode_sic_attrs(__TopXMLNS, _attrs, Xmlns);
 +decode_sic_attrs(__TopXMLNS, [], Xmlns) ->
 +    decode_sic_attr_xmlns(__TopXMLNS, Xmlns).
 +
 +encode_sic({sic, Ip, Port, Xmlns}, __TopXMLNS) ->
 +    __NewTopXMLNS = choose_top_xmlns(Xmlns,
 +                                   [<<"urn:xmpp:sic:0">>,
 +                                    <<"urn:xmpp:sic:1">>],
 +                                   __TopXMLNS),
 +    _els = lists:reverse('encode_sic_$ip'(Ip, __NewTopXMLNS,
 +                                        'encode_sic_$port'(Port,
 +                                                           __NewTopXMLNS,
 +                                                           []))),
 +    _attrs = enc_xmlns_attrs(__NewTopXMLNS, __TopXMLNS),
 +    {xmlel, <<"address">>, _attrs, _els}.
 +
 +'encode_sic_$ip'(undefined, __TopXMLNS, _acc) -> _acc;
 +'encode_sic_$ip'(Ip, __TopXMLNS, _acc) ->
 +    [encode_sic_ip(Ip, __TopXMLNS) | _acc].
 +
 +'encode_sic_$port'(undefined, __TopXMLNS, _acc) -> _acc;
 +'encode_sic_$port'(Port, __TopXMLNS, _acc) ->
 +    [encode_sip_port(Port, __TopXMLNS) | _acc].
 +
 +decode_sic_attr_xmlns(__TopXMLNS, undefined) -> <<>>;
 +decode_sic_attr_xmlns(__TopXMLNS, _val) -> _val.
 +
 +decode_sip_port(__TopXMLNS, __IgnoreEls,
 +              {xmlel, <<"port">>, _attrs, _els}) ->
 +    Cdata = decode_sip_port_els(__TopXMLNS, __IgnoreEls,
 +                              _els, <<>>),
 +    Cdata.
 +
 +decode_sip_port_els(__TopXMLNS, __IgnoreEls, [],
 +                  Cdata) ->
 +    decode_sip_port_cdata(__TopXMLNS, Cdata);
 +decode_sip_port_els(__TopXMLNS, __IgnoreEls,
 +                  [{xmlcdata, _data} | _els], Cdata) ->
 +    decode_sip_port_els(__TopXMLNS, __IgnoreEls, _els,
 +                      <<Cdata/binary, _data/binary>>);
 +decode_sip_port_els(__TopXMLNS, __IgnoreEls, [_ | _els],
 +                  Cdata) ->
 +    decode_sip_port_els(__TopXMLNS, __IgnoreEls, _els,
 +                      Cdata).
 +
 +encode_sip_port(Cdata, __TopXMLNS) ->
 +    __NewTopXMLNS = choose_top_xmlns(<<"urn:xmpp:sic:1">>,
 +                                   [], __TopXMLNS),
 +    _els = encode_sip_port_cdata(Cdata, []),
 +    _attrs = enc_xmlns_attrs(__NewTopXMLNS, __TopXMLNS),
 +    {xmlel, <<"port">>, _attrs, _els}.
 +
 +decode_sip_port_cdata(__TopXMLNS, <<>>) ->
 +    erlang:error({xmpp_codec,
 +                {missing_cdata, <<>>, <<"port">>, __TopXMLNS}});
 +decode_sip_port_cdata(__TopXMLNS, _val) ->
 +    case catch dec_int(_val, 0, 65535) of
 +      {'EXIT', _} ->
 +        erlang:error({xmpp_codec,
 +                      {bad_cdata_value, <<>>, <<"port">>, __TopXMLNS}});
 +      _res -> _res
 +    end.
 +
 +encode_sip_port_cdata(_val, _acc) ->
 +    [{xmlcdata, enc_int(_val)} | _acc].
 +
 +decode_sic_ip(__TopXMLNS, __IgnoreEls,
 +            {xmlel, <<"ip">>, _attrs, _els}) ->
 +    Cdata = decode_sic_ip_els(__TopXMLNS, __IgnoreEls, _els,
 +                            <<>>),
 +    Cdata.
 +
 +decode_sic_ip_els(__TopXMLNS, __IgnoreEls, [], Cdata) ->
 +    decode_sic_ip_cdata(__TopXMLNS, Cdata);
 +decode_sic_ip_els(__TopXMLNS, __IgnoreEls,
 +                [{xmlcdata, _data} | _els], Cdata) ->
 +    decode_sic_ip_els(__TopXMLNS, __IgnoreEls, _els,
 +                    <<Cdata/binary, _data/binary>>);
 +decode_sic_ip_els(__TopXMLNS, __IgnoreEls, [_ | _els],
 +                Cdata) ->
 +    decode_sic_ip_els(__TopXMLNS, __IgnoreEls, _els, Cdata).
 +
 +encode_sic_ip(Cdata, __TopXMLNS) ->
 +    __NewTopXMLNS = choose_top_xmlns(<<>>,
 +                                   [<<"urn:xmpp:sic:0">>,
 +                                    <<"urn:xmpp:sic:1">>],
 +                                   __TopXMLNS),
 +    _els = encode_sic_ip_cdata(Cdata, []),
 +    _attrs = enc_xmlns_attrs(__NewTopXMLNS, __TopXMLNS),
 +    {xmlel, <<"ip">>, _attrs, _els}.
 +
 +decode_sic_ip_cdata(__TopXMLNS, <<>>) ->
 +    erlang:error({xmpp_codec,
 +                {missing_cdata, <<>>, <<"ip">>, __TopXMLNS}});
 +decode_sic_ip_cdata(__TopXMLNS, _val) ->
 +    case catch dec_ip(_val) of
 +      {'EXIT', _} ->
 +        erlang:error({xmpp_codec,
 +                      {bad_cdata_value, <<>>, <<"ip">>, __TopXMLNS}});
 +      _res -> _res
 +    end.
 +
 +encode_sic_ip_cdata(_val, _acc) ->
 +    [{xmlcdata, enc_ip(_val)} | _acc].
 +
 +decode_oob_x(__TopXMLNS, __IgnoreEls,
 +           {xmlel, <<"x">>, _attrs, _els}) ->
 +    {Desc, Url} = decode_oob_x_els(__TopXMLNS, __IgnoreEls,
 +                                 _els, <<>>, error),
 +    Sid = decode_oob_x_attrs(__TopXMLNS, _attrs, undefined),
 +    {oob_x, Url, Desc, Sid}.
 +
 +decode_oob_x_els(__TopXMLNS, __IgnoreEls, [], Desc,
 +               Url) ->
 +    {Desc,
 +     case Url of
 +       error ->
 +         erlang:error({xmpp_codec,
 +                       {missing_tag, <<"url">>, __TopXMLNS}});
 +       {value, Url1} -> Url1
 +     end};
 +decode_oob_x_els(__TopXMLNS, __IgnoreEls,
 +               [{xmlel, <<"url">>, _attrs, _} = _el | _els], Desc,
 +               Url) ->
 +    case get_attr(<<"xmlns">>, _attrs) of
 +      <<"">> when __TopXMLNS == <<"jabber:x:oob">> ->
 +        decode_oob_x_els(__TopXMLNS, __IgnoreEls, _els, Desc,
 +                         {value,
 +                          decode_oob_url(__TopXMLNS, __IgnoreEls, _el)});
 +      <<"jabber:x:oob">> ->
 +        decode_oob_x_els(__TopXMLNS, __IgnoreEls, _els, Desc,
 +                         {value,
 +                          decode_oob_url(<<"jabber:x:oob">>, __IgnoreEls,
 +                                         _el)});
 +      _ ->
 +        decode_oob_x_els(__TopXMLNS, __IgnoreEls, _els, Desc,
 +                         Url)
 +    end;
 +decode_oob_x_els(__TopXMLNS, __IgnoreEls,
 +               [{xmlel, <<"desc">>, _attrs, _} = _el | _els], Desc,
 +               Url) ->
 +    case get_attr(<<"xmlns">>, _attrs) of
 +      <<"">> when __TopXMLNS == <<"jabber:x:oob">> ->
 +        decode_oob_x_els(__TopXMLNS, __IgnoreEls, _els,
 +                         decode_oob_desc(__TopXMLNS, __IgnoreEls, _el), Url);
 +      <<"jabber:x:oob">> ->
 +        decode_oob_x_els(__TopXMLNS, __IgnoreEls, _els,
 +                         decode_oob_desc(<<"jabber:x:oob">>, __IgnoreEls,
 +                                         _el),
 +                         Url);
 +      _ ->
 +        decode_oob_x_els(__TopXMLNS, __IgnoreEls, _els, Desc,
 +                         Url)
 +    end;
 +decode_oob_x_els(__TopXMLNS, __IgnoreEls, [_ | _els],
 +               Desc, Url) ->
 +    decode_oob_x_els(__TopXMLNS, __IgnoreEls, _els, Desc,
 +                   Url).
 +
 +decode_oob_x_attrs(__TopXMLNS,
 +                 [{<<"sid">>, _val} | _attrs], _Sid) ->
 +    decode_oob_x_attrs(__TopXMLNS, _attrs, _val);
 +decode_oob_x_attrs(__TopXMLNS, [_ | _attrs], Sid) ->
 +    decode_oob_x_attrs(__TopXMLNS, _attrs, Sid);
 +decode_oob_x_attrs(__TopXMLNS, [], Sid) ->
 +    decode_oob_x_attr_sid(__TopXMLNS, Sid).
 +
 +encode_oob_x({oob_x, Url, Desc, Sid}, __TopXMLNS) ->
 +    __NewTopXMLNS = choose_top_xmlns(<<"jabber:x:oob">>, [],
 +                                   __TopXMLNS),
 +    _els = lists:reverse('encode_oob_x_$desc'(Desc,
 +                                            __NewTopXMLNS,
 +                                            'encode_oob_x_$url'(Url,
 +                                                                __NewTopXMLNS,
 +                                                                []))),
 +    _attrs = encode_oob_x_attr_sid(Sid,
 +                                 enc_xmlns_attrs(__NewTopXMLNS, __TopXMLNS)),
 +    {xmlel, <<"x">>, _attrs, _els}.
 +
 +'encode_oob_x_$desc'(<<>>, __TopXMLNS, _acc) -> _acc;
 +'encode_oob_x_$desc'(Desc, __TopXMLNS, _acc) ->
 +    [encode_oob_desc(Desc, __TopXMLNS) | _acc].
 +
 +'encode_oob_x_$url'(Url, __TopXMLNS, _acc) ->
 +    [encode_oob_url(Url, __TopXMLNS) | _acc].
 +
 +decode_oob_x_attr_sid(__TopXMLNS, undefined) -> <<>>;
 +decode_oob_x_attr_sid(__TopXMLNS, _val) -> _val.
 +
 +encode_oob_x_attr_sid(<<>>, _acc) -> _acc;
 +encode_oob_x_attr_sid(_val, _acc) ->
 +    [{<<"sid">>, _val} | _acc].
 +
 +decode_oob_desc(__TopXMLNS, __IgnoreEls,
 +              {xmlel, <<"desc">>, _attrs, _els}) ->
 +    Cdata = decode_oob_desc_els(__TopXMLNS, __IgnoreEls,
 +                              _els, <<>>),
 +    Cdata.
 +
 +decode_oob_desc_els(__TopXMLNS, __IgnoreEls, [],
 +                  Cdata) ->
 +    decode_oob_desc_cdata(__TopXMLNS, Cdata);
 +decode_oob_desc_els(__TopXMLNS, __IgnoreEls,
 +                  [{xmlcdata, _data} | _els], Cdata) ->
 +    decode_oob_desc_els(__TopXMLNS, __IgnoreEls, _els,
 +                      <<Cdata/binary, _data/binary>>);
 +decode_oob_desc_els(__TopXMLNS, __IgnoreEls, [_ | _els],
 +                  Cdata) ->
 +    decode_oob_desc_els(__TopXMLNS, __IgnoreEls, _els,
 +                      Cdata).
 +
 +encode_oob_desc(Cdata, __TopXMLNS) ->
 +    __NewTopXMLNS = choose_top_xmlns(<<"jabber:x:oob">>, [],
 +                                   __TopXMLNS),
 +    _els = encode_oob_desc_cdata(Cdata, []),
 +    _attrs = enc_xmlns_attrs(__NewTopXMLNS, __TopXMLNS),
 +    {xmlel, <<"desc">>, _attrs, _els}.
 +
 +decode_oob_desc_cdata(__TopXMLNS, <<>>) -> <<>>;
 +decode_oob_desc_cdata(__TopXMLNS, _val) -> _val.
 +
 +encode_oob_desc_cdata(<<>>, _acc) -> _acc;
 +encode_oob_desc_cdata(_val, _acc) ->
 +    [{xmlcdata, _val} | _acc].
 +
 +decode_oob_url(__TopXMLNS, __IgnoreEls,
 +             {xmlel, <<"url">>, _attrs, _els}) ->
 +    Cdata = decode_oob_url_els(__TopXMLNS, __IgnoreEls,
 +                             _els, <<>>),
 +    Cdata.
 +
 +decode_oob_url_els(__TopXMLNS, __IgnoreEls, [],
 +                 Cdata) ->
 +    decode_oob_url_cdata(__TopXMLNS, Cdata);
 +decode_oob_url_els(__TopXMLNS, __IgnoreEls,
 +                 [{xmlcdata, _data} | _els], Cdata) ->
 +    decode_oob_url_els(__TopXMLNS, __IgnoreEls, _els,
 +                     <<Cdata/binary, _data/binary>>);
 +decode_oob_url_els(__TopXMLNS, __IgnoreEls, [_ | _els],
 +                 Cdata) ->
 +    decode_oob_url_els(__TopXMLNS, __IgnoreEls, _els,
 +                     Cdata).
 +
 +encode_oob_url(Cdata, __TopXMLNS) ->
 +    __NewTopXMLNS = choose_top_xmlns(<<"jabber:x:oob">>, [],
 +                                   __TopXMLNS),
 +    _els = encode_oob_url_cdata(Cdata, []),
 +    _attrs = enc_xmlns_attrs(__NewTopXMLNS, __TopXMLNS),
 +    {xmlel, <<"url">>, _attrs, _els}.
 +
 +decode_oob_url_cdata(__TopXMLNS, <<>>) ->
 +    erlang:error({xmpp_codec,
 +                {missing_cdata, <<>>, <<"url">>, __TopXMLNS}});
 +decode_oob_url_cdata(__TopXMLNS, _val) -> _val.
 +
 +encode_oob_url_cdata(_val, _acc) ->
 +    [{xmlcdata, _val} | _acc].
 +
 +decode_media(__TopXMLNS, __IgnoreEls,
 +           {xmlel, <<"media">>, _attrs, _els}) ->
 +    Uri = decode_media_els(__TopXMLNS, __IgnoreEls, _els,
 +                         []),
 +    {Height, Width} = decode_media_attrs(__TopXMLNS, _attrs,
 +                                       undefined, undefined),
 +    {media, Height, Width, Uri}.
 +
 +decode_media_els(__TopXMLNS, __IgnoreEls, [], Uri) ->
 +    lists:reverse(Uri);
 +decode_media_els(__TopXMLNS, __IgnoreEls,
 +               [{xmlel, <<"uri">>, _attrs, _} = _el | _els], Uri) ->
 +    case get_attr(<<"xmlns">>, _attrs) of
 +      <<"">>
 +        when __TopXMLNS == <<"urn:xmpp:media-element">> ->
 +        decode_media_els(__TopXMLNS, __IgnoreEls, _els,
 +                         [decode_media_uri(__TopXMLNS, __IgnoreEls, _el)
 +                          | Uri]);
 +      <<"urn:xmpp:media-element">> ->
 +        decode_media_els(__TopXMLNS, __IgnoreEls, _els,
 +                         [decode_media_uri(<<"urn:xmpp:media-element">>,
 +                                           __IgnoreEls, _el)
 +                          | Uri]);
 +      _ ->
 +        decode_media_els(__TopXMLNS, __IgnoreEls, _els, Uri)
 +    end;
 +decode_media_els(__TopXMLNS, __IgnoreEls, [_ | _els],
 +               Uri) ->
 +    decode_media_els(__TopXMLNS, __IgnoreEls, _els, Uri).
 +
 +decode_media_attrs(__TopXMLNS,
 +                 [{<<"height">>, _val} | _attrs], _Height, Width) ->
 +    decode_media_attrs(__TopXMLNS, _attrs, _val, Width);
 +decode_media_attrs(__TopXMLNS,
 +                 [{<<"width">>, _val} | _attrs], Height, _Width) ->
 +    decode_media_attrs(__TopXMLNS, _attrs, Height, _val);
 +decode_media_attrs(__TopXMLNS, [_ | _attrs], Height,
 +                 Width) ->
 +    decode_media_attrs(__TopXMLNS, _attrs, Height, Width);
 +decode_media_attrs(__TopXMLNS, [], Height, Width) ->
 +    {decode_media_attr_height(__TopXMLNS, Height),
 +     decode_media_attr_width(__TopXMLNS, Width)}.
 +
 +encode_media({media, Height, Width, Uri}, __TopXMLNS) ->
 +    __NewTopXMLNS =
 +      choose_top_xmlns(<<"urn:xmpp:media-element">>, [],
 +                       __TopXMLNS),
 +    _els = lists:reverse('encode_media_$uri'(Uri,
 +                                           __NewTopXMLNS, [])),
 +    _attrs = encode_media_attr_width(Width,
 +                                   encode_media_attr_height(Height,
 +                                                            enc_xmlns_attrs(__NewTopXMLNS,
 +                                                                            __TopXMLNS))),
 +    {xmlel, <<"media">>, _attrs, _els}.
 +
 +'encode_media_$uri'([], __TopXMLNS, _acc) -> _acc;
 +'encode_media_$uri'([Uri | _els], __TopXMLNS, _acc) ->
 +    'encode_media_$uri'(_els, __TopXMLNS,
 +                      [encode_media_uri(Uri, __TopXMLNS) | _acc]).
 +
 +decode_media_attr_height(__TopXMLNS, undefined) ->
 +    undefined;
 +decode_media_attr_height(__TopXMLNS, _val) ->
 +    case catch dec_int(_val, 0, infinity) of
 +      {'EXIT', _} ->
 +        erlang:error({xmpp_codec,
 +                      {bad_attr_value, <<"height">>, <<"media">>,
 +                       __TopXMLNS}});
 +      _res -> _res
 +    end.
 +
 +encode_media_attr_height(undefined, _acc) -> _acc;
 +encode_media_attr_height(_val, _acc) ->
 +    [{<<"height">>, enc_int(_val)} | _acc].
 +
 +decode_media_attr_width(__TopXMLNS, undefined) ->
 +    undefined;
 +decode_media_attr_width(__TopXMLNS, _val) ->
 +    case catch dec_int(_val, 0, inifinity) of
 +      {'EXIT', _} ->
 +        erlang:error({xmpp_codec,
 +                      {bad_attr_value, <<"width">>, <<"media">>,
 +                       __TopXMLNS}});
 +      _res -> _res
 +    end.
 +
 +encode_media_attr_width(undefined, _acc) -> _acc;
 +encode_media_attr_width(_val, _acc) ->
 +    [{<<"width">>, enc_int(_val)} | _acc].
 +
 +decode_media_uri(__TopXMLNS, __IgnoreEls,
 +               {xmlel, <<"uri">>, _attrs, _els}) ->
 +    Uri = decode_media_uri_els(__TopXMLNS, __IgnoreEls,
 +                             _els, <<>>),
 +    Type = decode_media_uri_attrs(__TopXMLNS, _attrs,
 +                                undefined),
 +    {media_uri, Type, Uri}.
 +
 +decode_media_uri_els(__TopXMLNS, __IgnoreEls, [],
 +                   Uri) ->
 +    decode_media_uri_cdata(__TopXMLNS, Uri);
 +decode_media_uri_els(__TopXMLNS, __IgnoreEls,
 +                   [{xmlcdata, _data} | _els], Uri) ->
 +    decode_media_uri_els(__TopXMLNS, __IgnoreEls, _els,
 +                       <<Uri/binary, _data/binary>>);
 +decode_media_uri_els(__TopXMLNS, __IgnoreEls,
 +                   [_ | _els], Uri) ->
 +    decode_media_uri_els(__TopXMLNS, __IgnoreEls, _els,
 +                       Uri).
 +
 +decode_media_uri_attrs(__TopXMLNS,
 +                     [{<<"type">>, _val} | _attrs], _Type) ->
 +    decode_media_uri_attrs(__TopXMLNS, _attrs, _val);
 +decode_media_uri_attrs(__TopXMLNS, [_ | _attrs],
 +                     Type) ->
 +    decode_media_uri_attrs(__TopXMLNS, _attrs, Type);
 +decode_media_uri_attrs(__TopXMLNS, [], Type) ->
 +    decode_media_uri_attr_type(__TopXMLNS, Type).
 +
 +encode_media_uri({media_uri, Type, Uri}, __TopXMLNS) ->
 +    __NewTopXMLNS =
 +      choose_top_xmlns(<<"urn:xmpp:media-element">>, [],
 +                       __TopXMLNS),
 +    _els = encode_media_uri_cdata(Uri, []),
 +    _attrs = encode_media_uri_attr_type(Type,
 +                                      enc_xmlns_attrs(__NewTopXMLNS,
 +                                                      __TopXMLNS)),
 +    {xmlel, <<"uri">>, _attrs, _els}.
 +
 +decode_media_uri_attr_type(__TopXMLNS, undefined) ->
 +    erlang:error({xmpp_codec,
 +                {missing_attr, <<"type">>, <<"uri">>, __TopXMLNS}});
 +decode_media_uri_attr_type(__TopXMLNS, _val) -> _val.
 +
 +encode_media_uri_attr_type(_val, _acc) ->
 +    [{<<"type">>, _val} | _acc].
 +
 +decode_media_uri_cdata(__TopXMLNS, <<>>) -> <<>>;
 +decode_media_uri_cdata(__TopXMLNS, _val) -> _val.
 +
 +encode_media_uri_cdata(<<>>, _acc) -> _acc;
 +encode_media_uri_cdata(_val, _acc) ->
 +    [{xmlcdata, _val} | _acc].
 +
 +decode_captcha(__TopXMLNS, __IgnoreEls,
 +             {xmlel, <<"captcha">>, _attrs, _els}) ->
 +    Xdata = decode_captcha_els(__TopXMLNS, __IgnoreEls,
 +                             _els, error),
 +    {xcaptcha, Xdata}.
 +
 +decode_captcha_els(__TopXMLNS, __IgnoreEls, [],
 +                 Xdata) ->
 +    case Xdata of
 +      error ->
 +        erlang:error({xmpp_codec,
 +                      {missing_tag, <<"x">>, __TopXMLNS}});
 +      {value, Xdata1} -> Xdata1
 +    end;
 +decode_captcha_els(__TopXMLNS, __IgnoreEls,
 +                 [{xmlel, <<"x">>, _attrs, _} = _el | _els], Xdata) ->
 +    case get_attr(<<"xmlns">>, _attrs) of
 +      <<"jabber:x:data">> ->
 +        decode_captcha_els(__TopXMLNS, __IgnoreEls, _els,
 +                           {value,
 +                            decode_xdata(<<"jabber:x:data">>, __IgnoreEls,
 +                                         _el)});
 +      _ ->
 +        decode_captcha_els(__TopXMLNS, __IgnoreEls, _els, Xdata)
 +    end;
 +decode_captcha_els(__TopXMLNS, __IgnoreEls, [_ | _els],
 +                 Xdata) ->
 +    decode_captcha_els(__TopXMLNS, __IgnoreEls, _els,
 +                     Xdata).
 +
 +encode_captcha({xcaptcha, Xdata}, __TopXMLNS) ->
 +    __NewTopXMLNS = choose_top_xmlns(<<"urn:xmpp:captcha">>,
 +                                   [], __TopXMLNS),
 +    _els = lists:reverse('encode_captcha_$xdata'(Xdata,
 +                                               __NewTopXMLNS, [])),
 +    _attrs = enc_xmlns_attrs(__NewTopXMLNS, __TopXMLNS),
 +    {xmlel, <<"captcha">>, _attrs, _els}.
 +
 +'encode_captcha_$xdata'(Xdata, __TopXMLNS, _acc) ->
 +    [encode_xdata(Xdata, __TopXMLNS) | _acc].
 +
 +decode_bob_data(__TopXMLNS, __IgnoreEls,
 +              {xmlel, <<"data">>, _attrs, _els}) ->
 +    Data = decode_bob_data_els(__TopXMLNS, __IgnoreEls,
 +                             _els, <<>>),
 +    {Cid, Max_age, Type} = decode_bob_data_attrs(__TopXMLNS,
 +                                               _attrs, undefined, undefined,
 +                                               undefined),
 +    {bob_data, Cid, Max_age, Type, Data}.
 +
 +decode_bob_data_els(__TopXMLNS, __IgnoreEls, [],
 +                  Data) ->
 +    decode_bob_data_cdata(__TopXMLNS, Data);
 +decode_bob_data_els(__TopXMLNS, __IgnoreEls,
 +                  [{xmlcdata, _data} | _els], Data) ->
 +    decode_bob_data_els(__TopXMLNS, __IgnoreEls, _els,
 +                      <<Data/binary, _data/binary>>);
 +decode_bob_data_els(__TopXMLNS, __IgnoreEls, [_ | _els],
 +                  Data) ->
 +    decode_bob_data_els(__TopXMLNS, __IgnoreEls, _els,
 +                      Data).
 +
 +decode_bob_data_attrs(__TopXMLNS,
 +                    [{<<"cid">>, _val} | _attrs], _Cid, Max_age, Type) ->
 +    decode_bob_data_attrs(__TopXMLNS, _attrs, _val, Max_age,
 +                        Type);
 +decode_bob_data_attrs(__TopXMLNS,
 +                    [{<<"max-age">>, _val} | _attrs], Cid, _Max_age,
 +                    Type) ->
 +    decode_bob_data_attrs(__TopXMLNS, _attrs, Cid, _val,
 +                        Type);
 +decode_bob_data_attrs(__TopXMLNS,
 +                    [{<<"type">>, _val} | _attrs], Cid, Max_age, _Type) ->
 +    decode_bob_data_attrs(__TopXMLNS, _attrs, Cid, Max_age,
 +                        _val);
 +decode_bob_data_attrs(__TopXMLNS, [_ | _attrs], Cid,
 +                    Max_age, Type) ->
 +    decode_bob_data_attrs(__TopXMLNS, _attrs, Cid, Max_age,
 +                        Type);
 +decode_bob_data_attrs(__TopXMLNS, [], Cid, Max_age,
 +                    Type) ->
 +    {decode_bob_data_attr_cid(__TopXMLNS, Cid),
 +     'decode_bob_data_attr_max-age'(__TopXMLNS, Max_age),
 +     decode_bob_data_attr_type(__TopXMLNS, Type)}.
 +
 +encode_bob_data({bob_data, Cid, Max_age, Type, Data},
 +              __TopXMLNS) ->
 +    __NewTopXMLNS = choose_top_xmlns(<<"urn:xmpp:bob">>, [],
 +                                   __TopXMLNS),
 +    _els = encode_bob_data_cdata(Data, []),
 +    _attrs = encode_bob_data_attr_type(Type,
 +                                     'encode_bob_data_attr_max-age'(Max_age,
 +                                                                    encode_bob_data_attr_cid(Cid,
 +                                                                                             enc_xmlns_attrs(__NewTopXMLNS,
 +                                                                                                             __TopXMLNS)))),
 +    {xmlel, <<"data">>, _attrs, _els}.
 +
 +decode_bob_data_attr_cid(__TopXMLNS, undefined) ->
 +    erlang:error({xmpp_codec,
 +                {missing_attr, <<"cid">>, <<"data">>, __TopXMLNS}});
 +decode_bob_data_attr_cid(__TopXMLNS, _val) -> _val.
 +
 +encode_bob_data_attr_cid(_val, _acc) ->
 +    [{<<"cid">>, _val} | _acc].
 +
 +'decode_bob_data_attr_max-age'(__TopXMLNS, undefined) ->
 +    undefined;
 +'decode_bob_data_attr_max-age'(__TopXMLNS, _val) ->
 +    case catch dec_int(_val, 0, infinity) of
 +      {'EXIT', _} ->
 +        erlang:error({xmpp_codec,
 +                      {bad_attr_value, <<"max-age">>, <<"data">>,
 +                       __TopXMLNS}});
 +      _res -> _res
 +    end.
 +
 +'encode_bob_data_attr_max-age'(undefined, _acc) -> _acc;
 +'encode_bob_data_attr_max-age'(_val, _acc) ->
 +    [{<<"max-age">>, enc_int(_val)} | _acc].
 +
 +decode_bob_data_attr_type(__TopXMLNS, undefined) ->
 +    <<>>;
 +decode_bob_data_attr_type(__TopXMLNS, _val) -> _val.
 +
 +encode_bob_data_attr_type(<<>>, _acc) -> _acc;
 +encode_bob_data_attr_type(_val, _acc) ->
 +    [{<<"type">>, _val} | _acc].
 +
 +decode_bob_data_cdata(__TopXMLNS, <<>>) -> <<>>;
 +decode_bob_data_cdata(__TopXMLNS, _val) ->
 +    case catch base64:decode(_val) of
 +      {'EXIT', _} ->
 +        erlang:error({xmpp_codec,
 +                      {bad_cdata_value, <<>>, <<"data">>, __TopXMLNS}});
 +      _res -> _res
 +    end.
 +
 +encode_bob_data_cdata(<<>>, _acc) -> _acc;
 +encode_bob_data_cdata(_val, _acc) ->
 +    [{xmlcdata, base64:encode(_val)} | _acc].
 +
 +decode_stream_start(__TopXMLNS, __IgnoreEls,
 +                  {xmlel, <<"stream:stream">>, _attrs, _els}) ->
 +    {From, To, Xmlns, Stream_xmlns, Db_xmlns, Lang, Version,
 +     Id} =
 +      decode_stream_start_attrs(__TopXMLNS, _attrs, undefined,
 +                                undefined, undefined, undefined, undefined,
 +                                undefined, undefined, undefined),
 +    {stream_start, From, To, Id, Version, Xmlns,
 +     Stream_xmlns, Db_xmlns, Lang}.
 +
 +decode_stream_start_attrs(__TopXMLNS,
 +                        [{<<"from">>, _val} | _attrs], _From, To, Xmlns,
 +                        Stream_xmlns, Db_xmlns, Lang, Version, Id) ->
 +    decode_stream_start_attrs(__TopXMLNS, _attrs, _val, To,
 +                            Xmlns, Stream_xmlns, Db_xmlns, Lang, Version, Id);
 +decode_stream_start_attrs(__TopXMLNS,
 +                        [{<<"to">>, _val} | _attrs], From, _To, Xmlns,
 +                        Stream_xmlns, Db_xmlns, Lang, Version, Id) ->
 +    decode_stream_start_attrs(__TopXMLNS, _attrs, From,
 +                            _val, Xmlns, Stream_xmlns, Db_xmlns, Lang,
 +                            Version, Id);
 +decode_stream_start_attrs(__TopXMLNS,
 +                        [{<<"xmlns">>, _val} | _attrs], From, To, _Xmlns,
 +                        Stream_xmlns, Db_xmlns, Lang, Version, Id) ->
 +    decode_stream_start_attrs(__TopXMLNS, _attrs, From, To,
 +                            _val, Stream_xmlns, Db_xmlns, Lang, Version, Id);
 +decode_stream_start_attrs(__TopXMLNS,
 +                        [{<<"xmlns:stream">>, _val} | _attrs], From, To,
 +                        Xmlns, _Stream_xmlns, Db_xmlns, Lang, Version, Id) ->
 +    decode_stream_start_attrs(__TopXMLNS, _attrs, From, To,
 +                            Xmlns, _val, Db_xmlns, Lang, Version, Id);
 +decode_stream_start_attrs(__TopXMLNS,
 +                        [{<<"xmlns:db">>, _val} | _attrs], From, To, Xmlns,
 +                        Stream_xmlns, _Db_xmlns, Lang, Version, Id) ->
 +    decode_stream_start_attrs(__TopXMLNS, _attrs, From, To,
 +                            Xmlns, Stream_xmlns, _val, Lang, Version, Id);
 +decode_stream_start_attrs(__TopXMLNS,
 +                        [{<<"xml:lang">>, _val} | _attrs], From, To, Xmlns,
 +                        Stream_xmlns, Db_xmlns, _Lang, Version, Id) ->
 +    decode_stream_start_attrs(__TopXMLNS, _attrs, From, To,
 +                            Xmlns, Stream_xmlns, Db_xmlns, _val, Version, Id);
 +decode_stream_start_attrs(__TopXMLNS,
 +                        [{<<"version">>, _val} | _attrs], From, To, Xmlns,
 +                        Stream_xmlns, Db_xmlns, Lang, _Version, Id) ->
 +    decode_stream_start_attrs(__TopXMLNS, _attrs, From, To,
 +                            Xmlns, Stream_xmlns, Db_xmlns, Lang, _val, Id);
 +decode_stream_start_attrs(__TopXMLNS,
 +                        [{<<"id">>, _val} | _attrs], From, To, Xmlns,
 +                        Stream_xmlns, Db_xmlns, Lang, Version, _Id) ->
 +    decode_stream_start_attrs(__TopXMLNS, _attrs, From, To,
 +                            Xmlns, Stream_xmlns, Db_xmlns, Lang, Version,
 +                            _val);
 +decode_stream_start_attrs(__TopXMLNS, [_ | _attrs],
 +                        From, To, Xmlns, Stream_xmlns, Db_xmlns, Lang,
 +                        Version, Id) ->
 +    decode_stream_start_attrs(__TopXMLNS, _attrs, From, To,
 +                            Xmlns, Stream_xmlns, Db_xmlns, Lang, Version, Id);
 +decode_stream_start_attrs(__TopXMLNS, [], From, To,
 +                        Xmlns, Stream_xmlns, Db_xmlns, Lang, Version, Id) ->
 +    {decode_stream_start_attr_from(__TopXMLNS, From),
 +     decode_stream_start_attr_to(__TopXMLNS, To),
 +     decode_stream_start_attr_xmlns(__TopXMLNS, Xmlns),
 +     'decode_stream_start_attr_xmlns:stream'(__TopXMLNS,
 +                                           Stream_xmlns),
 +     'decode_stream_start_attr_xmlns:db'(__TopXMLNS,
 +                                       Db_xmlns),
 +     'decode_stream_start_attr_xml:lang'(__TopXMLNS, Lang),
 +     decode_stream_start_attr_version(__TopXMLNS, Version),
 +     decode_stream_start_attr_id(__TopXMLNS, Id)}.
 +
 +encode_stream_start({stream_start, From, To, Id,
 +                   Version, Xmlns, Stream_xmlns, Db_xmlns, Lang},
 +                  __TopXMLNS) ->
 +    __NewTopXMLNS = choose_top_xmlns(Xmlns,
 +                                   [<<"jabber:client">>, <<"jabber:server">>,
 +                                    <<"jabber:component:accept">>],
 +                                   __TopXMLNS),
 +    _els = [],
 +    _attrs = encode_stream_start_attr_id(Id,
 +                                       encode_stream_start_attr_version(Version,
 +                                                                        'encode_stream_start_attr_xml:lang'(Lang,
 +                                                                                                            'encode_stream_start_attr_xmlns:db'(Db_xmlns,
 +                                                                                                                                                'encode_stream_start_attr_xmlns:stream'(Stream_xmlns,
 +                                                                                                                                                                                        encode_stream_start_attr_to(To,
 +                                                                                                                                                                                                                    encode_stream_start_attr_from(From,
 +                                                                                                                                                                                                                                                  enc_xmlns_attrs(__NewTopXMLNS,
 +                                                                                                                                                                                                                                                                  __TopXMLNS)))))))),
 +    {xmlel, <<"stream:stream">>, _attrs, _els}.
 +
 +decode_stream_start_attr_from(__TopXMLNS, undefined) ->
 +    undefined;
 +decode_stream_start_attr_from(__TopXMLNS, _val) ->
 +    case catch dec_jid(_val) of
 +      {'EXIT', _} ->
 +        erlang:error({xmpp_codec,
 +                      {bad_attr_value, <<"from">>, <<"stream:stream">>,
 +                       __TopXMLNS}});
 +      _res -> _res
 +    end.
 +
 +encode_stream_start_attr_from(undefined, _acc) -> _acc;
 +encode_stream_start_attr_from(_val, _acc) ->
 +    [{<<"from">>, enc_jid(_val)} | _acc].
 +
 +decode_stream_start_attr_to(__TopXMLNS, undefined) ->
 +    undefined;
 +decode_stream_start_attr_to(__TopXMLNS, _val) ->
 +    case catch dec_jid(_val) of
 +      {'EXIT', _} ->
 +        erlang:error({xmpp_codec,
 +                      {bad_attr_value, <<"to">>, <<"stream:stream">>,
 +                       __TopXMLNS}});
 +      _res -> _res
 +    end.
 +
 +encode_stream_start_attr_to(undefined, _acc) -> _acc;
 +encode_stream_start_attr_to(_val, _acc) ->
 +    [{<<"to">>, enc_jid(_val)} | _acc].
 +
 +decode_stream_start_attr_xmlns(__TopXMLNS, undefined) ->
 +    <<>>;
 +decode_stream_start_attr_xmlns(__TopXMLNS, _val) ->
 +    _val.
 +
 +'decode_stream_start_attr_xmlns:stream'(__TopXMLNS,
 +                                      undefined) ->
 +    <<>>;
 +'decode_stream_start_attr_xmlns:stream'(__TopXMLNS,
 +                                      _val) ->
 +    _val.
 +
 +'encode_stream_start_attr_xmlns:stream'(<<>>, _acc) ->
 +    _acc;
 +'encode_stream_start_attr_xmlns:stream'(_val, _acc) ->
 +    [{<<"xmlns:stream">>, _val} | _acc].
 +
 +'decode_stream_start_attr_xmlns:db'(__TopXMLNS,
 +                                  undefined) ->
 +    <<>>;
 +'decode_stream_start_attr_xmlns:db'(__TopXMLNS, _val) ->
 +    _val.
 +
 +'encode_stream_start_attr_xmlns:db'(<<>>, _acc) -> _acc;
 +'encode_stream_start_attr_xmlns:db'(_val, _acc) ->
 +    [{<<"xmlns:db">>, _val} | _acc].
 +
 +'decode_stream_start_attr_xml:lang'(__TopXMLNS,
 +                                  undefined) ->
 +    <<>>;
 +'decode_stream_start_attr_xml:lang'(__TopXMLNS, _val) ->
 +    _val.
 +
 +'encode_stream_start_attr_xml:lang'(<<>>, _acc) -> _acc;
 +'encode_stream_start_attr_xml:lang'(_val, _acc) ->
 +    [{<<"xml:lang">>, _val} | _acc].
 +
 +decode_stream_start_attr_version(__TopXMLNS,
 +                               undefined) ->
 +    undefined;
 +decode_stream_start_attr_version(__TopXMLNS, _val) ->
 +    case catch dec_version(_val) of
 +      {'EXIT', _} ->
 +        erlang:error({xmpp_codec,
 +                      {bad_attr_value, <<"version">>, <<"stream:stream">>,
 +                       __TopXMLNS}});
 +      _res -> _res
 +    end.
 +
 +encode_stream_start_attr_version(undefined, _acc) ->
 +    _acc;
 +encode_stream_start_attr_version(_val, _acc) ->
 +    [{<<"version">>, enc_version(_val)} | _acc].
 +
 +decode_stream_start_attr_id(__TopXMLNS, undefined) ->
 +    <<>>;
 +decode_stream_start_attr_id(__TopXMLNS, _val) -> _val.
 +
 +encode_stream_start_attr_id(<<>>, _acc) -> _acc;
 +encode_stream_start_attr_id(_val, _acc) ->
 +    [{<<"id">>, _val} | _acc].
 +
 +decode_handshake(__TopXMLNS, __IgnoreEls,
 +               {xmlel, <<"handshake">>, _attrs, _els}) ->
 +    Data = decode_handshake_els(__TopXMLNS, __IgnoreEls,
 +                              _els, <<>>),
 +    {handshake, Data}.
 +
 +decode_handshake_els(__TopXMLNS, __IgnoreEls, [],
 +                   Data) ->
 +    decode_handshake_cdata(__TopXMLNS, Data);
 +decode_handshake_els(__TopXMLNS, __IgnoreEls,
 +                   [{xmlcdata, _data} | _els], Data) ->
 +    decode_handshake_els(__TopXMLNS, __IgnoreEls, _els,
 +                       <<Data/binary, _data/binary>>);
 +decode_handshake_els(__TopXMLNS, __IgnoreEls,
 +                   [_ | _els], Data) ->
 +    decode_handshake_els(__TopXMLNS, __IgnoreEls, _els,
 +                       Data).
 +
 +encode_handshake({handshake, Data}, __TopXMLNS) ->
 +    __NewTopXMLNS =
 +      choose_top_xmlns(<<"jabber:component:accept">>, [],
 +                       __TopXMLNS),
 +    _els = encode_handshake_cdata(Data, []),
 +    _attrs = enc_xmlns_attrs(__NewTopXMLNS, __TopXMLNS),
 +    {xmlel, <<"handshake">>, _attrs, _els}.
 +
 +decode_handshake_cdata(__TopXMLNS, <<>>) -> <<>>;
 +decode_handshake_cdata(__TopXMLNS, _val) -> _val.
 +
 +encode_handshake_cdata(<<>>, _acc) -> _acc;
 +encode_handshake_cdata(_val, _acc) ->
 +    [{xmlcdata, _val} | _acc].
 +
 +decode_db_verify(__TopXMLNS, __IgnoreEls,
 +               {xmlel, <<"db:verify">>, _attrs, _els}) ->
 +    {Key, __Els} = decode_db_verify_els(__TopXMLNS,
 +                                      __IgnoreEls, _els, <<>>, []),
 +    {From, To, Id, Type} =
 +      decode_db_verify_attrs(__TopXMLNS, _attrs, undefined,
 +                             undefined, undefined, undefined),
 +    {db_verify, From, To, Id, Type, Key, __Els}.
 +
 +decode_db_verify_els(__TopXMLNS, __IgnoreEls, [], Key,
 +                   __Els) ->
 +    {decode_db_verify_cdata(__TopXMLNS, Key),
 +     lists:reverse(__Els)};
 +decode_db_verify_els(__TopXMLNS, __IgnoreEls,
 +                   [{xmlcdata, _data} | _els], Key, __Els) ->
 +    decode_db_verify_els(__TopXMLNS, __IgnoreEls, _els,
 +                       <<Key/binary, _data/binary>>, __Els);
 +decode_db_verify_els(__TopXMLNS, __IgnoreEls,
 +                   [{xmlel, _, _, _} = _el | _els], Key, __Els) ->
 +    if __IgnoreEls ->
 +         decode_db_verify_els(__TopXMLNS, __IgnoreEls, _els, Key,
 +                              [_el | __Els]);
 +       true ->
 +         case is_known_tag(_el, __TopXMLNS) of
 +           true ->
 +               decode_db_verify_els(__TopXMLNS, __IgnoreEls, _els, Key,
 +                                    [decode(_el, __TopXMLNS, []) | __Els]);
 +           false ->
 +               decode_db_verify_els(__TopXMLNS, __IgnoreEls, _els, Key,
 +                                    __Els)
 +         end
 +    end.
 +
 +decode_db_verify_attrs(__TopXMLNS,
 +                     [{<<"from">>, _val} | _attrs], _From, To, Id, Type) ->
 +    decode_db_verify_attrs(__TopXMLNS, _attrs, _val, To, Id,
 +                         Type);
 +decode_db_verify_attrs(__TopXMLNS,
 +                     [{<<"to">>, _val} | _attrs], From, _To, Id, Type) ->
 +    decode_db_verify_attrs(__TopXMLNS, _attrs, From, _val,
 +                         Id, Type);
 +decode_db_verify_attrs(__TopXMLNS,
 +                     [{<<"id">>, _val} | _attrs], From, To, _Id, Type) ->
 +    decode_db_verify_attrs(__TopXMLNS, _attrs, From, To,
 +                         _val, Type);
 +decode_db_verify_attrs(__TopXMLNS,
 +                     [{<<"type">>, _val} | _attrs], From, To, Id, _Type) ->
 +    decode_db_verify_attrs(__TopXMLNS, _attrs, From, To, Id,
 +                         _val);
 +decode_db_verify_attrs(__TopXMLNS, [_ | _attrs], From,
 +                     To, Id, Type) ->
 +    decode_db_verify_attrs(__TopXMLNS, _attrs, From, To, Id,
 +                         Type);
 +decode_db_verify_attrs(__TopXMLNS, [], From, To, Id,
 +                     Type) ->
 +    {decode_db_verify_attr_from(__TopXMLNS, From),
 +     decode_db_verify_attr_to(__TopXMLNS, To),
 +     decode_db_verify_attr_id(__TopXMLNS, Id),
 +     decode_db_verify_attr_type(__TopXMLNS, Type)}.
 +
 +encode_db_verify({db_verify, From, To, Id, Type, Key,
 +                __Els},
 +               __TopXMLNS) ->
 +    __NewTopXMLNS = choose_top_xmlns(<<"jabber:server">>,
 +                                   [], __TopXMLNS),
 +    _els = [encode(_el, __NewTopXMLNS) || _el <- __Els] ++
 +           encode_db_verify_cdata(Key, []),
 +    _attrs = encode_db_verify_attr_type(Type,
 +                                      encode_db_verify_attr_id(Id,
 +                                                               encode_db_verify_attr_to(To,
 +                                                                                        encode_db_verify_attr_from(From,
 +                                                                                                                   enc_xmlns_attrs(__NewTopXMLNS,
 +                                                                                                                                   __TopXMLNS))))),
 +    {xmlel, <<"db:verify">>, _attrs, _els}.
 +
 +decode_db_verify_attr_from(__TopXMLNS, undefined) ->
 +    erlang:error({xmpp_codec,
 +                {missing_attr, <<"from">>, <<"db:verify">>,
 +                 __TopXMLNS}});
 +decode_db_verify_attr_from(__TopXMLNS, _val) ->
 +    case catch nameprep(_val) of
 +      {'EXIT', _} ->
 +        erlang:error({xmpp_codec,
 +                      {bad_attr_value, <<"from">>, <<"db:verify">>,
 +                       __TopXMLNS}});
 +      _res -> _res
 +    end.
 +
 +encode_db_verify_attr_from(_val, _acc) ->
 +    [{<<"from">>, nameprep(_val)} | _acc].
 +
 +decode_db_verify_attr_to(__TopXMLNS, undefined) ->
 +    erlang:error({xmpp_codec,
 +                {missing_attr, <<"to">>, <<"db:verify">>, __TopXMLNS}});
 +decode_db_verify_attr_to(__TopXMLNS, _val) ->
 +    case catch nameprep(_val) of
 +      {'EXIT', _} ->
 +        erlang:error({xmpp_codec,
 +                      {bad_attr_value, <<"to">>, <<"db:verify">>,
 +                       __TopXMLNS}});
 +      _res -> _res
 +    end.
 +
 +encode_db_verify_attr_to(_val, _acc) ->
 +    [{<<"to">>, nameprep(_val)} | _acc].
 +
 +decode_db_verify_attr_id(__TopXMLNS, undefined) ->
 +    erlang:error({xmpp_codec,
 +                {missing_attr, <<"id">>, <<"db:verify">>, __TopXMLNS}});
 +decode_db_verify_attr_id(__TopXMLNS, _val) -> _val.
 +
 +encode_db_verify_attr_id(_val, _acc) ->
 +    [{<<"id">>, _val} | _acc].
 +
 +decode_db_verify_attr_type(__TopXMLNS, undefined) ->
 +    undefined;
 +decode_db_verify_attr_type(__TopXMLNS, _val) ->
 +    case catch dec_enum(_val, [valid, invalid, error]) of
 +      {'EXIT', _} ->
 +        erlang:error({xmpp_codec,
 +                      {bad_attr_value, <<"type">>, <<"db:verify">>,
 +                       __TopXMLNS}});
 +      _res -> _res
 +    end.
 +
 +encode_db_verify_attr_type(undefined, _acc) -> _acc;
 +encode_db_verify_attr_type(_val, _acc) ->
 +    [{<<"type">>, enc_enum(_val)} | _acc].
 +
 +decode_db_verify_cdata(__TopXMLNS, <<>>) -> <<>>;
 +decode_db_verify_cdata(__TopXMLNS, _val) -> _val.
 +
 +encode_db_verify_cdata(<<>>, _acc) -> _acc;
 +encode_db_verify_cdata(_val, _acc) ->
 +    [{xmlcdata, _val} | _acc].
 +
 +decode_db_result(__TopXMLNS, __IgnoreEls,
 +               {xmlel, <<"db:result">>, _attrs, _els}) ->
 +    {Key, __Els} = decode_db_result_els(__TopXMLNS,
 +                                      __IgnoreEls, _els, <<>>, []),
 +    {From, To, Type} = decode_db_result_attrs(__TopXMLNS,
 +                                            _attrs, undefined, undefined,
 +                                            undefined),
 +    {db_result, From, To, Type, Key, __Els}.
 +
 +decode_db_result_els(__TopXMLNS, __IgnoreEls, [], Key,
 +                   __Els) ->
 +    {decode_db_result_cdata(__TopXMLNS, Key),
 +     lists:reverse(__Els)};
 +decode_db_result_els(__TopXMLNS, __IgnoreEls,
 +                   [{xmlcdata, _data} | _els], Key, __Els) ->
 +    decode_db_result_els(__TopXMLNS, __IgnoreEls, _els,
 +                       <<Key/binary, _data/binary>>, __Els);
 +decode_db_result_els(__TopXMLNS, __IgnoreEls,
 +                   [{xmlel, _, _, _} = _el | _els], Key, __Els) ->
 +    if __IgnoreEls ->
 +         decode_db_result_els(__TopXMLNS, __IgnoreEls, _els, Key,
 +                              [_el | __Els]);
 +       true ->
 +         case is_known_tag(_el, __TopXMLNS) of
 +           true ->
 +               decode_db_result_els(__TopXMLNS, __IgnoreEls, _els, Key,
 +                                    [decode(_el, __TopXMLNS, []) | __Els]);
 +           false ->
 +               decode_db_result_els(__TopXMLNS, __IgnoreEls, _els, Key,
 +                                    __Els)
 +         end
 +    end.
 +
 +decode_db_result_attrs(__TopXMLNS,
 +                     [{<<"from">>, _val} | _attrs], _From, To, Type) ->
 +    decode_db_result_attrs(__TopXMLNS, _attrs, _val, To,
 +                         Type);
 +decode_db_result_attrs(__TopXMLNS,
 +                     [{<<"to">>, _val} | _attrs], From, _To, Type) ->
 +    decode_db_result_attrs(__TopXMLNS, _attrs, From, _val,
 +                         Type);
 +decode_db_result_attrs(__TopXMLNS,
 +                     [{<<"type">>, _val} | _attrs], From, To, _Type) ->
 +    decode_db_result_attrs(__TopXMLNS, _attrs, From, To,
 +                         _val);
 +decode_db_result_attrs(__TopXMLNS, [_ | _attrs], From,
 +                     To, Type) ->
 +    decode_db_result_attrs(__TopXMLNS, _attrs, From, To,
 +                         Type);
 +decode_db_result_attrs(__TopXMLNS, [], From, To,
 +                     Type) ->
 +    {decode_db_result_attr_from(__TopXMLNS, From),
 +     decode_db_result_attr_to(__TopXMLNS, To),
 +     decode_db_result_attr_type(__TopXMLNS, Type)}.
 +
 +encode_db_result({db_result, From, To, Type, Key,
 +                __Els},
 +               __TopXMLNS) ->
 +    __NewTopXMLNS = choose_top_xmlns(<<"jabber:server">>,
 +                                   [], __TopXMLNS),
 +    _els = [encode(_el, __NewTopXMLNS) || _el <- __Els] ++
 +           encode_db_result_cdata(Key, []),
 +    _attrs = encode_db_result_attr_type(Type,
 +                                      encode_db_result_attr_to(To,
 +                                                               encode_db_result_attr_from(From,
 +                                                                                          enc_xmlns_attrs(__NewTopXMLNS,
 +                                                                                                          __TopXMLNS)))),
 +    {xmlel, <<"db:result">>, _attrs, _els}.
 +
 +decode_db_result_attr_from(__TopXMLNS, undefined) ->
 +    erlang:error({xmpp_codec,
 +                {missing_attr, <<"from">>, <<"db:result">>,
 +                 __TopXMLNS}});
 +decode_db_result_attr_from(__TopXMLNS, _val) ->
 +    case catch nameprep(_val) of
 +      {'EXIT', _} ->
 +        erlang:error({xmpp_codec,
 +                      {bad_attr_value, <<"from">>, <<"db:result">>,
 +                       __TopXMLNS}});
 +      _res -> _res
 +    end.
 +
 +encode_db_result_attr_from(_val, _acc) ->
 +    [{<<"from">>, nameprep(_val)} | _acc].
 +
 +decode_db_result_attr_to(__TopXMLNS, undefined) ->
 +    erlang:error({xmpp_codec,
 +                {missing_attr, <<"to">>, <<"db:result">>, __TopXMLNS}});
 +decode_db_result_attr_to(__TopXMLNS, _val) ->
 +    case catch nameprep(_val) of
 +      {'EXIT', _} ->
 +        erlang:error({xmpp_codec,
 +                      {bad_attr_value, <<"to">>, <<"db:result">>,
 +                       __TopXMLNS}});
 +      _res -> _res
 +    end.
 +
 +encode_db_result_attr_to(_val, _acc) ->
 +    [{<<"to">>, nameprep(_val)} | _acc].
 +
 +decode_db_result_attr_type(__TopXMLNS, undefined) ->
 +    undefined;
 +decode_db_result_attr_type(__TopXMLNS, _val) ->
 +    case catch dec_enum(_val, [valid, invalid, error]) of
 +      {'EXIT', _} ->
 +        erlang:error({xmpp_codec,
 +                      {bad_attr_value, <<"type">>, <<"db:result">>,
 +                       __TopXMLNS}});
 +      _res -> _res
 +    end.
 +
 +encode_db_result_attr_type(undefined, _acc) -> _acc;
 +encode_db_result_attr_type(_val, _acc) ->
 +    [{<<"type">>, enc_enum(_val)} | _acc].
 +
 +decode_db_result_cdata(__TopXMLNS, <<>>) -> <<>>;
 +decode_db_result_cdata(__TopXMLNS, _val) -> _val.
 +
 +encode_db_result_cdata(<<>>, _acc) -> _acc;
 +encode_db_result_cdata(_val, _acc) ->
 +    [{xmlcdata, _val} | _acc].
 +
 +decode_adhoc_command(__TopXMLNS, __IgnoreEls,
 +                   {xmlel, <<"command">>, _attrs, _els}) ->
 +    {Xdata, Notes, Actions} =
 +      decode_adhoc_command_els(__TopXMLNS, __IgnoreEls, _els,
 +                               undefined, [], undefined),
 +    {Node, Lang, Sid, Status, Action} =
 +      decode_adhoc_command_attrs(__TopXMLNS, _attrs,
 +                                 undefined, undefined, undefined, undefined,
 +                                 undefined),
 +    {adhoc_command, Node, Action, Sid, Status, Lang,
 +     Actions, Notes, Xdata}.
 +
 +decode_adhoc_command_els(__TopXMLNS, __IgnoreEls, [],
 +                       Xdata, Notes, Actions) ->
 +    {Xdata, lists:reverse(Notes), Actions};
 +decode_adhoc_command_els(__TopXMLNS, __IgnoreEls,
 +                       [{xmlel, <<"actions">>, _attrs, _} = _el | _els],
 +                       Xdata, Notes, Actions) ->
 +    case get_attr(<<"xmlns">>, _attrs) of
 +      <<"">>
 +        when __TopXMLNS ==
 +               <<"http://jabber.org/protocol/commands">> ->
 +        decode_adhoc_command_els(__TopXMLNS, __IgnoreEls, _els,
 +                                 Xdata, Notes,
 +                                 decode_adhoc_command_actions(__TopXMLNS,
 +                                                              __IgnoreEls,
 +                                                              _el));
 +      <<"http://jabber.org/protocol/commands">> ->
 +        decode_adhoc_command_els(__TopXMLNS, __IgnoreEls, _els,
 +                                 Xdata, Notes,
 +                                 decode_adhoc_command_actions(<<"http://jabber.org/protocol/commands">>,
 +                                                              __IgnoreEls,
 +                                                              _el));
 +      _ ->
 +        decode_adhoc_command_els(__TopXMLNS, __IgnoreEls, _els,
 +                                 Xdata, Notes, Actions)
 +    end;
 +decode_adhoc_command_els(__TopXMLNS, __IgnoreEls,
 +                       [{xmlel, <<"x">>, _attrs, _} = _el | _els], Xdata,
 +                       Notes, Actions) ->
 +    case get_attr(<<"xmlns">>, _attrs) of
 +      <<"jabber:x:data">> ->
 +        decode_adhoc_command_els(__TopXMLNS, __IgnoreEls, _els,
 +                                 decode_xdata(<<"jabber:x:data">>,
 +                                              __IgnoreEls, _el),
 +                                 Notes, Actions);
 +      _ ->
 +        decode_adhoc_command_els(__TopXMLNS, __IgnoreEls, _els,
 +                                 Xdata, Notes, Actions)
 +    end;
 +decode_adhoc_command_els(__TopXMLNS, __IgnoreEls,
 +                       [{xmlel, <<"note">>, _attrs, _} = _el | _els], Xdata,
 +                       Notes, Actions) ->
 +    case get_attr(<<"xmlns">>, _attrs) of
 +      <<"">>
 +        when __TopXMLNS ==
 +               <<"http://jabber.org/protocol/commands">> ->
 +        decode_adhoc_command_els(__TopXMLNS, __IgnoreEls, _els,
 +                                 Xdata,
 +                                 [decode_adhoc_command_notes(__TopXMLNS,
 +                                                             __IgnoreEls, _el)
 +                                  | Notes],
 +                                 Actions);
 +      <<"http://jabber.org/protocol/commands">> ->
 +        decode_adhoc_command_els(__TopXMLNS, __IgnoreEls, _els,
 +                                 Xdata,
 +                                 [decode_adhoc_command_notes(<<"http://jabber.org/protocol/commands">>,
 +                                                             __IgnoreEls, _el)
 +                                  | Notes],
 +                                 Actions);
 +      _ ->
 +        decode_adhoc_command_els(__TopXMLNS, __IgnoreEls, _els,
 +                                 Xdata, Notes, Actions)
 +    end;
 +decode_adhoc_command_els(__TopXMLNS, __IgnoreEls,
 +                       [_ | _els], Xdata, Notes, Actions) ->
 +    decode_adhoc_command_els(__TopXMLNS, __IgnoreEls, _els,
 +                           Xdata, Notes, Actions).
 +
 +decode_adhoc_command_attrs(__TopXMLNS,
 +                         [{<<"node">>, _val} | _attrs], _Node, Lang, Sid,
 +                         Status, Action) ->
 +    decode_adhoc_command_attrs(__TopXMLNS, _attrs, _val,
 +                             Lang, Sid, Status, Action);
 +decode_adhoc_command_attrs(__TopXMLNS,
 +                         [{<<"xml:lang">>, _val} | _attrs], Node, _Lang, Sid,
 +                         Status, Action) ->
 +    decode_adhoc_command_attrs(__TopXMLNS, _attrs, Node,
 +                             _val, Sid, Status, Action);
 +decode_adhoc_command_attrs(__TopXMLNS,
 +                         [{<<"sessionid">>, _val} | _attrs], Node, Lang, _Sid,
 +                         Status, Action) ->
 +    decode_adhoc_command_attrs(__TopXMLNS, _attrs, Node,
 +                             Lang, _val, Status, Action);
 +decode_adhoc_command_attrs(__TopXMLNS,
 +                         [{<<"status">>, _val} | _attrs], Node, Lang, Sid,
 +                         _Status, Action) ->
 +    decode_adhoc_command_attrs(__TopXMLNS, _attrs, Node,
 +                             Lang, Sid, _val, Action);
 +decode_adhoc_command_attrs(__TopXMLNS,
 +                         [{<<"action">>, _val} | _attrs], Node, Lang, Sid,
 +                         Status, _Action) ->
 +    decode_adhoc_command_attrs(__TopXMLNS, _attrs, Node,
 +                             Lang, Sid, Status, _val);
 +decode_adhoc_command_attrs(__TopXMLNS, [_ | _attrs],
 +                         Node, Lang, Sid, Status, Action) ->
 +    decode_adhoc_command_attrs(__TopXMLNS, _attrs, Node,
 +                             Lang, Sid, Status, Action);
 +decode_adhoc_command_attrs(__TopXMLNS, [], Node, Lang,
 +                         Sid, Status, Action) ->
 +    {decode_adhoc_command_attr_node(__TopXMLNS, Node),
 +     'decode_adhoc_command_attr_xml:lang'(__TopXMLNS, Lang),
 +     decode_adhoc_command_attr_sessionid(__TopXMLNS, Sid),
 +     decode_adhoc_command_attr_status(__TopXMLNS, Status),
 +     decode_adhoc_command_attr_action(__TopXMLNS, Action)}.
 +
 +encode_adhoc_command({adhoc_command, Node, Action, Sid,
 +                    Status, Lang, Actions, Notes, Xdata},
 +                   __TopXMLNS) ->
 +    __NewTopXMLNS =
 +      choose_top_xmlns(<<"http://jabber.org/protocol/commands">>,
 +                       [], __TopXMLNS),
 +    _els =
 +      lists:reverse('encode_adhoc_command_$xdata'(Xdata,
 +                                                  __NewTopXMLNS,
 +                                                  'encode_adhoc_command_$notes'(Notes,
 +                                                                                __NewTopXMLNS,
 +                                                                                'encode_adhoc_command_$actions'(Actions,
 +                                                                                                                __NewTopXMLNS,
 +                                                                                                                [])))),
 +    _attrs = encode_adhoc_command_attr_action(Action,
 +                                            encode_adhoc_command_attr_status(Status,
 +                                                                             encode_adhoc_command_attr_sessionid(Sid,
 +                                                                                                                 'encode_adhoc_command_attr_xml:lang'(Lang,
 +                                                                                                                                                      encode_adhoc_command_attr_node(Node,
 +                                                                                                                                                                                     enc_xmlns_attrs(__NewTopXMLNS,
 +                                                                                                                                                                                                     __TopXMLNS)))))),
 +    {xmlel, <<"command">>, _attrs, _els}.
 +
 +'encode_adhoc_command_$xdata'(undefined, __TopXMLNS,
 +                            _acc) ->
 +    _acc;
 +'encode_adhoc_command_$xdata'(Xdata, __TopXMLNS,
 +                            _acc) ->
 +    [encode_xdata(Xdata, __TopXMLNS) | _acc].
 +
 +'encode_adhoc_command_$notes'([], __TopXMLNS, _acc) ->
 +    _acc;
 +'encode_adhoc_command_$notes'([Notes | _els],
 +                            __TopXMLNS, _acc) ->
 +    'encode_adhoc_command_$notes'(_els, __TopXMLNS,
 +                                [encode_adhoc_command_notes(Notes, __TopXMLNS)
 +                                 | _acc]).
 +
 +'encode_adhoc_command_$actions'(undefined, __TopXMLNS,
 +                              _acc) ->
 +    _acc;
 +'encode_adhoc_command_$actions'(Actions, __TopXMLNS,
 +                              _acc) ->
 +    [encode_adhoc_command_actions(Actions, __TopXMLNS)
 +     | _acc].
 +
 +decode_adhoc_command_attr_node(__TopXMLNS, undefined) ->
 +    erlang:error({xmpp_codec,
 +                {missing_attr, <<"node">>, <<"command">>, __TopXMLNS}});
 +decode_adhoc_command_attr_node(__TopXMLNS, _val) ->
 +    _val.
 +
 +encode_adhoc_command_attr_node(_val, _acc) ->
 +    [{<<"node">>, _val} | _acc].
 +
 +'decode_adhoc_command_attr_xml:lang'(__TopXMLNS,
 +                                   undefined) ->
 +    <<>>;
 +'decode_adhoc_command_attr_xml:lang'(__TopXMLNS,
 +                                   _val) ->
 +    _val.
 +
 +'encode_adhoc_command_attr_xml:lang'(<<>>, _acc) ->
 +    _acc;
 +'encode_adhoc_command_attr_xml:lang'(_val, _acc) ->
 +    [{<<"xml:lang">>, _val} | _acc].
 +
 +decode_adhoc_command_attr_sessionid(__TopXMLNS,
 +                                  undefined) ->
 +    <<>>;
 +decode_adhoc_command_attr_sessionid(__TopXMLNS, _val) ->
 +    _val.
 +
 +encode_adhoc_command_attr_sessionid(<<>>, _acc) -> _acc;
 +encode_adhoc_command_attr_sessionid(_val, _acc) ->
 +    [{<<"sessionid">>, _val} | _acc].
 +
 +decode_adhoc_command_attr_status(__TopXMLNS,
 +                               undefined) ->
 +    undefined;
 +decode_adhoc_command_attr_status(__TopXMLNS, _val) ->
 +    case catch dec_enum(_val,
 +                      [canceled, completed, executing])
 +      of
 +      {'EXIT', _} ->
 +        erlang:error({xmpp_codec,
 +                      {bad_attr_value, <<"status">>, <<"command">>,
 +                       __TopXMLNS}});
 +      _res -> _res
 +    end.
 +
 +encode_adhoc_command_attr_status(undefined, _acc) ->
 +    _acc;
 +encode_adhoc_command_attr_status(_val, _acc) ->
 +    [{<<"status">>, enc_enum(_val)} | _acc].
 +
 +decode_adhoc_command_attr_action(__TopXMLNS,
 +                               undefined) ->
 +    execute;
 +decode_adhoc_command_attr_action(__TopXMLNS, _val) ->
 +    case catch dec_enum(_val,
 +                      [cancel, complete, execute, next, prev])
 +      of
 +      {'EXIT', _} ->
 +        erlang:error({xmpp_codec,
 +                      {bad_attr_value, <<"action">>, <<"command">>,
 +                       __TopXMLNS}});
 +      _res -> _res
 +    end.
 +
 +encode_adhoc_command_attr_action(execute, _acc) -> _acc;
 +encode_adhoc_command_attr_action(_val, _acc) ->
 +    [{<<"action">>, enc_enum(_val)} | _acc].
 +
 +decode_adhoc_command_notes(__TopXMLNS, __IgnoreEls,
 +                         {xmlel, <<"note">>, _attrs, _els}) ->
 +    Data = decode_adhoc_command_notes_els(__TopXMLNS,
 +                                        __IgnoreEls, _els, <<>>),
 +    Type = decode_adhoc_command_notes_attrs(__TopXMLNS,
 +                                          _attrs, undefined),
 +    {adhoc_note, Type, Data}.
 +
 +decode_adhoc_command_notes_els(__TopXMLNS, __IgnoreEls,
 +                             [], Data) ->
 +    decode_adhoc_command_notes_cdata(__TopXMLNS, Data);
 +decode_adhoc_command_notes_els(__TopXMLNS, __IgnoreEls,
 +                             [{xmlcdata, _data} | _els], Data) ->
 +    decode_adhoc_command_notes_els(__TopXMLNS, __IgnoreEls,
 +                                 _els, <<Data/binary, _data/binary>>);
 +decode_adhoc_command_notes_els(__TopXMLNS, __IgnoreEls,
 +                             [_ | _els], Data) ->
 +    decode_adhoc_command_notes_els(__TopXMLNS, __IgnoreEls,
 +                                 _els, Data).
 +
 +decode_adhoc_command_notes_attrs(__TopXMLNS,
 +                               [{<<"type">>, _val} | _attrs], _Type) ->
 +    decode_adhoc_command_notes_attrs(__TopXMLNS, _attrs,
 +                                   _val);
 +decode_adhoc_command_notes_attrs(__TopXMLNS,
 +                               [_ | _attrs], Type) ->
 +    decode_adhoc_command_notes_attrs(__TopXMLNS, _attrs,
 +                                   Type);
 +decode_adhoc_command_notes_attrs(__TopXMLNS, [],
 +                               Type) ->
 +    decode_adhoc_command_notes_attr_type(__TopXMLNS, Type).
 +
 +encode_adhoc_command_notes({adhoc_note, Type, Data},
 +                         __TopXMLNS) ->
 +    __NewTopXMLNS =
 +      choose_top_xmlns(<<"http://jabber.org/protocol/commands">>,
 +                       [], __TopXMLNS),
 +    _els = encode_adhoc_command_notes_cdata(Data, []),
 +    _attrs = encode_adhoc_command_notes_attr_type(Type,
 +                                                enc_xmlns_attrs(__NewTopXMLNS,
 +                                                                __TopXMLNS)),
 +    {xmlel, <<"note">>, _attrs, _els}.
 +
 +decode_adhoc_command_notes_attr_type(__TopXMLNS,
 +                                   undefined) ->
 +    info;
 +decode_adhoc_command_notes_attr_type(__TopXMLNS,
 +                                   _val) ->
 +    case catch dec_enum(_val, [info, warn, error]) of
 +      {'EXIT', _} ->
 +        erlang:error({xmpp_codec,
 +                      {bad_attr_value, <<"type">>, <<"note">>, __TopXMLNS}});
 +      _res -> _res
 +    end.
 +
 +encode_adhoc_command_notes_attr_type(info, _acc) ->
 +    _acc;
 +encode_adhoc_command_notes_attr_type(_val, _acc) ->
 +    [{<<"type">>, enc_enum(_val)} | _acc].
 +
 +decode_adhoc_command_notes_cdata(__TopXMLNS, <<>>) ->
 +    <<>>;
 +decode_adhoc_command_notes_cdata(__TopXMLNS, _val) ->
 +    _val.
 +
 +encode_adhoc_command_notes_cdata(<<>>, _acc) -> _acc;
 +encode_adhoc_command_notes_cdata(_val, _acc) ->
 +    [{xmlcdata, _val} | _acc].
 +
 +decode_adhoc_command_actions(__TopXMLNS, __IgnoreEls,
 +                           {xmlel, <<"actions">>, _attrs, _els}) ->
 +    {Next, Complete, Prev} =
 +      decode_adhoc_command_actions_els(__TopXMLNS,
 +                                       __IgnoreEls, _els, false, false,
 +                                       false),
 +    Execute = decode_adhoc_command_actions_attrs(__TopXMLNS,
 +                                               _attrs, undefined),
 +    {adhoc_actions, Execute, Prev, Next, Complete}.
 +
 +decode_adhoc_command_actions_els(__TopXMLNS,
 +                               __IgnoreEls, [], Next, Complete, Prev) ->
 +    {Next, Complete, Prev};
 +decode_adhoc_command_actions_els(__TopXMLNS,
 +                               __IgnoreEls,
 +                               [{xmlel, <<"prev">>, _attrs, _} = _el | _els],
 +                               Next, Complete, Prev) ->
 +    case get_attr(<<"xmlns">>, _attrs) of
 +      <<"">>
 +        when __TopXMLNS ==
 +               <<"http://jabber.org/protocol/commands">> ->
 +        decode_adhoc_command_actions_els(__TopXMLNS,
 +                                         __IgnoreEls, _els, Next, Complete,
 +                                         decode_adhoc_command_prev(__TopXMLNS,
 +                                                                   __IgnoreEls,
 +                                                                   _el));
 +      <<"http://jabber.org/protocol/commands">> ->
 +        decode_adhoc_command_actions_els(__TopXMLNS,
 +                                         __IgnoreEls, _els, Next, Complete,
 +                                         decode_adhoc_command_prev(<<"http://jabber.org/protocol/commands">>,
 +                                                                   __IgnoreEls,
 +                                                                   _el));
 +      _ ->
 +        decode_adhoc_command_actions_els(__TopXMLNS,
 +                                         __IgnoreEls, _els, Next, Complete,
 +                                         Prev)
 +    end;
 +decode_adhoc_command_actions_els(__TopXMLNS,
 +                               __IgnoreEls,
 +                               [{xmlel, <<"next">>, _attrs, _} = _el | _els],
 +                               Next, Complete, Prev) ->
 +    case get_attr(<<"xmlns">>, _attrs) of
 +      <<"">>
 +        when __TopXMLNS ==
 +               <<"http://jabber.org/protocol/commands">> ->
 +        decode_adhoc_command_actions_els(__TopXMLNS,
 +                                         __IgnoreEls, _els,
 +                                         decode_adhoc_command_next(__TopXMLNS,
 +                                                                   __IgnoreEls,
 +                                                                   _el),
 +                                         Complete, Prev);
 +      <<"http://jabber.org/protocol/commands">> ->
 +        decode_adhoc_command_actions_els(__TopXMLNS,
 +                                         __IgnoreEls, _els,
 +                                         decode_adhoc_command_next(<<"http://jabber.org/protocol/commands">>,
 +                                                                   __IgnoreEls,
 +                                                                   _el),
 +                                         Complete, Prev);
 +      _ ->
 +        decode_adhoc_command_actions_els(__TopXMLNS,
 +                                         __IgnoreEls, _els, Next, Complete,
 +                                         Prev)
 +    end;
 +decode_adhoc_command_actions_els(__TopXMLNS,
 +                               __IgnoreEls,
 +                               [{xmlel, <<"complete">>, _attrs, _} = _el
 +                                | _els],
 +                               Next, Complete, Prev) ->
 +    case get_attr(<<"xmlns">>, _attrs) of
 +      <<"">>
 +        when __TopXMLNS ==
 +               <<"http://jabber.org/protocol/commands">> ->
 +        decode_adhoc_command_actions_els(__TopXMLNS,
 +                                         __IgnoreEls, _els, Next,
 +                                         decode_adhoc_command_complete(__TopXMLNS,
 +                                                                       __IgnoreEls,
 +                                                                       _el),
 +                                         Prev);
 +      <<"http://jabber.org/protocol/commands">> ->
 +        decode_adhoc_command_actions_els(__TopXMLNS,
 +                                         __IgnoreEls, _els, Next,
 +                                         decode_adhoc_command_complete(<<"http://jabber.org/protocol/commands">>,
 +                                                                       __IgnoreEls,
 +                                                                       _el),
 +                                         Prev);
 +      _ ->
 +        decode_adhoc_command_actions_els(__TopXMLNS,
 +                                         __IgnoreEls, _els, Next, Complete,
 +                                         Prev)
 +    end;
 +decode_adhoc_command_actions_els(__TopXMLNS,
 +                               __IgnoreEls, [_ | _els], Next, Complete,
 +                               Prev) ->
 +    decode_adhoc_command_actions_els(__TopXMLNS,
 +                                   __IgnoreEls, _els, Next, Complete, Prev).
 +
 +decode_adhoc_command_actions_attrs(__TopXMLNS,
 +                                 [{<<"execute">>, _val} | _attrs],
 +                                 _Execute) ->
 +    decode_adhoc_command_actions_attrs(__TopXMLNS, _attrs,
 +                                     _val);
 +decode_adhoc_command_actions_attrs(__TopXMLNS,
 +                                 [_ | _attrs], Execute) ->
 +    decode_adhoc_command_actions_attrs(__TopXMLNS, _attrs,
 +                                     Execute);
 +decode_adhoc_command_actions_attrs(__TopXMLNS, [],
 +                                 Execute) ->
 +    decode_adhoc_command_actions_attr_execute(__TopXMLNS,
 +                                            Execute).
 +
 +encode_adhoc_command_actions({adhoc_actions, Execute,
 +                            Prev, Next, Complete},
 +                           __TopXMLNS) ->
 +    __NewTopXMLNS =
 +      choose_top_xmlns(<<"http://jabber.org/protocol/commands">>,
 +                       [], __TopXMLNS),
 +    _els =
 +      lists:reverse('encode_adhoc_command_actions_$next'(Next,
 +                                                         __NewTopXMLNS,
 +                                                         'encode_adhoc_command_actions_$complete'(Complete,
 +                                                                                                  __NewTopXMLNS,
 +                                                                                                  'encode_adhoc_command_actions_$prev'(Prev,
 +                                                                                                                                       __NewTopXMLNS,
 +                                                                                                                                       [])))),
 +    _attrs =
 +      encode_adhoc_command_actions_attr_execute(Execute,
 +                                                enc_xmlns_attrs(__NewTopXMLNS,
 +                                                                __TopXMLNS)),
 +    {xmlel, <<"actions">>, _attrs, _els}.
 +
 +'encode_adhoc_command_actions_$next'(false, __TopXMLNS,
 +                                   _acc) ->
 +    _acc;
 +'encode_adhoc_command_actions_$next'(Next, __TopXMLNS,
 +                                   _acc) ->
 +    [encode_adhoc_command_next(Next, __TopXMLNS) | _acc].
 +
 +'encode_adhoc_command_actions_$complete'(false,
 +                                       __TopXMLNS, _acc) ->
 +    _acc;
 +'encode_adhoc_command_actions_$complete'(Complete,
 +                                       __TopXMLNS, _acc) ->
 +    [encode_adhoc_command_complete(Complete, __TopXMLNS)
 +     | _acc].
 +
 +'encode_adhoc_command_actions_$prev'(false, __TopXMLNS,
 +                                   _acc) ->
 +    _acc;
 +'encode_adhoc_command_actions_$prev'(Prev, __TopXMLNS,
 +                                   _acc) ->
 +    [encode_adhoc_command_prev(Prev, __TopXMLNS) | _acc].
 +
 +decode_adhoc_command_actions_attr_execute(__TopXMLNS,
 +                                        undefined) ->
 +    undefined;
 +decode_adhoc_command_actions_attr_execute(__TopXMLNS,
 +                                        _val) ->
 +    case catch dec_enum(_val, [complete, next, prev]) of
 +      {'EXIT', _} ->
 +        erlang:error({xmpp_codec,
 +                      {bad_attr_value, <<"execute">>, <<"actions">>,
 +                       __TopXMLNS}});
 +      _res -> _res
 +    end.
 +
 +encode_adhoc_command_actions_attr_execute(undefined,
 +                                        _acc) ->
 +    _acc;
 +encode_adhoc_command_actions_attr_execute(_val, _acc) ->
 +    [{<<"execute">>, enc_enum(_val)} | _acc].
 +
 +decode_adhoc_command_complete(__TopXMLNS, __IgnoreEls,
 +                            {xmlel, <<"complete">>, _attrs, _els}) ->
 +    true.
 +
 +encode_adhoc_command_complete(true, __TopXMLNS) ->
 +    __NewTopXMLNS =
 +      choose_top_xmlns(<<"http://jabber.org/protocol/commands">>,
 +                       [], __TopXMLNS),
 +    _els = [],
 +    _attrs = enc_xmlns_attrs(__NewTopXMLNS, __TopXMLNS),
 +    {xmlel, <<"complete">>, _attrs, _els}.
 +
 +decode_adhoc_command_next(__TopXMLNS, __IgnoreEls,
 +                        {xmlel, <<"next">>, _attrs, _els}) ->
 +    true.
 +
 +encode_adhoc_command_next(true, __TopXMLNS) ->
 +    __NewTopXMLNS =
 +      choose_top_xmlns(<<"http://jabber.org/protocol/commands">>,
 +                       [], __TopXMLNS),
 +    _els = [],
 +    _attrs = enc_xmlns_attrs(__NewTopXMLNS, __TopXMLNS),
 +    {xmlel, <<"next">>, _attrs, _els}.
 +
 +decode_adhoc_command_prev(__TopXMLNS, __IgnoreEls,
 +                        {xmlel, <<"prev">>, _attrs, _els}) ->
 +    true.
 +
 +encode_adhoc_command_prev(true, __TopXMLNS) ->
 +    __NewTopXMLNS =
 +      choose_top_xmlns(<<"http://jabber.org/protocol/commands">>,
 +                       [], __TopXMLNS),
 +    _els = [],
 +    _attrs = enc_xmlns_attrs(__NewTopXMLNS, __TopXMLNS),
 +    {xmlel, <<"prev">>, _attrs, _els}.
 +
 +decode_client_id(__TopXMLNS, __IgnoreEls,
 +               {xmlel, <<"client-id">>, _attrs, _els}) ->
 +    Id = decode_client_id_attrs(__TopXMLNS, _attrs,
 +                              undefined),
 +    {client_id, Id}.
 +
 +decode_client_id_attrs(__TopXMLNS,
 +                     [{<<"id">>, _val} | _attrs], _Id) ->
 +    decode_client_id_attrs(__TopXMLNS, _attrs, _val);
 +decode_client_id_attrs(__TopXMLNS, [_ | _attrs], Id) ->
 +    decode_client_id_attrs(__TopXMLNS, _attrs, Id);
 +decode_client_id_attrs(__TopXMLNS, [], Id) ->
 +    decode_client_id_attr_id(__TopXMLNS, Id).
 +
 +encode_client_id({client_id, Id}, __TopXMLNS) ->
 +    __NewTopXMLNS = choose_top_xmlns(<<"urn:xmpp:sid:0">>,
 +                                   [], __TopXMLNS),
 +    _els = [],
 +    _attrs = encode_client_id_attr_id(Id,
 +                                    enc_xmlns_attrs(__NewTopXMLNS,
 +                                                    __TopXMLNS)),
 +    {xmlel, <<"client-id">>, _attrs, _els}.
 +
 +decode_client_id_attr_id(__TopXMLNS, undefined) ->
 +    erlang:error({xmpp_codec,
 +                {missing_attr, <<"id">>, <<"client-id">>, __TopXMLNS}});
 +decode_client_id_attr_id(__TopXMLNS, _val) -> _val.
 +
 +encode_client_id_attr_id(_val, _acc) ->
 +    [{<<"id">>, _val} | _acc].
 +
 +decode_stanza_id(__TopXMLNS, __IgnoreEls,
 +               {xmlel, <<"stanza-id">>, _attrs, _els}) ->
 +    {Id, By} = decode_stanza_id_attrs(__TopXMLNS, _attrs,
 +                                    undefined, undefined),
 +    {stanza_id, By, Id}.
 +
 +decode_stanza_id_attrs(__TopXMLNS,
 +                     [{<<"id">>, _val} | _attrs], _Id, By) ->
 +    decode_stanza_id_attrs(__TopXMLNS, _attrs, _val, By);
 +decode_stanza_id_attrs(__TopXMLNS,
 +                     [{<<"by">>, _val} | _attrs], Id, _By) ->
 +    decode_stanza_id_attrs(__TopXMLNS, _attrs, Id, _val);
 +decode_stanza_id_attrs(__TopXMLNS, [_ | _attrs], Id,
 +                     By) ->
 +    decode_stanza_id_attrs(__TopXMLNS, _attrs, Id, By);
 +decode_stanza_id_attrs(__TopXMLNS, [], Id, By) ->
 +    {decode_stanza_id_attr_id(__TopXMLNS, Id),
 +     decode_stanza_id_attr_by(__TopXMLNS, By)}.
 +
 +encode_stanza_id({stanza_id, By, Id}, __TopXMLNS) ->
 +    __NewTopXMLNS = choose_top_xmlns(<<"urn:xmpp:sid:0">>,
 +                                   [], __TopXMLNS),
 +    _els = [],
 +    _attrs = encode_stanza_id_attr_by(By,
 +                                    encode_stanza_id_attr_id(Id,
 +                                                             enc_xmlns_attrs(__NewTopXMLNS,
 +                                                                             __TopXMLNS))),
 +    {xmlel, <<"stanza-id">>, _attrs, _els}.
 +
 +decode_stanza_id_attr_id(__TopXMLNS, undefined) ->
 +    erlang:error({xmpp_codec,
 +                {missing_attr, <<"id">>, <<"stanza-id">>, __TopXMLNS}});
 +decode_stanza_id_attr_id(__TopXMLNS, _val) -> _val.
 +
 +encode_stanza_id_attr_id(_val, _acc) ->
 +    [{<<"id">>, _val} | _acc].
 +
 +decode_stanza_id_attr_by(__TopXMLNS, undefined) ->
 +    erlang:error({xmpp_codec,
 +                {missing_attr, <<"by">>, <<"stanza-id">>, __TopXMLNS}});
 +decode_stanza_id_attr_by(__TopXMLNS, _val) ->
 +    case catch dec_jid(_val) of
 +      {'EXIT', _} ->
 +        erlang:error({xmpp_codec,
 +                      {bad_attr_value, <<"by">>, <<"stanza-id">>,
 +                       __TopXMLNS}});
 +      _res -> _res
 +    end.
 +
 +encode_stanza_id_attr_by(_val, _acc) ->
 +    [{<<"by">>, enc_jid(_val)} | _acc].
 +
 +decode_addresses(__TopXMLNS, __IgnoreEls,
 +               {xmlel, <<"addresses">>, _attrs, _els}) ->
 +    List = decode_addresses_els(__TopXMLNS, __IgnoreEls,
 +                              _els, []),
 +    {addresses, List}.
 +
 +decode_addresses_els(__TopXMLNS, __IgnoreEls, [],
 +                   List) ->
 +    lists:reverse(List);
 +decode_addresses_els(__TopXMLNS, __IgnoreEls,
 +                   [{xmlel, <<"address">>, _attrs, _} = _el | _els],
 +                   List) ->
 +    case get_attr(<<"xmlns">>, _attrs) of
 +      <<"">>
 +        when __TopXMLNS ==
 +               <<"http://jabber.org/protocol/address">> ->
 +        decode_addresses_els(__TopXMLNS, __IgnoreEls, _els,
 +                             [decode_address(__TopXMLNS, __IgnoreEls, _el)
 +                              | List]);
 +      <<"http://jabber.org/protocol/address">> ->
 +        decode_addresses_els(__TopXMLNS, __IgnoreEls, _els,
 +                             [decode_address(<<"http://jabber.org/protocol/address">>,
 +                                             __IgnoreEls, _el)
 +                              | List]);
 +      _ ->
 +        decode_addresses_els(__TopXMLNS, __IgnoreEls, _els,
 +                             List)
 +    end;
 +decode_addresses_els(__TopXMLNS, __IgnoreEls,
 +                   [_ | _els], List) ->
 +    decode_addresses_els(__TopXMLNS, __IgnoreEls, _els,
 +                       List).
 +
 +encode_addresses({addresses, List}, __TopXMLNS) ->
 +    __NewTopXMLNS =
 +      choose_top_xmlns(<<"http://jabber.org/protocol/address">>,
 +                       [], __TopXMLNS),
 +    _els = lists:reverse('encode_addresses_$list'(List,
 +                                                __NewTopXMLNS, [])),
 +    _attrs = enc_xmlns_attrs(__NewTopXMLNS, __TopXMLNS),
 +    {xmlel, <<"addresses">>, _attrs, _els}.
 +
 +'encode_addresses_$list'([], __TopXMLNS, _acc) -> _acc;
 +'encode_addresses_$list'([List | _els], __TopXMLNS,
 +                       _acc) ->
 +    'encode_addresses_$list'(_els, __TopXMLNS,
 +                           [encode_address(List, __TopXMLNS) | _acc]).
 +
 +decode_address(__TopXMLNS, __IgnoreEls,
 +             {xmlel, <<"address">>, _attrs, _els}) ->
 +    {Type, Jid, Desc, Node, Delivered} =
 +      decode_address_attrs(__TopXMLNS, _attrs, undefined,
 +                           undefined, undefined, undefined, undefined),
 +    {address, Type, Jid, Desc, Node, Delivered}.
 +
 +decode_address_attrs(__TopXMLNS,
 +                   [{<<"type">>, _val} | _attrs], _Type, Jid, Desc, Node,
 +                   Delivered) ->
 +    decode_address_attrs(__TopXMLNS, _attrs, _val, Jid,
 +                       Desc, Node, Delivered);
 +decode_address_attrs(__TopXMLNS,
 +                   [{<<"jid">>, _val} | _attrs], Type, _Jid, Desc, Node,
 +                   Delivered) ->
 +    decode_address_attrs(__TopXMLNS, _attrs, Type, _val,
 +                       Desc, Node, Delivered);
 +decode_address_attrs(__TopXMLNS,
 +                   [{<<"desc">>, _val} | _attrs], Type, Jid, _Desc, Node,
 +                   Delivered) ->
 +    decode_address_attrs(__TopXMLNS, _attrs, Type, Jid,
 +                       _val, Node, Delivered);
 +decode_address_attrs(__TopXMLNS,
 +                   [{<<"node">>, _val} | _attrs], Type, Jid, Desc, _Node,
 +                   Delivered) ->
 +    decode_address_attrs(__TopXMLNS, _attrs, Type, Jid,
 +                       Desc, _val, Delivered);
 +decode_address_attrs(__TopXMLNS,
 +                   [{<<"delivered">>, _val} | _attrs], Type, Jid, Desc,
 +                   Node, _Delivered) ->
 +    decode_address_attrs(__TopXMLNS, _attrs, Type, Jid,
 +                       Desc, Node, _val);
 +decode_address_attrs(__TopXMLNS, [_ | _attrs], Type,
 +                   Jid, Desc, Node, Delivered) ->
 +    decode_address_attrs(__TopXMLNS, _attrs, Type, Jid,
 +                       Desc, Node, Delivered);
 +decode_address_attrs(__TopXMLNS, [], Type, Jid, Desc,
 +                   Node, Delivered) ->
 +    {decode_address_attr_type(__TopXMLNS, Type),
 +     decode_address_attr_jid(__TopXMLNS, Jid),
 +     decode_address_attr_desc(__TopXMLNS, Desc),
 +     decode_address_attr_node(__TopXMLNS, Node),
 +     decode_address_attr_delivered(__TopXMLNS, Delivered)}.
 +
 +encode_address({address, Type, Jid, Desc, Node,
 +              Delivered},
 +             __TopXMLNS) ->
 +    __NewTopXMLNS =
 +      choose_top_xmlns(<<"http://jabber.org/protocol/address">>,
 +                       [], __TopXMLNS),
 +    _els = [],
 +    _attrs = encode_address_attr_delivered(Delivered,
 +                                         encode_address_attr_node(Node,
 +                                                                  encode_address_attr_desc(Desc,
 +                                                                                           encode_address_attr_jid(Jid,
 +                                                                                                                   encode_address_attr_type(Type,
 +                                                                                                                                            enc_xmlns_attrs(__NewTopXMLNS,
 +                                                                                                                                                            __TopXMLNS)))))),
 +    {xmlel, <<"address">>, _attrs, _els}.
 +
 +decode_address_attr_type(__TopXMLNS, undefined) ->
 +    erlang:error({xmpp_codec,
 +                {missing_attr, <<"type">>, <<"address">>, __TopXMLNS}});
 +decode_address_attr_type(__TopXMLNS, _val) ->
 +    case catch dec_enum(_val,
 +                      [bcc, cc, noreply, ofrom, replyroom, replyto, to])
 +      of
 +      {'EXIT', _} ->
 +        erlang:error({xmpp_codec,
 +                      {bad_attr_value, <<"type">>, <<"address">>,
 +                       __TopXMLNS}});
 +      _res -> _res
 +    end.
 +
 +encode_address_attr_type(_val, _acc) ->
 +    [{<<"type">>, enc_enum(_val)} | _acc].
 +
 +decode_address_attr_jid(__TopXMLNS, undefined) ->
 +    undefined;
 +decode_address_attr_jid(__TopXMLNS, _val) ->
 +    case catch dec_jid(_val) of
 +      {'EXIT', _} ->
 +        erlang:error({xmpp_codec,
 +                      {bad_attr_value, <<"jid">>, <<"address">>,
 +                       __TopXMLNS}});
 +      _res -> _res
 +    end.
 +
 +encode_address_attr_jid(undefined, _acc) -> _acc;
 +encode_address_attr_jid(_val, _acc) ->
 +    [{<<"jid">>, enc_jid(_val)} | _acc].
 +
 +decode_address_attr_desc(__TopXMLNS, undefined) -> <<>>;
 +decode_address_attr_desc(__TopXMLNS, _val) -> _val.
 +
 +encode_address_attr_desc(<<>>, _acc) -> _acc;
 +encode_address_attr_desc(_val, _acc) ->
 +    [{<<"desc">>, _val} | _acc].
 +
 +decode_address_attr_node(__TopXMLNS, undefined) -> <<>>;
 +decode_address_attr_node(__TopXMLNS, _val) -> _val.
 +
 +encode_address_attr_node(<<>>, _acc) -> _acc;
 +encode_address_attr_node(_val, _acc) ->
 +    [{<<"node">>, _val} | _acc].
 +
 +decode_address_attr_delivered(__TopXMLNS, undefined) ->
 +    undefined;
 +decode_address_attr_delivered(__TopXMLNS, _val) ->
 +    case catch dec_bool(_val) of
 +      {'EXIT', _} ->
 +        erlang:error({xmpp_codec,
 +                      {bad_attr_value, <<"delivered">>, <<"address">>,
 +                       __TopXMLNS}});
 +      _res -> _res
 +    end.
 +
 +encode_address_attr_delivered(undefined, _acc) -> _acc;
 +encode_address_attr_delivered(_val, _acc) ->
 +    [{<<"delivered">>, enc_bool(_val)} | _acc].
 +
 +decode_nick(__TopXMLNS, __IgnoreEls,
 +          {xmlel, <<"nick">>, _attrs, _els}) ->
 +    Name = decode_nick_els(__TopXMLNS, __IgnoreEls, _els,
 +                         <<>>),
 +    {nick, Name}.
 +
 +decode_nick_els(__TopXMLNS, __IgnoreEls, [], Name) ->
 +    decode_nick_cdata(__TopXMLNS, Name);
 +decode_nick_els(__TopXMLNS, __IgnoreEls,
 +              [{xmlcdata, _data} | _els], Name) ->
 +    decode_nick_els(__TopXMLNS, __IgnoreEls, _els,
 +                  <<Name/binary, _data/binary>>);
 +decode_nick_els(__TopXMLNS, __IgnoreEls, [_ | _els],
 +              Name) ->
 +    decode_nick_els(__TopXMLNS, __IgnoreEls, _els, Name).
 +
 +encode_nick({nick, Name}, __TopXMLNS) ->
 +    __NewTopXMLNS =
 +      choose_top_xmlns(<<"http://jabber.org/protocol/nick">>,
 +                       [], __TopXMLNS),
 +    _els = encode_nick_cdata(Name, []),
 +    _attrs = enc_xmlns_attrs(__NewTopXMLNS, __TopXMLNS),
 +    {xmlel, <<"nick">>, _attrs, _els}.
 +
 +decode_nick_cdata(__TopXMLNS, <<>>) ->
 +    erlang:error({xmpp_codec,
 +                {missing_cdata, <<>>, <<"nick">>, __TopXMLNS}});
 +decode_nick_cdata(__TopXMLNS, _val) -> _val.
 +
 +encode_nick_cdata(_val, _acc) ->
 +    [{xmlcdata, _val} | _acc].
 +
 +decode_expire(__TopXMLNS, __IgnoreEls,
 +            {xmlel, <<"x">>, _attrs, _els}) ->
 +    {Seconds, Stored} = decode_expire_attrs(__TopXMLNS,
 +                                          _attrs, undefined, undefined),
 +    {expire, Seconds, Stored}.
 +
 +decode_expire_attrs(__TopXMLNS,
 +                  [{<<"seconds">>, _val} | _attrs], _Seconds, Stored) ->
 +    decode_expire_attrs(__TopXMLNS, _attrs, _val, Stored);
 +decode_expire_attrs(__TopXMLNS,
 +                  [{<<"stored">>, _val} | _attrs], Seconds, _Stored) ->
 +    decode_expire_attrs(__TopXMLNS, _attrs, Seconds, _val);
 +decode_expire_attrs(__TopXMLNS, [_ | _attrs], Seconds,
 +                  Stored) ->
 +    decode_expire_attrs(__TopXMLNS, _attrs, Seconds,
 +                      Stored);
 +decode_expire_attrs(__TopXMLNS, [], Seconds, Stored) ->
 +    {decode_expire_attr_seconds(__TopXMLNS, Seconds),
 +     decode_expire_attr_stored(__TopXMLNS, Stored)}.
 +
 +encode_expire({expire, Seconds, Stored}, __TopXMLNS) ->
 +    __NewTopXMLNS = choose_top_xmlns(<<"jabber:x:expire">>,
 +                                   [], __TopXMLNS),
 +    _els = [],
 +    _attrs = encode_expire_attr_stored(Stored,
 +                                     encode_expire_attr_seconds(Seconds,
 +                                                                enc_xmlns_attrs(__NewTopXMLNS,
 +                                                                                __TopXMLNS))),
 +    {xmlel, <<"x">>, _attrs, _els}.
 +
 +decode_expire_attr_seconds(__TopXMLNS, undefined) ->
 +    erlang:error({xmpp_codec,
 +                {missing_attr, <<"seconds">>, <<"x">>, __TopXMLNS}});
 +decode_expire_attr_seconds(__TopXMLNS, _val) ->
 +    case catch dec_int(_val, 0, infinity) of
 +      {'EXIT', _} ->
 +        erlang:error({xmpp_codec,
 +                      {bad_attr_value, <<"seconds">>, <<"x">>, __TopXMLNS}});
 +      _res -> _res
 +    end.
 +
 +encode_expire_attr_seconds(_val, _acc) ->
 +    [{<<"seconds">>, enc_int(_val)} | _acc].
 +
 +decode_expire_attr_stored(__TopXMLNS, undefined) ->
 +    undefined;
 +decode_expire_attr_stored(__TopXMLNS, _val) ->
 +    case catch dec_int(_val, 0, infinity) of
 +      {'EXIT', _} ->
 +        erlang:error({xmpp_codec,
 +                      {bad_attr_value, <<"stored">>, <<"x">>, __TopXMLNS}});
 +      _res -> _res
 +    end.
 +
 +encode_expire_attr_stored(undefined, _acc) -> _acc;
 +encode_expire_attr_stored(_val, _acc) ->
 +    [{<<"stored">>, enc_int(_val)} | _acc].
 +
 +decode_xevent(__TopXMLNS, __IgnoreEls,
 +            {xmlel, <<"x">>, _attrs, _els}) ->
 +    {Id, Displayed, Delivered, Offline, Composing} =
 +      decode_xevent_els(__TopXMLNS, __IgnoreEls, _els,
 +                        undefined, false, false, false, false),
 +    {xevent, Offline, Delivered, Displayed, Composing, Id}.
 +
 +decode_xevent_els(__TopXMLNS, __IgnoreEls, [], Id,
 +                Displayed, Delivered, Offline, Composing) ->
 +    {Id, Displayed, Delivered, Offline, Composing};
 +decode_xevent_els(__TopXMLNS, __IgnoreEls,
 +                [{xmlel, <<"offline">>, _attrs, _} = _el | _els], Id,
 +                Displayed, Delivered, Offline, Composing) ->
 +    case get_attr(<<"xmlns">>, _attrs) of
 +      <<"">> when __TopXMLNS == <<"jabber:x:event">> ->
 +        decode_xevent_els(__TopXMLNS, __IgnoreEls, _els, Id,
 +                          Displayed, Delivered,
 +                          decode_xevent_offline(__TopXMLNS, __IgnoreEls, _el),
 +                          Composing);
 +      <<"jabber:x:event">> ->
 +        decode_xevent_els(__TopXMLNS, __IgnoreEls, _els, Id,
 +                          Displayed, Delivered,
 +                          decode_xevent_offline(<<"jabber:x:event">>,
 +                                                __IgnoreEls, _el),
 +                          Composing);
 +      _ ->
 +        decode_xevent_els(__TopXMLNS, __IgnoreEls, _els, Id,
 +                          Displayed, Delivered, Offline, Composing)
 +    end;
 +decode_xevent_els(__TopXMLNS, __IgnoreEls,
 +                [{xmlel, <<"delivered">>, _attrs, _} = _el | _els], Id,
 +                Displayed, Delivered, Offline, Composing) ->
 +    case get_attr(<<"xmlns">>, _attrs) of
 +      <<"">> when __TopXMLNS == <<"jabber:x:event">> ->
 +        decode_xevent_els(__TopXMLNS, __IgnoreEls, _els, Id,
 +                          Displayed,
 +                          decode_xevent_delivered(__TopXMLNS, __IgnoreEls,
 +                                                  _el),
 +                          Offline, Composing);
 +      <<"jabber:x:event">> ->
 +        decode_xevent_els(__TopXMLNS, __IgnoreEls, _els, Id,
 +                          Displayed,
 +                          decode_xevent_delivered(<<"jabber:x:event">>,
 +                                                  __IgnoreEls, _el),
 +                          Offline, Composing);
 +      _ ->
 +        decode_xevent_els(__TopXMLNS, __IgnoreEls, _els, Id,
 +                          Displayed, Delivered, Offline, Composing)
 +    end;
 +decode_xevent_els(__TopXMLNS, __IgnoreEls,
 +                [{xmlel, <<"displayed">>, _attrs, _} = _el | _els], Id,
 +                Displayed, Delivered, Offline, Composing) ->
 +    case get_attr(<<"xmlns">>, _attrs) of
 +      <<"">> when __TopXMLNS == <<"jabber:x:event">> ->
 +        decode_xevent_els(__TopXMLNS, __IgnoreEls, _els, Id,
 +                          decode_xevent_displayed(__TopXMLNS, __IgnoreEls,
 +                                                  _el),
 +                          Delivered, Offline, Composing);
 +      <<"jabber:x:event">> ->
 +        decode_xevent_els(__TopXMLNS, __IgnoreEls, _els, Id,
 +                          decode_xevent_displayed(<<"jabber:x:event">>,
 +                                                  __IgnoreEls, _el),
 +                          Delivered, Offline, Composing);
 +      _ ->
 +        decode_xevent_els(__TopXMLNS, __IgnoreEls, _els, Id,
 +                          Displayed, Delivered, Offline, Composing)
 +    end;
 +decode_xevent_els(__TopXMLNS, __IgnoreEls,
 +                [{xmlel, <<"composing">>, _attrs, _} = _el | _els], Id,
 +                Displayed, Delivered, Offline, Composing) ->
 +    case get_attr(<<"xmlns">>, _attrs) of
 +      <<"">> when __TopXMLNS == <<"jabber:x:event">> ->
 +        decode_xevent_els(__TopXMLNS, __IgnoreEls, _els, Id,
 +                          Displayed, Delivered, Offline,
 +                          decode_xevent_composing(__TopXMLNS, __IgnoreEls,
 +                                                  _el));
 +      <<"jabber:x:event">> ->
 +        decode_xevent_els(__TopXMLNS, __IgnoreEls, _els, Id,
 +                          Displayed, Delivered, Offline,
 +                          decode_xevent_composing(<<"jabber:x:event">>,
 +                                                  __IgnoreEls, _el));
 +      _ ->
 +        decode_xevent_els(__TopXMLNS, __IgnoreEls, _els, Id,
 +                          Displayed, Delivered, Offline, Composing)
 +    end;
 +decode_xevent_els(__TopXMLNS, __IgnoreEls,
 +                [{xmlel, <<"id">>, _attrs, _} = _el | _els], Id,
 +                Displayed, Delivered, Offline, Composing) ->
 +    case get_attr(<<"xmlns">>, _attrs) of
 +      <<"">> when __TopXMLNS == <<"jabber:x:event">> ->
 +        decode_xevent_els(__TopXMLNS, __IgnoreEls, _els,
 +                          decode_xevent_id(__TopXMLNS, __IgnoreEls, _el),
 +                          Displayed, Delivered, Offline, Composing);
 +      <<"jabber:x:event">> ->
 +        decode_xevent_els(__TopXMLNS, __IgnoreEls, _els,
 +                          decode_xevent_id(<<"jabber:x:event">>, __IgnoreEls,
 +                                           _el),
 +                          Displayed, Delivered, Offline, Composing);
 +      _ ->
 +        decode_xevent_els(__TopXMLNS, __IgnoreEls, _els, Id,
 +                          Displayed, Delivered, Offline, Composing)
 +    end;
 +decode_xevent_els(__TopXMLNS, __IgnoreEls, [_ | _els],
 +                Id, Displayed, Delivered, Offline, Composing) ->
 +    decode_xevent_els(__TopXMLNS, __IgnoreEls, _els, Id,
 +                    Displayed, Delivered, Offline, Composing).
 +
 +encode_xevent({xevent, Offline, Delivered, Displayed,
 +             Composing, Id},
 +            __TopXMLNS) ->
 +    __NewTopXMLNS = choose_top_xmlns(<<"jabber:x:event">>,
 +                                   [], __TopXMLNS),
 +    _els = lists:reverse('encode_xevent_$id'(Id,
 +                                           __NewTopXMLNS,
 +                                           'encode_xevent_$displayed'(Displayed,
 +                                                                      __NewTopXMLNS,
 +                                                                      'encode_xevent_$delivered'(Delivered,
 +                                                                                                 __NewTopXMLNS,
 +                                                                                                 'encode_xevent_$offline'(Offline,
 +                                                                                                                          __NewTopXMLNS,
 +                                                                                                                          'encode_xevent_$composing'(Composing,
 +                                                                                                                                                     __NewTopXMLNS,
 +                                                                                                                                                     [])))))),
 +    _attrs = enc_xmlns_attrs(__NewTopXMLNS, __TopXMLNS),
 +    {xmlel, <<"x">>, _attrs, _els}.
 +
 +'encode_xevent_$id'(undefined, __TopXMLNS, _acc) ->
 +    _acc;
 +'encode_xevent_$id'(Id, __TopXMLNS, _acc) ->
 +    [encode_xevent_id(Id, __TopXMLNS) | _acc].
 +
 +'encode_xevent_$displayed'(false, __TopXMLNS, _acc) ->
 +    _acc;
 +'encode_xevent_$displayed'(Displayed, __TopXMLNS,
 +                         _acc) ->
 +    [encode_xevent_displayed(Displayed, __TopXMLNS) | _acc].
 +
 +'encode_xevent_$delivered'(false, __TopXMLNS, _acc) ->
 +    _acc;
 +'encode_xevent_$delivered'(Delivered, __TopXMLNS,
 +                         _acc) ->
 +    [encode_xevent_delivered(Delivered, __TopXMLNS) | _acc].
 +
 +'encode_xevent_$offline'(false, __TopXMLNS, _acc) ->
 +    _acc;
 +'encode_xevent_$offline'(Offline, __TopXMLNS, _acc) ->
 +    [encode_xevent_offline(Offline, __TopXMLNS) | _acc].
 +
 +'encode_xevent_$composing'(false, __TopXMLNS, _acc) ->
 +    _acc;
 +'encode_xevent_$composing'(Composing, __TopXMLNS,
 +                         _acc) ->
 +    [encode_xevent_composing(Composing, __TopXMLNS) | _acc].
 +
 +decode_xevent_id(__TopXMLNS, __IgnoreEls,
 +               {xmlel, <<"id">>, _attrs, _els}) ->
 +    Cdata = decode_xevent_id_els(__TopXMLNS, __IgnoreEls,
 +                               _els, <<>>),
 +    Cdata.
 +
 +decode_xevent_id_els(__TopXMLNS, __IgnoreEls, [],
 +                   Cdata) ->
 +    decode_xevent_id_cdata(__TopXMLNS, Cdata);
 +decode_xevent_id_els(__TopXMLNS, __IgnoreEls,
 +                   [{xmlcdata, _data} | _els], Cdata) ->
 +    decode_xevent_id_els(__TopXMLNS, __IgnoreEls, _els,
 +                       <<Cdata/binary, _data/binary>>);
 +decode_xevent_id_els(__TopXMLNS, __IgnoreEls,
 +                   [_ | _els], Cdata) ->
 +    decode_xevent_id_els(__TopXMLNS, __IgnoreEls, _els,
 +                       Cdata).
 +
 +encode_xevent_id(Cdata, __TopXMLNS) ->
 +    __NewTopXMLNS = choose_top_xmlns(<<"jabber:x:event">>,
 +                                   [], __TopXMLNS),
 +    _els = encode_xevent_id_cdata(Cdata, []),
 +    _attrs = enc_xmlns_attrs(__NewTopXMLNS, __TopXMLNS),
 +    {xmlel, <<"id">>, _attrs, _els}.
 +
 +decode_xevent_id_cdata(__TopXMLNS, <<>>) -> <<>>;
 +decode_xevent_id_cdata(__TopXMLNS, _val) -> _val.
 +
 +encode_xevent_id_cdata(<<>>, _acc) -> _acc;
 +encode_xevent_id_cdata(_val, _acc) ->
 +    [{xmlcdata, _val} | _acc].
 +
 +decode_xevent_composing(__TopXMLNS, __IgnoreEls,
 +                      {xmlel, <<"composing">>, _attrs, _els}) ->
 +    true.
 +
 +encode_xevent_composing(true, __TopXMLNS) ->
 +    __NewTopXMLNS = choose_top_xmlns(<<"jabber:x:event">>,
 +                                   [], __TopXMLNS),
 +    _els = [],
 +    _attrs = enc_xmlns_attrs(__NewTopXMLNS, __TopXMLNS),
 +    {xmlel, <<"composing">>, _attrs, _els}.
 +
 +decode_xevent_displayed(__TopXMLNS, __IgnoreEls,
 +                      {xmlel, <<"displayed">>, _attrs, _els}) ->
 +    true.
 +
 +encode_xevent_displayed(true, __TopXMLNS) ->
 +    __NewTopXMLNS = choose_top_xmlns(<<"jabber:x:event">>,
 +                                   [], __TopXMLNS),
 +    _els = [],
 +    _attrs = enc_xmlns_attrs(__NewTopXMLNS, __TopXMLNS),
 +    {xmlel, <<"displayed">>, _attrs, _els}.
 +
 +decode_xevent_delivered(__TopXMLNS, __IgnoreEls,
 +                      {xmlel, <<"delivered">>, _attrs, _els}) ->
 +    true.
 +
 +encode_xevent_delivered(true, __TopXMLNS) ->
 +    __NewTopXMLNS = choose_top_xmlns(<<"jabber:x:event">>,
 +                                   [], __TopXMLNS),
 +    _els = [],
 +    _attrs = enc_xmlns_attrs(__NewTopXMLNS, __TopXMLNS),
 +    {xmlel, <<"delivered">>, _attrs, _els}.
 +
 +decode_xevent_offline(__TopXMLNS, __IgnoreEls,
 +                    {xmlel, <<"offline">>, _attrs, _els}) ->
 +    true.
 +
 +encode_xevent_offline(true, __TopXMLNS) ->
 +    __NewTopXMLNS = choose_top_xmlns(<<"jabber:x:event">>,
 +                                   [], __TopXMLNS),
 +    _els = [],
 +    _attrs = enc_xmlns_attrs(__NewTopXMLNS, __TopXMLNS),
 +    {xmlel, <<"offline">>, _attrs, _els}.
 +
 +decode_search(__TopXMLNS, __IgnoreEls,
 +            {xmlel, <<"query">>, _attrs, _els}) ->
 +    {Xdata, Items, Instructions, Last, First, Nick, Email} =
 +      decode_search_els(__TopXMLNS, __IgnoreEls, _els,
 +                        undefined, [], undefined, undefined, undefined,
 +                        undefined, undefined),
 +    {search, Instructions, First, Last, Nick, Email, Items,
 +     Xdata}.
 +
 +decode_search_els(__TopXMLNS, __IgnoreEls, [], Xdata,
 +                Items, Instructions, Last, First, Nick, Email) ->
 +    {Xdata, lists:reverse(Items), Instructions, Last, First,
 +     Nick, Email};
 +decode_search_els(__TopXMLNS, __IgnoreEls,
 +                [{xmlel, <<"instructions">>, _attrs, _} = _el | _els],
 +                Xdata, Items, Instructions, Last, First, Nick, Email) ->
 +    case get_attr(<<"xmlns">>, _attrs) of
 +      <<"">> when __TopXMLNS == <<"jabber:iq:search">> ->
 +        decode_search_els(__TopXMLNS, __IgnoreEls, _els, Xdata,
 +                          Items,
 +                          decode_search_instructions(__TopXMLNS, __IgnoreEls,
 +                                                     _el),
 +                          Last, First, Nick, Email);
 +      <<"jabber:iq:search">> ->
 +        decode_search_els(__TopXMLNS, __IgnoreEls, _els, Xdata,
 +                          Items,
 +                          decode_search_instructions(<<"jabber:iq:search">>,
 +                                                     __IgnoreEls, _el),
 +                          Last, First, Nick, Email);
 +      _ ->
 +        decode_search_els(__TopXMLNS, __IgnoreEls, _els, Xdata,
 +                          Items, Instructions, Last, First, Nick, Email)
 +    end;
 +decode_search_els(__TopXMLNS, __IgnoreEls,
 +                [{xmlel, <<"first">>, _attrs, _} = _el | _els], Xdata,
 +                Items, Instructions, Last, First, Nick, Email) ->
 +    case get_attr(<<"xmlns">>, _attrs) of
 +      <<"">> when __TopXMLNS == <<"jabber:iq:search">> ->
 +        decode_search_els(__TopXMLNS, __IgnoreEls, _els, Xdata,
 +                          Items, Instructions, Last,
 +                          decode_search_first(__TopXMLNS, __IgnoreEls, _el),
 +                          Nick, Email);
 +      <<"jabber:iq:search">> ->
 +        decode_search_els(__TopXMLNS, __IgnoreEls, _els, Xdata,
 +                          Items, Instructions, Last,
 +                          decode_search_first(<<"jabber:iq:search">>,
 +                                              __IgnoreEls, _el),
 +                          Nick, Email);
 +      _ ->
 +        decode_search_els(__TopXMLNS, __IgnoreEls, _els, Xdata,
 +                          Items, Instructions, Last, First, Nick, Email)
 +    end;
 +decode_search_els(__TopXMLNS, __IgnoreEls,
 +                [{xmlel, <<"last">>, _attrs, _} = _el | _els], Xdata,
 +                Items, Instructions, Last, First, Nick, Email) ->
 +    case get_attr(<<"xmlns">>, _attrs) of
 +      <<"">> when __TopXMLNS == <<"jabber:iq:search">> ->
 +        decode_search_els(__TopXMLNS, __IgnoreEls, _els, Xdata,
 +                          Items, Instructions,
 +                          decode_search_last(__TopXMLNS, __IgnoreEls, _el),
 +                          First, Nick, Email);
 +      <<"jabber:iq:search">> ->
 +        decode_search_els(__TopXMLNS, __IgnoreEls, _els, Xdata,
 +                          Items, Instructions,
 +                          decode_search_last(<<"jabber:iq:search">>,
 +                                             __IgnoreEls, _el),
 +                          First, Nick, Email);
 +      _ ->
 +        decode_search_els(__TopXMLNS, __IgnoreEls, _els, Xdata,
 +                          Items, Instructions, Last, First, Nick, Email)
 +    end;
 +decode_search_els(__TopXMLNS, __IgnoreEls,
 +                [{xmlel, <<"nick">>, _attrs, _} = _el | _els], Xdata,
 +                Items, Instructions, Last, First, Nick, Email) ->
 +    case get_attr(<<"xmlns">>, _attrs) of
 +      <<"">> when __TopXMLNS == <<"jabber:iq:search">> ->
 +        decode_search_els(__TopXMLNS, __IgnoreEls, _els, Xdata,
 +                          Items, Instructions, Last, First,
 +                          decode_search_nick(__TopXMLNS, __IgnoreEls, _el),
 +                          Email);
 +      <<"jabber:iq:search">> ->
 +        decode_search_els(__TopXMLNS, __IgnoreEls, _els, Xdata,
 +                          Items, Instructions, Last, First,
 +                          decode_search_nick(<<"jabber:iq:search">>,
 +                                             __IgnoreEls, _el),
 +                          Email);
 +      _ ->
 +        decode_search_els(__TopXMLNS, __IgnoreEls, _els, Xdata,
 +                          Items, Instructions, Last, First, Nick, Email)
 +    end;
 +decode_search_els(__TopXMLNS, __IgnoreEls,
 +                [{xmlel, <<"email">>, _attrs, _} = _el | _els], Xdata,
 +                Items, Instructions, Last, First, Nick, Email) ->
 +    case get_attr(<<"xmlns">>, _attrs) of
 +      <<"">> when __TopXMLNS == <<"jabber:iq:search">> ->
 +        decode_search_els(__TopXMLNS, __IgnoreEls, _els, Xdata,
 +                          Items, Instructions, Last, First, Nick,
 +                          decode_search_email(__TopXMLNS, __IgnoreEls, _el));
 +      <<"jabber:iq:search">> ->
 +        decode_search_els(__TopXMLNS, __IgnoreEls, _els, Xdata,
 +                          Items, Instructions, Last, First, Nick,
 +                          decode_search_email(<<"jabber:iq:search">>,
 +                                              __IgnoreEls, _el));
 +      _ ->
 +        decode_search_els(__TopXMLNS, __IgnoreEls, _els, Xdata,
 +                          Items, Instructions, Last, First, Nick, Email)
 +    end;
 +decode_search_els(__TopXMLNS, __IgnoreEls,
 +                [{xmlel, <<"item">>, _attrs, _} = _el | _els], Xdata,
 +                Items, Instructions, Last, First, Nick, Email) ->
 +    case get_attr(<<"xmlns">>, _attrs) of
 +      <<"">> when __TopXMLNS == <<"jabber:iq:search">> ->
 +        decode_search_els(__TopXMLNS, __IgnoreEls, _els, Xdata,
 +                          [decode_search_item(__TopXMLNS, __IgnoreEls, _el)
 +                           | Items],
 +                          Instructions, Last, First, Nick, Email);
 +      <<"jabber:iq:search">> ->
 +        decode_search_els(__TopXMLNS, __IgnoreEls, _els, Xdata,
 +                          [decode_search_item(<<"jabber:iq:search">>,
 +                                              __IgnoreEls, _el)
 +                           | Items],
 +                          Instructions, Last, First, Nick, Email);
 +      _ ->
 +        decode_search_els(__TopXMLNS, __IgnoreEls, _els, Xdata,
 +                          Items, Instructions, Last, First, Nick, Email)
 +    end;
 +decode_search_els(__TopXMLNS, __IgnoreEls,
 +                [{xmlel, <<"x">>, _attrs, _} = _el | _els], Xdata,
 +                Items, Instructions, Last, First, Nick, Email) ->
 +    case get_attr(<<"xmlns">>, _attrs) of
 +      <<"jabber:x:data">> ->
 +        decode_search_els(__TopXMLNS, __IgnoreEls, _els,
 +                          decode_xdata(<<"jabber:x:data">>, __IgnoreEls, _el),
 +                          Items, Instructions, Last, First, Nick, Email);
 +      _ ->
 +        decode_search_els(__TopXMLNS, __IgnoreEls, _els, Xdata,
 +                          Items, Instructions, Last, First, Nick, Email)
 +    end;
 +decode_search_els(__TopXMLNS, __IgnoreEls, [_ | _els],
 +                Xdata, Items, Instructions, Last, First, Nick, Email) ->
 +    decode_search_els(__TopXMLNS, __IgnoreEls, _els, Xdata,
 +                    Items, Instructions, Last, First, Nick, Email).
 +
 +encode_search({search, Instructions, First, Last, Nick,
 +             Email, Items, Xdata},
 +            __TopXMLNS) ->
 +    __NewTopXMLNS = choose_top_xmlns(<<"jabber:iq:search">>,
 +                                   [], __TopXMLNS),
 +    _els = lists:reverse('encode_search_$xdata'(Xdata,
 +                                              __NewTopXMLNS,
 +                                              'encode_search_$items'(Items,
 +                                                                     __NewTopXMLNS,
 +                                                                     'encode_search_$instructions'(Instructions,
 +                                                                                                   __NewTopXMLNS,
 +                                                                                                   'encode_search_$last'(Last,
 +                                                                                                                         __NewTopXMLNS,
 +                                                                                                                         'encode_search_$first'(First,
 +                                                                                                                                                __NewTopXMLNS,
 +                                                                                                                                                'encode_search_$nick'(Nick,
 +                                                                                                                                                                      __NewTopXMLNS,
 +                                                                                                                                                                      'encode_search_$email'(Email,
 +                                                                                                                                                                                             __NewTopXMLNS,
 +                                                                                                                                                                                             [])))))))),
 +    _attrs = enc_xmlns_attrs(__NewTopXMLNS, __TopXMLNS),
 +    {xmlel, <<"query">>, _attrs, _els}.
 +
 +'encode_search_$xdata'(undefined, __TopXMLNS, _acc) ->
 +    _acc;
 +'encode_search_$xdata'(Xdata, __TopXMLNS, _acc) ->
 +    [encode_xdata(Xdata, __TopXMLNS) | _acc].
 +
 +'encode_search_$items'([], __TopXMLNS, _acc) -> _acc;
 +'encode_search_$items'([Items | _els], __TopXMLNS,
 +                     _acc) ->
 +    'encode_search_$items'(_els, __TopXMLNS,
 +                         [encode_search_item(Items, __TopXMLNS) | _acc]).
 +
 +'encode_search_$instructions'(undefined, __TopXMLNS,
 +                            _acc) ->
 +    _acc;
 +'encode_search_$instructions'(Instructions, __TopXMLNS,
 +                            _acc) ->
 +    [encode_search_instructions(Instructions, __TopXMLNS)
 +     | _acc].
 +
 +'encode_search_$last'(undefined, __TopXMLNS, _acc) ->
 +    _acc;
 +'encode_search_$last'(Last, __TopXMLNS, _acc) ->
 +    [encode_search_last(Last, __TopXMLNS) | _acc].
 +
 +'encode_search_$first'(undefined, __TopXMLNS, _acc) ->
 +    _acc;
 +'encode_search_$first'(First, __TopXMLNS, _acc) ->
 +    [encode_search_first(First, __TopXMLNS) | _acc].
 +
 +'encode_search_$nick'(undefined, __TopXMLNS, _acc) ->
 +    _acc;
 +'encode_search_$nick'(Nick, __TopXMLNS, _acc) ->
 +    [encode_search_nick(Nick, __TopXMLNS) | _acc].
 +
 +'encode_search_$email'(undefined, __TopXMLNS, _acc) ->
 +    _acc;
 +'encode_search_$email'(Email, __TopXMLNS, _acc) ->
 +    [encode_search_email(Email, __TopXMLNS) | _acc].
 +
 +decode_search_item(__TopXMLNS, __IgnoreEls,
 +                 {xmlel, <<"item">>, _attrs, _els}) ->
 +    {Last, First, Nick, Email} =
 +      decode_search_item_els(__TopXMLNS, __IgnoreEls, _els,
 +                             undefined, undefined, undefined, undefined),
 +    Jid = decode_search_item_attrs(__TopXMLNS, _attrs,
 +                                 undefined),
 +    {search_item, Jid, First, Last, Nick, Email}.
 +
 +decode_search_item_els(__TopXMLNS, __IgnoreEls, [],
 +                     Last, First, Nick, Email) ->
 +    {Last, First, Nick, Email};
 +decode_search_item_els(__TopXMLNS, __IgnoreEls,
 +                     [{xmlel, <<"first">>, _attrs, _} = _el | _els], Last,
 +                     First, Nick, Email) ->
 +    case get_attr(<<"xmlns">>, _attrs) of
 +      <<"">> when __TopXMLNS == <<"jabber:iq:search">> ->
 +        decode_search_item_els(__TopXMLNS, __IgnoreEls, _els,
 +                               Last,
 +                               decode_search_first(__TopXMLNS, __IgnoreEls,
 +                                                   _el),
 +                               Nick, Email);
 +      <<"jabber:iq:search">> ->
 +        decode_search_item_els(__TopXMLNS, __IgnoreEls, _els,
 +                               Last,
 +                               decode_search_first(<<"jabber:iq:search">>,
 +                                                   __IgnoreEls, _el),
 +                               Nick, Email);
 +      _ ->
 +        decode_search_item_els(__TopXMLNS, __IgnoreEls, _els,
 +                               Last, First, Nick, Email)
 +    end;
 +decode_search_item_els(__TopXMLNS, __IgnoreEls,
 +                     [{xmlel, <<"last">>, _attrs, _} = _el | _els], Last,
 +                     First, Nick, Email) ->
 +    case get_attr(<<"xmlns">>, _attrs) of
 +      <<"">> when __TopXMLNS == <<"jabber:iq:search">> ->
 +        decode_search_item_els(__TopXMLNS, __IgnoreEls, _els,
 +                               decode_search_last(__TopXMLNS, __IgnoreEls,
 +                                                  _el),
 +                               First, Nick, Email);
 +      <<"jabber:iq:search">> ->
 +        decode_search_item_els(__TopXMLNS, __IgnoreEls, _els,
 +                               decode_search_last(<<"jabber:iq:search">>,
 +                                                  __IgnoreEls, _el),
 +                               First, Nick, Email);
 +      _ ->
 +        decode_search_item_els(__TopXMLNS, __IgnoreEls, _els,
 +                               Last, First, Nick, Email)
 +    end;
 +decode_search_item_els(__TopXMLNS, __IgnoreEls,
 +                     [{xmlel, <<"nick">>, _attrs, _} = _el | _els], Last,
 +                     First, Nick, Email) ->
 +    case get_attr(<<"xmlns">>, _attrs) of
 +      <<"">> when __TopXMLNS == <<"jabber:iq:search">> ->
 +        decode_search_item_els(__TopXMLNS, __IgnoreEls, _els,
 +                               Last, First,
 +                               decode_search_nick(__TopXMLNS, __IgnoreEls,
 +                                                  _el),
 +                               Email);
 +      <<"jabber:iq:search">> ->
 +        decode_search_item_els(__TopXMLNS, __IgnoreEls, _els,
 +                               Last, First,
 +                               decode_search_nick(<<"jabber:iq:search">>,
 +                                                  __IgnoreEls, _el),
 +                               Email);
 +      _ ->
 +        decode_search_item_els(__TopXMLNS, __IgnoreEls, _els,
 +                               Last, First, Nick, Email)
 +    end;
 +decode_search_item_els(__TopXMLNS, __IgnoreEls,
 +                     [{xmlel, <<"email">>, _attrs, _} = _el | _els], Last,
 +                     First, Nick, Email) ->
 +    case get_attr(<<"xmlns">>, _attrs) of
 +      <<"">> when __TopXMLNS == <<"jabber:iq:search">> ->
 +        decode_search_item_els(__TopXMLNS, __IgnoreEls, _els,
 +                               Last, First, Nick,
 +                               decode_search_email(__TopXMLNS, __IgnoreEls,
 +                                                   _el));
 +      <<"jabber:iq:search">> ->
 +        decode_search_item_els(__TopXMLNS, __IgnoreEls, _els,
 +                               Last, First, Nick,
 +                               decode_search_email(<<"jabber:iq:search">>,
 +                                                   __IgnoreEls, _el));
 +      _ ->
 +        decode_search_item_els(__TopXMLNS, __IgnoreEls, _els,
 +                               Last, First, Nick, Email)
 +    end;
 +decode_search_item_els(__TopXMLNS, __IgnoreEls,
 +                     [_ | _els], Last, First, Nick, Email) ->
 +    decode_search_item_els(__TopXMLNS, __IgnoreEls, _els,
 +                         Last, First, Nick, Email).
 +
 +decode_search_item_attrs(__TopXMLNS,
 +                       [{<<"jid">>, _val} | _attrs], _Jid) ->
 +    decode_search_item_attrs(__TopXMLNS, _attrs, _val);
 +decode_search_item_attrs(__TopXMLNS, [_ | _attrs],
 +                       Jid) ->
 +    decode_search_item_attrs(__TopXMLNS, _attrs, Jid);
 +decode_search_item_attrs(__TopXMLNS, [], Jid) ->
 +    decode_search_item_attr_jid(__TopXMLNS, Jid).
 +
 +encode_search_item({search_item, Jid, First, Last, Nick,
 +                  Email},
 +                 __TopXMLNS) ->
 +    __NewTopXMLNS = choose_top_xmlns(<<"jabber:iq:search">>,
 +                                   [], __TopXMLNS),
 +    _els = lists:reverse('encode_search_item_$last'(Last,
 +                                                  __NewTopXMLNS,
 +                                                  'encode_search_item_$first'(First,
 +                                                                              __NewTopXMLNS,
 +                                                                              'encode_search_item_$nick'(Nick,
 +                                                                                                         __NewTopXMLNS,
 +                                                                                                         'encode_search_item_$email'(Email,
 +                                                                                                                                     __NewTopXMLNS,
 +                                                                                                                                     []))))),
 +    _attrs = encode_search_item_attr_jid(Jid,
 +                                       enc_xmlns_attrs(__NewTopXMLNS,
 +                                                       __TopXMLNS)),
 +    {xmlel, <<"item">>, _attrs, _els}.
 +
 +'encode_search_item_$last'(undefined, __TopXMLNS,
 +                         _acc) ->
 +    _acc;
 +'encode_search_item_$last'(Last, __TopXMLNS, _acc) ->
 +    [encode_search_last(Last, __TopXMLNS) | _acc].
 +
 +'encode_search_item_$first'(undefined, __TopXMLNS,
 +                          _acc) ->
 +    _acc;
 +'encode_search_item_$first'(First, __TopXMLNS, _acc) ->
 +    [encode_search_first(First, __TopXMLNS) | _acc].
 +
 +'encode_search_item_$nick'(undefined, __TopXMLNS,
 +                         _acc) ->
 +    _acc;
 +'encode_search_item_$nick'(Nick, __TopXMLNS, _acc) ->
 +    [encode_search_nick(Nick, __TopXMLNS) | _acc].
 +
 +'encode_search_item_$email'(undefined, __TopXMLNS,
 +                          _acc) ->
 +    _acc;
 +'encode_search_item_$email'(Email, __TopXMLNS, _acc) ->
 +    [encode_search_email(Email, __TopXMLNS) | _acc].
 +
 +decode_search_item_attr_jid(__TopXMLNS, undefined) ->
 +    erlang:error({xmpp_codec,
 +                {missing_attr, <<"jid">>, <<"item">>, __TopXMLNS}});
 +decode_search_item_attr_jid(__TopXMLNS, _val) ->
 +    case catch dec_jid(_val) of
 +      {'EXIT', _} ->
 +        erlang:error({xmpp_codec,
 +                      {bad_attr_value, <<"jid">>, <<"item">>, __TopXMLNS}});
 +      _res -> _res
 +    end.
 +
 +encode_search_item_attr_jid(_val, _acc) ->
 +    [{<<"jid">>, enc_jid(_val)} | _acc].
 +
 +decode_search_email(__TopXMLNS, __IgnoreEls,
 +                  {xmlel, <<"email">>, _attrs, _els}) ->
 +    Cdata = decode_search_email_els(__TopXMLNS, __IgnoreEls,
 +                                  _els, <<>>),
 +    Cdata.
 +
 +decode_search_email_els(__TopXMLNS, __IgnoreEls, [],
 +                      Cdata) ->
 +    decode_search_email_cdata(__TopXMLNS, Cdata);
 +decode_search_email_els(__TopXMLNS, __IgnoreEls,
 +                      [{xmlcdata, _data} | _els], Cdata) ->
 +    decode_search_email_els(__TopXMLNS, __IgnoreEls, _els,
 +                          <<Cdata/binary, _data/binary>>);
 +decode_search_email_els(__TopXMLNS, __IgnoreEls,
 +                      [_ | _els], Cdata) ->
 +    decode_search_email_els(__TopXMLNS, __IgnoreEls, _els,
 +                          Cdata).
 +
 +encode_search_email(Cdata, __TopXMLNS) ->
 +    __NewTopXMLNS = choose_top_xmlns(<<"jabber:iq:search">>,
 +                                   [], __TopXMLNS),
 +    _els = encode_search_email_cdata(Cdata, []),
 +    _attrs = enc_xmlns_attrs(__NewTopXMLNS, __TopXMLNS),
 +    {xmlel, <<"email">>, _attrs, _els}.
 +
 +decode_search_email_cdata(__TopXMLNS, <<>>) -> <<>>;
 +decode_search_email_cdata(__TopXMLNS, _val) -> _val.
 +
 +encode_search_email_cdata(<<>>, _acc) -> _acc;
 +encode_search_email_cdata(_val, _acc) ->
 +    [{xmlcdata, _val} | _acc].
 +
 +decode_search_nick(__TopXMLNS, __IgnoreEls,
 +                 {xmlel, <<"nick">>, _attrs, _els}) ->
 +    Cdata = decode_search_nick_els(__TopXMLNS, __IgnoreEls,
 +                                 _els, <<>>),
 +    Cdata.
 +
 +decode_search_nick_els(__TopXMLNS, __IgnoreEls, [],
 +                     Cdata) ->
 +    decode_search_nick_cdata(__TopXMLNS, Cdata);
 +decode_search_nick_els(__TopXMLNS, __IgnoreEls,
 +                     [{xmlcdata, _data} | _els], Cdata) ->
 +    decode_search_nick_els(__TopXMLNS, __IgnoreEls, _els,
 +                         <<Cdata/binary, _data/binary>>);
 +decode_search_nick_els(__TopXMLNS, __IgnoreEls,
 +                     [_ | _els], Cdata) ->
 +    decode_search_nick_els(__TopXMLNS, __IgnoreEls, _els,
 +                         Cdata).
 +
 +encode_search_nick(Cdata, __TopXMLNS) ->
 +    __NewTopXMLNS = choose_top_xmlns(<<"jabber:iq:search">>,
 +                                   [], __TopXMLNS),
 +    _els = encode_search_nick_cdata(Cdata, []),
 +    _attrs = enc_xmlns_attrs(__NewTopXMLNS, __TopXMLNS),
 +    {xmlel, <<"nick">>, _attrs, _els}.
 +
 +decode_search_nick_cdata(__TopXMLNS, <<>>) -> <<>>;
 +decode_search_nick_cdata(__TopXMLNS, _val) -> _val.
 +
 +encode_search_nick_cdata(<<>>, _acc) -> _acc;
 +encode_search_nick_cdata(_val, _acc) ->
 +    [{xmlcdata, _val} | _acc].
 +
 +decode_search_last(__TopXMLNS, __IgnoreEls,
 +                 {xmlel, <<"last">>, _attrs, _els}) ->
 +    Cdata = decode_search_last_els(__TopXMLNS, __IgnoreEls,
 +                                 _els, <<>>),
 +    Cdata.
 +
 +decode_search_last_els(__TopXMLNS, __IgnoreEls, [],
 +                     Cdata) ->
 +    decode_search_last_cdata(__TopXMLNS, Cdata);
 +decode_search_last_els(__TopXMLNS, __IgnoreEls,
 +                     [{xmlcdata, _data} | _els], Cdata) ->
 +    decode_search_last_els(__TopXMLNS, __IgnoreEls, _els,
 +                         <<Cdata/binary, _data/binary>>);
 +decode_search_last_els(__TopXMLNS, __IgnoreEls,
 +                     [_ | _els], Cdata) ->
 +    decode_search_last_els(__TopXMLNS, __IgnoreEls, _els,
 +                         Cdata).
 +
 +encode_search_last(Cdata, __TopXMLNS) ->
 +    __NewTopXMLNS = choose_top_xmlns(<<"jabber:iq:search">>,
 +                                   [], __TopXMLNS),
 +    _els = encode_search_last_cdata(Cdata, []),
 +    _attrs = enc_xmlns_attrs(__NewTopXMLNS, __TopXMLNS),
 +    {xmlel, <<"last">>, _attrs, _els}.
 +
 +decode_search_last_cdata(__TopXMLNS, <<>>) -> <<>>;
 +decode_search_last_cdata(__TopXMLNS, _val) -> _val.
 +
 +encode_search_last_cdata(<<>>, _acc) -> _acc;
 +encode_search_last_cdata(_val, _acc) ->
 +    [{xmlcdata, _val} | _acc].
 +
 +decode_search_first(__TopXMLNS, __IgnoreEls,
 +                  {xmlel, <<"first">>, _attrs, _els}) ->
 +    Cdata = decode_search_first_els(__TopXMLNS, __IgnoreEls,
 +                                  _els, <<>>),
 +    Cdata.
 +
 +decode_search_first_els(__TopXMLNS, __IgnoreEls, [],
 +                      Cdata) ->
 +    decode_search_first_cdata(__TopXMLNS, Cdata);
 +decode_search_first_els(__TopXMLNS, __IgnoreEls,
 +                      [{xmlcdata, _data} | _els], Cdata) ->
 +    decode_search_first_els(__TopXMLNS, __IgnoreEls, _els,
 +                          <<Cdata/binary, _data/binary>>);
 +decode_search_first_els(__TopXMLNS, __IgnoreEls,
 +                      [_ | _els], Cdata) ->
 +    decode_search_first_els(__TopXMLNS, __IgnoreEls, _els,
 +                          Cdata).
 +
 +encode_search_first(Cdata, __TopXMLNS) ->
 +    __NewTopXMLNS = choose_top_xmlns(<<"jabber:iq:search">>,
 +                                   [], __TopXMLNS),
 +    _els = encode_search_first_cdata(Cdata, []),
 +    _attrs = enc_xmlns_attrs(__NewTopXMLNS, __TopXMLNS),
 +    {xmlel, <<"first">>, _attrs, _els}.
 +
 +decode_search_first_cdata(__TopXMLNS, <<>>) -> <<>>;
 +decode_search_first_cdata(__TopXMLNS, _val) -> _val.
 +
 +encode_search_first_cdata(<<>>, _acc) -> _acc;
 +encode_search_first_cdata(_val, _acc) ->
 +    [{xmlcdata, _val} | _acc].
 +
 +decode_search_instructions(__TopXMLNS, __IgnoreEls,
 +                         {xmlel, <<"instructions">>, _attrs, _els}) ->
 +    Cdata = decode_search_instructions_els(__TopXMLNS,
 +                                         __IgnoreEls, _els, <<>>),
 +    Cdata.
 +
 +decode_search_instructions_els(__TopXMLNS, __IgnoreEls,
 +                             [], Cdata) ->
 +    decode_search_instructions_cdata(__TopXMLNS, Cdata);
 +decode_search_instructions_els(__TopXMLNS, __IgnoreEls,
 +                             [{xmlcdata, _data} | _els], Cdata) ->
 +    decode_search_instructions_els(__TopXMLNS, __IgnoreEls,
 +                                 _els, <<Cdata/binary, _data/binary>>);
 +decode_search_instructions_els(__TopXMLNS, __IgnoreEls,
 +                             [_ | _els], Cdata) ->
 +    decode_search_instructions_els(__TopXMLNS, __IgnoreEls,
 +                                 _els, Cdata).
 +
 +encode_search_instructions(Cdata, __TopXMLNS) ->
 +    __NewTopXMLNS = choose_top_xmlns(<<"jabber:iq:search">>,
 +                                   [], __TopXMLNS),
 +    _els = encode_search_instructions_cdata(Cdata, []),
 +    _attrs = enc_xmlns_attrs(__NewTopXMLNS, __TopXMLNS),
 +    {xmlel, <<"instructions">>, _attrs, _els}.
 +
 +decode_search_instructions_cdata(__TopXMLNS, <<>>) ->
 +    <<>>;
 +decode_search_instructions_cdata(__TopXMLNS, _val) ->
 +    _val.
 +
 +encode_search_instructions_cdata(<<>>, _acc) -> _acc;
 +encode_search_instructions_cdata(_val, _acc) ->
 +    [{xmlcdata, _val} | _acc].
 +
 +decode_hint_no_permanent_storage(__TopXMLNS,
 +                               __IgnoreEls,
 +                               {xmlel, <<"no-permanent-storage">>, _attrs,
 +                                _els}) ->
 +    {hint, 'no-permanent-storage'}.
 +
 +encode_hint_no_permanent_storage({hint,
 +                                'no-permanent-storage'},
 +                               __TopXMLNS) ->
 +    __NewTopXMLNS = choose_top_xmlns(<<"urn:xmpp:hints">>,
 +                                   [], __TopXMLNS),
 +    _els = [],
 +    _attrs = enc_xmlns_attrs(__NewTopXMLNS, __TopXMLNS),
 +    {xmlel, <<"no-permanent-storage">>, _attrs, _els}.
 +
 +decode_hint_no_permanent_store(__TopXMLNS, __IgnoreEls,
 +                             {xmlel, <<"no-permanent-store">>, _attrs,
 +                              _els}) ->
 +    {hint, 'no-permanent-store'}.
 +
 +encode_hint_no_permanent_store({hint,
 +                              'no-permanent-store'},
 +                             __TopXMLNS) ->
 +    __NewTopXMLNS = choose_top_xmlns(<<"urn:xmpp:hints">>,
 +                                   [], __TopXMLNS),
 +    _els = [],
 +    _attrs = enc_xmlns_attrs(__NewTopXMLNS, __TopXMLNS),
 +    {xmlel, <<"no-permanent-store">>, _attrs, _els}.
 +
 +decode_hint_store(__TopXMLNS, __IgnoreEls,
 +                {xmlel, <<"store">>, _attrs, _els}) ->
 +    {hint, store}.
 +
 +encode_hint_store({hint, store}, __TopXMLNS) ->
 +    __NewTopXMLNS = choose_top_xmlns(<<"urn:xmpp:hints">>,
 +                                   [], __TopXMLNS),
 +    _els = [],
 +    _attrs = enc_xmlns_attrs(__NewTopXMLNS, __TopXMLNS),
 +    {xmlel, <<"store">>, _attrs, _els}.
 +
 +decode_hint_no_storage(__TopXMLNS, __IgnoreEls,
 +                     {xmlel, <<"no-storage">>, _attrs, _els}) ->
 +    {hint, 'no-storage'}.
 +
 +encode_hint_no_storage({hint, 'no-storage'},
 +                     __TopXMLNS) ->
 +    __NewTopXMLNS = choose_top_xmlns(<<"urn:xmpp:hints">>,
 +                                   [], __TopXMLNS),
 +    _els = [],
 +    _attrs = enc_xmlns_attrs(__NewTopXMLNS, __TopXMLNS),
 +    {xmlel, <<"no-storage">>, _attrs, _els}.
 +
 +decode_hint_no_store(__TopXMLNS, __IgnoreEls,
 +                   {xmlel, <<"no-store">>, _attrs, _els}) ->
 +    {hint, 'no-store'}.
 +
 +encode_hint_no_store({hint, 'no-store'}, __TopXMLNS) ->
 +    __NewTopXMLNS = choose_top_xmlns(<<"urn:xmpp:hints">>,
 +                                   [], __TopXMLNS),
 +    _els = [],
 +    _attrs = enc_xmlns_attrs(__NewTopXMLNS, __TopXMLNS),
 +    {xmlel, <<"no-store">>, _attrs, _els}.
 +
 +decode_hint_no_copy(__TopXMLNS, __IgnoreEls,
 +                  {xmlel, <<"no-copy">>, _attrs, _els}) ->
 +    {hint, 'no-copy'}.
 +
 +encode_hint_no_copy({hint, 'no-copy'}, __TopXMLNS) ->
 +    __NewTopXMLNS = choose_top_xmlns(<<"urn:xmpp:hints">>,
 +                                   [], __TopXMLNS),
 +    _els = [],
 +    _attrs = enc_xmlns_attrs(__NewTopXMLNS, __TopXMLNS),
 +    {xmlel, <<"no-copy">>, _attrs, _els}.
 +
 +decode_mix_participant(__TopXMLNS, __IgnoreEls,
 +                     {xmlel, <<"participant">>, _attrs, _els}) ->
 +    {Jid, Nick} = decode_mix_participant_attrs(__TopXMLNS,
 +                                             _attrs, undefined, undefined),
 +    {mix_participant, Jid, Nick}.
 +
 +decode_mix_participant_attrs(__TopXMLNS,
 +                           [{<<"jid">>, _val} | _attrs], _Jid, Nick) ->
 +    decode_mix_participant_attrs(__TopXMLNS, _attrs, _val,
 +                               Nick);
 +decode_mix_participant_attrs(__TopXMLNS,
 +                           [{<<"nick">>, _val} | _attrs], Jid, _Nick) ->
 +    decode_mix_participant_attrs(__TopXMLNS, _attrs, Jid,
 +                               _val);
 +decode_mix_participant_attrs(__TopXMLNS, [_ | _attrs],
 +                           Jid, Nick) ->
 +    decode_mix_participant_attrs(__TopXMLNS, _attrs, Jid,
 +                               Nick);
 +decode_mix_participant_attrs(__TopXMLNS, [], Jid,
 +                           Nick) ->
 +    {decode_mix_participant_attr_jid(__TopXMLNS, Jid),
 +     decode_mix_participant_attr_nick(__TopXMLNS, Nick)}.
 +
 +encode_mix_participant({mix_participant, Jid, Nick},
 +                     __TopXMLNS) ->
 +    __NewTopXMLNS = choose_top_xmlns(<<"urn:xmpp:mix:0">>,
 +                                   [], __TopXMLNS),
 +    _els = [],
 +    _attrs = encode_mix_participant_attr_nick(Nick,
 +                                            encode_mix_participant_attr_jid(Jid,
 +                                                                            enc_xmlns_attrs(__NewTopXMLNS,
 +                                                                                            __TopXMLNS))),
 +    {xmlel, <<"participant">>, _attrs, _els}.
 +
 +decode_mix_participant_attr_jid(__TopXMLNS,
 +                              undefined) ->
 +    erlang:error({xmpp_codec,
 +                {missing_attr, <<"jid">>, <<"participant">>,
 +                 __TopXMLNS}});
 +decode_mix_participant_attr_jid(__TopXMLNS, _val) ->
 +    case catch dec_jid(_val) of
 +      {'EXIT', _} ->
 +        erlang:error({xmpp_codec,
 +                      {bad_attr_value, <<"jid">>, <<"participant">>,
 +                       __TopXMLNS}});
 +      _res -> _res
 +    end.
 +
 +encode_mix_participant_attr_jid(_val, _acc) ->
 +    [{<<"jid">>, enc_jid(_val)} | _acc].
 +
 +decode_mix_participant_attr_nick(__TopXMLNS,
 +                               undefined) ->
 +    <<>>;
 +decode_mix_participant_attr_nick(__TopXMLNS, _val) ->
 +    _val.
 +
 +encode_mix_participant_attr_nick(<<>>, _acc) -> _acc;
 +encode_mix_participant_attr_nick(_val, _acc) ->
 +    [{<<"nick">>, _val} | _acc].
 +
 +decode_mix_leave(__TopXMLNS, __IgnoreEls,
 +               {xmlel, <<"leave">>, _attrs, _els}) ->
 +    {mix_leave}.
 +
 +encode_mix_leave({mix_leave}, __TopXMLNS) ->
 +    __NewTopXMLNS = choose_top_xmlns(<<"urn:xmpp:mix:0">>,
 +                                   [], __TopXMLNS),
 +    _els = [],
 +    _attrs = enc_xmlns_attrs(__NewTopXMLNS, __TopXMLNS),
 +    {xmlel, <<"leave">>, _attrs, _els}.
 +
 +decode_mix_join(__TopXMLNS, __IgnoreEls,
 +              {xmlel, <<"join">>, _attrs, _els}) ->
 +    Subscribe = decode_mix_join_els(__TopXMLNS, __IgnoreEls,
 +                                  _els, []),
 +    Jid = decode_mix_join_attrs(__TopXMLNS, _attrs,
 +                              undefined),
 +    {mix_join, Jid, Subscribe}.
 +
 +decode_mix_join_els(__TopXMLNS, __IgnoreEls, [],
 +                  Subscribe) ->
 +    lists:reverse(Subscribe);
 +decode_mix_join_els(__TopXMLNS, __IgnoreEls,
 +                  [{xmlel, <<"subscribe">>, _attrs, _} = _el | _els],
 +                  Subscribe) ->
 +    case get_attr(<<"xmlns">>, _attrs) of
 +      <<"">> when __TopXMLNS == <<"urn:xmpp:mix:0">> ->
 +        decode_mix_join_els(__TopXMLNS, __IgnoreEls, _els,
 +                            [decode_mix_subscribe(__TopXMLNS, __IgnoreEls,
 +                                                  _el)
 +                             | Subscribe]);
 +      <<"urn:xmpp:mix:0">> ->
 +        decode_mix_join_els(__TopXMLNS, __IgnoreEls, _els,
 +                            [decode_mix_subscribe(<<"urn:xmpp:mix:0">>,
 +                                                  __IgnoreEls, _el)
 +                             | Subscribe]);
 +      _ ->
 +        decode_mix_join_els(__TopXMLNS, __IgnoreEls, _els,
 +                            Subscribe)
 +    end;
 +decode_mix_join_els(__TopXMLNS, __IgnoreEls, [_ | _els],
 +                  Subscribe) ->
 +    decode_mix_join_els(__TopXMLNS, __IgnoreEls, _els,
 +                      Subscribe).
 +
 +decode_mix_join_attrs(__TopXMLNS,
 +                    [{<<"jid">>, _val} | _attrs], _Jid) ->
 +    decode_mix_join_attrs(__TopXMLNS, _attrs, _val);
 +decode_mix_join_attrs(__TopXMLNS, [_ | _attrs], Jid) ->
 +    decode_mix_join_attrs(__TopXMLNS, _attrs, Jid);
 +decode_mix_join_attrs(__TopXMLNS, [], Jid) ->
 +    decode_mix_join_attr_jid(__TopXMLNS, Jid).
 +
 +encode_mix_join({mix_join, Jid, Subscribe},
 +              __TopXMLNS) ->
 +    __NewTopXMLNS = choose_top_xmlns(<<"urn:xmpp:mix:0">>,
 +                                   [], __TopXMLNS),
 +    _els =
 +      lists:reverse('encode_mix_join_$subscribe'(Subscribe,
 +                                                 __NewTopXMLNS, [])),
 +    _attrs = encode_mix_join_attr_jid(Jid,
 +                                    enc_xmlns_attrs(__NewTopXMLNS,
 +                                                    __TopXMLNS)),
 +    {xmlel, <<"join">>, _attrs, _els}.
 +
 +'encode_mix_join_$subscribe'([], __TopXMLNS, _acc) ->
 +    _acc;
 +'encode_mix_join_$subscribe'([Subscribe | _els],
 +                           __TopXMLNS, _acc) ->
 +    'encode_mix_join_$subscribe'(_els, __TopXMLNS,
 +                               [encode_mix_subscribe(Subscribe, __TopXMLNS)
 +                                | _acc]).
 +
 +decode_mix_join_attr_jid(__TopXMLNS, undefined) ->
 +    undefined;
 +decode_mix_join_attr_jid(__TopXMLNS, _val) ->
 +    case catch dec_jid(_val) of
 +      {'EXIT', _} ->
 +        erlang:error({xmpp_codec,
 +                      {bad_attr_value, <<"jid">>, <<"join">>, __TopXMLNS}});
 +      _res -> _res
 +    end.
 +
 +encode_mix_join_attr_jid(undefined, _acc) -> _acc;
 +encode_mix_join_attr_jid(_val, _acc) ->
 +    [{<<"jid">>, enc_jid(_val)} | _acc].
 +
 +decode_mix_subscribe(__TopXMLNS, __IgnoreEls,
 +                   {xmlel, <<"subscribe">>, _attrs, _els}) ->
 +    Node = decode_mix_subscribe_attrs(__TopXMLNS, _attrs,
 +                                    undefined),
 +    Node.
 +
 +decode_mix_subscribe_attrs(__TopXMLNS,
 +                         [{<<"node">>, _val} | _attrs], _Node) ->
 +    decode_mix_subscribe_attrs(__TopXMLNS, _attrs, _val);
 +decode_mix_subscribe_attrs(__TopXMLNS, [_ | _attrs],
 +                         Node) ->
 +    decode_mix_subscribe_attrs(__TopXMLNS, _attrs, Node);
 +decode_mix_subscribe_attrs(__TopXMLNS, [], Node) ->
 +    decode_mix_subscribe_attr_node(__TopXMLNS, Node).
 +
 +encode_mix_subscribe(Node, __TopXMLNS) ->
 +    __NewTopXMLNS = choose_top_xmlns(<<"urn:xmpp:mix:0">>,
 +                                   [], __TopXMLNS),
 +    _els = [],
 +    _attrs = encode_mix_subscribe_attr_node(Node,
 +                                          enc_xmlns_attrs(__NewTopXMLNS,
 +                                                          __TopXMLNS)),
 +    {xmlel, <<"subscribe">>, _attrs, _els}.
 +
 +decode_mix_subscribe_attr_node(__TopXMLNS, undefined) ->
 +    erlang:error({xmpp_codec,
 +                {missing_attr, <<"node">>, <<"subscribe">>,
 +                 __TopXMLNS}});
 +decode_mix_subscribe_attr_node(__TopXMLNS, _val) ->
 +    _val.
 +
 +encode_mix_subscribe_attr_node(_val, _acc) ->
 +    [{<<"node">>, _val} | _acc].
 +
 +decode_offline(__TopXMLNS, __IgnoreEls,
 +             {xmlel, <<"offline">>, _attrs, _els}) ->
 +    {Items, Purge, Fetch} = decode_offline_els(__TopXMLNS,
 +                                             __IgnoreEls, _els, [], false,
 +                                             false),
 +    {offline, Items, Purge, Fetch}.
 +
 +decode_offline_els(__TopXMLNS, __IgnoreEls, [], Items,
 +                 Purge, Fetch) ->
 +    {lists:reverse(Items), Purge, Fetch};
 +decode_offline_els(__TopXMLNS, __IgnoreEls,
 +                 [{xmlel, <<"purge">>, _attrs, _} = _el | _els], Items,
 +                 Purge, Fetch) ->
 +    case get_attr(<<"xmlns">>, _attrs) of
 +      <<"">>
 +        when __TopXMLNS ==
 +               <<"http://jabber.org/protocol/offline">> ->
 +        decode_offline_els(__TopXMLNS, __IgnoreEls, _els, Items,
 +                           decode_offline_purge(__TopXMLNS, __IgnoreEls, _el),
 +                           Fetch);
 +      <<"http://jabber.org/protocol/offline">> ->
 +        decode_offline_els(__TopXMLNS, __IgnoreEls, _els, Items,
 +                           decode_offline_purge(<<"http://jabber.org/protocol/offline">>,
 +                                                __IgnoreEls, _el),
 +                           Fetch);
 +      _ ->
 +        decode_offline_els(__TopXMLNS, __IgnoreEls, _els, Items,
 +                           Purge, Fetch)
 +    end;
 +decode_offline_els(__TopXMLNS, __IgnoreEls,
 +                 [{xmlel, <<"fetch">>, _attrs, _} = _el | _els], Items,
 +                 Purge, Fetch) ->
 +    case get_attr(<<"xmlns">>, _attrs) of
 +      <<"">>
 +        when __TopXMLNS ==
 +               <<"http://jabber.org/protocol/offline">> ->
 +        decode_offline_els(__TopXMLNS, __IgnoreEls, _els, Items,
 +                           Purge,
 +                           decode_offline_fetch(__TopXMLNS, __IgnoreEls,
 +                                                _el));
 +      <<"http://jabber.org/protocol/offline">> ->
 +        decode_offline_els(__TopXMLNS, __IgnoreEls, _els, Items,
 +                           Purge,
 +                           decode_offline_fetch(<<"http://jabber.org/protocol/offline">>,
 +                                                __IgnoreEls, _el));
 +      _ ->
 +        decode_offline_els(__TopXMLNS, __IgnoreEls, _els, Items,
 +                           Purge, Fetch)
 +    end;
 +decode_offline_els(__TopXMLNS, __IgnoreEls,
 +                 [{xmlel, <<"item">>, _attrs, _} = _el | _els], Items,
 +                 Purge, Fetch) ->
 +    case get_attr(<<"xmlns">>, _attrs) of
 +      <<"">>
 +        when __TopXMLNS ==
 +               <<"http://jabber.org/protocol/offline">> ->
 +        decode_offline_els(__TopXMLNS, __IgnoreEls, _els,
 +                           [decode_offline_item(__TopXMLNS, __IgnoreEls, _el)
 +                            | Items],
 +                           Purge, Fetch);
 +      <<"http://jabber.org/protocol/offline">> ->
 +        decode_offline_els(__TopXMLNS, __IgnoreEls, _els,
 +                           [decode_offline_item(<<"http://jabber.org/protocol/offline">>,
 +                                                __IgnoreEls, _el)
 +                            | Items],
 +                           Purge, Fetch);
 +      _ ->
 +        decode_offline_els(__TopXMLNS, __IgnoreEls, _els, Items,
 +                           Purge, Fetch)
 +    end;
 +decode_offline_els(__TopXMLNS, __IgnoreEls, [_ | _els],
 +                 Items, Purge, Fetch) ->
 +    decode_offline_els(__TopXMLNS, __IgnoreEls, _els, Items,
 +                     Purge, Fetch).
 +
 +encode_offline({offline, Items, Purge, Fetch},
 +             __TopXMLNS) ->
 +    __NewTopXMLNS =
 +      choose_top_xmlns(<<"http://jabber.org/protocol/offline">>,
 +                       [], __TopXMLNS),
 +    _els = lists:reverse('encode_offline_$items'(Items,
 +                                               __NewTopXMLNS,
 +                                               'encode_offline_$purge'(Purge,
 +                                                                       __NewTopXMLNS,
 +                                                                       'encode_offline_$fetch'(Fetch,
 +                                                                                               __NewTopXMLNS,
 +                                                                                               [])))),
 +    _attrs = enc_xmlns_attrs(__NewTopXMLNS, __TopXMLNS),
 +    {xmlel, <<"offline">>, _attrs, _els}.
 +
 +'encode_offline_$items'([], __TopXMLNS, _acc) -> _acc;
 +'encode_offline_$items'([Items | _els], __TopXMLNS,
 +                      _acc) ->
 +    'encode_offline_$items'(_els, __TopXMLNS,
 +                          [encode_offline_item(Items, __TopXMLNS) | _acc]).
 +
 +'encode_offline_$purge'(false, __TopXMLNS, _acc) ->
 +    _acc;
 +'encode_offline_$purge'(Purge, __TopXMLNS, _acc) ->
 +    [encode_offline_purge(Purge, __TopXMLNS) | _acc].
 +
 +'encode_offline_$fetch'(false, __TopXMLNS, _acc) ->
 +    _acc;
 +'encode_offline_$fetch'(Fetch, __TopXMLNS, _acc) ->
 +    [encode_offline_fetch(Fetch, __TopXMLNS) | _acc].
 +
 +decode_offline_item(__TopXMLNS, __IgnoreEls,
 +                  {xmlel, <<"item">>, _attrs, _els}) ->
 +    {Node, Action} = decode_offline_item_attrs(__TopXMLNS,
 +                                             _attrs, undefined, undefined),
 +    {offline_item, Node, Action}.
 +
 +decode_offline_item_attrs(__TopXMLNS,
 +                        [{<<"node">>, _val} | _attrs], _Node, Action) ->
 +    decode_offline_item_attrs(__TopXMLNS, _attrs, _val,
 +                            Action);
 +decode_offline_item_attrs(__TopXMLNS,
 +                        [{<<"action">>, _val} | _attrs], Node, _Action) ->
 +    decode_offline_item_attrs(__TopXMLNS, _attrs, Node,
 +                            _val);
 +decode_offline_item_attrs(__TopXMLNS, [_ | _attrs],
 +                        Node, Action) ->
 +    decode_offline_item_attrs(__TopXMLNS, _attrs, Node,
 +                            Action);
 +decode_offline_item_attrs(__TopXMLNS, [], Node,
 +                        Action) ->
 +    {decode_offline_item_attr_node(__TopXMLNS, Node),
 +     decode_offline_item_attr_action(__TopXMLNS, Action)}.
 +
 +encode_offline_item({offline_item, Node, Action},
 +                  __TopXMLNS) ->
 +    __NewTopXMLNS =
 +      choose_top_xmlns(<<"http://jabber.org/protocol/offline">>,
 +                       [], __TopXMLNS),
 +    _els = [],
 +    _attrs = encode_offline_item_attr_action(Action,
 +                                           encode_offline_item_attr_node(Node,
 +                                                                         enc_xmlns_attrs(__NewTopXMLNS,
 +                                                                                         __TopXMLNS))),
 +    {xmlel, <<"item">>, _attrs, _els}.
 +
 +decode_offline_item_attr_node(__TopXMLNS, undefined) ->
 +    <<>>;
 +decode_offline_item_attr_node(__TopXMLNS, _val) -> _val.
 +
 +encode_offline_item_attr_node(<<>>, _acc) -> _acc;
 +encode_offline_item_attr_node(_val, _acc) ->
 +    [{<<"node">>, _val} | _acc].
 +
 +decode_offline_item_attr_action(__TopXMLNS,
 +                              undefined) ->
 +    undefined;
 +decode_offline_item_attr_action(__TopXMLNS, _val) ->
 +    case catch dec_enum(_val, [view, remove]) of
 +      {'EXIT', _} ->
 +        erlang:error({xmpp_codec,
 +                      {bad_attr_value, <<"action">>, <<"item">>,
 +                       __TopXMLNS}});
 +      _res -> _res
 +    end.
 +
 +encode_offline_item_attr_action(undefined, _acc) ->
 +    _acc;
 +encode_offline_item_attr_action(_val, _acc) ->
 +    [{<<"action">>, enc_enum(_val)} | _acc].
 +
 +decode_offline_fetch(__TopXMLNS, __IgnoreEls,
 +                   {xmlel, <<"fetch">>, _attrs, _els}) ->
 +    true.
 +
 +encode_offline_fetch(true, __TopXMLNS) ->
 +    __NewTopXMLNS =
 +      choose_top_xmlns(<<"http://jabber.org/protocol/offline">>,
 +                       [], __TopXMLNS),
 +    _els = [],
 +    _attrs = enc_xmlns_attrs(__NewTopXMLNS, __TopXMLNS),
 +    {xmlel, <<"fetch">>, _attrs, _els}.
 +
 +decode_offline_purge(__TopXMLNS, __IgnoreEls,
 +                   {xmlel, <<"purge">>, _attrs, _els}) ->
 +    true.
 +
 +encode_offline_purge(true, __TopXMLNS) ->
 +    __NewTopXMLNS =
 +      choose_top_xmlns(<<"http://jabber.org/protocol/offline">>,
 +                       [], __TopXMLNS),
 +    _els = [],
 +    _attrs = enc_xmlns_attrs(__NewTopXMLNS, __TopXMLNS),
 +    {xmlel, <<"purge">>, _attrs, _els}.
 +
 +decode_sm_failed(__TopXMLNS, __IgnoreEls,
 +               {xmlel, <<"failed">>, _attrs, _els}) ->
 +    Reason = decode_sm_failed_els(__TopXMLNS, __IgnoreEls,
 +                                _els, undefined),
 +    {H, Xmlns} = decode_sm_failed_attrs(__TopXMLNS, _attrs,
 +                                      undefined, undefined),
 +    {sm_failed, Reason, H, Xmlns}.
 +
 +decode_sm_failed_els(__TopXMLNS, __IgnoreEls, [],
 +                   Reason) ->
 +    Reason;
 +decode_sm_failed_els(__TopXMLNS, __IgnoreEls,
 +                   [{xmlel, <<"bad-request">>, _attrs, _} = _el | _els],
 +                   Reason) ->
 +    case get_attr(<<"xmlns">>, _attrs) of
 +      <<"urn:ietf:params:xml:ns:xmpp-stanzas">> ->
 +        decode_sm_failed_els(__TopXMLNS, __IgnoreEls, _els,
 +                             decode_error_bad_request(<<"urn:ietf:params:xml:ns:xmpp-stanzas">>,
 +                                                      __IgnoreEls, _el));
 +      _ ->
 +        decode_sm_failed_els(__TopXMLNS, __IgnoreEls, _els,
 +                             Reason)
 +    end;
 +decode_sm_failed_els(__TopXMLNS, __IgnoreEls,
 +                   [{xmlel, <<"conflict">>, _attrs, _} = _el | _els],
 +                   Reason) ->
 +    case get_attr(<<"xmlns">>, _attrs) of
 +      <<"urn:ietf:params:xml:ns:xmpp-stanzas">> ->
 +        decode_sm_failed_els(__TopXMLNS, __IgnoreEls, _els,
 +                             decode_error_conflict(<<"urn:ietf:params:xml:ns:xmpp-stanzas">>,
 +                                                   __IgnoreEls, _el));
 +      _ ->
 +        decode_sm_failed_els(__TopXMLNS, __IgnoreEls, _els,
 +                             Reason)
 +    end;
 +decode_sm_failed_els(__TopXMLNS, __IgnoreEls,
 +                   [{xmlel, <<"feature-not-implemented">>, _attrs, _} = _el
 +                    | _els],
 +                   Reason) ->
 +    case get_attr(<<"xmlns">>, _attrs) of
 +      <<"urn:ietf:params:xml:ns:xmpp-stanzas">> ->
 +        decode_sm_failed_els(__TopXMLNS, __IgnoreEls, _els,
 +                             decode_error_feature_not_implemented(<<"urn:ietf:params:xml:ns:xmpp-stanzas">>,
 +                                                                  __IgnoreEls,
 +                                                                  _el));
 +      _ ->
 +        decode_sm_failed_els(__TopXMLNS, __IgnoreEls, _els,
 +                             Reason)
 +    end;
 +decode_sm_failed_els(__TopXMLNS, __IgnoreEls,
 +                   [{xmlel, <<"forbidden">>, _attrs, _} = _el | _els],
 +                   Reason) ->
 +    case get_attr(<<"xmlns">>, _attrs) of
 +      <<"urn:ietf:params:xml:ns:xmpp-stanzas">> ->
 +        decode_sm_failed_els(__TopXMLNS, __IgnoreEls, _els,
 +                             decode_error_forbidden(<<"urn:ietf:params:xml:ns:xmpp-stanzas">>,
 +                                                    __IgnoreEls, _el));
 +      _ ->
 +        decode_sm_failed_els(__TopXMLNS, __IgnoreEls, _els,
 +                             Reason)
 +    end;
 +decode_sm_failed_els(__TopXMLNS, __IgnoreEls,
 +                   [{xmlel, <<"gone">>, _attrs, _} = _el | _els],
 +                   Reason) ->
 +    case get_attr(<<"xmlns">>, _attrs) of
 +      <<"urn:ietf:params:xml:ns:xmpp-stanzas">> ->
 +        decode_sm_failed_els(__TopXMLNS, __IgnoreEls, _els,
 +                             decode_error_gone(<<"urn:ietf:params:xml:ns:xmpp-stanzas">>,
 +                                               __IgnoreEls, _el));
 +      _ ->
 +        decode_sm_failed_els(__TopXMLNS, __IgnoreEls, _els,
 +                             Reason)
 +    end;
 +decode_sm_failed_els(__TopXMLNS, __IgnoreEls,
 +                   [{xmlel, <<"internal-server-error">>, _attrs, _} = _el
 +                    | _els],
 +                   Reason) ->
 +    case get_attr(<<"xmlns">>, _attrs) of
 +      <<"urn:ietf:params:xml:ns:xmpp-stanzas">> ->
 +        decode_sm_failed_els(__TopXMLNS, __IgnoreEls, _els,
 +                             decode_error_internal_server_error(<<"urn:ietf:params:xml:ns:xmpp-stanzas">>,
 +                                                                __IgnoreEls,
 +                                                                _el));
 +      _ ->
 +        decode_sm_failed_els(__TopXMLNS, __IgnoreEls, _els,
 +                             Reason)
 +    end;
 +decode_sm_failed_els(__TopXMLNS, __IgnoreEls,
 +                   [{xmlel, <<"item-not-found">>, _attrs, _} = _el | _els],
 +                   Reason) ->
 +    case get_attr(<<"xmlns">>, _attrs) of
 +      <<"urn:ietf:params:xml:ns:xmpp-stanzas">> ->
 +        decode_sm_failed_els(__TopXMLNS, __IgnoreEls, _els,
 +                             decode_error_item_not_found(<<"urn:ietf:params:xml:ns:xmpp-stanzas">>,
 +                                                         __IgnoreEls, _el));
 +      _ ->
 +        decode_sm_failed_els(__TopXMLNS, __IgnoreEls, _els,
 +                             Reason)
 +    end;
 +decode_sm_failed_els(__TopXMLNS, __IgnoreEls,
 +                   [{xmlel, <<"jid-malformed">>, _attrs, _} = _el | _els],
 +                   Reason) ->
 +    case get_attr(<<"xmlns">>, _attrs) of
 +      <<"urn:ietf:params:xml:ns:xmpp-stanzas">> ->
 +        decode_sm_failed_els(__TopXMLNS, __IgnoreEls, _els,
 +                             decode_error_jid_malformed(<<"urn:ietf:params:xml:ns:xmpp-stanzas">>,
 +                                                        __IgnoreEls, _el));
 +      _ ->
 +        decode_sm_failed_els(__TopXMLNS, __IgnoreEls, _els,
 +                             Reason)
 +    end;
 +decode_sm_failed_els(__TopXMLNS, __IgnoreEls,
 +                   [{xmlel, <<"not-acceptable">>, _attrs, _} = _el | _els],
 +                   Reason) ->
 +    case get_attr(<<"xmlns">>, _attrs) of
 +      <<"urn:ietf:params:xml:ns:xmpp-stanzas">> ->
 +        decode_sm_failed_els(__TopXMLNS, __IgnoreEls, _els,
 +                             decode_error_not_acceptable(<<"urn:ietf:params:xml:ns:xmpp-stanzas">>,
 +                                                         __IgnoreEls, _el));
 +      _ ->
 +        decode_sm_failed_els(__TopXMLNS, __IgnoreEls, _els,
 +                             Reason)
 +    end;
 +decode_sm_failed_els(__TopXMLNS, __IgnoreEls,
 +                   [{xmlel, <<"not-allowed">>, _attrs, _} = _el | _els],
 +                   Reason) ->
 +    case get_attr(<<"xmlns">>, _attrs) of
 +      <<"urn:ietf:params:xml:ns:xmpp-stanzas">> ->
 +        decode_sm_failed_els(__TopXMLNS, __IgnoreEls, _els,
 +                             decode_error_not_allowed(<<"urn:ietf:params:xml:ns:xmpp-stanzas">>,
 +                                                      __IgnoreEls, _el));
 +      _ ->
 +        decode_sm_failed_els(__TopXMLNS, __IgnoreEls, _els,
 +                             Reason)
 +    end;
 +decode_sm_failed_els(__TopXMLNS, __IgnoreEls,
 +                   [{xmlel, <<"not-authorized">>, _attrs, _} = _el | _els],
 +                   Reason) ->
 +    case get_attr(<<"xmlns">>, _attrs) of
 +      <<"urn:ietf:params:xml:ns:xmpp-stanzas">> ->
 +        decode_sm_failed_els(__TopXMLNS, __IgnoreEls, _els,
 +                             decode_error_not_authorized(<<"urn:ietf:params:xml:ns:xmpp-stanzas">>,
 +                                                         __IgnoreEls, _el));
 +      _ ->
 +        decode_sm_failed_els(__TopXMLNS, __IgnoreEls, _els,
 +                             Reason)
 +    end;
 +decode_sm_failed_els(__TopXMLNS, __IgnoreEls,
 +                   [{xmlel, <<"policy-violation">>, _attrs, _} = _el
 +                    | _els],
 +                   Reason) ->
 +    case get_attr(<<"xmlns">>, _attrs) of
 +      <<"urn:ietf:params:xml:ns:xmpp-stanzas">> ->
 +        decode_sm_failed_els(__TopXMLNS, __IgnoreEls, _els,
 +                             decode_error_policy_violation(<<"urn:ietf:params:xml:ns:xmpp-stanzas">>,
 +                                                           __IgnoreEls, _el));
 +      _ ->
 +        decode_sm_failed_els(__TopXMLNS, __IgnoreEls, _els,
 +                             Reason)
 +    end;
 +decode_sm_failed_els(__TopXMLNS, __IgnoreEls,
 +                   [{xmlel, <<"recipient-unavailable">>, _attrs, _} = _el
 +                    | _els],
 +                   Reason) ->
 +    case get_attr(<<"xmlns">>, _attrs) of
 +      <<"urn:ietf:params:xml:ns:xmpp-stanzas">> ->
 +        decode_sm_failed_els(__TopXMLNS, __IgnoreEls, _els,
 +                             decode_error_recipient_unavailable(<<"urn:ietf:params:xml:ns:xmpp-stanzas">>,
 +                                                                __IgnoreEls,
 +                                                                _el));
 +      _ ->
 +        decode_sm_failed_els(__TopXMLNS, __IgnoreEls, _els,
 +                             Reason)
 +    end;
 +decode_sm_failed_els(__TopXMLNS, __IgnoreEls,
 +                   [{xmlel, <<"redirect">>, _attrs, _} = _el | _els],
 +                   Reason) ->
 +    case get_attr(<<"xmlns">>, _attrs) of
 +      <<"urn:ietf:params:xml:ns:xmpp-stanzas">> ->
 +        decode_sm_failed_els(__TopXMLNS, __IgnoreEls, _els,
 +                             decode_error_redirect(<<"urn:ietf:params:xml:ns:xmpp-stanzas">>,
 +                                                   __IgnoreEls, _el));
 +      _ ->
 +        decode_sm_failed_els(__TopXMLNS, __IgnoreEls, _els,
 +                             Reason)
 +    end;
 +decode_sm_failed_els(__TopXMLNS, __IgnoreEls,
 +                   [{xmlel, <<"registration-required">>, _attrs, _} = _el
 +                    | _els],
 +                   Reason) ->
 +    case get_attr(<<"xmlns">>, _attrs) of
 +      <<"urn:ietf:params:xml:ns:xmpp-stanzas">> ->
 +        decode_sm_failed_els(__TopXMLNS, __IgnoreEls, _els,
 +                             decode_error_registration_required(<<"urn:ietf:params:xml:ns:xmpp-stanzas">>,
 +                                                                __IgnoreEls,
 +                                                                _el));
 +      _ ->
 +        decode_sm_failed_els(__TopXMLNS, __IgnoreEls, _els,
 +                             Reason)
 +    end;
 +decode_sm_failed_els(__TopXMLNS, __IgnoreEls,
 +                   [{xmlel, <<"remote-server-not-found">>, _attrs, _} = _el
 +                    | _els],
 +                   Reason) ->
 +    case get_attr(<<"xmlns">>, _attrs) of
 +      <<"urn:ietf:params:xml:ns:xmpp-stanzas">> ->
 +        decode_sm_failed_els(__TopXMLNS, __IgnoreEls, _els,
 +                             decode_error_remote_server_not_found(<<"urn:ietf:params:xml:ns:xmpp-stanzas">>,
 +                                                                  __IgnoreEls,
 +                                                                  _el));
 +      _ ->
 +        decode_sm_failed_els(__TopXMLNS, __IgnoreEls, _els,
 +                             Reason)
 +    end;
 +decode_sm_failed_els(__TopXMLNS, __IgnoreEls,
 +                   [{xmlel, <<"remote-server-timeout">>, _attrs, _} = _el
 +                    | _els],
 +                   Reason) ->
 +    case get_attr(<<"xmlns">>, _attrs) of
 +      <<"urn:ietf:params:xml:ns:xmpp-stanzas">> ->
 +        decode_sm_failed_els(__TopXMLNS, __IgnoreEls, _els,
 +                             decode_error_remote_server_timeout(<<"urn:ietf:params:xml:ns:xmpp-stanzas">>,
 +                                                                __IgnoreEls,
 +                                                                _el));
 +      _ ->
 +        decode_sm_failed_els(__TopXMLNS, __IgnoreEls, _els,
 +                             Reason)
 +    end;
 +decode_sm_failed_els(__TopXMLNS, __IgnoreEls,
 +                   [{xmlel, <<"resource-constraint">>, _attrs, _} = _el
 +                    | _els],
 +                   Reason) ->
 +    case get_attr(<<"xmlns">>, _attrs) of
 +      <<"urn:ietf:params:xml:ns:xmpp-stanzas">> ->
 +        decode_sm_failed_els(__TopXMLNS, __IgnoreEls, _els,
 +                             decode_error_resource_constraint(<<"urn:ietf:params:xml:ns:xmpp-stanzas">>,
 +                                                              __IgnoreEls,
 +                                                              _el));
 +      _ ->
 +        decode_sm_failed_els(__TopXMLNS, __IgnoreEls, _els,
 +                             Reason)
 +    end;
 +decode_sm_failed_els(__TopXMLNS, __IgnoreEls,
 +                   [{xmlel, <<"service-unavailable">>, _attrs, _} = _el
 +                    | _els],
 +                   Reason) ->
 +    case get_attr(<<"xmlns">>, _attrs) of
 +      <<"urn:ietf:params:xml:ns:xmpp-stanzas">> ->
 +        decode_sm_failed_els(__TopXMLNS, __IgnoreEls, _els,
 +                             decode_error_service_unavailable(<<"urn:ietf:params:xml:ns:xmpp-stanzas">>,
 +                                                              __IgnoreEls,
 +                                                              _el));
 +      _ ->
 +        decode_sm_failed_els(__TopXMLNS, __IgnoreEls, _els,
 +                             Reason)
 +    end;
 +decode_sm_failed_els(__TopXMLNS, __IgnoreEls,
 +                   [{xmlel, <<"subscription-required">>, _attrs, _} = _el
 +                    | _els],
 +                   Reason) ->
 +    case get_attr(<<"xmlns">>, _attrs) of
 +      <<"urn:ietf:params:xml:ns:xmpp-stanzas">> ->
 +        decode_sm_failed_els(__TopXMLNS, __IgnoreEls, _els,
 +                             decode_error_subscription_required(<<"urn:ietf:params:xml:ns:xmpp-stanzas">>,
 +                                                                __IgnoreEls,
 +                                                                _el));
 +      _ ->
 +        decode_sm_failed_els(__TopXMLNS, __IgnoreEls, _els,
 +                             Reason)
 +    end;
 +decode_sm_failed_els(__TopXMLNS, __IgnoreEls,
 +                   [{xmlel, <<"undefined-condition">>, _attrs, _} = _el
 +                    | _els],
 +                   Reason) ->
 +    case get_attr(<<"xmlns">>, _attrs) of
 +      <<"urn:ietf:params:xml:ns:xmpp-stanzas">> ->
 +        decode_sm_failed_els(__TopXMLNS, __IgnoreEls, _els,
 +                             decode_error_undefined_condition(<<"urn:ietf:params:xml:ns:xmpp-stanzas">>,
 +                                                              __IgnoreEls,
 +                                                              _el));
 +      _ ->
 +        decode_sm_failed_els(__TopXMLNS, __IgnoreEls, _els,
 +                             Reason)
 +    end;
 +decode_sm_failed_els(__TopXMLNS, __IgnoreEls,
 +                   [{xmlel, <<"unexpected-request">>, _attrs, _} = _el
 +                    | _els],
 +                   Reason) ->
 +    case get_attr(<<"xmlns">>, _attrs) of
 +      <<"urn:ietf:params:xml:ns:xmpp-stanzas">> ->
 +        decode_sm_failed_els(__TopXMLNS, __IgnoreEls, _els,
 +                             decode_error_unexpected_request(<<"urn:ietf:params:xml:ns:xmpp-stanzas">>,
 +                                                             __IgnoreEls,
 +                                                             _el));
 +      _ ->
 +        decode_sm_failed_els(__TopXMLNS, __IgnoreEls, _els,
 +                             Reason)
 +    end;
 +decode_sm_failed_els(__TopXMLNS, __IgnoreEls,
 +                   [_ | _els], Reason) ->
 +    decode_sm_failed_els(__TopXMLNS, __IgnoreEls, _els,
 +                       Reason).
 +
 +decode_sm_failed_attrs(__TopXMLNS,
 +                     [{<<"h">>, _val} | _attrs], _H, Xmlns) ->
 +    decode_sm_failed_attrs(__TopXMLNS, _attrs, _val, Xmlns);
 +decode_sm_failed_attrs(__TopXMLNS,
 +                     [{<<"xmlns">>, _val} | _attrs], H, _Xmlns) ->
 +    decode_sm_failed_attrs(__TopXMLNS, _attrs, H, _val);
 +decode_sm_failed_attrs(__TopXMLNS, [_ | _attrs], H,
 +                     Xmlns) ->
 +    decode_sm_failed_attrs(__TopXMLNS, _attrs, H, Xmlns);
 +decode_sm_failed_attrs(__TopXMLNS, [], H, Xmlns) ->
 +    {decode_sm_failed_attr_h(__TopXMLNS, H),
 +     decode_sm_failed_attr_xmlns(__TopXMLNS, Xmlns)}.
 +
 +encode_sm_failed({sm_failed, Reason, H, Xmlns},
 +               __TopXMLNS) ->
 +    __NewTopXMLNS = choose_top_xmlns(Xmlns,
 +                                   [<<"urn:xmpp:sm:2">>, <<"urn:xmpp:sm:3">>],
 +                                   __TopXMLNS),
 +    _els = lists:reverse('encode_sm_failed_$reason'(Reason,
 +                                                  __NewTopXMLNS, [])),
 +    _attrs = encode_sm_failed_attr_h(H,
 +                                   enc_xmlns_attrs(__NewTopXMLNS,
 +                                                   __TopXMLNS)),
 +    {xmlel, <<"failed">>, _attrs, _els}.
 +
 +'encode_sm_failed_$reason'(undefined, __TopXMLNS,
 +                         _acc) ->
 +    _acc;
 +'encode_sm_failed_$reason'('bad-request' = Reason,
 +                         __TopXMLNS, _acc) ->
 +    [encode_error_bad_request(Reason, __TopXMLNS) | _acc];
 +'encode_sm_failed_$reason'(conflict = Reason,
 +                         __TopXMLNS, _acc) ->
 +    [encode_error_conflict(Reason, __TopXMLNS) | _acc];
 +'encode_sm_failed_$reason'('feature-not-implemented' =
 +                             Reason,
 +                         __TopXMLNS, _acc) ->
 +    [encode_error_feature_not_implemented(Reason,
 +                                        __TopXMLNS)
 +     | _acc];
 +'encode_sm_failed_$reason'(forbidden = Reason,
 +                         __TopXMLNS, _acc) ->
 +    [encode_error_forbidden(Reason, __TopXMLNS) | _acc];
 +'encode_sm_failed_$reason'({gone, _} = Reason,
 +                         __TopXMLNS, _acc) ->
 +    [encode_error_gone(Reason, __TopXMLNS) | _acc];
 +'encode_sm_failed_$reason'('internal-server-error' =
 +                             Reason,
 +                         __TopXMLNS, _acc) ->
 +    [encode_error_internal_server_error(Reason, __TopXMLNS)
 +     | _acc];
 +'encode_sm_failed_$reason'('item-not-found' = Reason,
 +                         __TopXMLNS, _acc) ->
 +    [encode_error_item_not_found(Reason, __TopXMLNS)
 +     | _acc];
 +'encode_sm_failed_$reason'('jid-malformed' = Reason,
 +                         __TopXMLNS, _acc) ->
 +    [encode_error_jid_malformed(Reason, __TopXMLNS) | _acc];
 +'encode_sm_failed_$reason'('not-acceptable' = Reason,
 +                         __TopXMLNS, _acc) ->
 +    [encode_error_not_acceptable(Reason, __TopXMLNS)
 +     | _acc];
 +'encode_sm_failed_$reason'('not-allowed' = Reason,
 +                         __TopXMLNS, _acc) ->
 +    [encode_error_not_allowed(Reason, __TopXMLNS) | _acc];
 +'encode_sm_failed_$reason'('not-authorized' = Reason,
 +                         __TopXMLNS, _acc) ->
 +    [encode_error_not_authorized(Reason, __TopXMLNS)
 +     | _acc];
 +'encode_sm_failed_$reason'('policy-violation' = Reason,
 +                         __TopXMLNS, _acc) ->
 +    [encode_error_policy_violation(Reason, __TopXMLNS)
 +     | _acc];
 +'encode_sm_failed_$reason'('recipient-unavailable' =
 +                             Reason,
 +                         __TopXMLNS, _acc) ->
 +    [encode_error_recipient_unavailable(Reason, __TopXMLNS)
 +     | _acc];
 +'encode_sm_failed_$reason'({redirect, _} = Reason,
 +                         __TopXMLNS, _acc) ->
 +    [encode_error_redirect(Reason, __TopXMLNS) | _acc];
 +'encode_sm_failed_$reason'('registration-required' =
 +                             Reason,
 +                         __TopXMLNS, _acc) ->
 +    [encode_error_registration_required(Reason, __TopXMLNS)
 +     | _acc];
 +'encode_sm_failed_$reason'('remote-server-not-found' =
 +                             Reason,
 +                         __TopXMLNS, _acc) ->
 +    [encode_error_remote_server_not_found(Reason,
 +                                        __TopXMLNS)
 +     | _acc];
 +'encode_sm_failed_$reason'('remote-server-timeout' =
 +                             Reason,
 +                         __TopXMLNS, _acc) ->
 +    [encode_error_remote_server_timeout(Reason, __TopXMLNS)
 +     | _acc];
 +'encode_sm_failed_$reason'('resource-constraint' =
 +                             Reason,
 +                         __TopXMLNS, _acc) ->
 +    [encode_error_resource_constraint(Reason, __TopXMLNS)
 +     | _acc];
 +'encode_sm_failed_$reason'('service-unavailable' =
 +                             Reason,
 +                         __TopXMLNS, _acc) ->
 +    [encode_error_service_unavailable(Reason, __TopXMLNS)
 +     | _acc];
 +'encode_sm_failed_$reason'('subscription-required' =
 +                             Reason,
 +                         __TopXMLNS, _acc) ->
 +    [encode_error_subscription_required(Reason, __TopXMLNS)
 +     | _acc];
 +'encode_sm_failed_$reason'('undefined-condition' =
 +                             Reason,
 +                         __TopXMLNS, _acc) ->
 +    [encode_error_undefined_condition(Reason, __TopXMLNS)
 +     | _acc];
 +'encode_sm_failed_$reason'('unexpected-request' =
 +                             Reason,
 +                         __TopXMLNS, _acc) ->
 +    [encode_error_unexpected_request(Reason, __TopXMLNS)
 +     | _acc].
 +
 +decode_sm_failed_attr_h(__TopXMLNS, undefined) ->
 +    undefined;
 +decode_sm_failed_attr_h(__TopXMLNS, _val) ->
 +    case catch dec_int(_val, 0, infinity) of
 +      {'EXIT', _} ->
 +        erlang:error({xmpp_codec,
 +                      {bad_attr_value, <<"h">>, <<"failed">>, __TopXMLNS}});
 +      _res -> _res
 +    end.
 +
 +encode_sm_failed_attr_h(undefined, _acc) -> _acc;
 +encode_sm_failed_attr_h(_val, _acc) ->
 +    [{<<"h">>, enc_int(_val)} | _acc].
 +
 +decode_sm_failed_attr_xmlns(__TopXMLNS, undefined) ->
 +    <<>>;
 +decode_sm_failed_attr_xmlns(__TopXMLNS, _val) -> _val.
 +
 +decode_sm_a(__TopXMLNS, __IgnoreEls,
 +          {xmlel, <<"a">>, _attrs, _els}) ->
 +    {H, Xmlns} = decode_sm_a_attrs(__TopXMLNS, _attrs,
 +                                 undefined, undefined),
 +    {sm_a, H, Xmlns}.
 +
 +decode_sm_a_attrs(__TopXMLNS,
 +                [{<<"h">>, _val} | _attrs], _H, Xmlns) ->
 +    decode_sm_a_attrs(__TopXMLNS, _attrs, _val, Xmlns);
 +decode_sm_a_attrs(__TopXMLNS,
 +                [{<<"xmlns">>, _val} | _attrs], H, _Xmlns) ->
 +    decode_sm_a_attrs(__TopXMLNS, _attrs, H, _val);
 +decode_sm_a_attrs(__TopXMLNS, [_ | _attrs], H, Xmlns) ->
 +    decode_sm_a_attrs(__TopXMLNS, _attrs, H, Xmlns);
 +decode_sm_a_attrs(__TopXMLNS, [], H, Xmlns) ->
 +    {decode_sm_a_attr_h(__TopXMLNS, H),
 +     decode_sm_a_attr_xmlns(__TopXMLNS, Xmlns)}.
 +
 +encode_sm_a({sm_a, H, Xmlns}, __TopXMLNS) ->
 +    __NewTopXMLNS = choose_top_xmlns(Xmlns,
 +                                   [<<"urn:xmpp:sm:2">>, <<"urn:xmpp:sm:3">>],
 +                                   __TopXMLNS),
 +    _els = [],
 +    _attrs = encode_sm_a_attr_h(H,
 +                              enc_xmlns_attrs(__NewTopXMLNS, __TopXMLNS)),
 +    {xmlel, <<"a">>, _attrs, _els}.
 +
 +decode_sm_a_attr_h(__TopXMLNS, undefined) ->
 +    erlang:error({xmpp_codec,
 +                {missing_attr, <<"h">>, <<"a">>, __TopXMLNS}});
 +decode_sm_a_attr_h(__TopXMLNS, _val) ->
 +    case catch dec_int(_val, 0, infinity) of
 +      {'EXIT', _} ->
 +        erlang:error({xmpp_codec,
 +                      {bad_attr_value, <<"h">>, <<"a">>, __TopXMLNS}});
 +      _res -> _res
 +    end.
 +
 +encode_sm_a_attr_h(_val, _acc) ->
 +    [{<<"h">>, enc_int(_val)} | _acc].
 +
 +decode_sm_a_attr_xmlns(__TopXMLNS, undefined) -> <<>>;
 +decode_sm_a_attr_xmlns(__TopXMLNS, _val) -> _val.
 +
 +decode_sm_r(__TopXMLNS, __IgnoreEls,
 +          {xmlel, <<"r">>, _attrs, _els}) ->
 +    Xmlns = decode_sm_r_attrs(__TopXMLNS, _attrs,
 +                            undefined),
 +    {sm_r, Xmlns}.
 +
 +decode_sm_r_attrs(__TopXMLNS,
 +                [{<<"xmlns">>, _val} | _attrs], _Xmlns) ->
 +    decode_sm_r_attrs(__TopXMLNS, _attrs, _val);
 +decode_sm_r_attrs(__TopXMLNS, [_ | _attrs], Xmlns) ->
 +    decode_sm_r_attrs(__TopXMLNS, _attrs, Xmlns);
 +decode_sm_r_attrs(__TopXMLNS, [], Xmlns) ->
 +    decode_sm_r_attr_xmlns(__TopXMLNS, Xmlns).
 +
 +encode_sm_r({sm_r, Xmlns}, __TopXMLNS) ->
 +    __NewTopXMLNS = choose_top_xmlns(Xmlns,
 +                                   [<<"urn:xmpp:sm:2">>, <<"urn:xmpp:sm:3">>],
 +                                   __TopXMLNS),
 +    _els = [],
 +    _attrs = enc_xmlns_attrs(__NewTopXMLNS, __TopXMLNS),
 +    {xmlel, <<"r">>, _attrs, _els}.
 +
 +decode_sm_r_attr_xmlns(__TopXMLNS, undefined) -> <<>>;
 +decode_sm_r_attr_xmlns(__TopXMLNS, _val) -> _val.
 +
 +decode_sm_resumed(__TopXMLNS, __IgnoreEls,
 +                {xmlel, <<"resumed">>, _attrs, _els}) ->
 +    {H, Xmlns, Previd} = decode_sm_resumed_attrs(__TopXMLNS,
 +                                               _attrs, undefined, undefined,
 +                                               undefined),
 +    {sm_resumed, H, Previd, Xmlns}.
 +
 +decode_sm_resumed_attrs(__TopXMLNS,
 +                      [{<<"h">>, _val} | _attrs], _H, Xmlns, Previd) ->
 +    decode_sm_resumed_attrs(__TopXMLNS, _attrs, _val, Xmlns,
 +                          Previd);
 +decode_sm_resumed_attrs(__TopXMLNS,
 +                      [{<<"xmlns">>, _val} | _attrs], H, _Xmlns, Previd) ->
 +    decode_sm_resumed_attrs(__TopXMLNS, _attrs, H, _val,
 +                          Previd);
 +decode_sm_resumed_attrs(__TopXMLNS,
 +                      [{<<"previd">>, _val} | _attrs], H, Xmlns, _Previd) ->
 +    decode_sm_resumed_attrs(__TopXMLNS, _attrs, H, Xmlns,
 +                          _val);
 +decode_sm_resumed_attrs(__TopXMLNS, [_ | _attrs], H,
 +                      Xmlns, Previd) ->
 +    decode_sm_resumed_attrs(__TopXMLNS, _attrs, H, Xmlns,
 +                          Previd);
 +decode_sm_resumed_attrs(__TopXMLNS, [], H, Xmlns,
 +                      Previd) ->
 +    {decode_sm_resumed_attr_h(__TopXMLNS, H),
 +     decode_sm_resumed_attr_xmlns(__TopXMLNS, Xmlns),
 +     decode_sm_resumed_attr_previd(__TopXMLNS, Previd)}.
 +
 +encode_sm_resumed({sm_resumed, H, Previd, Xmlns},
 +                __TopXMLNS) ->
 +    __NewTopXMLNS = choose_top_xmlns(Xmlns,
 +                                   [<<"urn:xmpp:sm:2">>, <<"urn:xmpp:sm:3">>],
 +                                   __TopXMLNS),
 +    _els = [],
 +    _attrs = encode_sm_resumed_attr_previd(Previd,
 +                                         encode_sm_resumed_attr_h(H,
 +                                                                  enc_xmlns_attrs(__NewTopXMLNS,
 +                                                                                  __TopXMLNS))),
 +    {xmlel, <<"resumed">>, _attrs, _els}.
 +
 +decode_sm_resumed_attr_h(__TopXMLNS, undefined) ->
 +    erlang:error({xmpp_codec,
 +                {missing_attr, <<"h">>, <<"resumed">>, __TopXMLNS}});
 +decode_sm_resumed_attr_h(__TopXMLNS, _val) ->
 +    case catch dec_int(_val, 0, infinity) of
 +      {'EXIT', _} ->
 +        erlang:error({xmpp_codec,
 +                      {bad_attr_value, <<"h">>, <<"resumed">>, __TopXMLNS}});
 +      _res -> _res
 +    end.
 +
 +encode_sm_resumed_attr_h(_val, _acc) ->
 +    [{<<"h">>, enc_int(_val)} | _acc].
 +
 +decode_sm_resumed_attr_xmlns(__TopXMLNS, undefined) ->
 +    <<>>;
 +decode_sm_resumed_attr_xmlns(__TopXMLNS, _val) -> _val.
 +
 +decode_sm_resumed_attr_previd(__TopXMLNS, undefined) ->
 +    erlang:error({xmpp_codec,
 +                {missing_attr, <<"previd">>, <<"resumed">>,
 +                 __TopXMLNS}});
 +decode_sm_resumed_attr_previd(__TopXMLNS, _val) -> _val.
 +
 +encode_sm_resumed_attr_previd(_val, _acc) ->
 +    [{<<"previd">>, _val} | _acc].
 +
 +decode_sm_resume(__TopXMLNS, __IgnoreEls,
 +               {xmlel, <<"resume">>, _attrs, _els}) ->
 +    {H, Xmlns, Previd} = decode_sm_resume_attrs(__TopXMLNS,
 +                                              _attrs, undefined, undefined,
 +                                              undefined),
 +    {sm_resume, H, Previd, Xmlns}.
 +
 +decode_sm_resume_attrs(__TopXMLNS,
 +                     [{<<"h">>, _val} | _attrs], _H, Xmlns, Previd) ->
 +    decode_sm_resume_attrs(__TopXMLNS, _attrs, _val, Xmlns,
 +                         Previd);
 +decode_sm_resume_attrs(__TopXMLNS,
 +                     [{<<"xmlns">>, _val} | _attrs], H, _Xmlns, Previd) ->
 +    decode_sm_resume_attrs(__TopXMLNS, _attrs, H, _val,
 +                         Previd);
 +decode_sm_resume_attrs(__TopXMLNS,
 +                     [{<<"previd">>, _val} | _attrs], H, Xmlns, _Previd) ->
 +    decode_sm_resume_attrs(__TopXMLNS, _attrs, H, Xmlns,
 +                         _val);
 +decode_sm_resume_attrs(__TopXMLNS, [_ | _attrs], H,
 +                     Xmlns, Previd) ->
 +    decode_sm_resume_attrs(__TopXMLNS, _attrs, H, Xmlns,
 +                         Previd);
 +decode_sm_resume_attrs(__TopXMLNS, [], H, Xmlns,
 +                     Previd) ->
 +    {decode_sm_resume_attr_h(__TopXMLNS, H),
 +     decode_sm_resume_attr_xmlns(__TopXMLNS, Xmlns),
 +     decode_sm_resume_attr_previd(__TopXMLNS, Previd)}.
 +
 +encode_sm_resume({sm_resume, H, Previd, Xmlns},
 +               __TopXMLNS) ->
 +    __NewTopXMLNS = choose_top_xmlns(Xmlns,
 +                                   [<<"urn:xmpp:sm:2">>, <<"urn:xmpp:sm:3">>],
 +                                   __TopXMLNS),
 +    _els = [],
 +    _attrs = encode_sm_resume_attr_previd(Previd,
 +                                        encode_sm_resume_attr_h(H,
 +                                                                enc_xmlns_attrs(__NewTopXMLNS,
 +                                                                                __TopXMLNS))),
 +    {xmlel, <<"resume">>, _attrs, _els}.
 +
 +decode_sm_resume_attr_h(__TopXMLNS, undefined) ->
 +    erlang:error({xmpp_codec,
 +                {missing_attr, <<"h">>, <<"resume">>, __TopXMLNS}});
 +decode_sm_resume_attr_h(__TopXMLNS, _val) ->
 +    case catch dec_int(_val, 0, infinity) of
 +      {'EXIT', _} ->
 +        erlang:error({xmpp_codec,
 +                      {bad_attr_value, <<"h">>, <<"resume">>, __TopXMLNS}});
 +      _res -> _res
 +    end.
 +
 +encode_sm_resume_attr_h(_val, _acc) ->
 +    [{<<"h">>, enc_int(_val)} | _acc].
 +
 +decode_sm_resume_attr_xmlns(__TopXMLNS, undefined) ->
 +    <<>>;
 +decode_sm_resume_attr_xmlns(__TopXMLNS, _val) -> _val.
 +
 +decode_sm_resume_attr_previd(__TopXMLNS, undefined) ->
 +    erlang:error({xmpp_codec,
 +                {missing_attr, <<"previd">>, <<"resume">>,
 +                 __TopXMLNS}});
 +decode_sm_resume_attr_previd(__TopXMLNS, _val) -> _val.
 +
 +encode_sm_resume_attr_previd(_val, _acc) ->
 +    [{<<"previd">>, _val} | _acc].
 +
 +decode_sm_enabled(__TopXMLNS, __IgnoreEls,
 +                {xmlel, <<"enabled">>, _attrs, _els}) ->
 +    {Id, Location, Xmlns, Max, Resume} =
 +      decode_sm_enabled_attrs(__TopXMLNS, _attrs, undefined,
 +                              undefined, undefined, undefined, undefined),
 +    {sm_enabled, Id, Location, Max, Resume, Xmlns}.
 +
 +decode_sm_enabled_attrs(__TopXMLNS,
 +                      [{<<"id">>, _val} | _attrs], _Id, Location, Xmlns, Max,
 +                      Resume) ->
 +    decode_sm_enabled_attrs(__TopXMLNS, _attrs, _val,
 +                          Location, Xmlns, Max, Resume);
 +decode_sm_enabled_attrs(__TopXMLNS,
 +                      [{<<"location">>, _val} | _attrs], Id, _Location, Xmlns,
 +                      Max, Resume) ->
 +    decode_sm_enabled_attrs(__TopXMLNS, _attrs, Id, _val,
 +                          Xmlns, Max, Resume);
 +decode_sm_enabled_attrs(__TopXMLNS,
 +                      [{<<"xmlns">>, _val} | _attrs], Id, Location, _Xmlns,
 +                      Max, Resume) ->
 +    decode_sm_enabled_attrs(__TopXMLNS, _attrs, Id,
 +                          Location, _val, Max, Resume);
 +decode_sm_enabled_attrs(__TopXMLNS,
 +                      [{<<"max">>, _val} | _attrs], Id, Location, Xmlns, _Max,
 +                      Resume) ->
 +    decode_sm_enabled_attrs(__TopXMLNS, _attrs, Id,
 +                          Location, Xmlns, _val, Resume);
 +decode_sm_enabled_attrs(__TopXMLNS,
 +                      [{<<"resume">>, _val} | _attrs], Id, Location, Xmlns,
 +                      Max, _Resume) ->
 +    decode_sm_enabled_attrs(__TopXMLNS, _attrs, Id,
 +                          Location, Xmlns, Max, _val);
 +decode_sm_enabled_attrs(__TopXMLNS, [_ | _attrs], Id,
 +                      Location, Xmlns, Max, Resume) ->
 +    decode_sm_enabled_attrs(__TopXMLNS, _attrs, Id,
 +                          Location, Xmlns, Max, Resume);
 +decode_sm_enabled_attrs(__TopXMLNS, [], Id, Location,
 +                      Xmlns, Max, Resume) ->
 +    {decode_sm_enabled_attr_id(__TopXMLNS, Id),
 +     decode_sm_enabled_attr_location(__TopXMLNS, Location),
 +     decode_sm_enabled_attr_xmlns(__TopXMLNS, Xmlns),
 +     decode_sm_enabled_attr_max(__TopXMLNS, Max),
 +     decode_sm_enabled_attr_resume(__TopXMLNS, Resume)}.
 +
 +encode_sm_enabled({sm_enabled, Id, Location, Max,
 +                 Resume, Xmlns},
 +                __TopXMLNS) ->
 +    __NewTopXMLNS = choose_top_xmlns(Xmlns,
 +                                   [<<"urn:xmpp:sm:2">>, <<"urn:xmpp:sm:3">>],
 +                                   __TopXMLNS),
 +    _els = [],
 +    _attrs = encode_sm_enabled_attr_resume(Resume,
 +                                         encode_sm_enabled_attr_max(Max,
 +                                                                    encode_sm_enabled_attr_location(Location,
 +                                                                                                    encode_sm_enabled_attr_id(Id,
 +                                                                                                                              enc_xmlns_attrs(__NewTopXMLNS,
 +                                                                                                                                              __TopXMLNS))))),
 +    {xmlel, <<"enabled">>, _attrs, _els}.
 +
 +decode_sm_enabled_attr_id(__TopXMLNS, undefined) ->
 +    <<>>;
 +decode_sm_enabled_attr_id(__TopXMLNS, _val) -> _val.
 +
 +encode_sm_enabled_attr_id(<<>>, _acc) -> _acc;
 +encode_sm_enabled_attr_id(_val, _acc) ->
 +    [{<<"id">>, _val} | _acc].
 +
 +decode_sm_enabled_attr_location(__TopXMLNS,
 +                              undefined) ->
 +    <<>>;
 +decode_sm_enabled_attr_location(__TopXMLNS, _val) ->
 +    _val.
 +
 +encode_sm_enabled_attr_location(<<>>, _acc) -> _acc;
 +encode_sm_enabled_attr_location(_val, _acc) ->
 +    [{<<"location">>, _val} | _acc].
 +
 +decode_sm_enabled_attr_xmlns(__TopXMLNS, undefined) ->
 +    <<>>;
 +decode_sm_enabled_attr_xmlns(__TopXMLNS, _val) -> _val.
 +
 +decode_sm_enabled_attr_max(__TopXMLNS, undefined) ->
 +    undefined;
 +decode_sm_enabled_attr_max(__TopXMLNS, _val) ->
 +    case catch dec_int(_val, 0, infinity) of
 +      {'EXIT', _} ->
 +        erlang:error({xmpp_codec,
 +                      {bad_attr_value, <<"max">>, <<"enabled">>,
 +                       __TopXMLNS}});
 +      _res -> _res
 +    end.
 +
 +encode_sm_enabled_attr_max(undefined, _acc) -> _acc;
 +encode_sm_enabled_attr_max(_val, _acc) ->
 +    [{<<"max">>, enc_int(_val)} | _acc].
 +
 +decode_sm_enabled_attr_resume(__TopXMLNS, undefined) ->
 +    false;
 +decode_sm_enabled_attr_resume(__TopXMLNS, _val) ->
 +    case catch dec_bool(_val) of
 +      {'EXIT', _} ->
 +        erlang:error({xmpp_codec,
 +                      {bad_attr_value, <<"resume">>, <<"enabled">>,
 +                       __TopXMLNS}});
 +      _res -> _res
 +    end.
 +
 +encode_sm_enabled_attr_resume(false, _acc) -> _acc;
 +encode_sm_enabled_attr_resume(_val, _acc) ->
 +    [{<<"resume">>, enc_bool(_val)} | _acc].
 +
 +decode_sm_enable(__TopXMLNS, __IgnoreEls,
 +               {xmlel, <<"enable">>, _attrs, _els}) ->
 +    {Max, Xmlns, Resume} =
 +      decode_sm_enable_attrs(__TopXMLNS, _attrs, undefined,
 +                             undefined, undefined),
 +    {sm_enable, Max, Resume, Xmlns}.
 +
 +decode_sm_enable_attrs(__TopXMLNS,
 +                     [{<<"max">>, _val} | _attrs], _Max, Xmlns, Resume) ->
 +    decode_sm_enable_attrs(__TopXMLNS, _attrs, _val, Xmlns,
 +                         Resume);
 +decode_sm_enable_attrs(__TopXMLNS,
 +                     [{<<"xmlns">>, _val} | _attrs], Max, _Xmlns, Resume) ->
 +    decode_sm_enable_attrs(__TopXMLNS, _attrs, Max, _val,
 +                         Resume);
 +decode_sm_enable_attrs(__TopXMLNS,
 +                     [{<<"resume">>, _val} | _attrs], Max, Xmlns, _Resume) ->
 +    decode_sm_enable_attrs(__TopXMLNS, _attrs, Max, Xmlns,
 +                         _val);
 +decode_sm_enable_attrs(__TopXMLNS, [_ | _attrs], Max,
 +                     Xmlns, Resume) ->
 +    decode_sm_enable_attrs(__TopXMLNS, _attrs, Max, Xmlns,
 +                         Resume);
 +decode_sm_enable_attrs(__TopXMLNS, [], Max, Xmlns,
 +                     Resume) ->
 +    {decode_sm_enable_attr_max(__TopXMLNS, Max),
 +     decode_sm_enable_attr_xmlns(__TopXMLNS, Xmlns),
 +     decode_sm_enable_attr_resume(__TopXMLNS, Resume)}.
 +
 +encode_sm_enable({sm_enable, Max, Resume, Xmlns},
 +               __TopXMLNS) ->
 +    __NewTopXMLNS = choose_top_xmlns(Xmlns,
 +                                   [<<"urn:xmpp:sm:2">>, <<"urn:xmpp:sm:3">>],
 +                                   __TopXMLNS),
 +    _els = [],
 +    _attrs = encode_sm_enable_attr_resume(Resume,
 +                                        encode_sm_enable_attr_max(Max,
 +                                                                  enc_xmlns_attrs(__NewTopXMLNS,
 +                                                                                  __TopXMLNS))),
 +    {xmlel, <<"enable">>, _attrs, _els}.
 +
 +decode_sm_enable_attr_max(__TopXMLNS, undefined) ->
 +    undefined;
 +decode_sm_enable_attr_max(__TopXMLNS, _val) ->
 +    case catch dec_int(_val, 0, infinity) of
 +      {'EXIT', _} ->
 +        erlang:error({xmpp_codec,
 +                      {bad_attr_value, <<"max">>, <<"enable">>, __TopXMLNS}});
 +      _res -> _res
 +    end.
 +
 +encode_sm_enable_attr_max(undefined, _acc) -> _acc;
 +encode_sm_enable_attr_max(_val, _acc) ->
 +    [{<<"max">>, enc_int(_val)} | _acc].
 +
 +decode_sm_enable_attr_xmlns(__TopXMLNS, undefined) ->
 +    <<>>;
 +decode_sm_enable_attr_xmlns(__TopXMLNS, _val) -> _val.
 +
 +decode_sm_enable_attr_resume(__TopXMLNS, undefined) ->
 +    false;
 +decode_sm_enable_attr_resume(__TopXMLNS, _val) ->
 +    case catch dec_bool(_val) of
 +      {'EXIT', _} ->
 +        erlang:error({xmpp_codec,
 +                      {bad_attr_value, <<"resume">>, <<"enable">>,
 +                       __TopXMLNS}});
 +      _res -> _res
 +    end.
 +
 +encode_sm_enable_attr_resume(false, _acc) -> _acc;
 +encode_sm_enable_attr_resume(_val, _acc) ->
 +    [{<<"resume">>, enc_bool(_val)} | _acc].
 +
 +decode_feature_sm(__TopXMLNS, __IgnoreEls,
 +                {xmlel, <<"sm">>, _attrs, _els}) ->
 +    Xmlns = decode_feature_sm_attrs(__TopXMLNS, _attrs,
 +                                  undefined),
 +    {feature_sm, Xmlns}.
 +
 +decode_feature_sm_attrs(__TopXMLNS,
 +                      [{<<"xmlns">>, _val} | _attrs], _Xmlns) ->
 +    decode_feature_sm_attrs(__TopXMLNS, _attrs, _val);
 +decode_feature_sm_attrs(__TopXMLNS, [_ | _attrs],
 +                      Xmlns) ->
 +    decode_feature_sm_attrs(__TopXMLNS, _attrs, Xmlns);
 +decode_feature_sm_attrs(__TopXMLNS, [], Xmlns) ->
 +    decode_feature_sm_attr_xmlns(__TopXMLNS, Xmlns).
 +
 +encode_feature_sm({feature_sm, Xmlns}, __TopXMLNS) ->
 +    __NewTopXMLNS = choose_top_xmlns(Xmlns,
 +                                   [<<"urn:xmpp:sm:2">>, <<"urn:xmpp:sm:3">>],
 +                                   __TopXMLNS),
 +    _els = [],
 +    _attrs = enc_xmlns_attrs(__NewTopXMLNS, __TopXMLNS),
 +    {xmlel, <<"sm">>, _attrs, _els}.
 +
 +decode_feature_sm_attr_xmlns(__TopXMLNS, undefined) ->
 +    <<>>;
 +decode_feature_sm_attr_xmlns(__TopXMLNS, _val) -> _val.
 +
 +decode_csi_inactive(__TopXMLNS, __IgnoreEls,
 +                  {xmlel, <<"inactive">>, _attrs, _els}) ->
 +    {csi, inactive}.
 +
 +encode_csi_inactive({csi, inactive}, __TopXMLNS) ->
 +    __NewTopXMLNS = choose_top_xmlns(<<"urn:xmpp:csi:0">>,
 +                                   [], __TopXMLNS),
 +    _els = [],
 +    _attrs = enc_xmlns_attrs(__NewTopXMLNS, __TopXMLNS),
 +    {xmlel, <<"inactive">>, _attrs, _els}.
 +
 +decode_csi_active(__TopXMLNS, __IgnoreEls,
 +                {xmlel, <<"active">>, _attrs, _els}) ->
 +    {csi, active}.
 +
 +encode_csi_active({csi, active}, __TopXMLNS) ->
 +    __NewTopXMLNS = choose_top_xmlns(<<"urn:xmpp:csi:0">>,
 +                                   [], __TopXMLNS),
 +    _els = [],
 +    _attrs = enc_xmlns_attrs(__NewTopXMLNS, __TopXMLNS),
 +    {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}, __TopXMLNS) ->
 +    __NewTopXMLNS = choose_top_xmlns(Xmlns,
 +                                   [<<"urn:xmpp:csi:0">>], __TopXMLNS),
 +    _els = [],
 +    _attrs = enc_xmlns_attrs(__NewTopXMLNS, __TopXMLNS),
 +    {xmlel, <<"csi">>, _attrs, _els}.
 +
 +decode_feature_csi_attr_xmlns(__TopXMLNS, undefined) ->
 +    <<>>;
 +decode_feature_csi_attr_xmlns(__TopXMLNS, _val) -> _val.
 +
 +decode_carbons_sent(__TopXMLNS, __IgnoreEls,
 +                  {xmlel, <<"sent">>, _attrs, _els}) ->
 +    Forwarded = decode_carbons_sent_els(__TopXMLNS,
 +                                      __IgnoreEls, _els, error),
 +    {carbons_sent, Forwarded}.
 +
 +decode_carbons_sent_els(__TopXMLNS, __IgnoreEls, [],
 +                      Forwarded) ->
 +    case Forwarded of
 +      error ->
 +        erlang:error({xmpp_codec,
 +                      {missing_tag, <<"forwarded">>, __TopXMLNS}});
 +      {value, Forwarded1} -> Forwarded1
 +    end;
 +decode_carbons_sent_els(__TopXMLNS, __IgnoreEls,
 +                      [{xmlel, <<"forwarded">>, _attrs, _} = _el | _els],
 +                      Forwarded) ->
 +    case get_attr(<<"xmlns">>, _attrs) of
 +      <<"urn:xmpp:forward:0">> ->
 +        decode_carbons_sent_els(__TopXMLNS, __IgnoreEls, _els,
 +                                {value,
 +                                 decode_forwarded(<<"urn:xmpp:forward:0">>,
 +                                                  __IgnoreEls, _el)});
 +      _ ->
 +        decode_carbons_sent_els(__TopXMLNS, __IgnoreEls, _els,
 +                                Forwarded)
 +    end;
 +decode_carbons_sent_els(__TopXMLNS, __IgnoreEls,
 +                      [_ | _els], Forwarded) ->
 +    decode_carbons_sent_els(__TopXMLNS, __IgnoreEls, _els,
 +                          Forwarded).
 +
 +encode_carbons_sent({carbons_sent, Forwarded},
 +                  __TopXMLNS) ->
 +    __NewTopXMLNS =
 +      choose_top_xmlns(<<"urn:xmpp:carbons:2">>, [],
 +                       __TopXMLNS),
 +    _els =
 +      lists:reverse('encode_carbons_sent_$forwarded'(Forwarded,
 +                                                     __NewTopXMLNS, [])),
 +    _attrs = enc_xmlns_attrs(__NewTopXMLNS, __TopXMLNS),
 +    {xmlel, <<"sent">>, _attrs, _els}.
 +
 +'encode_carbons_sent_$forwarded'(Forwarded, __TopXMLNS,
 +                               _acc) ->
 +    [encode_forwarded(Forwarded, __TopXMLNS) | _acc].
 +
 +decode_carbons_received(__TopXMLNS, __IgnoreEls,
 +                      {xmlel, <<"received">>, _attrs, _els}) ->
 +    Forwarded = decode_carbons_received_els(__TopXMLNS,
 +                                          __IgnoreEls, _els, error),
 +    {carbons_received, Forwarded}.
 +
 +decode_carbons_received_els(__TopXMLNS, __IgnoreEls, [],
 +                          Forwarded) ->
 +    case Forwarded of
 +      error ->
 +        erlang:error({xmpp_codec,
 +                      {missing_tag, <<"forwarded">>, __TopXMLNS}});
 +      {value, Forwarded1} -> Forwarded1
 +    end;
 +decode_carbons_received_els(__TopXMLNS, __IgnoreEls,
 +                          [{xmlel, <<"forwarded">>, _attrs, _} = _el | _els],
 +                          Forwarded) ->
 +    case get_attr(<<"xmlns">>, _attrs) of
 +      <<"urn:xmpp:forward:0">> ->
 +        decode_carbons_received_els(__TopXMLNS, __IgnoreEls,
 +                                    _els,
 +                                    {value,
 +                                     decode_forwarded(<<"urn:xmpp:forward:0">>,
 +                                                      __IgnoreEls, _el)});
 +      _ ->
 +        decode_carbons_received_els(__TopXMLNS, __IgnoreEls,
 +                                    _els, Forwarded)
 +    end;
 +decode_carbons_received_els(__TopXMLNS, __IgnoreEls,
 +                          [_ | _els], Forwarded) ->
 +    decode_carbons_received_els(__TopXMLNS, __IgnoreEls,
 +                              _els, Forwarded).
 +
 +encode_carbons_received({carbons_received, Forwarded},
 +                      __TopXMLNS) ->
 +    __NewTopXMLNS =
 +      choose_top_xmlns(<<"urn:xmpp:carbons:2">>, [],
 +                       __TopXMLNS),
 +    _els =
 +      lists:reverse('encode_carbons_received_$forwarded'(Forwarded,
 +                                                         __NewTopXMLNS, [])),
 +    _attrs = enc_xmlns_attrs(__NewTopXMLNS, __TopXMLNS),
 +    {xmlel, <<"received">>, _attrs, _els}.
 +
 +'encode_carbons_received_$forwarded'(Forwarded,
 +                                   __TopXMLNS, _acc) ->
 +    [encode_forwarded(Forwarded, __TopXMLNS) | _acc].
 +
 +decode_carbons_private(__TopXMLNS, __IgnoreEls,
 +                     {xmlel, <<"private">>, _attrs, _els}) ->
 +    {carbons_private}.
 +
 +encode_carbons_private({carbons_private}, __TopXMLNS) ->
 +    __NewTopXMLNS =
 +      choose_top_xmlns(<<"urn:xmpp:carbons:2">>, [],
 +                       __TopXMLNS),
 +    _els = [],
 +    _attrs = enc_xmlns_attrs(__NewTopXMLNS, __TopXMLNS),
 +    {xmlel, <<"private">>, _attrs, _els}.
 +
 +decode_carbons_enable(__TopXMLNS, __IgnoreEls,
 +                    {xmlel, <<"enable">>, _attrs, _els}) ->
 +    {carbons_enable}.
 +
 +encode_carbons_enable({carbons_enable}, __TopXMLNS) ->
 +    __NewTopXMLNS =
 +      choose_top_xmlns(<<"urn:xmpp:carbons:2">>, [],
 +                       __TopXMLNS),
 +    _els = [],
 +    _attrs = enc_xmlns_attrs(__NewTopXMLNS, __TopXMLNS),
 +    {xmlel, <<"enable">>, _attrs, _els}.
 +
 +decode_carbons_disable(__TopXMLNS, __IgnoreEls,
 +                     {xmlel, <<"disable">>, _attrs, _els}) ->
 +    {carbons_disable}.
 +
 +encode_carbons_disable({carbons_disable}, __TopXMLNS) ->
 +    __NewTopXMLNS =
 +      choose_top_xmlns(<<"urn:xmpp:carbons:2">>, [],
 +                       __TopXMLNS),
 +    _els = [],
 +    _attrs = enc_xmlns_attrs(__NewTopXMLNS, __TopXMLNS),
 +    {xmlel, <<"disable">>, _attrs, _els}.
 +
 +decode_forwarded(__TopXMLNS, __IgnoreEls,
 +               {xmlel, <<"forwarded">>, _attrs, _els}) ->
 +    {Delay, __Els} = decode_forwarded_els(__TopXMLNS,
 +                                        __IgnoreEls, _els, undefined, []),
 +    {forwarded, Delay, __Els}.
 +
 +decode_forwarded_els(__TopXMLNS, __IgnoreEls, [], Delay,
 +                   __Els) ->
 +    {Delay, lists:reverse(__Els)};
 +decode_forwarded_els(__TopXMLNS, __IgnoreEls,
 +                   [{xmlel, <<"delay">>, _attrs, _} = _el | _els], Delay,
 +                   __Els) ->
 +    case get_attr(<<"xmlns">>, _attrs) of
 +      <<"urn:xmpp:delay">> ->
 +        decode_forwarded_els(__TopXMLNS, __IgnoreEls, _els,
 +                             decode_delay(<<"urn:xmpp:delay">>, __IgnoreEls,
 +                                          _el),
 +                             __Els);
 +      _ ->
 +        decode_forwarded_els(__TopXMLNS, __IgnoreEls, _els,
 +                             Delay, __Els)
 +    end;
 +decode_forwarded_els(__TopXMLNS, __IgnoreEls,
 +                   [{xmlel, _, _, _} = _el | _els], Delay, __Els) ->
 +    if __IgnoreEls ->
 +         decode_forwarded_els(__TopXMLNS, __IgnoreEls, _els,
 +                              Delay, [_el | __Els]);
 +       true ->
 +         case is_known_tag(_el, __TopXMLNS) of
 +           true ->
 +               decode_forwarded_els(__TopXMLNS, __IgnoreEls, _els,
 +                                    Delay,
 +                                    [decode(_el, __TopXMLNS, []) | __Els]);
 +           false ->
 +               decode_forwarded_els(__TopXMLNS, __IgnoreEls, _els,
 +                                    Delay, __Els)
 +         end
 +    end;
 +decode_forwarded_els(__TopXMLNS, __IgnoreEls,
 +                   [_ | _els], Delay, __Els) ->
 +    decode_forwarded_els(__TopXMLNS, __IgnoreEls, _els,
 +                       Delay, __Els).
 +
 +encode_forwarded({forwarded, Delay, __Els},
 +               __TopXMLNS) ->
 +    __NewTopXMLNS =
 +      choose_top_xmlns(<<"urn:xmpp:forward:0">>, [],
 +                       __TopXMLNS),
 +    _els = [encode(_el, __NewTopXMLNS) || _el <- __Els] ++
 +           lists:reverse('encode_forwarded_$delay'(Delay,
 +                                                   __NewTopXMLNS, [])),
 +    _attrs = enc_xmlns_attrs(__NewTopXMLNS, __TopXMLNS),
 +    {xmlel, <<"forwarded">>, _attrs, _els}.
 +
 +'encode_forwarded_$delay'(undefined, __TopXMLNS,
 +                        _acc) ->
 +    _acc;
 +'encode_forwarded_$delay'(Delay, __TopXMLNS, _acc) ->
 +    [encode_delay(Delay, __TopXMLNS) | _acc].
 +
 +decode_mam_fin(__TopXMLNS, __IgnoreEls,
 +             {xmlel, <<"fin">>, _attrs, _els}) ->
 +    Rsm = decode_mam_fin_els(__TopXMLNS, __IgnoreEls, _els,
 +                           undefined),
 +    {Id, Xmlns, Stable, Complete} =
 +      decode_mam_fin_attrs(__TopXMLNS, _attrs, undefined,
 +                           undefined, undefined, undefined),
 +    {mam_fin, Xmlns, Id, Rsm, Stable, Complete}.
 +
 +decode_mam_fin_els(__TopXMLNS, __IgnoreEls, [], Rsm) ->
 +    Rsm;
 +decode_mam_fin_els(__TopXMLNS, __IgnoreEls,
 +                 [{xmlel, <<"set">>, _attrs, _} = _el | _els], Rsm) ->
 +    case get_attr(<<"xmlns">>, _attrs) of
 +      <<"http://jabber.org/protocol/rsm">> ->
 +        decode_mam_fin_els(__TopXMLNS, __IgnoreEls, _els,
 +                           decode_rsm_set(<<"http://jabber.org/protocol/rsm">>,
 +                                          __IgnoreEls, _el));
 +      _ ->
 +        decode_mam_fin_els(__TopXMLNS, __IgnoreEls, _els, Rsm)
 +    end;
 +decode_mam_fin_els(__TopXMLNS, __IgnoreEls, [_ | _els],
 +                 Rsm) ->
 +    decode_mam_fin_els(__TopXMLNS, __IgnoreEls, _els, Rsm).
 +
 +decode_mam_fin_attrs(__TopXMLNS,
 +                   [{<<"queryid">>, _val} | _attrs], _Id, Xmlns, Stable,
 +                   Complete) ->
 +    decode_mam_fin_attrs(__TopXMLNS, _attrs, _val, Xmlns,
 +                       Stable, Complete);
 +decode_mam_fin_attrs(__TopXMLNS,
 +                   [{<<"xmlns">>, _val} | _attrs], Id, _Xmlns, Stable,
 +                   Complete) ->
 +    decode_mam_fin_attrs(__TopXMLNS, _attrs, Id, _val,
 +                       Stable, Complete);
 +decode_mam_fin_attrs(__TopXMLNS,
 +                   [{<<"stable">>, _val} | _attrs], Id, Xmlns, _Stable,
 +                   Complete) ->
 +    decode_mam_fin_attrs(__TopXMLNS, _attrs, Id, Xmlns,
 +                       _val, Complete);
 +decode_mam_fin_attrs(__TopXMLNS,
 +                   [{<<"complete">>, _val} | _attrs], Id, Xmlns, Stable,
 +                   _Complete) ->
 +    decode_mam_fin_attrs(__TopXMLNS, _attrs, Id, Xmlns,
 +                       Stable, _val);
 +decode_mam_fin_attrs(__TopXMLNS, [_ | _attrs], Id,
 +                   Xmlns, Stable, Complete) ->
 +    decode_mam_fin_attrs(__TopXMLNS, _attrs, Id, Xmlns,
 +                       Stable, Complete);
 +decode_mam_fin_attrs(__TopXMLNS, [], Id, Xmlns, Stable,
 +                   Complete) ->
 +    {decode_mam_fin_attr_queryid(__TopXMLNS, Id),
 +     decode_mam_fin_attr_xmlns(__TopXMLNS, Xmlns),
 +     decode_mam_fin_attr_stable(__TopXMLNS, Stable),
 +     decode_mam_fin_attr_complete(__TopXMLNS, Complete)}.
 +
 +encode_mam_fin({mam_fin, Xmlns, Id, Rsm, Stable,
 +              Complete},
 +             __TopXMLNS) ->
 +    __NewTopXMLNS = choose_top_xmlns(Xmlns,
 +                                   [<<"urn:xmpp:mam:0">>,
 +                                    <<"urn:xmpp:mam:1">>],
 +                                   __TopXMLNS),
 +    _els = lists:reverse('encode_mam_fin_$rsm'(Rsm,
 +                                             __NewTopXMLNS, [])),
 +    _attrs = encode_mam_fin_attr_complete(Complete,
 +                                        encode_mam_fin_attr_stable(Stable,
 +                                                                   encode_mam_fin_attr_queryid(Id,
 +                                                                                               enc_xmlns_attrs(__NewTopXMLNS,
 +                                                                                                               __TopXMLNS)))),
 +    {xmlel, <<"fin">>, _attrs, _els}.
 +
 +'encode_mam_fin_$rsm'(undefined, __TopXMLNS, _acc) ->
 +    _acc;
 +'encode_mam_fin_$rsm'(Rsm, __TopXMLNS, _acc) ->
 +    [encode_rsm_set(Rsm, __TopXMLNS) | _acc].
 +
 +decode_mam_fin_attr_queryid(__TopXMLNS, undefined) ->
 +    <<>>;
 +decode_mam_fin_attr_queryid(__TopXMLNS, _val) -> _val.
 +
 +encode_mam_fin_attr_queryid(<<>>, _acc) -> _acc;
 +encode_mam_fin_attr_queryid(_val, _acc) ->
 +    [{<<"queryid">>, _val} | _acc].
 +
 +decode_mam_fin_attr_xmlns(__TopXMLNS, undefined) ->
 +    <<>>;
 +decode_mam_fin_attr_xmlns(__TopXMLNS, _val) -> _val.
 +
 +decode_mam_fin_attr_stable(__TopXMLNS, undefined) ->
 +    undefined;
 +decode_mam_fin_attr_stable(__TopXMLNS, _val) ->
 +    case catch dec_bool(_val) of
 +      {'EXIT', _} ->
 +        erlang:error({xmpp_codec,
 +                      {bad_attr_value, <<"stable">>, <<"fin">>, __TopXMLNS}});
 +      _res -> _res
 +    end.
 +
 +encode_mam_fin_attr_stable(undefined, _acc) -> _acc;
 +encode_mam_fin_attr_stable(_val, _acc) ->
 +    [{<<"stable">>, enc_bool(_val)} | _acc].
 +
 +decode_mam_fin_attr_complete(__TopXMLNS, undefined) ->
 +    undefined;
 +decode_mam_fin_attr_complete(__TopXMLNS, _val) ->
 +    case catch dec_bool(_val) of
 +      {'EXIT', _} ->
 +        erlang:error({xmpp_codec,
 +                      {bad_attr_value, <<"complete">>, <<"fin">>,
 +                       __TopXMLNS}});
 +      _res -> _res
 +    end.
 +
 +encode_mam_fin_attr_complete(undefined, _acc) -> _acc;
 +encode_mam_fin_attr_complete(_val, _acc) ->
 +    [{<<"complete">>, enc_bool(_val)} | _acc].
 +
 +decode_mam_prefs(__TopXMLNS, __IgnoreEls,
 +               {xmlel, <<"prefs">>, _attrs, _els}) ->
 +    {Never, Always} = decode_mam_prefs_els(__TopXMLNS,
 +                                         __IgnoreEls, _els, undefined,
 +                                         undefined),
 +    {Default, Xmlns} = decode_mam_prefs_attrs(__TopXMLNS,
 +                                            _attrs, undefined, undefined),
 +    {mam_prefs, Xmlns, Default, Always, Never}.
 +
 +decode_mam_prefs_els(__TopXMLNS, __IgnoreEls, [], Never,
 +                   Always) ->
 +    {Never, Always};
 +decode_mam_prefs_els(__TopXMLNS, __IgnoreEls,
 +                   [{xmlel, <<"always">>, _attrs, _} = _el | _els], Never,
 +                   Always) ->
 +    case get_attr(<<"xmlns">>, _attrs) of
 +      <<"">>
 +        when __TopXMLNS == <<"urn:xmpp:mam:1">>;
 +             __TopXMLNS == <<"urn:xmpp:mam:0">>;
 +             __TopXMLNS == <<"urn:xmpp:mam:tmp">> ->
 +        decode_mam_prefs_els(__TopXMLNS, __IgnoreEls, _els,
 +                             Never,
 +                             decode_mam_always(__TopXMLNS, __IgnoreEls, _el));
 +      <<"urn:xmpp:mam:0">> ->
 +        decode_mam_prefs_els(__TopXMLNS, __IgnoreEls, _els,
 +                             Never,
 +                             decode_mam_always(<<"urn:xmpp:mam:0">>,
 +                                               __IgnoreEls, _el));
 +      <<"urn:xmpp:mam:1">> ->
 +        decode_mam_prefs_els(__TopXMLNS, __IgnoreEls, _els,
 +                             Never,
 +                             decode_mam_always(<<"urn:xmpp:mam:1">>,
 +                                               __IgnoreEls, _el));
 +      <<"urn:xmpp:mam:tmp">> ->
 +        decode_mam_prefs_els(__TopXMLNS, __IgnoreEls, _els,
 +                             Never,
 +                             decode_mam_always(<<"urn:xmpp:mam:tmp">>,
 +                                               __IgnoreEls, _el));
 +      _ ->
 +        decode_mam_prefs_els(__TopXMLNS, __IgnoreEls, _els,
 +                             Never, Always)
 +    end;
 +decode_mam_prefs_els(__TopXMLNS, __IgnoreEls,
 +                   [{xmlel, <<"never">>, _attrs, _} = _el | _els], Never,
 +                   Always) ->
 +    case get_attr(<<"xmlns">>, _attrs) of
 +      <<"">>
 +        when __TopXMLNS == <<"urn:xmpp:mam:1">>;
 +             __TopXMLNS == <<"urn:xmpp:mam:0">>;
 +             __TopXMLNS == <<"urn:xmpp:mam:tmp">> ->
 +        decode_mam_prefs_els(__TopXMLNS, __IgnoreEls, _els,
 +                             decode_mam_never(__TopXMLNS, __IgnoreEls, _el),
 +                             Always);
 +      <<"urn:xmpp:mam:0">> ->
 +        decode_mam_prefs_els(__TopXMLNS, __IgnoreEls, _els,
 +                             decode_mam_never(<<"urn:xmpp:mam:0">>,
 +                                              __IgnoreEls, _el),
 +                             Always);
 +      <<"urn:xmpp:mam:1">> ->
 +        decode_mam_prefs_els(__TopXMLNS, __IgnoreEls, _els,
 +                             decode_mam_never(<<"urn:xmpp:mam:1">>,
 +                                              __IgnoreEls, _el),
 +                             Always);
 +      <<"urn:xmpp:mam:tmp">> ->
 +        decode_mam_prefs_els(__TopXMLNS, __IgnoreEls, _els,
 +                             decode_mam_never(<<"urn:xmpp:mam:tmp">>,
 +                                              __IgnoreEls, _el),
 +                             Always);
 +      _ ->
 +        decode_mam_prefs_els(__TopXMLNS, __IgnoreEls, _els,
 +                             Never, Always)
 +    end;
 +decode_mam_prefs_els(__TopXMLNS, __IgnoreEls,
 +                   [_ | _els], Never, Always) ->
 +    decode_mam_prefs_els(__TopXMLNS, __IgnoreEls, _els,
 +                       Never, Always).
 +
 +decode_mam_prefs_attrs(__TopXMLNS,
 +                     [{<<"default">>, _val} | _attrs], _Default, Xmlns) ->
 +    decode_mam_prefs_attrs(__TopXMLNS, _attrs, _val, Xmlns);
 +decode_mam_prefs_attrs(__TopXMLNS,
 +                     [{<<"xmlns">>, _val} | _attrs], Default, _Xmlns) ->
 +    decode_mam_prefs_attrs(__TopXMLNS, _attrs, Default,
 +                         _val);
 +decode_mam_prefs_attrs(__TopXMLNS, [_ | _attrs],
 +                     Default, Xmlns) ->
 +    decode_mam_prefs_attrs(__TopXMLNS, _attrs, Default,
 +                         Xmlns);
 +decode_mam_prefs_attrs(__TopXMLNS, [], Default,
 +                     Xmlns) ->
 +    {decode_mam_prefs_attr_default(__TopXMLNS, Default),
 +     decode_mam_prefs_attr_xmlns(__TopXMLNS, Xmlns)}.
 +
 +encode_mam_prefs({mam_prefs, Xmlns, Default, Always,
 +                Never},
 +               __TopXMLNS) ->
 +    __NewTopXMLNS = choose_top_xmlns(Xmlns,
 +                                   [<<"urn:xmpp:mam:0">>,
 +                                    <<"urn:xmpp:mam:1">>,
 +                                    <<"urn:xmpp:mam:tmp">>],
 +                                   __TopXMLNS),
 +    _els = lists:reverse('encode_mam_prefs_$never'(Never,
 +                                                 __NewTopXMLNS,
 +                                                 'encode_mam_prefs_$always'(Always,
 +                                                                            __NewTopXMLNS,
 +                                                                            []))),
 +    _attrs = encode_mam_prefs_attr_default(Default,
 +                                         enc_xmlns_attrs(__NewTopXMLNS,
 +                                                         __TopXMLNS)),
 +    {xmlel, <<"prefs">>, _attrs, _els}.
 +
 +'encode_mam_prefs_$never'(undefined, __TopXMLNS,
 +                        _acc) ->
 +    _acc;
 +'encode_mam_prefs_$never'(Never, __TopXMLNS, _acc) ->
 +    [encode_mam_never(Never, __TopXMLNS) | _acc].
 +
 +'encode_mam_prefs_$always'(undefined, __TopXMLNS,
 +                         _acc) ->
 +    _acc;
 +'encode_mam_prefs_$always'(Always, __TopXMLNS, _acc) ->
 +    [encode_mam_always(Always, __TopXMLNS) | _acc].
 +
 +decode_mam_prefs_attr_default(__TopXMLNS, undefined) ->
 +    undefined;
 +decode_mam_prefs_attr_default(__TopXMLNS, _val) ->
 +    case catch dec_enum(_val, [always, never, roster]) of
 +      {'EXIT', _} ->
 +        erlang:error({xmpp_codec,
 +                      {bad_attr_value, <<"default">>, <<"prefs">>,
 +                       __TopXMLNS}});
 +      _res -> _res
 +    end.
 +
 +encode_mam_prefs_attr_default(undefined, _acc) -> _acc;
 +encode_mam_prefs_attr_default(_val, _acc) ->
 +    [{<<"default">>, enc_enum(_val)} | _acc].
 +
 +decode_mam_prefs_attr_xmlns(__TopXMLNS, undefined) ->
 +    <<>>;
 +decode_mam_prefs_attr_xmlns(__TopXMLNS, _val) -> _val.
 +
 +decode_mam_always(__TopXMLNS, __IgnoreEls,
 +                {xmlel, <<"always">>, _attrs, _els}) ->
 +    Jids = decode_mam_always_els(__TopXMLNS, __IgnoreEls,
 +                               _els, []),
 +    Jids.
 +
 +decode_mam_always_els(__TopXMLNS, __IgnoreEls, [],
 +                    Jids) ->
 +    lists:reverse(Jids);
 +decode_mam_always_els(__TopXMLNS, __IgnoreEls,
 +                    [{xmlel, <<"jid">>, _attrs, _} = _el | _els], Jids) ->
 +    case get_attr(<<"xmlns">>, _attrs) of
 +      <<"">>
 +        when __TopXMLNS == <<"urn:xmpp:mam:1">>;
 +             __TopXMLNS == <<"urn:xmpp:mam:0">>;
 +             __TopXMLNS == <<"urn:xmpp:mam:tmp">> ->
 +        decode_mam_always_els(__TopXMLNS, __IgnoreEls, _els,
 +                              [decode_mam_jid(__TopXMLNS, __IgnoreEls, _el)
 +                               | Jids]);
 +      <<"urn:xmpp:mam:0">> ->
 +        decode_mam_always_els(__TopXMLNS, __IgnoreEls, _els,
 +                              [decode_mam_jid(<<"urn:xmpp:mam:0">>,
 +                                              __IgnoreEls, _el)
 +                               | Jids]);
 +      <<"urn:xmpp:mam:1">> ->
 +        decode_mam_always_els(__TopXMLNS, __IgnoreEls, _els,
 +                              [decode_mam_jid(<<"urn:xmpp:mam:1">>,
 +                                              __IgnoreEls, _el)
 +                               | Jids]);
 +      <<"urn:xmpp:mam:tmp">> ->
 +        decode_mam_always_els(__TopXMLNS, __IgnoreEls, _els,
 +                              [decode_mam_jid(<<"urn:xmpp:mam:tmp">>,
 +                                              __IgnoreEls, _el)
 +                               | Jids]);
 +      _ ->
 +        decode_mam_always_els(__TopXMLNS, __IgnoreEls, _els,
 +                              Jids)
 +    end;
 +decode_mam_always_els(__TopXMLNS, __IgnoreEls,
 +                    [_ | _els], Jids) ->
 +    decode_mam_always_els(__TopXMLNS, __IgnoreEls, _els,
 +                        Jids).
 +
 +encode_mam_always(Jids, __TopXMLNS) ->
 +    __NewTopXMLNS = choose_top_xmlns(<<>>,
 +                                   [<<"urn:xmpp:mam:0">>,
 +                                    <<"urn:xmpp:mam:1">>,
 +                                    <<"urn:xmpp:mam:tmp">>],
 +                                   __TopXMLNS),
 +    _els = lists:reverse('encode_mam_always_$jids'(Jids,
 +                                                 __NewTopXMLNS, [])),
 +    _attrs = enc_xmlns_attrs(__NewTopXMLNS, __TopXMLNS),
 +    {xmlel, <<"always">>, _attrs, _els}.
 +
 +'encode_mam_always_$jids'([], __TopXMLNS, _acc) -> _acc;
 +'encode_mam_always_$jids'([Jids | _els], __TopXMLNS,
 +                        _acc) ->
 +    'encode_mam_always_$jids'(_els, __TopXMLNS,
 +                            [encode_mam_jid(Jids, __TopXMLNS) | _acc]).
 +
 +decode_mam_never(__TopXMLNS, __IgnoreEls,
 +               {xmlel, <<"never">>, _attrs, _els}) ->
 +    Jids = decode_mam_never_els(__TopXMLNS, __IgnoreEls,
 +                              _els, []),
 +    Jids.
 +
 +decode_mam_never_els(__TopXMLNS, __IgnoreEls, [],
 +                   Jids) ->
 +    lists:reverse(Jids);
 +decode_mam_never_els(__TopXMLNS, __IgnoreEls,
 +                   [{xmlel, <<"jid">>, _attrs, _} = _el | _els], Jids) ->
 +    case get_attr(<<"xmlns">>, _attrs) of
 +      <<"">>
 +        when __TopXMLNS == <<"urn:xmpp:mam:1">>;
 +             __TopXMLNS == <<"urn:xmpp:mam:0">>;
 +             __TopXMLNS == <<"urn:xmpp:mam:tmp">> ->
 +        decode_mam_never_els(__TopXMLNS, __IgnoreEls, _els,
 +                             [decode_mam_jid(__TopXMLNS, __IgnoreEls, _el)
 +                              | Jids]);
 +      <<"urn:xmpp:mam:0">> ->
 +        decode_mam_never_els(__TopXMLNS, __IgnoreEls, _els,
 +                             [decode_mam_jid(<<"urn:xmpp:mam:0">>,
 +                                             __IgnoreEls, _el)
 +                              | Jids]);
 +      <<"urn:xmpp:mam:1">> ->
 +        decode_mam_never_els(__TopXMLNS, __IgnoreEls, _els,
 +                             [decode_mam_jid(<<"urn:xmpp:mam:1">>,
 +                                             __IgnoreEls, _el)
 +                              | Jids]);
 +      <<"urn:xmpp:mam:tmp">> ->
 +        decode_mam_never_els(__TopXMLNS, __IgnoreEls, _els,
 +                             [decode_mam_jid(<<"urn:xmpp:mam:tmp">>,
 +                                             __IgnoreEls, _el)
 +                              | Jids]);
 +      _ ->
 +        decode_mam_never_els(__TopXMLNS, __IgnoreEls, _els,
 +                             Jids)
 +    end;
 +decode_mam_never_els(__TopXMLNS, __IgnoreEls,
 +                   [_ | _els], Jids) ->
 +    decode_mam_never_els(__TopXMLNS, __IgnoreEls, _els,
 +                       Jids).
 +
 +encode_mam_never(Jids, __TopXMLNS) ->
 +    __NewTopXMLNS = choose_top_xmlns(<<>>,
 +                                   [<<"urn:xmpp:mam:0">>,
 +                                    <<"urn:xmpp:mam:1">>,
 +                                    <<"urn:xmpp:mam:tmp">>],
 +                                   __TopXMLNS),
 +    _els = lists:reverse('encode_mam_never_$jids'(Jids,
 +                                                __NewTopXMLNS, [])),
 +    _attrs = enc_xmlns_attrs(__NewTopXMLNS, __TopXMLNS),
 +    {xmlel, <<"never">>, _attrs, _els}.
 +
 +'encode_mam_never_$jids'([], __TopXMLNS, _acc) -> _acc;
 +'encode_mam_never_$jids'([Jids | _els], __TopXMLNS,
 +                       _acc) ->
 +    'encode_mam_never_$jids'(_els, __TopXMLNS,
 +                           [encode_mam_jid(Jids, __TopXMLNS) | _acc]).
 +
 +decode_mam_jid(__TopXMLNS, __IgnoreEls,
 +             {xmlel, <<"jid">>, _attrs, _els}) ->
 +    Cdata = decode_mam_jid_els(__TopXMLNS, __IgnoreEls,
 +                             _els, <<>>),
 +    Cdata.
 +
 +decode_mam_jid_els(__TopXMLNS, __IgnoreEls, [],
 +                 Cdata) ->
 +    decode_mam_jid_cdata(__TopXMLNS, Cdata);
 +decode_mam_jid_els(__TopXMLNS, __IgnoreEls,
 +                 [{xmlcdata, _data} | _els], Cdata) ->
 +    decode_mam_jid_els(__TopXMLNS, __IgnoreEls, _els,
 +                     <<Cdata/binary, _data/binary>>);
 +decode_mam_jid_els(__TopXMLNS, __IgnoreEls, [_ | _els],
 +                 Cdata) ->
 +    decode_mam_jid_els(__TopXMLNS, __IgnoreEls, _els,
 +                     Cdata).
 +
 +encode_mam_jid(Cdata, __TopXMLNS) ->
 +    __NewTopXMLNS = choose_top_xmlns(<<>>,
 +                                   [<<"urn:xmpp:mam:0">>,
 +                                    <<"urn:xmpp:mam:1">>,
 +                                    <<"urn:xmpp:mam:tmp">>],
 +                                   __TopXMLNS),
 +    _els = encode_mam_jid_cdata(Cdata, []),
 +    _attrs = enc_xmlns_attrs(__NewTopXMLNS, __TopXMLNS),
 +    {xmlel, <<"jid">>, _attrs, _els}.
 +
 +decode_mam_jid_cdata(__TopXMLNS, <<>>) ->
 +    erlang:error({xmpp_codec,
 +                {missing_cdata, <<>>, <<"jid">>, __TopXMLNS}});
 +decode_mam_jid_cdata(__TopXMLNS, _val) ->
 +    case catch dec_jid(_val) of
 +      {'EXIT', _} ->
 +        erlang:error({xmpp_codec,
 +                      {bad_cdata_value, <<>>, <<"jid">>, __TopXMLNS}});
 +      _res -> _res
 +    end.
 +
 +encode_mam_jid_cdata(_val, _acc) ->
 +    [{xmlcdata, enc_jid(_val)} | _acc].
 +
 +decode_mam_result(__TopXMLNS, __IgnoreEls,
 +                {xmlel, <<"result">>, _attrs, _els}) ->
 +    __Els = decode_mam_result_els(__TopXMLNS, __IgnoreEls,
 +                                _els, []),
 +    {Queryid, Xmlns, Id} =
 +      decode_mam_result_attrs(__TopXMLNS, _attrs, undefined,
 +                              undefined, undefined),
 +    {mam_result, Xmlns, Queryid, Id, __Els}.
 +
 +decode_mam_result_els(__TopXMLNS, __IgnoreEls, [],
 +                    __Els) ->
 +    lists:reverse(__Els);
 +decode_mam_result_els(__TopXMLNS, __IgnoreEls,
 +                    [{xmlel, _, _, _} = _el | _els], __Els) ->
 +    if __IgnoreEls ->
 +         decode_mam_result_els(__TopXMLNS, __IgnoreEls, _els,
 +                               [_el | __Els]);
 +       true ->
 +         case is_known_tag(_el, __TopXMLNS) of
 +           true ->
 +               decode_mam_result_els(__TopXMLNS, __IgnoreEls, _els,
 +                                     [decode(_el, __TopXMLNS, []) | __Els]);
 +           false ->
 +               decode_mam_result_els(__TopXMLNS, __IgnoreEls, _els,
 +                                     __Els)
 +         end
 +    end;
 +decode_mam_result_els(__TopXMLNS, __IgnoreEls,
 +                    [_ | _els], __Els) ->
 +    decode_mam_result_els(__TopXMLNS, __IgnoreEls, _els,
 +                        __Els).
 +
 +decode_mam_result_attrs(__TopXMLNS,
 +                      [{<<"queryid">>, _val} | _attrs], _Queryid, Xmlns,
 +                      Id) ->
 +    decode_mam_result_attrs(__TopXMLNS, _attrs, _val, Xmlns,
 +                          Id);
 +decode_mam_result_attrs(__TopXMLNS,
 +                      [{<<"xmlns">>, _val} | _attrs], Queryid, _Xmlns, Id) ->
 +    decode_mam_result_attrs(__TopXMLNS, _attrs, Queryid,
 +                          _val, Id);
 +decode_mam_result_attrs(__TopXMLNS,
 +                      [{<<"id">>, _val} | _attrs], Queryid, Xmlns, _Id) ->
 +    decode_mam_result_attrs(__TopXMLNS, _attrs, Queryid,
 +                          Xmlns, _val);
 +decode_mam_result_attrs(__TopXMLNS, [_ | _attrs],
 +                      Queryid, Xmlns, Id) ->
 +    decode_mam_result_attrs(__TopXMLNS, _attrs, Queryid,
 +                          Xmlns, Id);
 +decode_mam_result_attrs(__TopXMLNS, [], Queryid, Xmlns,
 +                      Id) ->
 +    {decode_mam_result_attr_queryid(__TopXMLNS, Queryid),
 +     decode_mam_result_attr_xmlns(__TopXMLNS, Xmlns),
 +     decode_mam_result_attr_id(__TopXMLNS, Id)}.
 +
 +encode_mam_result({mam_result, Xmlns, Queryid, Id,
 +                 __Els},
 +                __TopXMLNS) ->
 +    __NewTopXMLNS = choose_top_xmlns(Xmlns,
 +                                   [<<"urn:xmpp:mam:0">>,
 +                                    <<"urn:xmpp:mam:1">>,
 +                                    <<"urn:xmpp:mam:tmp">>],
 +                                   __TopXMLNS),
 +    _els = [encode(_el, __NewTopXMLNS) || _el <- __Els],
 +    _attrs = encode_mam_result_attr_id(Id,
 +                                     encode_mam_result_attr_queryid(Queryid,
 +                                                                    enc_xmlns_attrs(__NewTopXMLNS,
 +                                                                                    __TopXMLNS))),
 +    {xmlel, <<"result">>, _attrs, _els}.
 +
 +decode_mam_result_attr_queryid(__TopXMLNS, undefined) ->
 +    <<>>;
 +decode_mam_result_attr_queryid(__TopXMLNS, _val) ->
 +    _val.
 +
 +encode_mam_result_attr_queryid(<<>>, _acc) -> _acc;
 +encode_mam_result_attr_queryid(_val, _acc) ->
 +    [{<<"queryid">>, _val} | _acc].
 +
 +decode_mam_result_attr_xmlns(__TopXMLNS, undefined) ->
 +    <<>>;
 +decode_mam_result_attr_xmlns(__TopXMLNS, _val) -> _val.
 +
 +decode_mam_result_attr_id(__TopXMLNS, undefined) ->
 +    <<>>;
 +decode_mam_result_attr_id(__TopXMLNS, _val) -> _val.
 +
 +encode_mam_result_attr_id(<<>>, _acc) -> _acc;
 +encode_mam_result_attr_id(_val, _acc) ->
 +    [{<<"id">>, _val} | _acc].
 +
 +decode_mam_archived(__TopXMLNS, __IgnoreEls,
 +                  {xmlel, <<"archived">>, _attrs, _els}) ->
 +    {Id, By} = decode_mam_archived_attrs(__TopXMLNS, _attrs,
 +                                       undefined, undefined),
 +    {mam_archived, By, Id}.
 +
 +decode_mam_archived_attrs(__TopXMLNS,
 +                        [{<<"id">>, _val} | _attrs], _Id, By) ->
 +    decode_mam_archived_attrs(__TopXMLNS, _attrs, _val, By);
 +decode_mam_archived_attrs(__TopXMLNS,
 +                        [{<<"by">>, _val} | _attrs], Id, _By) ->
 +    decode_mam_archived_attrs(__TopXMLNS, _attrs, Id, _val);
 +decode_mam_archived_attrs(__TopXMLNS, [_ | _attrs], Id,
 +                        By) ->
 +    decode_mam_archived_attrs(__TopXMLNS, _attrs, Id, By);
 +decode_mam_archived_attrs(__TopXMLNS, [], Id, By) ->
 +    {decode_mam_archived_attr_id(__TopXMLNS, Id),
 +     decode_mam_archived_attr_by(__TopXMLNS, By)}.
 +
 +encode_mam_archived({mam_archived, By, Id},
 +                  __TopXMLNS) ->
 +    __NewTopXMLNS = choose_top_xmlns(<<"urn:xmpp:mam:tmp">>,
 +                                   [], __TopXMLNS),
 +    _els = [],
 +    _attrs = encode_mam_archived_attr_by(By,
 +                                       encode_mam_archived_attr_id(Id,
 +                                                                   enc_xmlns_attrs(__NewTopXMLNS,
 +                                                                                   __TopXMLNS))),
 +    {xmlel, <<"archived">>, _attrs, _els}.
 +
 +decode_mam_archived_attr_id(__TopXMLNS, undefined) ->
 +    <<>>;
 +decode_mam_archived_attr_id(__TopXMLNS, _val) -> _val.
 +
 +encode_mam_archived_attr_id(<<>>, _acc) -> _acc;
 +encode_mam_archived_attr_id(_val, _acc) ->
 +    [{<<"id">>, _val} | _acc].
 +
 +decode_mam_archived_attr_by(__TopXMLNS, undefined) ->
 +    erlang:error({xmpp_codec,
 +                {missing_attr, <<"by">>, <<"archived">>, __TopXMLNS}});
 +decode_mam_archived_attr_by(__TopXMLNS, _val) ->
 +    case catch dec_jid(_val) of
 +      {'EXIT', _} ->
 +        erlang:error({xmpp_codec,
 +                      {bad_attr_value, <<"by">>, <<"archived">>,
 +                       __TopXMLNS}});
 +      _res -> _res
 +    end.
 +
 +encode_mam_archived_attr_by(_val, _acc) ->
 +    [{<<"by">>, enc_jid(_val)} | _acc].
 +
 +decode_mam_query(__TopXMLNS, __IgnoreEls,
 +               {xmlel, <<"query">>, _attrs, _els}) ->
 +    {Xdata, Withtext, End, Start, With, Rsm} =
 +      decode_mam_query_els(__TopXMLNS, __IgnoreEls, _els,
 +                           undefined, undefined, undefined, undefined,
 +                           undefined, undefined),
 +    {Id, Xmlns} = decode_mam_query_attrs(__TopXMLNS, _attrs,
 +                                       undefined, undefined),
 +    {mam_query, Xmlns, Id, Start, End, With, Withtext, Rsm,
 +     Xdata}.
 +
 +decode_mam_query_els(__TopXMLNS, __IgnoreEls, [], Xdata,
 +                   Withtext, End, Start, With, Rsm) ->
 +    {Xdata, Withtext, End, Start, With, Rsm};
 +decode_mam_query_els(__TopXMLNS, __IgnoreEls,
 +                   [{xmlel, <<"start">>, _attrs, _} = _el | _els], Xdata,
 +                   Withtext, End, Start, With, Rsm) ->
 +    case get_attr(<<"xmlns">>, _attrs) of
 +      <<"">> when __TopXMLNS == <<"urn:xmpp:mam:tmp">> ->
 +        decode_mam_query_els(__TopXMLNS, __IgnoreEls, _els,
 +                             Xdata, Withtext, End,
 +                             decode_mam_start(__TopXMLNS, __IgnoreEls, _el),
 +                             With, Rsm);
 +      <<"urn:xmpp:mam:tmp">> ->
 +        decode_mam_query_els(__TopXMLNS, __IgnoreEls, _els,
 +                             Xdata, Withtext, End,
 +                             decode_mam_start(<<"urn:xmpp:mam:tmp">>,
 +                                              __IgnoreEls, _el),
 +                             With, Rsm);
 +      _ ->
 +        decode_mam_query_els(__TopXMLNS, __IgnoreEls, _els,
 +                             Xdata, Withtext, End, Start, With, Rsm)
 +    end;
 +decode_mam_query_els(__TopXMLNS, __IgnoreEls,
 +                   [{xmlel, <<"end">>, _attrs, _} = _el | _els], Xdata,
 +                   Withtext, End, Start, With, Rsm) ->
 +    case get_attr(<<"xmlns">>, _attrs) of
 +      <<"">> when __TopXMLNS == <<"urn:xmpp:mam:tmp">> ->
 +        decode_mam_query_els(__TopXMLNS, __IgnoreEls, _els,
 +                             Xdata, Withtext,
 +                             decode_mam_end(__TopXMLNS, __IgnoreEls, _el),
 +                             Start, With, Rsm);
 +      <<"urn:xmpp:mam:tmp">> ->
 +        decode_mam_query_els(__TopXMLNS, __IgnoreEls, _els,
 +                             Xdata, Withtext,
 +                             decode_mam_end(<<"urn:xmpp:mam:tmp">>,
 +                                            __IgnoreEls, _el),
 +                             Start, With, Rsm);
 +      _ ->
 +        decode_mam_query_els(__TopXMLNS, __IgnoreEls, _els,
 +                             Xdata, Withtext, End, Start, With, Rsm)
 +    end;
 +decode_mam_query_els(__TopXMLNS, __IgnoreEls,
 +                   [{xmlel, <<"with">>, _attrs, _} = _el | _els], Xdata,
 +                   Withtext, End, Start, With, Rsm) ->
 +    case get_attr(<<"xmlns">>, _attrs) of
 +      <<"">> when __TopXMLNS == <<"urn:xmpp:mam:tmp">> ->
 +        decode_mam_query_els(__TopXMLNS, __IgnoreEls, _els,
 +                             Xdata, Withtext, End, Start,
 +                             decode_mam_with(__TopXMLNS, __IgnoreEls, _el),
 +                             Rsm);
 +      <<"urn:xmpp:mam:tmp">> ->
 +        decode_mam_query_els(__TopXMLNS, __IgnoreEls, _els,
 +                             Xdata, Withtext, End, Start,
 +                             decode_mam_with(<<"urn:xmpp:mam:tmp">>,
 +                                             __IgnoreEls, _el),
 +                             Rsm);
 +      _ ->
 +        decode_mam_query_els(__TopXMLNS, __IgnoreEls, _els,
 +                             Xdata, Withtext, End, Start, With, Rsm)
 +    end;
 +decode_mam_query_els(__TopXMLNS, __IgnoreEls,
 +                   [{xmlel, <<"withtext">>, _attrs, _} = _el | _els],
 +                   Xdata, Withtext, End, Start, With, Rsm) ->
 +    case get_attr(<<"xmlns">>, _attrs) of
 +      <<"">> when __TopXMLNS == <<"urn:xmpp:mam:tmp">> ->
 +        decode_mam_query_els(__TopXMLNS, __IgnoreEls, _els,
 +                             Xdata,
 +                             decode_mam_withtext(__TopXMLNS, __IgnoreEls,
 +                                                 _el),
 +                             End, Start, With, Rsm);
 +      <<"urn:xmpp:mam:tmp">> ->
 +        decode_mam_query_els(__TopXMLNS, __IgnoreEls, _els,
 +                             Xdata,
 +                             decode_mam_withtext(<<"urn:xmpp:mam:tmp">>,
 +                                                 __IgnoreEls, _el),
 +                             End, Start, With, Rsm);
 +      _ ->
 +        decode_mam_query_els(__TopXMLNS, __IgnoreEls, _els,
 +                             Xdata, Withtext, End, Start, With, Rsm)
 +    end;
 +decode_mam_query_els(__TopXMLNS, __IgnoreEls,
 +                   [{xmlel, <<"set">>, _attrs, _} = _el | _els], Xdata,
 +                   Withtext, End, Start, With, Rsm) ->
 +    case get_attr(<<"xmlns">>, _attrs) of
 +      <<"http://jabber.org/protocol/rsm">> ->
 +        decode_mam_query_els(__TopXMLNS, __IgnoreEls, _els,
 +                             Xdata, Withtext, End, Start, With,
 +                             decode_rsm_set(<<"http://jabber.org/protocol/rsm">>,
 +                                            __IgnoreEls, _el));
 +      _ ->
 +        decode_mam_query_els(__TopXMLNS, __IgnoreEls, _els,
 +                             Xdata, Withtext, End, Start, With, Rsm)
 +    end;
 +decode_mam_query_els(__TopXMLNS, __IgnoreEls,
 +                   [{xmlel, <<"x">>, _attrs, _} = _el | _els], Xdata,
 +                   Withtext, End, Start, With, Rsm) ->
 +    case get_attr(<<"xmlns">>, _attrs) of
 +      <<"jabber:x:data">> ->
 +        decode_mam_query_els(__TopXMLNS, __IgnoreEls, _els,
 +                             decode_xdata(<<"jabber:x:data">>, __IgnoreEls,
 +                                          _el),
 +                             Withtext, End, Start, With, Rsm);
 +      _ ->
 +        decode_mam_query_els(__TopXMLNS, __IgnoreEls, _els,
 +                             Xdata, Withtext, End, Start, With, Rsm)
 +    end;
 +decode_mam_query_els(__TopXMLNS, __IgnoreEls,
 +                   [_ | _els], Xdata, Withtext, End, Start, With, Rsm) ->
 +    decode_mam_query_els(__TopXMLNS, __IgnoreEls, _els,
 +                       Xdata, Withtext, End, Start, With, Rsm).
 +
 +decode_mam_query_attrs(__TopXMLNS,
 +                     [{<<"queryid">>, _val} | _attrs], _Id, Xmlns) ->
 +    decode_mam_query_attrs(__TopXMLNS, _attrs, _val, Xmlns);
 +decode_mam_query_attrs(__TopXMLNS,
 +                     [{<<"xmlns">>, _val} | _attrs], Id, _Xmlns) ->
 +    decode_mam_query_attrs(__TopXMLNS, _attrs, Id, _val);
 +decode_mam_query_attrs(__TopXMLNS, [_ | _attrs], Id,
 +                     Xmlns) ->
 +    decode_mam_query_attrs(__TopXMLNS, _attrs, Id, Xmlns);
 +decode_mam_query_attrs(__TopXMLNS, [], Id, Xmlns) ->
 +    {decode_mam_query_attr_queryid(__TopXMLNS, Id),
 +     decode_mam_query_attr_xmlns(__TopXMLNS, Xmlns)}.
 +
 +encode_mam_query({mam_query, Xmlns, Id, Start, End,
 +                With, Withtext, Rsm, Xdata},
 +               __TopXMLNS) ->
 +    __NewTopXMLNS = choose_top_xmlns(Xmlns,
 +                                   [<<"urn:xmpp:mam:0">>,
 +                                    <<"urn:xmpp:mam:1">>,
 +                                    <<"urn:xmpp:mam:tmp">>],
 +                                   __TopXMLNS),
 +    _els = lists:reverse('encode_mam_query_$xdata'(Xdata,
 +                                                 __NewTopXMLNS,
 +                                                 'encode_mam_query_$withtext'(Withtext,
 +                                                                              __NewTopXMLNS,
 +                                                                              'encode_mam_query_$end'(End,
 +                                                                                                      __NewTopXMLNS,
 +                                                                                                      'encode_mam_query_$start'(Start,
 +                                                                                                                                __NewTopXMLNS,
 +                                                                                                                                'encode_mam_query_$with'(With,
 +                                                                                                                                                         __NewTopXMLNS,
 +                                                                                                                                                         'encode_mam_query_$rsm'(Rsm,
 +                                                                                                                                                                                 __NewTopXMLNS,
 +                                                                                                                                                                                 []))))))),
 +    _attrs = encode_mam_query_attr_queryid(Id,
 +                                         enc_xmlns_attrs(__NewTopXMLNS,
 +                                                         __TopXMLNS)),
 +    {xmlel, <<"query">>, _attrs, _els}.
 +
 +'encode_mam_query_$xdata'(undefined, __TopXMLNS,
 +                        _acc) ->
 +    _acc;
 +'encode_mam_query_$xdata'(Xdata, __TopXMLNS, _acc) ->
 +    [encode_xdata(Xdata, __TopXMLNS) | _acc].
 +
 +'encode_mam_query_$withtext'(undefined, __TopXMLNS,
 +                           _acc) ->
 +    _acc;
 +'encode_mam_query_$withtext'(Withtext, __TopXMLNS,
 +                           _acc) ->
 +    [encode_mam_withtext(Withtext, __TopXMLNS) | _acc].
 +
 +'encode_mam_query_$end'(undefined, __TopXMLNS, _acc) ->
 +    _acc;
 +'encode_mam_query_$end'(End, __TopXMLNS, _acc) ->
 +    [encode_mam_end(End, __TopXMLNS) | _acc].
 +
 +'encode_mam_query_$start'(undefined, __TopXMLNS,
 +                        _acc) ->
 +    _acc;
 +'encode_mam_query_$start'(Start, __TopXMLNS, _acc) ->
 +    [encode_mam_start(Start, __TopXMLNS) | _acc].
 +
 +'encode_mam_query_$with'(undefined, __TopXMLNS, _acc) ->
 +    _acc;
 +'encode_mam_query_$with'(With, __TopXMLNS, _acc) ->
 +    [encode_mam_with(With, __TopXMLNS) | _acc].
 +
 +'encode_mam_query_$rsm'(undefined, __TopXMLNS, _acc) ->
 +    _acc;
 +'encode_mam_query_$rsm'(Rsm, __TopXMLNS, _acc) ->
 +    [encode_rsm_set(Rsm, __TopXMLNS) | _acc].
 +
 +decode_mam_query_attr_queryid(__TopXMLNS, undefined) ->
 +    <<>>;
 +decode_mam_query_attr_queryid(__TopXMLNS, _val) -> _val.
 +
 +encode_mam_query_attr_queryid(<<>>, _acc) -> _acc;
 +encode_mam_query_attr_queryid(_val, _acc) ->
 +    [{<<"queryid">>, _val} | _acc].
 +
 +decode_mam_query_attr_xmlns(__TopXMLNS, undefined) ->
 +    <<>>;
 +decode_mam_query_attr_xmlns(__TopXMLNS, _val) -> _val.
 +
 +decode_mam_withtext(__TopXMLNS, __IgnoreEls,
 +                  {xmlel, <<"withtext">>, _attrs, _els}) ->
 +    Cdata = decode_mam_withtext_els(__TopXMLNS, __IgnoreEls,
 +                                  _els, <<>>),
 +    Cdata.
 +
 +decode_mam_withtext_els(__TopXMLNS, __IgnoreEls, [],
 +                      Cdata) ->
 +    decode_mam_withtext_cdata(__TopXMLNS, Cdata);
 +decode_mam_withtext_els(__TopXMLNS, __IgnoreEls,
 +                      [{xmlcdata, _data} | _els], Cdata) ->
 +    decode_mam_withtext_els(__TopXMLNS, __IgnoreEls, _els,
 +                          <<Cdata/binary, _data/binary>>);
 +decode_mam_withtext_els(__TopXMLNS, __IgnoreEls,
 +                      [_ | _els], Cdata) ->
 +    decode_mam_withtext_els(__TopXMLNS, __IgnoreEls, _els,
 +                          Cdata).
 +
 +encode_mam_withtext(Cdata, __TopXMLNS) ->
 +    __NewTopXMLNS = choose_top_xmlns(<<"urn:xmpp:mam:tmp">>,
 +                                   [], __TopXMLNS),
 +    _els = encode_mam_withtext_cdata(Cdata, []),
 +    _attrs = enc_xmlns_attrs(__NewTopXMLNS, __TopXMLNS),
 +    {xmlel, <<"withtext">>, _attrs, _els}.
 +
 +decode_mam_withtext_cdata(__TopXMLNS, <<>>) ->
 +    erlang:error({xmpp_codec,
 +                {missing_cdata, <<>>, <<"withtext">>, __TopXMLNS}});
 +decode_mam_withtext_cdata(__TopXMLNS, _val) -> _val.
 +
 +encode_mam_withtext_cdata(_val, _acc) ->
 +    [{xmlcdata, _val} | _acc].
 +
 +decode_mam_with(__TopXMLNS, __IgnoreEls,
 +              {xmlel, <<"with">>, _attrs, _els}) ->
 +    Cdata = decode_mam_with_els(__TopXMLNS, __IgnoreEls,
 +                              _els, <<>>),
 +    Cdata.
 +
 +decode_mam_with_els(__TopXMLNS, __IgnoreEls, [],
 +                  Cdata) ->
 +    decode_mam_with_cdata(__TopXMLNS, Cdata);
 +decode_mam_with_els(__TopXMLNS, __IgnoreEls,
 +                  [{xmlcdata, _data} | _els], Cdata) ->
 +    decode_mam_with_els(__TopXMLNS, __IgnoreEls, _els,
 +                      <<Cdata/binary, _data/binary>>);
 +decode_mam_with_els(__TopXMLNS, __IgnoreEls, [_ | _els],
 +                  Cdata) ->
 +    decode_mam_with_els(__TopXMLNS, __IgnoreEls, _els,
 +                      Cdata).
 +
 +encode_mam_with(Cdata, __TopXMLNS) ->
 +    __NewTopXMLNS = choose_top_xmlns(<<"urn:xmpp:mam:tmp">>,
 +                                   [], __TopXMLNS),
 +    _els = encode_mam_with_cdata(Cdata, []),
 +    _attrs = enc_xmlns_attrs(__NewTopXMLNS, __TopXMLNS),
 +    {xmlel, <<"with">>, _attrs, _els}.
 +
 +decode_mam_with_cdata(__TopXMLNS, <<>>) ->
 +    erlang:error({xmpp_codec,
 +                {missing_cdata, <<>>, <<"with">>, __TopXMLNS}});
 +decode_mam_with_cdata(__TopXMLNS, _val) ->
 +    case catch dec_jid(_val) of
 +      {'EXIT', _} ->
 +        erlang:error({xmpp_codec,
 +                      {bad_cdata_value, <<>>, <<"with">>, __TopXMLNS}});
 +      _res -> _res
 +    end.
 +
 +encode_mam_with_cdata(_val, _acc) ->
 +    [{xmlcdata, enc_jid(_val)} | _acc].
 +
 +decode_mam_end(__TopXMLNS, __IgnoreEls,
 +             {xmlel, <<"end">>, _attrs, _els}) ->
 +    Cdata = decode_mam_end_els(__TopXMLNS, __IgnoreEls,
 +                             _els, <<>>),
 +    Cdata.
 +
 +decode_mam_end_els(__TopXMLNS, __IgnoreEls, [],
 +                 Cdata) ->
 +    decode_mam_end_cdata(__TopXMLNS, Cdata);
 +decode_mam_end_els(__TopXMLNS, __IgnoreEls,
 +                 [{xmlcdata, _data} | _els], Cdata) ->
 +    decode_mam_end_els(__TopXMLNS, __IgnoreEls, _els,
 +                     <<Cdata/binary, _data/binary>>);
 +decode_mam_end_els(__TopXMLNS, __IgnoreEls, [_ | _els],
 +                 Cdata) ->
 +    decode_mam_end_els(__TopXMLNS, __IgnoreEls, _els,
 +                     Cdata).
 +
 +encode_mam_end(Cdata, __TopXMLNS) ->
 +    __NewTopXMLNS = choose_top_xmlns(<<"urn:xmpp:mam:tmp">>,
 +                                   [], __TopXMLNS),
 +    _els = encode_mam_end_cdata(Cdata, []),
 +    _attrs = enc_xmlns_attrs(__NewTopXMLNS, __TopXMLNS),
 +    {xmlel, <<"end">>, _attrs, _els}.
 +
 +decode_mam_end_cdata(__TopXMLNS, <<>>) ->
 +    erlang:error({xmpp_codec,
 +                {missing_cdata, <<>>, <<"end">>, __TopXMLNS}});
 +decode_mam_end_cdata(__TopXMLNS, _val) ->
 +    case catch dec_utc(_val) of
 +      {'EXIT', _} ->
 +        erlang:error({xmpp_codec,
 +                      {bad_cdata_value, <<>>, <<"end">>, __TopXMLNS}});
 +      _res -> _res
 +    end.
 +
 +encode_mam_end_cdata(_val, _acc) ->
 +    [{xmlcdata, enc_utc(_val)} | _acc].
 +
 +decode_mam_start(__TopXMLNS, __IgnoreEls,
 +               {xmlel, <<"start">>, _attrs, _els}) ->
 +    Cdata = decode_mam_start_els(__TopXMLNS, __IgnoreEls,
 +                               _els, <<>>),
 +    Cdata.
 +
 +decode_mam_start_els(__TopXMLNS, __IgnoreEls, [],
 +                   Cdata) ->
 +    decode_mam_start_cdata(__TopXMLNS, Cdata);
 +decode_mam_start_els(__TopXMLNS, __IgnoreEls,
 +                   [{xmlcdata, _data} | _els], Cdata) ->
 +    decode_mam_start_els(__TopXMLNS, __IgnoreEls, _els,
 +                       <<Cdata/binary, _data/binary>>);
 +decode_mam_start_els(__TopXMLNS, __IgnoreEls,
 +                   [_ | _els], Cdata) ->
 +    decode_mam_start_els(__TopXMLNS, __IgnoreEls, _els,
 +                       Cdata).
 +
 +encode_mam_start(Cdata, __TopXMLNS) ->
 +    __NewTopXMLNS = choose_top_xmlns(<<"urn:xmpp:mam:tmp">>,
 +                                   [], __TopXMLNS),
 +    _els = encode_mam_start_cdata(Cdata, []),
 +    _attrs = enc_xmlns_attrs(__NewTopXMLNS, __TopXMLNS),
 +    {xmlel, <<"start">>, _attrs, _els}.
 +
 +decode_mam_start_cdata(__TopXMLNS, <<>>) ->
 +    erlang:error({xmpp_codec,
 +                {missing_cdata, <<>>, <<"start">>, __TopXMLNS}});
 +decode_mam_start_cdata(__TopXMLNS, _val) ->
 +    case catch dec_utc(_val) of
 +      {'EXIT', _} ->
 +        erlang:error({xmpp_codec,
 +                      {bad_cdata_value, <<>>, <<"start">>, __TopXMLNS}});
 +      _res -> _res
 +    end.
 +
 +encode_mam_start_cdata(_val, _acc) ->
 +    [{xmlcdata, enc_utc(_val)} | _acc].
 +
 +decode_rsm_set(__TopXMLNS, __IgnoreEls,
 +             {xmlel, <<"set">>, _attrs, _els}) ->
 +    {After, Last, First, Count, Before, Max, Index} =
 +      decode_rsm_set_els(__TopXMLNS, __IgnoreEls, _els,
 +                         undefined, undefined, undefined, undefined,
 +                         undefined, undefined, undefined),
 +    {rsm_set, After, Before, Count, First, Index, Last,
 +     Max}.
 +
 +decode_rsm_set_els(__TopXMLNS, __IgnoreEls, [], After,
 +                 Last, First, Count, Before, Max, Index) ->
 +    {After, Last, First, Count, Before, Max, Index};
 +decode_rsm_set_els(__TopXMLNS, __IgnoreEls,
 +                 [{xmlel, <<"after">>, _attrs, _} = _el | _els], After,
 +                 Last, First, Count, Before, Max, Index) ->
 +    case get_attr(<<"xmlns">>, _attrs) of
 +      <<"">>
 +        when __TopXMLNS ==
 +               <<"http://jabber.org/protocol/rsm">> ->
 +        decode_rsm_set_els(__TopXMLNS, __IgnoreEls, _els,
 +                           decode_rsm_after(__TopXMLNS, __IgnoreEls, _el),
 +                           Last, First, Count, Before, Max, Index);
 +      <<"http://jabber.org/protocol/rsm">> ->
 +        decode_rsm_set_els(__TopXMLNS, __IgnoreEls, _els,
 +                           decode_rsm_after(<<"http://jabber.org/protocol/rsm">>,
 +                                            __IgnoreEls, _el),
 +                           Last, First, Count, Before, Max, Index);
 +      _ ->
 +        decode_rsm_set_els(__TopXMLNS, __IgnoreEls, _els, After,
 +                           Last, First, Count, Before, Max, Index)
 +    end;
 +decode_rsm_set_els(__TopXMLNS, __IgnoreEls,
 +                 [{xmlel, <<"before">>, _attrs, _} = _el | _els], After,
 +                 Last, First, Count, Before, Max, Index) ->
 +    case get_attr(<<"xmlns">>, _attrs) of
 +      <<"">>
 +        when __TopXMLNS ==
 +               <<"http://jabber.org/protocol/rsm">> ->
 +        decode_rsm_set_els(__TopXMLNS, __IgnoreEls, _els, After,
 +                           Last, First, Count,
 +                           decode_rsm_before(__TopXMLNS, __IgnoreEls, _el),
 +                           Max, Index);
 +      <<"http://jabber.org/protocol/rsm">> ->
 +        decode_rsm_set_els(__TopXMLNS, __IgnoreEls, _els, After,
 +                           Last, First, Count,
 +                           decode_rsm_before(<<"http://jabber.org/protocol/rsm">>,
 +                                             __IgnoreEls, _el),
 +                           Max, Index);
 +      _ ->
 +        decode_rsm_set_els(__TopXMLNS, __IgnoreEls, _els, After,
 +                           Last, First, Count, Before, Max, Index)
 +    end;
 +decode_rsm_set_els(__TopXMLNS, __IgnoreEls,
 +                 [{xmlel, <<"count">>, _attrs, _} = _el | _els], After,
 +                 Last, First, Count, Before, Max, Index) ->
 +    case get_attr(<<"xmlns">>, _attrs) of
 +      <<"">>
 +        when __TopXMLNS ==
 +               <<"http://jabber.org/protocol/rsm">> ->
 +        decode_rsm_set_els(__TopXMLNS, __IgnoreEls, _els, After,
 +                           Last, First,
 +                           decode_rsm_count(__TopXMLNS, __IgnoreEls, _el),
 +                           Before, Max, Index);
 +      <<"http://jabber.org/protocol/rsm">> ->
 +        decode_rsm_set_els(__TopXMLNS, __IgnoreEls, _els, After,
 +                           Last, First,
 +                           decode_rsm_count(<<"http://jabber.org/protocol/rsm">>,
 +                                            __IgnoreEls, _el),
 +                           Before, Max, Index);
 +      _ ->
 +        decode_rsm_set_els(__TopXMLNS, __IgnoreEls, _els, After,
 +                           Last, First, Count, Before, Max, Index)
 +    end;
 +decode_rsm_set_els(__TopXMLNS, __IgnoreEls,
 +                 [{xmlel, <<"first">>, _attrs, _} = _el | _els], After,
 +                 Last, First, Count, Before, Max, Index) ->
 +    case get_attr(<<"xmlns">>, _attrs) of
 +      <<"">>
 +        when __TopXMLNS ==
 +               <<"http://jabber.org/protocol/rsm">> ->
 +        decode_rsm_set_els(__TopXMLNS, __IgnoreEls, _els, After,
 +                           Last,
 +                           decode_rsm_first(__TopXMLNS, __IgnoreEls, _el),
 +                           Count, Before, Max, Index);
 +      <<"http://jabber.org/protocol/rsm">> ->
 +        decode_rsm_set_els(__TopXMLNS, __IgnoreEls, _els, After,
 +                           Last,
 +                           decode_rsm_first(<<"http://jabber.org/protocol/rsm">>,
 +                                            __IgnoreEls, _el),
 +                           Count, Before, Max, Index);
 +      _ ->
 +        decode_rsm_set_els(__TopXMLNS, __IgnoreEls, _els, After,
 +                           Last, First, Count, Before, Max, Index)
 +    end;
 +decode_rsm_set_els(__TopXMLNS, __IgnoreEls,
 +                 [{xmlel, <<"index">>, _attrs, _} = _el | _els], After,
 +                 Last, First, Count, Before, Max, Index) ->
 +    case get_attr(<<"xmlns">>, _attrs) of
 +      <<"">>
 +        when __TopXMLNS ==
 +               <<"http://jabber.org/protocol/rsm">> ->
 +        decode_rsm_set_els(__TopXMLNS, __IgnoreEls, _els, After,
 +                           Last, First, Count, Before, Max,
 +                           decode_rsm_index(__TopXMLNS, __IgnoreEls, _el));
 +      <<"http://jabber.org/protocol/rsm">> ->
 +        decode_rsm_set_els(__TopXMLNS, __IgnoreEls, _els, After,
 +                           Last, First, Count, Before, Max,
 +                           decode_rsm_index(<<"http://jabber.org/protocol/rsm">>,
 +                                            __IgnoreEls, _el));
 +      _ ->
 +        decode_rsm_set_els(__TopXMLNS, __IgnoreEls, _els, After,
 +                           Last, First, Count, Before, Max, Index)
 +    end;
 +decode_rsm_set_els(__TopXMLNS, __IgnoreEls,
 +                 [{xmlel, <<"last">>, _attrs, _} = _el | _els], After,
 +                 Last, First, Count, Before, Max, Index) ->
 +    case get_attr(<<"xmlns">>, _attrs) of
 +      <<"">>
 +        when __TopXMLNS ==
 +               <<"http://jabber.org/protocol/rsm">> ->
 +        decode_rsm_set_els(__TopXMLNS, __IgnoreEls, _els, After,
 +                           decode_rsm_last(__TopXMLNS, __IgnoreEls, _el),
 +                           First, Count, Before, Max, Index);
 +      <<"http://jabber.org/protocol/rsm">> ->
 +        decode_rsm_set_els(__TopXMLNS, __IgnoreEls, _els, After,
 +                           decode_rsm_last(<<"http://jabber.org/protocol/rsm">>,
 +                                           __IgnoreEls, _el),
 +                           First, Count, Before, Max, Index);
 +      _ ->
 +        decode_rsm_set_els(__TopXMLNS, __IgnoreEls, _els, After,
 +                           Last, First, Count, Before, Max, Index)
 +    end;
 +decode_rsm_set_els(__TopXMLNS, __IgnoreEls,
 +                 [{xmlel, <<"max">>, _attrs, _} = _el | _els], After,
 +                 Last, First, Count, Before, Max, Index) ->
 +    case get_attr(<<"xmlns">>, _attrs) of
 +      <<"">>
 +        when __TopXMLNS ==
 +               <<"http://jabber.org/protocol/rsm">> ->
 +        decode_rsm_set_els(__TopXMLNS, __IgnoreEls, _els, After,
 +                           Last, First, Count, Before,
 +                           decode_rsm_max(__TopXMLNS, __IgnoreEls, _el),
 +                           Index);
 +      <<"http://jabber.org/protocol/rsm">> ->
 +        decode_rsm_set_els(__TopXMLNS, __IgnoreEls, _els, After,
 +                           Last, First, Count, Before,
 +                           decode_rsm_max(<<"http://jabber.org/protocol/rsm">>,
 +                                          __IgnoreEls, _el),
 +                           Index);
 +      _ ->
 +        decode_rsm_set_els(__TopXMLNS, __IgnoreEls, _els, After,
 +                           Last, First, Count, Before, Max, Index)
 +    end;
 +decode_rsm_set_els(__TopXMLNS, __IgnoreEls, [_ | _els],
 +                 After, Last, First, Count, Before, Max, Index) ->
 +    decode_rsm_set_els(__TopXMLNS, __IgnoreEls, _els, After,
 +                     Last, First, Count, Before, Max, Index).
 +
 +encode_rsm_set({rsm_set, After, Before, Count, First,
 +              Index, Last, Max},
 +             __TopXMLNS) ->
 +    __NewTopXMLNS =
 +      choose_top_xmlns(<<"http://jabber.org/protocol/rsm">>,
 +                       [], __TopXMLNS),
 +    _els = lists:reverse('encode_rsm_set_$after'(After,
 +                                               __NewTopXMLNS,
 +                                               'encode_rsm_set_$last'(Last,
 +                                                                      __NewTopXMLNS,
 +                                                                      'encode_rsm_set_$first'(First,
 +                                                                                              __NewTopXMLNS,
 +                                                                                              'encode_rsm_set_$count'(Count,
 +                                                                                                                      __NewTopXMLNS,
 +                                                                                                                      'encode_rsm_set_$before'(Before,
 +                                                                                                                                               __NewTopXMLNS,
 +                                                                                                                                               'encode_rsm_set_$max'(Max,
 +                                                                                                                                                                     __NewTopXMLNS,
 +                                                                                                                                                                     'encode_rsm_set_$index'(Index,
 +                                                                                                                                                                                             __NewTopXMLNS,
 +                                                                                                                                                                                             [])))))))),
 +    _attrs = enc_xmlns_attrs(__NewTopXMLNS, __TopXMLNS),
 +    {xmlel, <<"set">>, _attrs, _els}.
 +
 +'encode_rsm_set_$after'(undefined, __TopXMLNS, _acc) ->
 +    _acc;
 +'encode_rsm_set_$after'(After, __TopXMLNS, _acc) ->
 +    [encode_rsm_after(After, __TopXMLNS) | _acc].
 +
 +'encode_rsm_set_$last'(undefined, __TopXMLNS, _acc) ->
 +    _acc;
 +'encode_rsm_set_$last'(Last, __TopXMLNS, _acc) ->
 +    [encode_rsm_last(Last, __TopXMLNS) | _acc].
 +
 +'encode_rsm_set_$first'(undefined, __TopXMLNS, _acc) ->
 +    _acc;
 +'encode_rsm_set_$first'(First, __TopXMLNS, _acc) ->
 +    [encode_rsm_first(First, __TopXMLNS) | _acc].
 +
 +'encode_rsm_set_$count'(undefined, __TopXMLNS, _acc) ->
 +    _acc;
 +'encode_rsm_set_$count'(Count, __TopXMLNS, _acc) ->
 +    [encode_rsm_count(Count, __TopXMLNS) | _acc].
 +
 +'encode_rsm_set_$before'(undefined, __TopXMLNS, _acc) ->
 +    _acc;
 +'encode_rsm_set_$before'(Before, __TopXMLNS, _acc) ->
 +    [encode_rsm_before(Before, __TopXMLNS) | _acc].
 +
 +'encode_rsm_set_$max'(undefined, __TopXMLNS, _acc) ->
 +    _acc;
 +'encode_rsm_set_$max'(Max, __TopXMLNS, _acc) ->
 +    [encode_rsm_max(Max, __TopXMLNS) | _acc].
 +
 +'encode_rsm_set_$index'(undefined, __TopXMLNS, _acc) ->
 +    _acc;
 +'encode_rsm_set_$index'(Index, __TopXMLNS, _acc) ->
 +    [encode_rsm_index(Index, __TopXMLNS) | _acc].
 +
 +decode_rsm_first(__TopXMLNS, __IgnoreEls,
 +               {xmlel, <<"first">>, _attrs, _els}) ->
 +    Data = decode_rsm_first_els(__TopXMLNS, __IgnoreEls,
 +                              _els, <<>>),
 +    Index = decode_rsm_first_attrs(__TopXMLNS, _attrs,
 +                                 undefined),
 +    {rsm_first, Index, Data}.
 +
 +decode_rsm_first_els(__TopXMLNS, __IgnoreEls, [],
 +                   Data) ->
 +    decode_rsm_first_cdata(__TopXMLNS, Data);
 +decode_rsm_first_els(__TopXMLNS, __IgnoreEls,
 +                   [{xmlcdata, _data} | _els], Data) ->
 +    decode_rsm_first_els(__TopXMLNS, __IgnoreEls, _els,
 +                       <<Data/binary, _data/binary>>);
 +decode_rsm_first_els(__TopXMLNS, __IgnoreEls,
 +                   [_ | _els], Data) ->
 +    decode_rsm_first_els(__TopXMLNS, __IgnoreEls, _els,
 +                       Data).
 +
 +decode_rsm_first_attrs(__TopXMLNS,
 +                     [{<<"index">>, _val} | _attrs], _Index) ->
 +    decode_rsm_first_attrs(__TopXMLNS, _attrs, _val);
 +decode_rsm_first_attrs(__TopXMLNS, [_ | _attrs],
 +                     Index) ->
 +    decode_rsm_first_attrs(__TopXMLNS, _attrs, Index);
 +decode_rsm_first_attrs(__TopXMLNS, [], Index) ->
 +    decode_rsm_first_attr_index(__TopXMLNS, Index).
 +
 +encode_rsm_first({rsm_first, Index, Data},
 +               __TopXMLNS) ->
 +    __NewTopXMLNS =
 +      choose_top_xmlns(<<"http://jabber.org/protocol/rsm">>,
 +                       [], __TopXMLNS),
 +    _els = encode_rsm_first_cdata(Data, []),
 +    _attrs = encode_rsm_first_attr_index(Index,
 +                                       enc_xmlns_attrs(__NewTopXMLNS,
 +                                                       __TopXMLNS)),
 +    {xmlel, <<"first">>, _attrs, _els}.
 +
 +decode_rsm_first_attr_index(__TopXMLNS, undefined) ->
 +    undefined;
 +decode_rsm_first_attr_index(__TopXMLNS, _val) ->
 +    case catch dec_int(_val, 0, infinity) of
 +      {'EXIT', _} ->
 +        erlang:error({xmpp_codec,
 +                      {bad_attr_value, <<"index">>, <<"first">>,
 +                       __TopXMLNS}});
 +      _res -> _res
 +    end.
 +
 +encode_rsm_first_attr_index(undefined, _acc) -> _acc;
 +encode_rsm_first_attr_index(_val, _acc) ->
 +    [{<<"index">>, enc_int(_val)} | _acc].
 +
 +decode_rsm_first_cdata(__TopXMLNS, <<>>) -> <<>>;
 +decode_rsm_first_cdata(__TopXMLNS, _val) -> _val.
 +
 +encode_rsm_first_cdata(<<>>, _acc) -> _acc;
 +encode_rsm_first_cdata(_val, _acc) ->
 +    [{xmlcdata, _val} | _acc].
 +
 +decode_rsm_max(__TopXMLNS, __IgnoreEls,
 +             {xmlel, <<"max">>, _attrs, _els}) ->
 +    Cdata = decode_rsm_max_els(__TopXMLNS, __IgnoreEls,
 +                             _els, <<>>),
 +    Cdata.
 +
 +decode_rsm_max_els(__TopXMLNS, __IgnoreEls, [],
 +                 Cdata) ->
 +    decode_rsm_max_cdata(__TopXMLNS, Cdata);
 +decode_rsm_max_els(__TopXMLNS, __IgnoreEls,
 +                 [{xmlcdata, _data} | _els], Cdata) ->
 +    decode_rsm_max_els(__TopXMLNS, __IgnoreEls, _els,
 +                     <<Cdata/binary, _data/binary>>);
 +decode_rsm_max_els(__TopXMLNS, __IgnoreEls, [_ | _els],
 +                 Cdata) ->
 +    decode_rsm_max_els(__TopXMLNS, __IgnoreEls, _els,
 +                     Cdata).
 +
 +encode_rsm_max(Cdata, __TopXMLNS) ->
 +    __NewTopXMLNS =
 +      choose_top_xmlns(<<"http://jabber.org/protocol/rsm">>,
 +                       [], __TopXMLNS),
 +    _els = encode_rsm_max_cdata(Cdata, []),
 +    _attrs = enc_xmlns_attrs(__NewTopXMLNS, __TopXMLNS),
 +    {xmlel, <<"max">>, _attrs, _els}.
 +
 +decode_rsm_max_cdata(__TopXMLNS, <<>>) -> undefined;
 +decode_rsm_max_cdata(__TopXMLNS, _val) ->
 +    case catch dec_int(_val, 0, infinity) of
 +      {'EXIT', _} ->
 +        erlang:error({xmpp_codec,
 +                      {bad_cdata_value, <<>>, <<"max">>, __TopXMLNS}});
 +      _res -> _res
 +    end.
 +
 +encode_rsm_max_cdata(undefined, _acc) -> _acc;
 +encode_rsm_max_cdata(_val, _acc) ->
 +    [{xmlcdata, enc_int(_val)} | _acc].
 +
 +decode_rsm_index(__TopXMLNS, __IgnoreEls,
 +               {xmlel, <<"index">>, _attrs, _els}) ->
 +    Cdata = decode_rsm_index_els(__TopXMLNS, __IgnoreEls,
 +                               _els, <<>>),
 +    Cdata.
 +
 +decode_rsm_index_els(__TopXMLNS, __IgnoreEls, [],
 +                   Cdata) ->
 +    decode_rsm_index_cdata(__TopXMLNS, Cdata);
 +decode_rsm_index_els(__TopXMLNS, __IgnoreEls,
 +                   [{xmlcdata, _data} | _els], Cdata) ->
 +    decode_rsm_index_els(__TopXMLNS, __IgnoreEls, _els,
 +                       <<Cdata/binary, _data/binary>>);
 +decode_rsm_index_els(__TopXMLNS, __IgnoreEls,
 +                   [_ | _els], Cdata) ->
 +    decode_rsm_index_els(__TopXMLNS, __IgnoreEls, _els,
 +                       Cdata).
 +
 +encode_rsm_index(Cdata, __TopXMLNS) ->
 +    __NewTopXMLNS =
 +      choose_top_xmlns(<<"http://jabber.org/protocol/rsm">>,
 +                       [], __TopXMLNS),
 +    _els = encode_rsm_index_cdata(Cdata, []),
 +    _attrs = enc_xmlns_attrs(__NewTopXMLNS, __TopXMLNS),
 +    {xmlel, <<"index">>, _attrs, _els}.
 +
 +decode_rsm_index_cdata(__TopXMLNS, <<>>) -> undefined;
 +decode_rsm_index_cdata(__TopXMLNS, _val) ->
 +    case catch dec_int(_val, 0, infinity) of
 +      {'EXIT', _} ->
 +        erlang:error({xmpp_codec,
 +                      {bad_cdata_value, <<>>, <<"index">>, __TopXMLNS}});
 +      _res -> _res
 +    end.
 +
 +encode_rsm_index_cdata(undefined, _acc) -> _acc;
 +encode_rsm_index_cdata(_val, _acc) ->
 +    [{xmlcdata, enc_int(_val)} | _acc].
 +
 +decode_rsm_count(__TopXMLNS, __IgnoreEls,
 +               {xmlel, <<"count">>, _attrs, _els}) ->
 +    Cdata = decode_rsm_count_els(__TopXMLNS, __IgnoreEls,
 +                               _els, <<>>),
 +    Cdata.
 +
 +decode_rsm_count_els(__TopXMLNS, __IgnoreEls, [],
 +                   Cdata) ->
 +    decode_rsm_count_cdata(__TopXMLNS, Cdata);
 +decode_rsm_count_els(__TopXMLNS, __IgnoreEls,
 +                   [{xmlcdata, _data} | _els], Cdata) ->
 +    decode_rsm_count_els(__TopXMLNS, __IgnoreEls, _els,
 +                       <<Cdata/binary, _data/binary>>);
 +decode_rsm_count_els(__TopXMLNS, __IgnoreEls,
 +                   [_ | _els], Cdata) ->
 +    decode_rsm_count_els(__TopXMLNS, __IgnoreEls, _els,
 +                       Cdata).
 +
 +encode_rsm_count(Cdata, __TopXMLNS) ->
 +    __NewTopXMLNS =
 +      choose_top_xmlns(<<"http://jabber.org/protocol/rsm">>,
 +                       [], __TopXMLNS),
 +    _els = encode_rsm_count_cdata(Cdata, []),
 +    _attrs = enc_xmlns_attrs(__NewTopXMLNS, __TopXMLNS),
 +    {xmlel, <<"count">>, _attrs, _els}.
 +
 +decode_rsm_count_cdata(__TopXMLNS, <<>>) -> undefined;
 +decode_rsm_count_cdata(__TopXMLNS, _val) ->
 +    case catch dec_int(_val, 0, infinity) of
 +      {'EXIT', _} ->
 +        erlang:error({xmpp_codec,
 +                      {bad_cdata_value, <<>>, <<"count">>, __TopXMLNS}});
 +      _res -> _res
 +    end.
 +
 +encode_rsm_count_cdata(undefined, _acc) -> _acc;
 +encode_rsm_count_cdata(_val, _acc) ->
 +    [{xmlcdata, enc_int(_val)} | _acc].
 +
 +decode_rsm_last(__TopXMLNS, __IgnoreEls,
 +              {xmlel, <<"last">>, _attrs, _els}) ->
 +    Cdata = decode_rsm_last_els(__TopXMLNS, __IgnoreEls,
 +                              _els, <<>>),
 +    Cdata.
 +
 +decode_rsm_last_els(__TopXMLNS, __IgnoreEls, [],
 +                  Cdata) ->
 +    decode_rsm_last_cdata(__TopXMLNS, Cdata);
 +decode_rsm_last_els(__TopXMLNS, __IgnoreEls,
 +                  [{xmlcdata, _data} | _els], Cdata) ->
 +    decode_rsm_last_els(__TopXMLNS, __IgnoreEls, _els,
 +                      <<Cdata/binary, _data/binary>>);
 +decode_rsm_last_els(__TopXMLNS, __IgnoreEls, [_ | _els],
 +                  Cdata) ->
 +    decode_rsm_last_els(__TopXMLNS, __IgnoreEls, _els,
 +                      Cdata).
 +
 +encode_rsm_last(Cdata, __TopXMLNS) ->
 +    __NewTopXMLNS =
 +      choose_top_xmlns(<<"http://jabber.org/protocol/rsm">>,
 +                       [], __TopXMLNS),
 +    _els = encode_rsm_last_cdata(Cdata, []),
 +    _attrs = enc_xmlns_attrs(__NewTopXMLNS, __TopXMLNS),
 +    {xmlel, <<"last">>, _attrs, _els}.
 +
 +decode_rsm_last_cdata(__TopXMLNS, <<>>) -> <<>>;
 +decode_rsm_last_cdata(__TopXMLNS, _val) -> _val.
 +
 +encode_rsm_last_cdata(<<>>, _acc) -> _acc;
 +encode_rsm_last_cdata(_val, _acc) ->
 +    [{xmlcdata, _val} | _acc].
 +
 +decode_rsm_before(__TopXMLNS, __IgnoreEls,
 +                {xmlel, <<"before">>, _attrs, _els}) ->
 +    Cdata = decode_rsm_before_els(__TopXMLNS, __IgnoreEls,
 +                                _els, <<>>),
 +    Cdata.
 +
 +decode_rsm_before_els(__TopXMLNS, __IgnoreEls, [],
 +                    Cdata) ->
 +    decode_rsm_before_cdata(__TopXMLNS, Cdata);
 +decode_rsm_before_els(__TopXMLNS, __IgnoreEls,
 +                    [{xmlcdata, _data} | _els], Cdata) ->
 +    decode_rsm_before_els(__TopXMLNS, __IgnoreEls, _els,
 +                        <<Cdata/binary, _data/binary>>);
 +decode_rsm_before_els(__TopXMLNS, __IgnoreEls,
 +                    [_ | _els], Cdata) ->
 +    decode_rsm_before_els(__TopXMLNS, __IgnoreEls, _els,
 +                        Cdata).
 +
 +encode_rsm_before(Cdata, __TopXMLNS) ->
 +    __NewTopXMLNS =
 +      choose_top_xmlns(<<"http://jabber.org/protocol/rsm">>,
 +                       [], __TopXMLNS),
 +    _els = encode_rsm_before_cdata(Cdata, []),
 +    _attrs = enc_xmlns_attrs(__NewTopXMLNS, __TopXMLNS),
 +    {xmlel, <<"before">>, _attrs, _els}.
 +
 +decode_rsm_before_cdata(__TopXMLNS, <<>>) -> <<>>;
 +decode_rsm_before_cdata(__TopXMLNS, _val) -> _val.
 +
 +encode_rsm_before_cdata(<<>>, _acc) -> _acc;
 +encode_rsm_before_cdata(_val, _acc) ->
 +    [{xmlcdata, _val} | _acc].
 +
 +decode_rsm_after(__TopXMLNS, __IgnoreEls,
 +               {xmlel, <<"after">>, _attrs, _els}) ->
 +    Cdata = decode_rsm_after_els(__TopXMLNS, __IgnoreEls,
 +                               _els, <<>>),
 +    Cdata.
 +
 +decode_rsm_after_els(__TopXMLNS, __IgnoreEls, [],
 +                   Cdata) ->
 +    decode_rsm_after_cdata(__TopXMLNS, Cdata);
 +decode_rsm_after_els(__TopXMLNS, __IgnoreEls,
 +                   [{xmlcdata, _data} | _els], Cdata) ->
 +    decode_rsm_after_els(__TopXMLNS, __IgnoreEls, _els,
 +                       <<Cdata/binary, _data/binary>>);
 +decode_rsm_after_els(__TopXMLNS, __IgnoreEls,
 +                   [_ | _els], Cdata) ->
 +    decode_rsm_after_els(__TopXMLNS, __IgnoreEls, _els,
 +                       Cdata).
 +
 +encode_rsm_after(Cdata, __TopXMLNS) ->
 +    __NewTopXMLNS =
 +      choose_top_xmlns(<<"http://jabber.org/protocol/rsm">>,
 +                       [], __TopXMLNS),
 +    _els = encode_rsm_after_cdata(Cdata, []),
 +    _attrs = enc_xmlns_attrs(__NewTopXMLNS, __TopXMLNS),
 +    {xmlel, <<"after">>, _attrs, _els}.
 +
 +decode_rsm_after_cdata(__TopXMLNS, <<>>) -> <<>>;
 +decode_rsm_after_cdata(__TopXMLNS, _val) -> _val.
 +
 +encode_rsm_after_cdata(<<>>, _acc) -> _acc;
 +encode_rsm_after_cdata(_val, _acc) ->
 +    [{xmlcdata, _val} | _acc].
 +
 +decode_muc_unsubscribe(__TopXMLNS, __IgnoreEls,
 +                     {xmlel, <<"unsubscribe">>, _attrs, _els}) ->
 +    {muc_unsubscribe}.
 +
 +encode_muc_unsubscribe({muc_unsubscribe}, __TopXMLNS) ->
 +    __NewTopXMLNS =
 +      choose_top_xmlns(<<"urn:xmpp:mucsub:0">>, [],
 +                       __TopXMLNS),
 +    _els = [],
 +    _attrs = enc_xmlns_attrs(__NewTopXMLNS, __TopXMLNS),
 +    {xmlel, <<"unsubscribe">>, _attrs, _els}.
 +
 +decode_muc_subscribe(__TopXMLNS, __IgnoreEls,
 +                   {xmlel, <<"subscribe">>, _attrs, _els}) ->
 +    Events = decode_muc_subscribe_els(__TopXMLNS,
 +                                    __IgnoreEls, _els, []),
 +    Nick = decode_muc_subscribe_attrs(__TopXMLNS, _attrs,
 +                                    undefined),
 +    {muc_subscribe, Nick, Events}.
 +
 +decode_muc_subscribe_els(__TopXMLNS, __IgnoreEls, [],
 +                       Events) ->
 +    lists:reverse(Events);
 +decode_muc_subscribe_els(__TopXMLNS, __IgnoreEls,
 +                       [{xmlel, <<"event">>, _attrs, _} = _el | _els],
 +                       Events) ->
 +    case get_attr(<<"xmlns">>, _attrs) of
 +      <<"">> when __TopXMLNS == <<"urn:xmpp:mucsub:0">> ->
 +        decode_muc_subscribe_els(__TopXMLNS, __IgnoreEls, _els,
 +                                 [decode_muc_subscribe_event(__TopXMLNS,
 +                                                             __IgnoreEls, _el)
 +                                  | Events]);
 +      <<"urn:xmpp:mucsub:0">> ->
 +        decode_muc_subscribe_els(__TopXMLNS, __IgnoreEls, _els,
 +                                 [decode_muc_subscribe_event(<<"urn:xmpp:mucsub:0">>,
 +                                                             __IgnoreEls, _el)
 +                                  | Events]);
 +      _ ->
 +        decode_muc_subscribe_els(__TopXMLNS, __IgnoreEls, _els,
 +                                 Events)
 +    end;
 +decode_muc_subscribe_els(__TopXMLNS, __IgnoreEls,
 +                       [_ | _els], Events) ->
 +    decode_muc_subscribe_els(__TopXMLNS, __IgnoreEls, _els,
 +                           Events).
 +
 +decode_muc_subscribe_attrs(__TopXMLNS,
 +                         [{<<"nick">>, _val} | _attrs], _Nick) ->
 +    decode_muc_subscribe_attrs(__TopXMLNS, _attrs, _val);
 +decode_muc_subscribe_attrs(__TopXMLNS, [_ | _attrs],
 +                         Nick) ->
 +    decode_muc_subscribe_attrs(__TopXMLNS, _attrs, Nick);
 +decode_muc_subscribe_attrs(__TopXMLNS, [], Nick) ->
 +    decode_muc_subscribe_attr_nick(__TopXMLNS, Nick).
 +
 +encode_muc_subscribe({muc_subscribe, Nick, Events},
 +                   __TopXMLNS) ->
 +    __NewTopXMLNS =
 +      choose_top_xmlns(<<"urn:xmpp:mucsub:0">>, [],
 +                       __TopXMLNS),
 +    _els =
 +      lists:reverse('encode_muc_subscribe_$events'(Events,
 +                                                   __NewTopXMLNS, [])),
 +    _attrs = encode_muc_subscribe_attr_nick(Nick,
 +                                          enc_xmlns_attrs(__NewTopXMLNS,
 +                                                          __TopXMLNS)),
 +    {xmlel, <<"subscribe">>, _attrs, _els}.
 +
 +'encode_muc_subscribe_$events'([], __TopXMLNS, _acc) ->
 +    _acc;
 +'encode_muc_subscribe_$events'([Events | _els],
 +                             __TopXMLNS, _acc) ->
 +    'encode_muc_subscribe_$events'(_els, __TopXMLNS,
 +                                 [encode_muc_subscribe_event(Events,
 +                                                             __TopXMLNS)
 +                                  | _acc]).
 +
 +decode_muc_subscribe_attr_nick(__TopXMLNS, undefined) ->
 +    erlang:error({xmpp_codec,
 +                {missing_attr, <<"nick">>, <<"subscribe">>,
 +                 __TopXMLNS}});
 +decode_muc_subscribe_attr_nick(__TopXMLNS, _val) ->
 +    _val.
 +
 +encode_muc_subscribe_attr_nick(_val, _acc) ->
 +    [{<<"nick">>, _val} | _acc].
 +
 +decode_muc_subscribe_event(__TopXMLNS, __IgnoreEls,
 +                         {xmlel, <<"event">>, _attrs, _els}) ->
 +    Node = decode_muc_subscribe_event_attrs(__TopXMLNS,
 +                                          _attrs, undefined),
 +    Node.
 +
 +decode_muc_subscribe_event_attrs(__TopXMLNS,
 +                               [{<<"node">>, _val} | _attrs], _Node) ->
 +    decode_muc_subscribe_event_attrs(__TopXMLNS, _attrs,
 +                                   _val);
 +decode_muc_subscribe_event_attrs(__TopXMLNS,
 +                               [_ | _attrs], Node) ->
 +    decode_muc_subscribe_event_attrs(__TopXMLNS, _attrs,
 +                                   Node);
 +decode_muc_subscribe_event_attrs(__TopXMLNS, [],
 +                               Node) ->
 +    decode_muc_subscribe_event_attr_node(__TopXMLNS, Node).
 +
 +encode_muc_subscribe_event(Node, __TopXMLNS) ->
 +    __NewTopXMLNS =
 +      choose_top_xmlns(<<"urn:xmpp:mucsub:0">>, [],
 +                       __TopXMLNS),
 +    _els = [],
 +    _attrs = encode_muc_subscribe_event_attr_node(Node,
 +                                                enc_xmlns_attrs(__NewTopXMLNS,
 +                                                                __TopXMLNS)),
 +    {xmlel, <<"event">>, _attrs, _els}.
 +
 +decode_muc_subscribe_event_attr_node(__TopXMLNS,
 +                                   undefined) ->
 +    erlang:error({xmpp_codec,
 +                {missing_attr, <<"node">>, <<"event">>, __TopXMLNS}});
 +decode_muc_subscribe_event_attr_node(__TopXMLNS,
 +                                   _val) ->
 +    _val.
 +
 +encode_muc_subscribe_event_attr_node(_val, _acc) ->
 +    [{<<"node">>, _val} | _acc].
 +
 +decode_muc_subscriptions(__TopXMLNS, __IgnoreEls,
 +                       {xmlel, <<"subscriptions">>, _attrs, _els}) ->
 +    List = decode_muc_subscriptions_els(__TopXMLNS,
 +                                      __IgnoreEls, _els, []),
 +    {muc_subscriptions, List}.
 +
 +decode_muc_subscriptions_els(__TopXMLNS, __IgnoreEls,
 +                           [], List) ->
 +    lists:reverse(List);
 +decode_muc_subscriptions_els(__TopXMLNS, __IgnoreEls,
 +                           [{xmlel, <<"subscription">>, _attrs, _} = _el
 +                            | _els],
 +                           List) ->
 +    case get_attr(<<"xmlns">>, _attrs) of
 +      <<"">> when __TopXMLNS == <<"urn:xmpp:mucsub:0">> ->
 +        decode_muc_subscriptions_els(__TopXMLNS, __IgnoreEls,
 +                                     _els,
 +                                     [decode_muc_subscription(__TopXMLNS,
 +                                                              __IgnoreEls,
 +                                                              _el)
 +                                      | List]);
 +      <<"urn:xmpp:mucsub:0">> ->
 +        decode_muc_subscriptions_els(__TopXMLNS, __IgnoreEls,
 +                                     _els,
 +                                     [decode_muc_subscription(<<"urn:xmpp:mucsub:0">>,
 +                                                              __IgnoreEls,
 +                                                              _el)
 +                                      | List]);
 +      _ ->
 +        decode_muc_subscriptions_els(__TopXMLNS, __IgnoreEls,
 +                                     _els, List)
 +    end;
 +decode_muc_subscriptions_els(__TopXMLNS, __IgnoreEls,
 +                           [_ | _els], List) ->
 +    decode_muc_subscriptions_els(__TopXMLNS, __IgnoreEls,
 +                               _els, List).
 +
 +encode_muc_subscriptions({muc_subscriptions, List},
 +                       __TopXMLNS) ->
 +    __NewTopXMLNS =
 +      choose_top_xmlns(<<"urn:xmpp:mucsub:0">>, [],
 +                       __TopXMLNS),
 +    _els =
 +      lists:reverse('encode_muc_subscriptions_$list'(List,
 +                                                     __NewTopXMLNS, [])),
 +    _attrs = enc_xmlns_attrs(__NewTopXMLNS, __TopXMLNS),
 +    {xmlel, <<"subscriptions">>, _attrs, _els}.
 +
 +'encode_muc_subscriptions_$list'([], __TopXMLNS,
 +                               _acc) ->
 +    _acc;
 +'encode_muc_subscriptions_$list'([List | _els],
 +                               __TopXMLNS, _acc) ->
 +    'encode_muc_subscriptions_$list'(_els, __TopXMLNS,
 +                                   [encode_muc_subscription(List, __TopXMLNS)
 +                                    | _acc]).
 +
 +decode_muc_subscription(__TopXMLNS, __IgnoreEls,
 +                      {xmlel, <<"subscription">>, _attrs, _els}) ->
 +    Jid = decode_muc_subscription_attrs(__TopXMLNS, _attrs,
 +                                      undefined),
 +    Jid.
 +
 +decode_muc_subscription_attrs(__TopXMLNS,
 +                            [{<<"jid">>, _val} | _attrs], _Jid) ->
 +    decode_muc_subscription_attrs(__TopXMLNS, _attrs, _val);
 +decode_muc_subscription_attrs(__TopXMLNS, [_ | _attrs],
 +                            Jid) ->
 +    decode_muc_subscription_attrs(__TopXMLNS, _attrs, Jid);
 +decode_muc_subscription_attrs(__TopXMLNS, [], Jid) ->
 +    decode_muc_subscription_attr_jid(__TopXMLNS, Jid).
 +
 +encode_muc_subscription(Jid, __TopXMLNS) ->
 +    __NewTopXMLNS =
 +      choose_top_xmlns(<<"urn:xmpp:mucsub:0">>, [],
 +                       __TopXMLNS),
 +    _els = [],
 +    _attrs = encode_muc_subscription_attr_jid(Jid,
 +                                            enc_xmlns_attrs(__NewTopXMLNS,
 +                                                            __TopXMLNS)),
 +    {xmlel, <<"subscription">>, _attrs, _els}.
 +
 +decode_muc_subscription_attr_jid(__TopXMLNS,
 +                               undefined) ->
 +    erlang:error({xmpp_codec,
 +                {missing_attr, <<"jid">>, <<"subscription">>,
 +                 __TopXMLNS}});
 +decode_muc_subscription_attr_jid(__TopXMLNS, _val) ->
 +    case catch dec_jid(_val) of
 +      {'EXIT', _} ->
 +        erlang:error({xmpp_codec,
 +                      {bad_attr_value, <<"jid">>, <<"subscription">>,
 +                       __TopXMLNS}});
 +      _res -> _res
 +    end.
 +
 +encode_muc_subscription_attr_jid(_val, _acc) ->
 +    [{<<"jid">>, enc_jid(_val)} | _acc].
 +
 +decode_x_conference(__TopXMLNS, __IgnoreEls,
 +                  {xmlel, <<"x">>, _attrs, _els}) ->
 +    {Jid, Password, Reason, Thread, Continue} =
 +      decode_x_conference_attrs(__TopXMLNS, _attrs, undefined,
 +                                undefined, undefined, undefined, undefined),
 +    {x_conference, Jid, Password, Reason, Continue, Thread}.
 +
 +decode_x_conference_attrs(__TopXMLNS,
 +                        [{<<"jid">>, _val} | _attrs], _Jid, Password, Reason,
 +                        Thread, Continue) ->
 +    decode_x_conference_attrs(__TopXMLNS, _attrs, _val,
 +                            Password, Reason, Thread, Continue);
 +decode_x_conference_attrs(__TopXMLNS,
 +                        [{<<"password">>, _val} | _attrs], Jid, _Password,
 +                        Reason, Thread, Continue) ->
 +    decode_x_conference_attrs(__TopXMLNS, _attrs, Jid, _val,
 +                            Reason, Thread, Continue);
 +decode_x_conference_attrs(__TopXMLNS,
 +                        [{<<"reason">>, _val} | _attrs], Jid, Password,
 +                        _Reason, Thread, Continue) ->
 +    decode_x_conference_attrs(__TopXMLNS, _attrs, Jid,
 +                            Password, _val, Thread, Continue);
 +decode_x_conference_attrs(__TopXMLNS,
 +                        [{<<"thread">>, _val} | _attrs], Jid, Password,
 +                        Reason, _Thread, Continue) ->
 +    decode_x_conference_attrs(__TopXMLNS, _attrs, Jid,
 +                            Password, Reason, _val, Continue);
 +decode_x_conference_attrs(__TopXMLNS,
 +                        [{<<"continue">>, _val} | _attrs], Jid, Password,
 +                        Reason, Thread, _Continue) ->
 +    decode_x_conference_attrs(__TopXMLNS, _attrs, Jid,
 +                            Password, Reason, Thread, _val);
 +decode_x_conference_attrs(__TopXMLNS, [_ | _attrs], Jid,
 +                        Password, Reason, Thread, Continue) ->
 +    decode_x_conference_attrs(__TopXMLNS, _attrs, Jid,
 +                            Password, Reason, Thread, Continue);
 +decode_x_conference_attrs(__TopXMLNS, [], Jid, Password,
 +                        Reason, Thread, Continue) ->
 +    {decode_x_conference_attr_jid(__TopXMLNS, Jid),
 +     decode_x_conference_attr_password(__TopXMLNS, Password),
 +     decode_x_conference_attr_reason(__TopXMLNS, Reason),
 +     decode_x_conference_attr_thread(__TopXMLNS, Thread),
 +     decode_x_conference_attr_continue(__TopXMLNS,
 +                                     Continue)}.
 +
 +encode_x_conference({x_conference, Jid, Password,
 +                   Reason, Continue, Thread},
 +                  __TopXMLNS) ->
 +    __NewTopXMLNS =
 +      choose_top_xmlns(<<"jabber:x:conference">>, [],
 +                       __TopXMLNS),
 +    _els = [],
 +    _attrs = encode_x_conference_attr_continue(Continue,
 +                                             encode_x_conference_attr_thread(Thread,
 +                                                                             encode_x_conference_attr_reason(Reason,
 +                                                                                                             encode_x_conference_attr_password(Password,
 +                                                                                                                                               encode_x_conference_attr_jid(Jid,
 +                                                                                                                                                                            enc_xmlns_attrs(__NewTopXMLNS,
 +                                                                                                                                                                                            __TopXMLNS)))))),
 +    {xmlel, <<"x">>, _attrs, _els}.
 +
 +decode_x_conference_attr_jid(__TopXMLNS, undefined) ->
 +    erlang:error({xmpp_codec,
 +                {missing_attr, <<"jid">>, <<"x">>, __TopXMLNS}});
 +decode_x_conference_attr_jid(__TopXMLNS, _val) ->
 +    case catch dec_jid(_val) of
 +      {'EXIT', _} ->
 +        erlang:error({xmpp_codec,
 +                      {bad_attr_value, <<"jid">>, <<"x">>, __TopXMLNS}});
 +      _res -> _res
 +    end.
 +
 +encode_x_conference_attr_jid(_val, _acc) ->
 +    [{<<"jid">>, enc_jid(_val)} | _acc].
 +
 +decode_x_conference_attr_password(__TopXMLNS,
 +                                undefined) ->
 +    <<>>;
 +decode_x_conference_attr_password(__TopXMLNS, _val) ->
 +    _val.
 +
 +encode_x_conference_attr_password(<<>>, _acc) -> _acc;
 +encode_x_conference_attr_password(_val, _acc) ->
 +    [{<<"password">>, _val} | _acc].
 +
 +decode_x_conference_attr_reason(__TopXMLNS,
 +                              undefined) ->
 +    <<>>;
 +decode_x_conference_attr_reason(__TopXMLNS, _val) ->
 +    _val.
 +
 +encode_x_conference_attr_reason(<<>>, _acc) -> _acc;
 +encode_x_conference_attr_reason(_val, _acc) ->
 +    [{<<"reason">>, _val} | _acc].
 +
 +decode_x_conference_attr_thread(__TopXMLNS,
 +                              undefined) ->
 +    <<>>;
 +decode_x_conference_attr_thread(__TopXMLNS, _val) ->
 +    _val.
 +
 +encode_x_conference_attr_thread(<<>>, _acc) -> _acc;
 +encode_x_conference_attr_thread(_val, _acc) ->
 +    [{<<"thread">>, _val} | _acc].
 +
 +decode_x_conference_attr_continue(__TopXMLNS,
 +                                undefined) ->
 +    undefined;
 +decode_x_conference_attr_continue(__TopXMLNS, _val) ->
 +    case catch dec_bool(_val) of
 +      {'EXIT', _} ->
 +        erlang:error({xmpp_codec,
 +                      {bad_attr_value, <<"continue">>, <<"x">>, __TopXMLNS}});
 +      _res -> _res
 +    end.
 +
 +encode_x_conference_attr_continue(undefined, _acc) ->
 +    _acc;
 +encode_x_conference_attr_continue(_val, _acc) ->
 +    [{<<"continue">>, enc_bool(_val)} | _acc].
 +
 +decode_muc_unique(__TopXMLNS, __IgnoreEls,
 +                {xmlel, <<"unique">>, _attrs, _els}) ->
 +    Name = decode_muc_unique_els(__TopXMLNS, __IgnoreEls,
 +                               _els, <<>>),
 +    {muc_unique, Name}.
 +
 +decode_muc_unique_els(__TopXMLNS, __IgnoreEls, [],
 +                    Name) ->
 +    decode_muc_unique_cdata(__TopXMLNS, Name);
 +decode_muc_unique_els(__TopXMLNS, __IgnoreEls,
 +                    [{xmlcdata, _data} | _els], Name) ->
 +    decode_muc_unique_els(__TopXMLNS, __IgnoreEls, _els,
 +                        <<Name/binary, _data/binary>>);
 +decode_muc_unique_els(__TopXMLNS, __IgnoreEls,
 +                    [_ | _els], Name) ->
 +    decode_muc_unique_els(__TopXMLNS, __IgnoreEls, _els,
 +                        Name).
 +
 +encode_muc_unique({muc_unique, Name}, __TopXMLNS) ->
 +    __NewTopXMLNS =
 +      choose_top_xmlns(<<"http://jabber.org/protocol/muc#unique">>,
 +                       [], __TopXMLNS),
 +    _els = encode_muc_unique_cdata(Name, []),
 +    _attrs = enc_xmlns_attrs(__NewTopXMLNS, __TopXMLNS),
 +    {xmlel, <<"unique">>, _attrs, _els}.
 +
 +decode_muc_unique_cdata(__TopXMLNS, <<>>) -> <<>>;
 +decode_muc_unique_cdata(__TopXMLNS, _val) -> _val.
 +
 +encode_muc_unique_cdata(<<>>, _acc) -> _acc;
 +encode_muc_unique_cdata(_val, _acc) ->
 +    [{xmlcdata, _val} | _acc].
 +
 +decode_muc(__TopXMLNS, __IgnoreEls,
 +         {xmlel, <<"x">>, _attrs, _els}) ->
 +    {Password, History} = decode_muc_els(__TopXMLNS,
 +                                       __IgnoreEls, _els, undefined,
 +                                       undefined),
 +    {muc, History, Password}.
 +
 +decode_muc_els(__TopXMLNS, __IgnoreEls, [], Password,
 +             History) ->
 +    {Password, History};
 +decode_muc_els(__TopXMLNS, __IgnoreEls,
 +             [{xmlel, <<"history">>, _attrs, _} = _el | _els],
 +             Password, History) ->
 +    case get_attr(<<"xmlns">>, _attrs) of
 +      <<"">>
 +        when __TopXMLNS ==
 +               <<"http://jabber.org/protocol/muc">> ->
 +        decode_muc_els(__TopXMLNS, __IgnoreEls, _els, Password,
 +                       decode_muc_history(__TopXMLNS, __IgnoreEls, _el));
 +      <<"http://jabber.org/protocol/muc">> ->
 +        decode_muc_els(__TopXMLNS, __IgnoreEls, _els, Password,
 +                       decode_muc_history(<<"http://jabber.org/protocol/muc">>,
 +                                          __IgnoreEls, _el));
 +      _ ->
 +        decode_muc_els(__TopXMLNS, __IgnoreEls, _els, Password,
 +                       History)
 +    end;
 +decode_muc_els(__TopXMLNS, __IgnoreEls,
 +             [{xmlel, <<"password">>, _attrs, _} = _el | _els],
 +             Password, History) ->
 +    case get_attr(<<"xmlns">>, _attrs) of
 +      <<"">>
 +        when __TopXMLNS ==
 +               <<"http://jabber.org/protocol/muc">> ->
 +        decode_muc_els(__TopXMLNS, __IgnoreEls, _els,
 +                       decode_muc_password(__TopXMLNS, __IgnoreEls, _el),
 +                       History);
 +      <<"http://jabber.org/protocol/muc#owner">> ->
 +        decode_muc_els(__TopXMLNS, __IgnoreEls, _els,
 +                       decode_muc_password(<<"http://jabber.org/protocol/muc#owner">>,
 +                                           __IgnoreEls, _el),
 +                       History);
 +      <<"http://jabber.org/protocol/muc#user">> ->
 +        decode_muc_els(__TopXMLNS, __IgnoreEls, _els,
 +                       decode_muc_password(<<"http://jabber.org/protocol/muc#user">>,
 +                                           __IgnoreEls, _el),
 +                       History);
 +      <<"http://jabber.org/protocol/muc">> ->
 +        decode_muc_els(__TopXMLNS, __IgnoreEls, _els,
 +                       decode_muc_password(<<"http://jabber.org/protocol/muc">>,
 +                                           __IgnoreEls, _el),
 +                       History);
 +      _ ->
 +        decode_muc_els(__TopXMLNS, __IgnoreEls, _els, Password,
 +                       History)
 +    end;
 +decode_muc_els(__TopXMLNS, __IgnoreEls, [_ | _els],
 +             Password, History) ->
 +    decode_muc_els(__TopXMLNS, __IgnoreEls, _els, Password,
 +                 History).
 +
 +encode_muc({muc, History, Password}, __TopXMLNS) ->
 +    __NewTopXMLNS =
 +      choose_top_xmlns(<<"http://jabber.org/protocol/muc">>,
 +                       [], __TopXMLNS),
 +    _els = lists:reverse('encode_muc_$password'(Password,
 +                                              __NewTopXMLNS,
 +                                              'encode_muc_$history'(History,
 +                                                                    __NewTopXMLNS,
 +                                                                    []))),
 +    _attrs = enc_xmlns_attrs(__NewTopXMLNS, __TopXMLNS),
 +    {xmlel, <<"x">>, _attrs, _els}.
 +
 +'encode_muc_$password'(undefined, __TopXMLNS, _acc) ->
 +    _acc;
 +'encode_muc_$password'(Password, __TopXMLNS, _acc) ->
 +    [encode_muc_password(Password, __TopXMLNS) | _acc].
 +
 +'encode_muc_$history'(undefined, __TopXMLNS, _acc) ->
 +    _acc;
 +'encode_muc_$history'(History, __TopXMLNS, _acc) ->
 +    [encode_muc_history(History, __TopXMLNS) | _acc].
 +
 +decode_muc_admin(__TopXMLNS, __IgnoreEls,
 +               {xmlel, <<"query">>, _attrs, _els}) ->
 +    Items = decode_muc_admin_els(__TopXMLNS, __IgnoreEls,
 +                               _els, []),
 +    {muc_admin, Items}.
 +
 +decode_muc_admin_els(__TopXMLNS, __IgnoreEls, [],
 +                   Items) ->
 +    lists:reverse(Items);
 +decode_muc_admin_els(__TopXMLNS, __IgnoreEls,
 +                   [{xmlel, <<"item">>, _attrs, _} = _el | _els], Items) ->
 +    case get_attr(<<"xmlns">>, _attrs) of
 +      <<"">>
 +        when __TopXMLNS ==
 +               <<"http://jabber.org/protocol/muc#admin">> ->
 +        decode_muc_admin_els(__TopXMLNS, __IgnoreEls, _els,
 +                             [decode_muc_admin_item(__TopXMLNS, __IgnoreEls,
 +                                                    _el)
 +                              | Items]);
 +      <<"http://jabber.org/protocol/muc#admin">> ->
 +        decode_muc_admin_els(__TopXMLNS, __IgnoreEls, _els,
 +                             [decode_muc_admin_item(<<"http://jabber.org/protocol/muc#admin">>,
 +                                                    __IgnoreEls, _el)
 +                              | Items]);
 +      _ ->
 +        decode_muc_admin_els(__TopXMLNS, __IgnoreEls, _els,
 +                             Items)
 +    end;
 +decode_muc_admin_els(__TopXMLNS, __IgnoreEls,
 +                   [_ | _els], Items) ->
 +    decode_muc_admin_els(__TopXMLNS, __IgnoreEls, _els,
 +                       Items).
 +
 +encode_muc_admin({muc_admin, Items}, __TopXMLNS) ->
 +    __NewTopXMLNS =
 +      choose_top_xmlns(<<"http://jabber.org/protocol/muc#admin">>,
 +                       [], __TopXMLNS),
 +    _els = lists:reverse('encode_muc_admin_$items'(Items,
 +                                                 __NewTopXMLNS, [])),
 +    _attrs = enc_xmlns_attrs(__NewTopXMLNS, __TopXMLNS),
 +    {xmlel, <<"query">>, _attrs, _els}.
 +
 +'encode_muc_admin_$items'([], __TopXMLNS, _acc) -> _acc;
 +'encode_muc_admin_$items'([Items | _els], __TopXMLNS,
 +                        _acc) ->
 +    'encode_muc_admin_$items'(_els, __TopXMLNS,
 +                            [encode_muc_admin_item(Items, __TopXMLNS)
 +                             | _acc]).
 +
 +decode_muc_admin_continue(__TopXMLNS, __IgnoreEls,
 +                        {xmlel, <<"continue">>, _attrs, _els}) ->
 +    Thread = decode_muc_admin_continue_attrs(__TopXMLNS,
 +                                           _attrs, undefined),
 +    Thread.
 +
 +decode_muc_admin_continue_attrs(__TopXMLNS,
 +                              [{<<"thread">>, _val} | _attrs], _Thread) ->
 +    decode_muc_admin_continue_attrs(__TopXMLNS, _attrs,
 +                                  _val);
 +decode_muc_admin_continue_attrs(__TopXMLNS,
 +                              [_ | _attrs], Thread) ->
 +    decode_muc_admin_continue_attrs(__TopXMLNS, _attrs,
 +                                  Thread);
 +decode_muc_admin_continue_attrs(__TopXMLNS, [],
 +                              Thread) ->
 +    decode_muc_admin_continue_attr_thread(__TopXMLNS,
 +                                        Thread).
 +
 +encode_muc_admin_continue(Thread, __TopXMLNS) ->
 +    __NewTopXMLNS =
 +      choose_top_xmlns(<<"http://jabber.org/protocol/muc#admin">>,
 +                       [], __TopXMLNS),
 +    _els = [],
 +    _attrs = encode_muc_admin_continue_attr_thread(Thread,
 +                                                 enc_xmlns_attrs(__NewTopXMLNS,
 +                                                                 __TopXMLNS)),
 +    {xmlel, <<"continue">>, _attrs, _els}.
 +
 +decode_muc_admin_continue_attr_thread(__TopXMLNS,
 +                                    undefined) ->
 +    <<>>;
 +decode_muc_admin_continue_attr_thread(__TopXMLNS,
 +                                    _val) ->
 +    _val.
 +
 +encode_muc_admin_continue_attr_thread(<<>>, _acc) ->
 +    _acc;
 +encode_muc_admin_continue_attr_thread(_val, _acc) ->
 +    [{<<"thread">>, _val} | _acc].
 +
 +decode_muc_admin_actor(__TopXMLNS, __IgnoreEls,
 +                     {xmlel, <<"actor">>, _attrs, _els}) ->
 +    {Jid, Nick} = decode_muc_admin_actor_attrs(__TopXMLNS,
 +                                             _attrs, undefined, undefined),
 +    {muc_actor, Jid, Nick}.
 +
 +decode_muc_admin_actor_attrs(__TopXMLNS,
 +                           [{<<"jid">>, _val} | _attrs], _Jid, Nick) ->
 +    decode_muc_admin_actor_attrs(__TopXMLNS, _attrs, _val,
 +                               Nick);
 +decode_muc_admin_actor_attrs(__TopXMLNS,
 +                           [{<<"nick">>, _val} | _attrs], Jid, _Nick) ->
 +    decode_muc_admin_actor_attrs(__TopXMLNS, _attrs, Jid,
 +                               _val);
 +decode_muc_admin_actor_attrs(__TopXMLNS, [_ | _attrs],
 +                           Jid, Nick) ->
 +    decode_muc_admin_actor_attrs(__TopXMLNS, _attrs, Jid,
 +                               Nick);
 +decode_muc_admin_actor_attrs(__TopXMLNS, [], Jid,
 +                           Nick) ->
 +    {decode_muc_admin_actor_attr_jid(__TopXMLNS, Jid),
 +     decode_muc_admin_actor_attr_nick(__TopXMLNS, Nick)}.
 +
 +encode_muc_admin_actor({muc_actor, Jid, Nick},
 +                     __TopXMLNS) ->
 +    __NewTopXMLNS =
 +      choose_top_xmlns(<<"http://jabber.org/protocol/muc#admin">>,
 +                       [], __TopXMLNS),
 +    _els = [],
 +    _attrs = encode_muc_admin_actor_attr_nick(Nick,
 +                                            encode_muc_admin_actor_attr_jid(Jid,
 +                                                                            enc_xmlns_attrs(__NewTopXMLNS,
 +                                                                                            __TopXMLNS))),
 +    {xmlel, <<"actor">>, _attrs, _els}.
 +
 +decode_muc_admin_actor_attr_jid(__TopXMLNS,
 +                              undefined) ->
 +    undefined;
 +decode_muc_admin_actor_attr_jid(__TopXMLNS, _val) ->
 +    case catch dec_jid(_val) of
 +      {'EXIT', _} ->
 +        erlang:error({xmpp_codec,
 +                      {bad_attr_value, <<"jid">>, <<"actor">>, __TopXMLNS}});
 +      _res -> _res
 +    end.
 +
 +encode_muc_admin_actor_attr_jid(undefined, _acc) ->
 +    _acc;
 +encode_muc_admin_actor_attr_jid(_val, _acc) ->
 +    [{<<"jid">>, enc_jid(_val)} | _acc].
 +
 +decode_muc_admin_actor_attr_nick(__TopXMLNS,
 +                               undefined) ->
 +    <<>>;
 +decode_muc_admin_actor_attr_nick(__TopXMLNS, _val) ->
 +    _val.
 +
 +encode_muc_admin_actor_attr_nick(<<>>, _acc) -> _acc;
 +encode_muc_admin_actor_attr_nick(_val, _acc) ->
 +    [{<<"nick">>, _val} | _acc].
 +
 +decode_muc_admin_item(__TopXMLNS, __IgnoreEls,
 +                    {xmlel, <<"item">>, _attrs, _els}) ->
 +    {Actor, Continue, Reason} =
 +      decode_muc_admin_item_els(__TopXMLNS, __IgnoreEls, _els,
 +                                undefined, undefined, <<>>),
 +    {Affiliation, Role, Jid, Nick} =
 +      decode_muc_admin_item_attrs(__TopXMLNS, _attrs,
 +                                  undefined, undefined, undefined, undefined),
 +    {muc_item, Actor, Continue, Reason, Affiliation, Role,
 +     Jid, Nick}.
 +
 +decode_muc_admin_item_els(__TopXMLNS, __IgnoreEls, [],
 +                        Actor, Continue, Reason) ->
 +    {Actor, Continue, Reason};
 +decode_muc_admin_item_els(__TopXMLNS, __IgnoreEls,
 +                        [{xmlel, <<"actor">>, _attrs, _} = _el | _els], Actor,
 +                        Continue, Reason) ->
 +    case get_attr(<<"xmlns">>, _attrs) of
 +      <<"">>
 +        when __TopXMLNS ==
 +               <<"http://jabber.org/protocol/muc#admin">> ->
 +        decode_muc_admin_item_els(__TopXMLNS, __IgnoreEls, _els,
 +                                  decode_muc_admin_actor(__TopXMLNS,
 +                                                         __IgnoreEls, _el),
 +                                  Continue, Reason);
 +      <<"http://jabber.org/protocol/muc#admin">> ->
 +        decode_muc_admin_item_els(__TopXMLNS, __IgnoreEls, _els,
 +                                  decode_muc_admin_actor(<<"http://jabber.org/protocol/muc#admin">>,
 +                                                         __IgnoreEls, _el),
 +                                  Continue, Reason);
 +      _ ->
 +        decode_muc_admin_item_els(__TopXMLNS, __IgnoreEls, _els,
 +                                  Actor, Continue, Reason)
 +    end;
 +decode_muc_admin_item_els(__TopXMLNS, __IgnoreEls,
 +                        [{xmlel, <<"continue">>, _attrs, _} = _el | _els],
 +                        Actor, Continue, Reason) ->
 +    case get_attr(<<"xmlns">>, _attrs) of
 +      <<"">>
 +        when __TopXMLNS ==
 +               <<"http://jabber.org/protocol/muc#admin">> ->
 +        decode_muc_admin_item_els(__TopXMLNS, __IgnoreEls, _els,
 +                                  Actor,
 +                                  decode_muc_admin_continue(__TopXMLNS,
 +                                                            __IgnoreEls, _el),
 +                                  Reason);
 +      <<"http://jabber.org/protocol/muc#admin">> ->
 +        decode_muc_admin_item_els(__TopXMLNS, __IgnoreEls, _els,
 +                                  Actor,
 +                                  decode_muc_admin_continue(<<"http://jabber.org/protocol/muc#admin">>,
 +                                                            __IgnoreEls, _el),
 +                                  Reason);
 +      _ ->
 +        decode_muc_admin_item_els(__TopXMLNS, __IgnoreEls, _els,
 +                                  Actor, Continue, Reason)
 +    end;
 +decode_muc_admin_item_els(__TopXMLNS, __IgnoreEls,
 +                        [{xmlel, <<"reason">>, _attrs, _} = _el | _els],
 +                        Actor, Continue, Reason) ->
 +    case get_attr(<<"xmlns">>, _attrs) of
 +      <<"">>
 +        when __TopXMLNS ==
 +               <<"http://jabber.org/protocol/muc#admin">> ->
 +        decode_muc_admin_item_els(__TopXMLNS, __IgnoreEls, _els,
 +                                  Actor, Continue,
 +                                  decode_muc_reason(__TopXMLNS, __IgnoreEls,
 +                                                    _el));
 +      <<"http://jabber.org/protocol/muc#user">> ->
 +        decode_muc_admin_item_els(__TopXMLNS, __IgnoreEls, _els,
 +                                  Actor, Continue,
 +                                  decode_muc_reason(<<"http://jabber.org/protocol/muc#user">>,
 +                                                    __IgnoreEls, _el));
 +      <<"http://jabber.org/protocol/muc#admin">> ->
 +        decode_muc_admin_item_els(__TopXMLNS, __IgnoreEls, _els,
 +                                  Actor, Continue,
 +                                  decode_muc_reason(<<"http://jabber.org/protocol/muc#admin">>,
 +                                                    __IgnoreEls, _el));
 +      <<"http://jabber.org/protocol/muc#owner">> ->
 +        decode_muc_admin_item_els(__TopXMLNS, __IgnoreEls, _els,
 +                                  Actor, Continue,
 +                                  decode_muc_reason(<<"http://jabber.org/protocol/muc#owner">>,
 +                                                    __IgnoreEls, _el));
 +      _ ->
 +        decode_muc_admin_item_els(__TopXMLNS, __IgnoreEls, _els,
 +                                  Actor, Continue, Reason)
 +    end;
 +decode_muc_admin_item_els(__TopXMLNS, __IgnoreEls,
 +                        [_ | _els], Actor, Continue, Reason) ->
 +    decode_muc_admin_item_els(__TopXMLNS, __IgnoreEls, _els,
 +                            Actor, Continue, Reason).
 +
 +decode_muc_admin_item_attrs(__TopXMLNS,
 +                          [{<<"affiliation">>, _val} | _attrs], _Affiliation,
 +                          Role, Jid, Nick) ->
 +    decode_muc_admin_item_attrs(__TopXMLNS, _attrs, _val,
 +                              Role, Jid, Nick);
 +decode_muc_admin_item_attrs(__TopXMLNS,
 +                          [{<<"role">>, _val} | _attrs], Affiliation, _Role,
 +                          Jid, Nick) ->
 +    decode_muc_admin_item_attrs(__TopXMLNS, _attrs,
 +                              Affiliation, _val, Jid, Nick);
 +decode_muc_admin_item_attrs(__TopXMLNS,
 +                          [{<<"jid">>, _val} | _attrs], Affiliation, Role,
 +                          _Jid, Nick) ->
 +    decode_muc_admin_item_attrs(__TopXMLNS, _attrs,
 +                              Affiliation, Role, _val, Nick);
 +decode_muc_admin_item_attrs(__TopXMLNS,
 +                          [{<<"nick">>, _val} | _attrs], Affiliation, Role,
 +                          Jid, _Nick) ->
 +    decode_muc_admin_item_attrs(__TopXMLNS, _attrs,
 +                              Affiliation, Role, Jid, _val);
 +decode_muc_admin_item_attrs(__TopXMLNS, [_ | _attrs],
 +                          Affiliation, Role, Jid, Nick) ->
 +    decode_muc_admin_item_attrs(__TopXMLNS, _attrs,
 +                              Affiliation, Role, Jid, Nick);
 +decode_muc_admin_item_attrs(__TopXMLNS, [], Affiliation,
 +                          Role, Jid, Nick) ->
 +    {decode_muc_admin_item_attr_affiliation(__TopXMLNS,
 +                                          Affiliation),
 +     decode_muc_admin_item_attr_role(__TopXMLNS, Role),
 +     decode_muc_admin_item_attr_jid(__TopXMLNS, Jid),
 +     decode_muc_admin_item_attr_nick(__TopXMLNS, Nick)}.
 +
 +encode_muc_admin_item({muc_item, Actor, Continue,
 +                     Reason, Affiliation, Role, Jid, Nick},
 +                    __TopXMLNS) ->
 +    __NewTopXMLNS =
 +      choose_top_xmlns(<<"http://jabber.org/protocol/muc#admin">>,
 +                       [], __TopXMLNS),
 +    _els =
 +      lists:reverse('encode_muc_admin_item_$actor'(Actor,
 +                                                   __NewTopXMLNS,
 +                                                   'encode_muc_admin_item_$continue'(Continue,
 +                                                                                     __NewTopXMLNS,
 +                                                                                     'encode_muc_admin_item_$reason'(Reason,
 +                                                                                                                     __NewTopXMLNS,
 +                                                                                                                     [])))),
 +    _attrs = encode_muc_admin_item_attr_nick(Nick,
 +                                           encode_muc_admin_item_attr_jid(Jid,
 +                                                                          encode_muc_admin_item_attr_role(Role,
 +                                                                                                          encode_muc_admin_item_attr_affiliation(Affiliation,
 +                                                                                                                                                 enc_xmlns_attrs(__NewTopXMLNS,
 +                                                                                                                                                                 __TopXMLNS))))),
 +    {xmlel, <<"item">>, _attrs, _els}.
 +
 +'encode_muc_admin_item_$actor'(undefined, __TopXMLNS,
 +                             _acc) ->
 +    _acc;
 +'encode_muc_admin_item_$actor'(Actor, __TopXMLNS,
 +                             _acc) ->
 +    [encode_muc_admin_actor(Actor, __TopXMLNS) | _acc].
 +
 +'encode_muc_admin_item_$continue'(undefined, __TopXMLNS,
 +                                _acc) ->
 +    _acc;
 +'encode_muc_admin_item_$continue'(Continue, __TopXMLNS,
 +                                _acc) ->
 +    [encode_muc_admin_continue(Continue, __TopXMLNS)
 +     | _acc].
 +
 +'encode_muc_admin_item_$reason'(<<>>, __TopXMLNS,
 +                              _acc) ->
 +    _acc;
 +'encode_muc_admin_item_$reason'(Reason, __TopXMLNS,
 +                              _acc) ->
 +    [encode_muc_reason(Reason, __TopXMLNS) | _acc].
 +
 +decode_muc_admin_item_attr_affiliation(__TopXMLNS,
 +                                     undefined) ->
 +    undefined;
 +decode_muc_admin_item_attr_affiliation(__TopXMLNS,
 +                                     _val) ->
 +    case catch dec_enum(_val,
 +                      [admin, member, none, outcast, owner])
 +      of
 +      {'EXIT', _} ->
 +        erlang:error({xmpp_codec,
 +                      {bad_attr_value, <<"affiliation">>, <<"item">>,
 +                       __TopXMLNS}});
 +      _res -> _res
 +    end.
 +
 +encode_muc_admin_item_attr_affiliation(undefined,
 +                                     _acc) ->
 +    _acc;
 +encode_muc_admin_item_attr_affiliation(_val, _acc) ->
 +    [{<<"affiliation">>, enc_enum(_val)} | _acc].
 +
 +decode_muc_admin_item_attr_role(__TopXMLNS,
 +                              undefined) ->
 +    undefined;
 +decode_muc_admin_item_attr_role(__TopXMLNS, _val) ->
 +    case catch dec_enum(_val,
 +                      [moderator, none, participant, visitor])
 +      of
 +      {'EXIT', _} ->
 +        erlang:error({xmpp_codec,
 +                      {bad_attr_value, <<"role">>, <<"item">>, __TopXMLNS}});
 +      _res -> _res
 +    end.
 +
 +encode_muc_admin_item_attr_role(undefined, _acc) ->
 +    _acc;
 +encode_muc_admin_item_attr_role(_val, _acc) ->
 +    [{<<"role">>, enc_enum(_val)} | _acc].
 +
 +decode_muc_admin_item_attr_jid(__TopXMLNS, undefined) ->
 +    undefined;
 +decode_muc_admin_item_attr_jid(__TopXMLNS, _val) ->
 +    case catch dec_jid(_val) of
 +      {'EXIT', _} ->
 +        erlang:error({xmpp_codec,
 +                      {bad_attr_value, <<"jid">>, <<"item">>, __TopXMLNS}});
 +      _res -> _res
 +    end.
 +
 +encode_muc_admin_item_attr_jid(undefined, _acc) -> _acc;
 +encode_muc_admin_item_attr_jid(_val, _acc) ->
 +    [{<<"jid">>, enc_jid(_val)} | _acc].
 +
 +decode_muc_admin_item_attr_nick(__TopXMLNS,
 +                              undefined) ->
 +    <<>>;
 +decode_muc_admin_item_attr_nick(__TopXMLNS, _val) ->
 +    _val.
 +
 +encode_muc_admin_item_attr_nick(<<>>, _acc) -> _acc;
 +encode_muc_admin_item_attr_nick(_val, _acc) ->
 +    [{<<"nick">>, _val} | _acc].
 +
 +decode_muc_owner_item(__TopXMLNS, __IgnoreEls,
 +                    {xmlel, <<"item">>, _attrs, _els}) ->
 +    {Actor, Continue, Reason} =
 +      decode_muc_owner_item_els(__TopXMLNS, __IgnoreEls, _els,
 +                                undefined, undefined, <<>>),
 +    {Affiliation, Role, Jid, Nick} =
 +      decode_muc_owner_item_attrs(__TopXMLNS, _attrs,
 +                                  undefined, undefined, undefined, undefined),
 +    {muc_item, Actor, Continue, Reason, Affiliation, Role,
 +     Jid, Nick}.
 +
 +decode_muc_owner_item_els(__TopXMLNS, __IgnoreEls, [],
 +                        Actor, Continue, Reason) ->
 +    {Actor, Continue, Reason};
 +decode_muc_owner_item_els(__TopXMLNS, __IgnoreEls,
 +                        [{xmlel, <<"actor">>, _attrs, _} = _el | _els], Actor,
 +                        Continue, Reason) ->
 +    case get_attr(<<"xmlns">>, _attrs) of
 +      <<"http://jabber.org/protocol/muc#admin">> ->
 +        decode_muc_owner_item_els(__TopXMLNS, __IgnoreEls, _els,
 +                                  decode_muc_admin_actor(<<"http://jabber.org/protocol/muc#admin">>,
 +                                                         __IgnoreEls, _el),
 +                                  Continue, Reason);
 +      _ ->
 +        decode_muc_owner_item_els(__TopXMLNS, __IgnoreEls, _els,
 +                                  Actor, Continue, Reason)
 +    end;
 +decode_muc_owner_item_els(__TopXMLNS, __IgnoreEls,
 +                        [{xmlel, <<"continue">>, _attrs, _} = _el | _els],
 +                        Actor, Continue, Reason) ->
 +    case get_attr(<<"xmlns">>, _attrs) of
 +      <<"http://jabber.org/protocol/muc#admin">> ->
 +        decode_muc_owner_item_els(__TopXMLNS, __IgnoreEls, _els,
 +                                  Actor,
 +                                  decode_muc_admin_continue(<<"http://jabber.org/protocol/muc#admin">>,
 +                                                            __IgnoreEls, _el),
 +                                  Reason);
 +      _ ->
 +        decode_muc_owner_item_els(__TopXMLNS, __IgnoreEls, _els,
 +                                  Actor, Continue, Reason)
 +    end;
 +decode_muc_owner_item_els(__TopXMLNS, __IgnoreEls,
 +                        [{xmlel, <<"reason">>, _attrs, _} = _el | _els],
 +                        Actor, Continue, Reason) ->
 +    case get_attr(<<"xmlns">>, _attrs) of
 +      <<"">>
 +        when __TopXMLNS ==
 +               <<"http://jabber.org/protocol/muc#owner">> ->
 +        decode_muc_owner_item_els(__TopXMLNS, __IgnoreEls, _els,
 +                                  Actor, Continue,
 +                                  decode_muc_reason(__TopXMLNS, __IgnoreEls,
 +                                                    _el));
 +      <<"http://jabber.org/protocol/muc#user">> ->
 +        decode_muc_owner_item_els(__TopXMLNS, __IgnoreEls, _els,
 +                                  Actor, Continue,
 +                                  decode_muc_reason(<<"http://jabber.org/protocol/muc#user">>,
 +                                                    __IgnoreEls, _el));
 +      <<"http://jabber.org/protocol/muc#admin">> ->
 +        decode_muc_owner_item_els(__TopXMLNS, __IgnoreEls, _els,
 +                                  Actor, Continue,
 +                                  decode_muc_reason(<<"http://jabber.org/protocol/muc#admin">>,
 +                                                    __IgnoreEls, _el));
 +      <<"http://jabber.org/protocol/muc#owner">> ->
 +        decode_muc_owner_item_els(__TopXMLNS, __IgnoreEls, _els,
 +                                  Actor, Continue,
 +                                  decode_muc_reason(<<"http://jabber.org/protocol/muc#owner">>,
 +                                                    __IgnoreEls, _el));
 +      _ ->
 +        decode_muc_owner_item_els(__TopXMLNS, __IgnoreEls, _els,
 +                                  Actor, Continue, Reason)
 +    end;
 +decode_muc_owner_item_els(__TopXMLNS, __IgnoreEls,
 +                        [_ | _els], Actor, Continue, Reason) ->
 +    decode_muc_owner_item_els(__TopXMLNS, __IgnoreEls, _els,
 +                            Actor, Continue, Reason).
 +
 +decode_muc_owner_item_attrs(__TopXMLNS,
 +                          [{<<"affiliation">>, _val} | _attrs], _Affiliation,
 +                          Role, Jid, Nick) ->
 +    decode_muc_owner_item_attrs(__TopXMLNS, _attrs, _val,
 +                              Role, Jid, Nick);
 +decode_muc_owner_item_attrs(__TopXMLNS,
 +                          [{<<"role">>, _val} | _attrs], Affiliation, _Role,
 +                          Jid, Nick) ->
 +    decode_muc_owner_item_attrs(__TopXMLNS, _attrs,
 +                              Affiliation, _val, Jid, Nick);
 +decode_muc_owner_item_attrs(__TopXMLNS,
 +                          [{<<"jid">>, _val} | _attrs], Affiliation, Role,
 +                          _Jid, Nick) ->
 +    decode_muc_owner_item_attrs(__TopXMLNS, _attrs,
 +                              Affiliation, Role, _val, Nick);
 +decode_muc_owner_item_attrs(__TopXMLNS,
 +                          [{<<"nick">>, _val} | _attrs], Affiliation, Role,
 +                          Jid, _Nick) ->
 +    decode_muc_owner_item_attrs(__TopXMLNS, _attrs,
 +                              Affiliation, Role, Jid, _val);
 +decode_muc_owner_item_attrs(__TopXMLNS, [_ | _attrs],
 +                          Affiliation, Role, Jid, Nick) ->
 +    decode_muc_owner_item_attrs(__TopXMLNS, _attrs,
 +                              Affiliation, Role, Jid, Nick);
 +decode_muc_owner_item_attrs(__TopXMLNS, [], Affiliation,
 +                          Role, Jid, Nick) ->
 +    {decode_muc_owner_item_attr_affiliation(__TopXMLNS,
 +                                          Affiliation),
 +     decode_muc_owner_item_attr_role(__TopXMLNS, Role),
 +     decode_muc_owner_item_attr_jid(__TopXMLNS, Jid),
 +     decode_muc_owner_item_attr_nick(__TopXMLNS, Nick)}.
 +
 +encode_muc_owner_item({muc_item, Actor, Continue,
 +                     Reason, Affiliation, Role, Jid, Nick},
 +                    __TopXMLNS) ->
 +    __NewTopXMLNS =
 +      choose_top_xmlns(<<"http://jabber.org/protocol/muc#owner">>,
 +                       [], __TopXMLNS),
 +    _els =
 +      lists:reverse('encode_muc_owner_item_$actor'(Actor,
 +                                                   __NewTopXMLNS,
 +                                                   'encode_muc_owner_item_$continue'(Continue,
 +                                                                                     __NewTopXMLNS,
 +                                                                                     'encode_muc_owner_item_$reason'(Reason,
 +                                                                                                                     __NewTopXMLNS,
 +                                                                                                                     [])))),
 +    _attrs = encode_muc_owner_item_attr_nick(Nick,
 +                                           encode_muc_owner_item_attr_jid(Jid,
 +                                                                          encode_muc_owner_item_attr_role(Role,
 +                                                                                                          encode_muc_owner_item_attr_affiliation(Affiliation,
 +                                                                                                                                                 enc_xmlns_attrs(__NewTopXMLNS,
 +                                                                                                                                                                 __TopXMLNS))))),
 +    {xmlel, <<"item">>, _attrs, _els}.
 +
 +'encode_muc_owner_item_$actor'(undefined, __TopXMLNS,
 +                             _acc) ->
 +    _acc;
 +'encode_muc_owner_item_$actor'(Actor, __TopXMLNS,
 +                             _acc) ->
 +    [encode_muc_admin_actor(Actor, __TopXMLNS) | _acc].
 +
 +'encode_muc_owner_item_$continue'(undefined, __TopXMLNS,
 +                                _acc) ->
 +    _acc;
 +'encode_muc_owner_item_$continue'(Continue, __TopXMLNS,
 +                                _acc) ->
 +    [encode_muc_admin_continue(Continue, __TopXMLNS)
 +     | _acc].
 +
 +'encode_muc_owner_item_$reason'(<<>>, __TopXMLNS,
 +                              _acc) ->
 +    _acc;
 +'encode_muc_owner_item_$reason'(Reason, __TopXMLNS,
 +                              _acc) ->
 +    [encode_muc_reason(Reason, __TopXMLNS) | _acc].
 +
 +decode_muc_owner_item_attr_affiliation(__TopXMLNS,
 +                                     undefined) ->
 +    undefined;
 +decode_muc_owner_item_attr_affiliation(__TopXMLNS,
 +                                     _val) ->
 +    case catch dec_enum(_val,
 +                      [admin, member, none, outcast, owner])
 +      of
 +      {'EXIT', _} ->
 +        erlang:error({xmpp_codec,
 +                      {bad_attr_value, <<"affiliation">>, <<"item">>,
 +                       __TopXMLNS}});
 +      _res -> _res
 +    end.
 +
 +encode_muc_owner_item_attr_affiliation(undefined,
 +                                     _acc) ->
 +    _acc;
 +encode_muc_owner_item_attr_affiliation(_val, _acc) ->
 +    [{<<"affiliation">>, enc_enum(_val)} | _acc].
 +
 +decode_muc_owner_item_attr_role(__TopXMLNS,
 +                              undefined) ->
 +    undefined;
 +decode_muc_owner_item_attr_role(__TopXMLNS, _val) ->
 +    case catch dec_enum(_val,
 +                      [moderator, none, participant, visitor])
 +      of
 +      {'EXIT', _} ->
 +        erlang:error({xmpp_codec,
 +                      {bad_attr_value, <<"role">>, <<"item">>, __TopXMLNS}});
 +      _res -> _res
 +    end.
 +
 +encode_muc_owner_item_attr_role(undefined, _acc) ->
 +    _acc;
 +encode_muc_owner_item_attr_role(_val, _acc) ->
 +    [{<<"role">>, enc_enum(_val)} | _acc].
 +
 +decode_muc_owner_item_attr_jid(__TopXMLNS, undefined) ->
 +    undefined;
 +decode_muc_owner_item_attr_jid(__TopXMLNS, _val) ->
 +    case catch dec_jid(_val) of
 +      {'EXIT', _} ->
 +        erlang:error({xmpp_codec,
 +                      {bad_attr_value, <<"jid">>, <<"item">>, __TopXMLNS}});
 +      _res -> _res
 +    end.
 +
 +encode_muc_owner_item_attr_jid(undefined, _acc) -> _acc;
 +encode_muc_owner_item_attr_jid(_val, _acc) ->
 +    [{<<"jid">>, enc_jid(_val)} | _acc].
 +
 +decode_muc_owner_item_attr_nick(__TopXMLNS,
 +                              undefined) ->
 +    <<>>;
 +decode_muc_owner_item_attr_nick(__TopXMLNS, _val) ->
 +    _val.
 +
 +encode_muc_owner_item_attr_nick(<<>>, _acc) -> _acc;
 +encode_muc_owner_item_attr_nick(_val, _acc) ->
 +    [{<<"nick">>, _val} | _acc].
 +
 +decode_muc_owner(__TopXMLNS, __IgnoreEls,
 +               {xmlel, <<"query">>, _attrs, _els}) ->
 +    {Items, Config, Destroy} =
 +      decode_muc_owner_els(__TopXMLNS, __IgnoreEls, _els, [],
 +                           undefined, undefined),
 +    {muc_owner, Destroy, Config, Items}.
 +
 +decode_muc_owner_els(__TopXMLNS, __IgnoreEls, [], Items,
 +                   Config, Destroy) ->
 +    {lists:reverse(Items), Config, Destroy};
 +decode_muc_owner_els(__TopXMLNS, __IgnoreEls,
 +                   [{xmlel, <<"destroy">>, _attrs, _} = _el | _els], Items,
 +                   Config, Destroy) ->
 +    case get_attr(<<"xmlns">>, _attrs) of
 +      <<"">>
 +        when __TopXMLNS ==
 +               <<"http://jabber.org/protocol/muc#owner">> ->
 +        decode_muc_owner_els(__TopXMLNS, __IgnoreEls, _els,
 +                             Items, Config,
 +                             decode_muc_destroy(__TopXMLNS, __IgnoreEls,
 +                                                _el));
 +      <<"http://jabber.org/protocol/muc#user">> ->
 +        decode_muc_owner_els(__TopXMLNS, __IgnoreEls, _els,
 +                             Items, Config,
 +                             decode_muc_destroy(<<"http://jabber.org/protocol/muc#user">>,
 +                                                __IgnoreEls, _el));
 +      <<"http://jabber.org/protocol/muc#owner">> ->
 +        decode_muc_owner_els(__TopXMLNS, __IgnoreEls, _els,
 +                             Items, Config,
 +                             decode_muc_destroy(<<"http://jabber.org/protocol/muc#owner">>,
 +                                                __IgnoreEls, _el));
 +      _ ->
 +        decode_muc_owner_els(__TopXMLNS, __IgnoreEls, _els,
 +                             Items, Config, Destroy)
 +    end;
 +decode_muc_owner_els(__TopXMLNS, __IgnoreEls,
 +                   [{xmlel, <<"x">>, _attrs, _} = _el | _els], Items,
 +                   Config, Destroy) ->
 +    case get_attr(<<"xmlns">>, _attrs) of
 +      <<"jabber:x:data">> ->
 +        decode_muc_owner_els(__TopXMLNS, __IgnoreEls, _els,
 +                             Items,
 +                             decode_xdata(<<"jabber:x:data">>, __IgnoreEls,
 +                                          _el),
 +                             Destroy);
 +      _ ->
 +        decode_muc_owner_els(__TopXMLNS, __IgnoreEls, _els,
 +                             Items, Config, Destroy)
 +    end;
 +decode_muc_owner_els(__TopXMLNS, __IgnoreEls,
 +                   [{xmlel, <<"item">>, _attrs, _} = _el | _els], Items,
 +                   Config, Destroy) ->
 +    case get_attr(<<"xmlns">>, _attrs) of
 +      <<"">>
 +        when __TopXMLNS ==
 +               <<"http://jabber.org/protocol/muc#owner">> ->
 +        decode_muc_owner_els(__TopXMLNS, __IgnoreEls, _els,
 +                             [decode_muc_owner_item(__TopXMLNS, __IgnoreEls,
 +                                                    _el)
 +                              | Items],
 +                             Config, Destroy);
 +      <<"http://jabber.org/protocol/muc#owner">> ->
 +        decode_muc_owner_els(__TopXMLNS, __IgnoreEls, _els,
 +                             [decode_muc_owner_item(<<"http://jabber.org/protocol/muc#owner">>,
 +                                                    __IgnoreEls, _el)
 +                              | Items],
 +                             Config, Destroy);
 +      _ ->
 +        decode_muc_owner_els(__TopXMLNS, __IgnoreEls, _els,
 +                             Items, Config, Destroy)
 +    end;
 +decode_muc_owner_els(__TopXMLNS, __IgnoreEls,
 +                   [_ | _els], Items, Config, Destroy) ->
 +    decode_muc_owner_els(__TopXMLNS, __IgnoreEls, _els,
 +                       Items, Config, Destroy).
 +
 +encode_muc_owner({muc_owner, Destroy, Config, Items},
 +               __TopXMLNS) ->
 +    __NewTopXMLNS =
 +      choose_top_xmlns(<<"http://jabber.org/protocol/muc#owner">>,
 +                       [], __TopXMLNS),
 +    _els = lists:reverse('encode_muc_owner_$items'(Items,
 +                                                 __NewTopXMLNS,
 +                                                 'encode_muc_owner_$config'(Config,
 +                                                                            __NewTopXMLNS,
 +                                                                            'encode_muc_owner_$destroy'(Destroy,
 +                                                                                                        __NewTopXMLNS,
 +                                                                                                        [])))),
 +    _attrs = enc_xmlns_attrs(__NewTopXMLNS, __TopXMLNS),
 +    {xmlel, <<"query">>, _attrs, _els}.
 +
 +'encode_muc_owner_$items'([], __TopXMLNS, _acc) -> _acc;
 +'encode_muc_owner_$items'([Items | _els], __TopXMLNS,
 +                        _acc) ->
 +    'encode_muc_owner_$items'(_els, __TopXMLNS,
 +                            [encode_muc_owner_item(Items, __TopXMLNS)
 +                             | _acc]).
 +
 +'encode_muc_owner_$config'(undefined, __TopXMLNS,
 +                         _acc) ->
 +    _acc;
 +'encode_muc_owner_$config'(Config, __TopXMLNS, _acc) ->
 +    [encode_xdata(Config, __TopXMLNS) | _acc].
 +
 +'encode_muc_owner_$destroy'(undefined, __TopXMLNS,
 +                          _acc) ->
 +    _acc;
 +'encode_muc_owner_$destroy'(Destroy, __TopXMLNS,
 +                          _acc) ->
 +    [encode_muc_destroy(Destroy, __TopXMLNS) | _acc].
 +
 +decode_muc_password(__TopXMLNS, __IgnoreEls,
 +                  {xmlel, <<"password">>, _attrs, _els}) ->
 +    Cdata = decode_muc_password_els(__TopXMLNS, __IgnoreEls,
 +                                  _els, <<>>),
 +    Cdata.
 +
 +decode_muc_password_els(__TopXMLNS, __IgnoreEls, [],
 +                      Cdata) ->
 +    decode_muc_password_cdata(__TopXMLNS, Cdata);
 +decode_muc_password_els(__TopXMLNS, __IgnoreEls,
 +                      [{xmlcdata, _data} | _els], Cdata) ->
 +    decode_muc_password_els(__TopXMLNS, __IgnoreEls, _els,
 +                          <<Cdata/binary, _data/binary>>);
 +decode_muc_password_els(__TopXMLNS, __IgnoreEls,
 +                      [_ | _els], Cdata) ->
 +    decode_muc_password_els(__TopXMLNS, __IgnoreEls, _els,
 +                          Cdata).
 +
 +encode_muc_password(Cdata, __TopXMLNS) ->
 +    __NewTopXMLNS = choose_top_xmlns(<<>>,
 +                                   [<<"http://jabber.org/protocol/muc#owner">>,
 +                                    <<"http://jabber.org/protocol/muc#user">>,
 +                                    <<"http://jabber.org/protocol/muc">>],
 +                                   __TopXMLNS),
 +    _els = encode_muc_password_cdata(Cdata, []),
 +    _attrs = enc_xmlns_attrs(__NewTopXMLNS, __TopXMLNS),
 +    {xmlel, <<"password">>, _attrs, _els}.
 +
 +decode_muc_password_cdata(__TopXMLNS, <<>>) -> <<>>;
 +decode_muc_password_cdata(__TopXMLNS, _val) -> _val.
 +
 +encode_muc_password_cdata(<<>>, _acc) -> _acc;
 +encode_muc_password_cdata(_val, _acc) ->
 +    [{xmlcdata, _val} | _acc].
 +
 +decode_muc_user(__TopXMLNS, __IgnoreEls,
 +              {xmlel, <<"x">>, _attrs, _els}) ->
 +    {Status_codes, Items, Invites, Password, Decline,
 +     Destroy} =
 +      decode_muc_user_els(__TopXMLNS, __IgnoreEls, _els, [],
 +                          [], [], undefined, undefined, undefined),
 +    {muc_user, Decline, Destroy, Invites, Items,
 +     Status_codes, Password}.
 +
 +decode_muc_user_els(__TopXMLNS, __IgnoreEls, [],
 +                  Status_codes, Items, Invites, Password, Decline,
 +                  Destroy) ->
 +    {lists:reverse(Status_codes), lists:reverse(Items),
 +     lists:reverse(Invites), Password, Decline, Destroy};
 +decode_muc_user_els(__TopXMLNS, __IgnoreEls,
 +                  [{xmlel, <<"decline">>, _attrs, _} = _el | _els],
 +                  Status_codes, Items, Invites, Password, Decline,
 +                  Destroy) ->
 +    case get_attr(<<"xmlns">>, _attrs) of
 +      <<"">>
 +        when __TopXMLNS ==
 +               <<"http://jabber.org/protocol/muc#user">> ->
 +        decode_muc_user_els(__TopXMLNS, __IgnoreEls, _els,
 +                            Status_codes, Items, Invites, Password,
 +                            decode_muc_user_decline(__TopXMLNS, __IgnoreEls,
 +                                                    _el),
 +                            Destroy);
 +      <<"http://jabber.org/protocol/muc#user">> ->
 +        decode_muc_user_els(__TopXMLNS, __IgnoreEls, _els,
 +                            Status_codes, Items, Invites, Password,
 +                            decode_muc_user_decline(<<"http://jabber.org/protocol/muc#user">>,
 +                                                    __IgnoreEls, _el),
 +                            Destroy);
 +      _ ->
 +        decode_muc_user_els(__TopXMLNS, __IgnoreEls, _els,
 +                            Status_codes, Items, Invites, Password, Decline,
 +                            Destroy)
 +    end;
 +decode_muc_user_els(__TopXMLNS, __IgnoreEls,
 +                  [{xmlel, <<"destroy">>, _attrs, _} = _el | _els],
 +                  Status_codes, Items, Invites, Password, Decline,
 +                  Destroy) ->
 +    case get_attr(<<"xmlns">>, _attrs) of
 +      <<"">>
 +        when __TopXMLNS ==
 +               <<"http://jabber.org/protocol/muc#user">> ->
 +        decode_muc_user_els(__TopXMLNS, __IgnoreEls, _els,
 +                            Status_codes, Items, Invites, Password, Decline,
 +                            decode_muc_destroy(__TopXMLNS, __IgnoreEls, _el));
 +      <<"http://jabber.org/protocol/muc#user">> ->
 +        decode_muc_user_els(__TopXMLNS, __IgnoreEls, _els,
 +                            Status_codes, Items, Invites, Password, Decline,
 +                            decode_muc_destroy(<<"http://jabber.org/protocol/muc#user">>,
 +                                               __IgnoreEls, _el));
 +      <<"http://jabber.org/protocol/muc#owner">> ->
 +        decode_muc_user_els(__TopXMLNS, __IgnoreEls, _els,
 +                            Status_codes, Items, Invites, Password, Decline,
 +                            decode_muc_destroy(<<"http://jabber.org/protocol/muc#owner">>,
 +                                               __IgnoreEls, _el));
 +      _ ->
 +        decode_muc_user_els(__TopXMLNS, __IgnoreEls, _els,
 +                            Status_codes, Items, Invites, Password, Decline,
 +                            Destroy)
 +    end;
 +decode_muc_user_els(__TopXMLNS, __IgnoreEls,
 +                  [{xmlel, <<"password">>, _attrs, _} = _el | _els],
 +                  Status_codes, Items, Invites, Password, Decline,
 +                  Destroy) ->
 +    case get_attr(<<"xmlns">>, _attrs) of
 +      <<"">>
 +        when __TopXMLNS ==
 +               <<"http://jabber.org/protocol/muc#user">> ->
 +        decode_muc_user_els(__TopXMLNS, __IgnoreEls, _els,
 +                            Status_codes, Items, Invites,
 +                            decode_muc_password(__TopXMLNS, __IgnoreEls, _el),
 +                            Decline, Destroy);
 +      <<"http://jabber.org/protocol/muc#owner">> ->
 +        decode_muc_user_els(__TopXMLNS, __IgnoreEls, _els,
 +                            Status_codes, Items, Invites,
 +                            decode_muc_password(<<"http://jabber.org/protocol/muc#owner">>,
 +                                                __IgnoreEls, _el),
 +                            Decline, Destroy);
 +      <<"http://jabber.org/protocol/muc#user">> ->
 +        decode_muc_user_els(__TopXMLNS, __IgnoreEls, _els,
 +                            Status_codes, Items, Invites,
 +                            decode_muc_password(<<"http://jabber.org/protocol/muc#user">>,
 +                                                __IgnoreEls, _el),
 +                            Decline, Destroy);
 +      <<"http://jabber.org/protocol/muc">> ->
 +        decode_muc_user_els(__TopXMLNS, __IgnoreEls, _els,
 +                            Status_codes, Items, Invites,
 +                            decode_muc_password(<<"http://jabber.org/protocol/muc">>,
 +                                                __IgnoreEls, _el),
 +                            Decline, Destroy);
 +      _ ->
 +        decode_muc_user_els(__TopXMLNS, __IgnoreEls, _els,
 +                            Status_codes, Items, Invites, Password, Decline,
 +                            Destroy)
 +    end;
 +decode_muc_user_els(__TopXMLNS, __IgnoreEls,
 +                  [{xmlel, <<"invite">>, _attrs, _} = _el | _els],
 +                  Status_codes, Items, Invites, Password, Decline,
 +                  Destroy) ->
 +    case get_attr(<<"xmlns">>, _attrs) of
 +      <<"">>
 +        when __TopXMLNS ==
 +               <<"http://jabber.org/protocol/muc#user">> ->
 +        decode_muc_user_els(__TopXMLNS, __IgnoreEls, _els,
 +                            Status_codes, Items,
 +                            [decode_muc_user_invite(__TopXMLNS, __IgnoreEls,
 +                                                    _el)
 +                             | Invites],
 +                            Password, Decline, Destroy);
 +      <<"http://jabber.org/protocol/muc#user">> ->
 +        decode_muc_user_els(__TopXMLNS, __IgnoreEls, _els,
 +                            Status_codes, Items,
 +                            [decode_muc_user_invite(<<"http://jabber.org/protocol/muc#user">>,
 +                                                    __IgnoreEls, _el)
 +                             | Invites],
 +                            Password, Decline, Destroy);
 +      _ ->
 +        decode_muc_user_els(__TopXMLNS, __IgnoreEls, _els,
 +                            Status_codes, Items, Invites, Password, Decline,
 +                            Destroy)
 +    end;
 +decode_muc_user_els(__TopXMLNS, __IgnoreEls,
 +                  [{xmlel, <<"item">>, _attrs, _} = _el | _els],
 +                  Status_codes, Items, Invites, Password, Decline,
 +                  Destroy) ->
 +    case get_attr(<<"xmlns">>, _attrs) of
 +      <<"">>
 +        when __TopXMLNS ==
 +               <<"http://jabber.org/protocol/muc#user">> ->
 +        decode_muc_user_els(__TopXMLNS, __IgnoreEls, _els,
 +                            Status_codes,
 +                            [decode_muc_user_item(__TopXMLNS, __IgnoreEls,
 +                                                  _el)
 +                             | Items],
 +                            Invites, Password, Decline, Destroy);
 +      <<"http://jabber.org/protocol/muc#user">> ->
 +        decode_muc_user_els(__TopXMLNS, __IgnoreEls, _els,
 +                            Status_codes,
 +                            [decode_muc_user_item(<<"http://jabber.org/protocol/muc#user">>,
 +                                                  __IgnoreEls, _el)
 +                             | Items],
 +                            Invites, Password, Decline, Destroy);
 +      _ ->
 +        decode_muc_user_els(__TopXMLNS, __IgnoreEls, _els,
 +                            Status_codes, Items, Invites, Password, Decline,
 +                            Destroy)
 +    end;
 +decode_muc_user_els(__TopXMLNS, __IgnoreEls,
 +                  [{xmlel, <<"status">>, _attrs, _} = _el | _els],
 +                  Status_codes, Items, Invites, Password, Decline,
 +                  Destroy) ->
 +    case get_attr(<<"xmlns">>, _attrs) of
 +      <<"">>
 +        when __TopXMLNS ==
 +               <<"http://jabber.org/protocol/muc#user">> ->
 +        decode_muc_user_els(__TopXMLNS, __IgnoreEls, _els,
 +                            case decode_muc_user_status(__TopXMLNS,
 +                                                        __IgnoreEls, _el)
 +                                of
 +                              undefined -> Status_codes;
 +                              _new_el -> [_new_el | Status_codes]
 +                            end,
 +                            Items, Invites, Password, Decline, Destroy);
 +      <<"http://jabber.org/protocol/muc#user">> ->
 +        decode_muc_user_els(__TopXMLNS, __IgnoreEls, _els,
 +                            case
 +                              decode_muc_user_status(<<"http://jabber.org/protocol/muc#user">>,
 +                                                     __IgnoreEls, _el)
 +                                of
 +                              undefined -> Status_codes;
 +                              _new_el -> [_new_el | Status_codes]
 +                            end,
 +                            Items, Invites, Password, Decline, Destroy);
 +      _ ->
 +        decode_muc_user_els(__TopXMLNS, __IgnoreEls, _els,
 +                            Status_codes, Items, Invites, Password, Decline,
 +                            Destroy)
 +    end;
 +decode_muc_user_els(__TopXMLNS, __IgnoreEls, [_ | _els],
 +                  Status_codes, Items, Invites, Password, Decline,
 +                  Destroy) ->
 +    decode_muc_user_els(__TopXMLNS, __IgnoreEls, _els,
 +                      Status_codes, Items, Invites, Password, Decline,
 +                      Destroy).
 +
 +encode_muc_user({muc_user, Decline, Destroy, Invites,
 +               Items, Status_codes, Password},
 +              __TopXMLNS) ->
 +    __NewTopXMLNS =
 +      choose_top_xmlns(<<"http://jabber.org/protocol/muc#user">>,
 +                       [], __TopXMLNS),
 +    _els =
 +      lists:reverse('encode_muc_user_$status_codes'(Status_codes,
 +                                                    __NewTopXMLNS,
 +                                                    'encode_muc_user_$items'(Items,
 +                                                                             __NewTopXMLNS,
 +                                                                             'encode_muc_user_$invites'(Invites,
 +                                                                                                        __NewTopXMLNS,
 +                                                                                                        'encode_muc_user_$password'(Password,
 +                                                                                                                                    __NewTopXMLNS,
 +                                                                                                                                    'encode_muc_user_$decline'(Decline,
 +                                                                                                                                                               __NewTopXMLNS,
 +                                                                                                                                                               'encode_muc_user_$destroy'(Destroy,
 +                                                                                                                                                                                          __NewTopXMLNS,
 +                                                                                                                                                                                          []))))))),
 +    _attrs = enc_xmlns_attrs(__NewTopXMLNS, __TopXMLNS),
 +    {xmlel, <<"x">>, _attrs, _els}.
 +
 +'encode_muc_user_$status_codes'([], __TopXMLNS, _acc) ->
 +    _acc;
 +'encode_muc_user_$status_codes'([Status_codes | _els],
 +                              __TopXMLNS, _acc) ->
 +    'encode_muc_user_$status_codes'(_els, __TopXMLNS,
 +                                  [encode_muc_user_status(Status_codes,
 +                                                          __TopXMLNS)
 +                                   | _acc]).
 +
 +'encode_muc_user_$items'([], __TopXMLNS, _acc) -> _acc;
 +'encode_muc_user_$items'([Items | _els], __TopXMLNS,
 +                       _acc) ->
 +    'encode_muc_user_$items'(_els, __TopXMLNS,
 +                           [encode_muc_user_item(Items, __TopXMLNS) | _acc]).
 +
 +'encode_muc_user_$invites'([], __TopXMLNS, _acc) ->
 +    _acc;
 +'encode_muc_user_$invites'([Invites | _els], __TopXMLNS,
 +                         _acc) ->
 +    'encode_muc_user_$invites'(_els, __TopXMLNS,
 +                             [encode_muc_user_invite(Invites, __TopXMLNS)
 +                              | _acc]).
 +
 +'encode_muc_user_$password'(undefined, __TopXMLNS,
 +                          _acc) ->
 +    _acc;
 +'encode_muc_user_$password'(Password, __TopXMLNS,
 +                          _acc) ->
 +    [encode_muc_password(Password, __TopXMLNS) | _acc].
 +
 +'encode_muc_user_$decline'(undefined, __TopXMLNS,
 +                         _acc) ->
 +    _acc;
 +'encode_muc_user_$decline'(Decline, __TopXMLNS, _acc) ->
 +    [encode_muc_user_decline(Decline, __TopXMLNS) | _acc].
 +
 +'encode_muc_user_$destroy'(undefined, __TopXMLNS,
 +                         _acc) ->
 +    _acc;
 +'encode_muc_user_$destroy'(Destroy, __TopXMLNS, _acc) ->
 +    [encode_muc_destroy(Destroy, __TopXMLNS) | _acc].
 +
 +decode_muc_user_item(__TopXMLNS, __IgnoreEls,
 +                   {xmlel, <<"item">>, _attrs, _els}) ->
 +    {Actor, Continue, Reason} =
 +      decode_muc_user_item_els(__TopXMLNS, __IgnoreEls, _els,
 +                               undefined, undefined, <<>>),
 +    {Affiliation, Role, Jid, Nick} =
 +      decode_muc_user_item_attrs(__TopXMLNS, _attrs,
 +                                 undefined, undefined, undefined, undefined),
 +    {muc_item, Actor, Continue, Reason, Affiliation, Role,
 +     Jid, Nick}.
 +
 +decode_muc_user_item_els(__TopXMLNS, __IgnoreEls, [],
 +                       Actor, Continue, Reason) ->
 +    {Actor, Continue, Reason};
 +decode_muc_user_item_els(__TopXMLNS, __IgnoreEls,
 +                       [{xmlel, <<"actor">>, _attrs, _} = _el | _els], Actor,
 +                       Continue, Reason) ->
 +    case get_attr(<<"xmlns">>, _attrs) of
 +      <<"">>
 +        when __TopXMLNS ==
 +               <<"http://jabber.org/protocol/muc#user">> ->
 +        decode_muc_user_item_els(__TopXMLNS, __IgnoreEls, _els,
 +                                 decode_muc_user_actor(__TopXMLNS,
 +                                                       __IgnoreEls, _el),
 +                                 Continue, Reason);
 +      <<"http://jabber.org/protocol/muc#user">> ->
 +        decode_muc_user_item_els(__TopXMLNS, __IgnoreEls, _els,
 +                                 decode_muc_user_actor(<<"http://jabber.org/protocol/muc#user">>,
 +                                                       __IgnoreEls, _el),
 +                                 Continue, Reason);
 +      _ ->
 +        decode_muc_user_item_els(__TopXMLNS, __IgnoreEls, _els,
 +                                 Actor, Continue, Reason)
 +    end;
 +decode_muc_user_item_els(__TopXMLNS, __IgnoreEls,
 +                       [{xmlel, <<"continue">>, _attrs, _} = _el | _els],
 +                       Actor, Continue, Reason) ->
 +    case get_attr(<<"xmlns">>, _attrs) of
 +      <<"">>
 +        when __TopXMLNS ==
 +               <<"http://jabber.org/protocol/muc#user">> ->
 +        decode_muc_user_item_els(__TopXMLNS, __IgnoreEls, _els,
 +                                 Actor,
 +                                 decode_muc_user_continue(__TopXMLNS,
 +                                                          __IgnoreEls, _el),
 +                                 Reason);
 +      <<"http://jabber.org/protocol/muc#user">> ->
 +        decode_muc_user_item_els(__TopXMLNS, __IgnoreEls, _els,
 +                                 Actor,
 +                                 decode_muc_user_continue(<<"http://jabber.org/protocol/muc#user">>,
 +                                                          __IgnoreEls, _el),
 +                                 Reason);
 +      _ ->
 +        decode_muc_user_item_els(__TopXMLNS, __IgnoreEls, _els,
 +                                 Actor, Continue, Reason)
 +    end;
 +decode_muc_user_item_els(__TopXMLNS, __IgnoreEls,
 +                       [{xmlel, <<"reason">>, _attrs, _} = _el | _els], Actor,
 +                       Continue, Reason) ->
 +    case get_attr(<<"xmlns">>, _attrs) of
 +      <<"">>
 +        when __TopXMLNS ==
 +               <<"http://jabber.org/protocol/muc#user">> ->
 +        decode_muc_user_item_els(__TopXMLNS, __IgnoreEls, _els,
 +                                 Actor, Continue,
 +                                 decode_muc_reason(__TopXMLNS, __IgnoreEls,
 +                                                   _el));
 +      <<"http://jabber.org/protocol/muc#user">> ->
 +        decode_muc_user_item_els(__TopXMLNS, __IgnoreEls, _els,
 +                                 Actor, Continue,
 +                                 decode_muc_reason(<<"http://jabber.org/protocol/muc#user">>,
 +                                                   __IgnoreEls, _el));
 +      <<"http://jabber.org/protocol/muc#admin">> ->
 +        decode_muc_user_item_els(__TopXMLNS, __IgnoreEls, _els,
 +                                 Actor, Continue,
 +                                 decode_muc_reason(<<"http://jabber.org/protocol/muc#admin">>,
 +                                                   __IgnoreEls, _el));
 +      <<"http://jabber.org/protocol/muc#owner">> ->
 +        decode_muc_user_item_els(__TopXMLNS, __IgnoreEls, _els,
 +                                 Actor, Continue,
 +                                 decode_muc_reason(<<"http://jabber.org/protocol/muc#owner">>,
 +                                                   __IgnoreEls, _el));
 +      _ ->
 +        decode_muc_user_item_els(__TopXMLNS, __IgnoreEls, _els,
 +                                 Actor, Continue, Reason)
 +    end;
 +decode_muc_user_item_els(__TopXMLNS, __IgnoreEls,
 +                       [_ | _els], Actor, Continue, Reason) ->
 +    decode_muc_user_item_els(__TopXMLNS, __IgnoreEls, _els,
 +                           Actor, Continue, Reason).
 +
 +decode_muc_user_item_attrs(__TopXMLNS,
 +                         [{<<"affiliation">>, _val} | _attrs], _Affiliation,
 +                         Role, Jid, Nick) ->
 +    decode_muc_user_item_attrs(__TopXMLNS, _attrs, _val,
 +                             Role, Jid, Nick);
 +decode_muc_user_item_attrs(__TopXMLNS,
 +                         [{<<"role">>, _val} | _attrs], Affiliation, _Role,
 +                         Jid, Nick) ->
 +    decode_muc_user_item_attrs(__TopXMLNS, _attrs,
 +                             Affiliation, _val, Jid, Nick);
 +decode_muc_user_item_attrs(__TopXMLNS,
 +                         [{<<"jid">>, _val} | _attrs], Affiliation, Role,
 +                         _Jid, Nick) ->
 +    decode_muc_user_item_attrs(__TopXMLNS, _attrs,
 +                             Affiliation, Role, _val, Nick);
 +decode_muc_user_item_attrs(__TopXMLNS,
 +                         [{<<"nick">>, _val} | _attrs], Affiliation, Role,
 +                         Jid, _Nick) ->
 +    decode_muc_user_item_attrs(__TopXMLNS, _attrs,
 +                             Affiliation, Role, Jid, _val);
 +decode_muc_user_item_attrs(__TopXMLNS, [_ | _attrs],
 +                         Affiliation, Role, Jid, Nick) ->
 +    decode_muc_user_item_attrs(__TopXMLNS, _attrs,
 +                             Affiliation, Role, Jid, Nick);
 +decode_muc_user_item_attrs(__TopXMLNS, [], Affiliation,
 +                         Role, Jid, Nick) ->
 +    {decode_muc_user_item_attr_affiliation(__TopXMLNS,
 +                                         Affiliation),
 +     decode_muc_user_item_attr_role(__TopXMLNS, Role),
 +     decode_muc_user_item_attr_jid(__TopXMLNS, Jid),
 +     decode_muc_user_item_attr_nick(__TopXMLNS, Nick)}.
 +
 +encode_muc_user_item({muc_item, Actor, Continue, Reason,
 +                    Affiliation, Role, Jid, Nick},
 +                   __TopXMLNS) ->
 +    __NewTopXMLNS =
 +      choose_top_xmlns(<<"http://jabber.org/protocol/muc#user">>,
 +                       [], __TopXMLNS),
 +    _els =
 +      lists:reverse('encode_muc_user_item_$actor'(Actor,
 +                                                  __NewTopXMLNS,
 +                                                  'encode_muc_user_item_$continue'(Continue,
 +                                                                                   __NewTopXMLNS,
 +                                                                                   'encode_muc_user_item_$reason'(Reason,
 +                                                                                                                  __NewTopXMLNS,
 +                                                                                                                  [])))),
 +    _attrs = encode_muc_user_item_attr_nick(Nick,
 +                                          encode_muc_user_item_attr_jid(Jid,
 +                                                                        encode_muc_user_item_attr_role(Role,
 +                                                                                                       encode_muc_user_item_attr_affiliation(Affiliation,
 +                                                                                                                                             enc_xmlns_attrs(__NewTopXMLNS,
 +                                                                                                                                                             __TopXMLNS))))),
 +    {xmlel, <<"item">>, _attrs, _els}.
 +
 +'encode_muc_user_item_$actor'(undefined, __TopXMLNS,
 +                            _acc) ->
 +    _acc;
 +'encode_muc_user_item_$actor'(Actor, __TopXMLNS,
 +                            _acc) ->
 +    [encode_muc_user_actor(Actor, __TopXMLNS) | _acc].
 +
 +'encode_muc_user_item_$continue'(undefined, __TopXMLNS,
 +                               _acc) ->
 +    _acc;
 +'encode_muc_user_item_$continue'(Continue, __TopXMLNS,
 +                               _acc) ->
 +    [encode_muc_user_continue(Continue, __TopXMLNS) | _acc].
 +
 +'encode_muc_user_item_$reason'(<<>>, __TopXMLNS,
 +                             _acc) ->
 +    _acc;
 +'encode_muc_user_item_$reason'(Reason, __TopXMLNS,
 +                             _acc) ->
 +    [encode_muc_reason(Reason, __TopXMLNS) | _acc].
 +
 +decode_muc_user_item_attr_affiliation(__TopXMLNS,
 +                                    undefined) ->
 +    undefined;
 +decode_muc_user_item_attr_affiliation(__TopXMLNS,
 +                                    _val) ->
 +    case catch dec_enum(_val,
 +                      [admin, member, none, outcast, owner])
 +      of
 +      {'EXIT', _} ->
 +        erlang:error({xmpp_codec,
 +                      {bad_attr_value, <<"affiliation">>, <<"item">>,
 +                       __TopXMLNS}});
 +      _res -> _res
 +    end.
 +
 +encode_muc_user_item_attr_affiliation(undefined,
 +                                    _acc) ->
 +    _acc;
 +encode_muc_user_item_attr_affiliation(_val, _acc) ->
 +    [{<<"affiliation">>, enc_enum(_val)} | _acc].
 +
 +decode_muc_user_item_attr_role(__TopXMLNS, undefined) ->
 +    undefined;
 +decode_muc_user_item_attr_role(__TopXMLNS, _val) ->
 +    case catch dec_enum(_val,
 +                      [moderator, none, participant, visitor])
 +      of
 +      {'EXIT', _} ->
 +        erlang:error({xmpp_codec,
 +                      {bad_attr_value, <<"role">>, <<"item">>, __TopXMLNS}});
 +      _res -> _res
 +    end.
 +
 +encode_muc_user_item_attr_role(undefined, _acc) -> _acc;
 +encode_muc_user_item_attr_role(_val, _acc) ->
 +    [{<<"role">>, enc_enum(_val)} | _acc].
 +
 +decode_muc_user_item_attr_jid(__TopXMLNS, undefined) ->
 +    undefined;
 +decode_muc_user_item_attr_jid(__TopXMLNS, _val) ->
 +    case catch dec_jid(_val) of
 +      {'EXIT', _} ->
 +        erlang:error({xmpp_codec,
 +                      {bad_attr_value, <<"jid">>, <<"item">>, __TopXMLNS}});
 +      _res -> _res
 +    end.
 +
 +encode_muc_user_item_attr_jid(undefined, _acc) -> _acc;
 +encode_muc_user_item_attr_jid(_val, _acc) ->
 +    [{<<"jid">>, enc_jid(_val)} | _acc].
 +
 +decode_muc_user_item_attr_nick(__TopXMLNS, undefined) ->
 +    <<>>;
 +decode_muc_user_item_attr_nick(__TopXMLNS, _val) ->
 +    _val.
 +
 +encode_muc_user_item_attr_nick(<<>>, _acc) -> _acc;
 +encode_muc_user_item_attr_nick(_val, _acc) ->
 +    [{<<"nick">>, _val} | _acc].
 +
 +decode_muc_user_status(__TopXMLNS, __IgnoreEls,
 +                     {xmlel, <<"status">>, _attrs, _els}) ->
 +    Code = decode_muc_user_status_attrs(__TopXMLNS, _attrs,
 +                                      undefined),
 +    Code.
 +
 +decode_muc_user_status_attrs(__TopXMLNS,
 +                           [{<<"code">>, _val} | _attrs], _Code) ->
 +    decode_muc_user_status_attrs(__TopXMLNS, _attrs, _val);
 +decode_muc_user_status_attrs(__TopXMLNS, [_ | _attrs],
 +                           Code) ->
 +    decode_muc_user_status_attrs(__TopXMLNS, _attrs, Code);
 +decode_muc_user_status_attrs(__TopXMLNS, [], Code) ->
 +    decode_muc_user_status_attr_code(__TopXMLNS, Code).
 +
 +encode_muc_user_status(Code, __TopXMLNS) ->
 +    __NewTopXMLNS =
 +      choose_top_xmlns(<<"http://jabber.org/protocol/muc#user">>,
 +                       [], __TopXMLNS),
 +    _els = [],
 +    _attrs = encode_muc_user_status_attr_code(Code,
 +                                            enc_xmlns_attrs(__NewTopXMLNS,
 +                                                            __TopXMLNS)),
 +    {xmlel, <<"status">>, _attrs, _els}.
 +
 +decode_muc_user_status_attr_code(__TopXMLNS,
 +                               undefined) ->
 +    undefined;
 +decode_muc_user_status_attr_code(__TopXMLNS, _val) ->
 +    case catch dec_int(_val, 100, 999) of
 +      {'EXIT', _} ->
 +        erlang:error({xmpp_codec,
 +                      {bad_attr_value, <<"code">>, <<"status">>,
 +                       __TopXMLNS}});
 +      _res -> _res
 +    end.
 +
 +encode_muc_user_status_attr_code(undefined, _acc) ->
 +    _acc;
 +encode_muc_user_status_attr_code(_val, _acc) ->
 +    [{<<"code">>, enc_int(_val)} | _acc].
 +
 +decode_muc_user_continue(__TopXMLNS, __IgnoreEls,
 +                       {xmlel, <<"continue">>, _attrs, _els}) ->
 +    Thread = decode_muc_user_continue_attrs(__TopXMLNS,
 +                                          _attrs, undefined),
 +    Thread.
 +
 +decode_muc_user_continue_attrs(__TopXMLNS,
 +                             [{<<"thread">>, _val} | _attrs], _Thread) ->
 +    decode_muc_user_continue_attrs(__TopXMLNS, _attrs,
 +                                 _val);
 +decode_muc_user_continue_attrs(__TopXMLNS, [_ | _attrs],
 +                             Thread) ->
 +    decode_muc_user_continue_attrs(__TopXMLNS, _attrs,
 +                                 Thread);
 +decode_muc_user_continue_attrs(__TopXMLNS, [],
 +                             Thread) ->
 +    decode_muc_user_continue_attr_thread(__TopXMLNS,
 +                                       Thread).
 +
 +encode_muc_user_continue(Thread, __TopXMLNS) ->
 +    __NewTopXMLNS =
 +      choose_top_xmlns(<<"http://jabber.org/protocol/muc#user">>,
 +                       [], __TopXMLNS),
 +    _els = [],
 +    _attrs = encode_muc_user_continue_attr_thread(Thread,
 +                                                enc_xmlns_attrs(__NewTopXMLNS,
 +                                                                __TopXMLNS)),
 +    {xmlel, <<"continue">>, _attrs, _els}.
 +
 +decode_muc_user_continue_attr_thread(__TopXMLNS,
 +                                   undefined) ->
 +    <<>>;
 +decode_muc_user_continue_attr_thread(__TopXMLNS,
 +                                   _val) ->
 +    _val.
 +
 +encode_muc_user_continue_attr_thread(<<>>, _acc) ->
 +    _acc;
 +encode_muc_user_continue_attr_thread(_val, _acc) ->
 +    [{<<"thread">>, _val} | _acc].
 +
 +decode_muc_user_actor(__TopXMLNS, __IgnoreEls,
 +                    {xmlel, <<"actor">>, _attrs, _els}) ->
 +    {Jid, Nick} = decode_muc_user_actor_attrs(__TopXMLNS,
 +                                            _attrs, undefined, undefined),
 +    {muc_actor, Jid, Nick}.
 +
 +decode_muc_user_actor_attrs(__TopXMLNS,
 +                          [{<<"jid">>, _val} | _attrs], _Jid, Nick) ->
 +    decode_muc_user_actor_attrs(__TopXMLNS, _attrs, _val,
 +                              Nick);
 +decode_muc_user_actor_attrs(__TopXMLNS,
 +                          [{<<"nick">>, _val} | _attrs], Jid, _Nick) ->
 +    decode_muc_user_actor_attrs(__TopXMLNS, _attrs, Jid,
 +                              _val);
 +decode_muc_user_actor_attrs(__TopXMLNS, [_ | _attrs],
 +                          Jid, Nick) ->
 +    decode_muc_user_actor_attrs(__TopXMLNS, _attrs, Jid,
 +                              Nick);
 +decode_muc_user_actor_attrs(__TopXMLNS, [], Jid,
 +                          Nick) ->
 +    {decode_muc_user_actor_attr_jid(__TopXMLNS, Jid),
 +     decode_muc_user_actor_attr_nick(__TopXMLNS, Nick)}.
 +
 +encode_muc_user_actor({muc_actor, Jid, Nick},
 +                    __TopXMLNS) ->
 +    __NewTopXMLNS =
 +      choose_top_xmlns(<<"http://jabber.org/protocol/muc#user">>,
 +                       [], __TopXMLNS),
 +    _els = [],
 +    _attrs = encode_muc_user_actor_attr_nick(Nick,
 +                                           encode_muc_user_actor_attr_jid(Jid,
 +                                                                          enc_xmlns_attrs(__NewTopXMLNS,
 +                                                                                          __TopXMLNS))),
 +    {xmlel, <<"actor">>, _attrs, _els}.
 +
 +decode_muc_user_actor_attr_jid(__TopXMLNS, undefined) ->
 +    undefined;
 +decode_muc_user_actor_attr_jid(__TopXMLNS, _val) ->
 +    case catch dec_jid(_val) of
 +      {'EXIT', _} ->
 +        erlang:error({xmpp_codec,
 +                      {bad_attr_value, <<"jid">>, <<"actor">>, __TopXMLNS}});
 +      _res -> _res
 +    end.
 +
 +encode_muc_user_actor_attr_jid(undefined, _acc) -> _acc;
 +encode_muc_user_actor_attr_jid(_val, _acc) ->
 +    [{<<"jid">>, enc_jid(_val)} | _acc].
 +
 +decode_muc_user_actor_attr_nick(__TopXMLNS,
 +                              undefined) ->
 +    <<>>;
 +decode_muc_user_actor_attr_nick(__TopXMLNS, _val) ->
 +    _val.
 +
 +encode_muc_user_actor_attr_nick(<<>>, _acc) -> _acc;
 +encode_muc_user_actor_attr_nick(_val, _acc) ->
 +    [{<<"nick">>, _val} | _acc].
 +
 +decode_muc_user_invite(__TopXMLNS, __IgnoreEls,
 +                     {xmlel, <<"invite">>, _attrs, _els}) ->
 +    {Continue, Reason} =
 +      decode_muc_user_invite_els(__TopXMLNS, __IgnoreEls,
 +                                 _els, undefined, <<>>),
 +    {To, From} = decode_muc_user_invite_attrs(__TopXMLNS,
 +                                            _attrs, undefined, undefined),
 +    {muc_invite, Reason, From, To, Continue}.
 +
 +decode_muc_user_invite_els(__TopXMLNS, __IgnoreEls, [],
 +                         Continue, Reason) ->
 +    {Continue, Reason};
 +decode_muc_user_invite_els(__TopXMLNS, __IgnoreEls,
 +                         [{xmlel, <<"reason">>, _attrs, _} = _el | _els],
 +                         Continue, Reason) ->
 +    case get_attr(<<"xmlns">>, _attrs) of
 +      <<"">>
 +        when __TopXMLNS ==
 +               <<"http://jabber.org/protocol/muc#user">> ->
 +        decode_muc_user_invite_els(__TopXMLNS, __IgnoreEls,
 +                                   _els, Continue,
 +                                   decode_muc_reason(__TopXMLNS, __IgnoreEls,
 +                                                     _el));
 +      <<"http://jabber.org/protocol/muc#user">> ->
 +        decode_muc_user_invite_els(__TopXMLNS, __IgnoreEls,
 +                                   _els, Continue,
 +                                   decode_muc_reason(<<"http://jabber.org/protocol/muc#user">>,
 +                                                     __IgnoreEls, _el));
 +      <<"http://jabber.org/protocol/muc#admin">> ->
 +        decode_muc_user_invite_els(__TopXMLNS, __IgnoreEls,
 +                                   _els, Continue,
 +                                   decode_muc_reason(<<"http://jabber.org/protocol/muc#admin">>,
 +                                                     __IgnoreEls, _el));
 +      <<"http://jabber.org/protocol/muc#owner">> ->
 +        decode_muc_user_invite_els(__TopXMLNS, __IgnoreEls,
 +                                   _els, Continue,
 +                                   decode_muc_reason(<<"http://jabber.org/protocol/muc#owner">>,
 +                                                     __IgnoreEls, _el));
 +      _ ->
 +        decode_muc_user_invite_els(__TopXMLNS, __IgnoreEls,
 +                                   _els, Continue, Reason)
 +    end;
 +decode_muc_user_invite_els(__TopXMLNS, __IgnoreEls,
 +                         [{xmlel, <<"continue">>, _attrs, _} = _el | _els],
 +                         Continue, Reason) ->
 +    case get_attr(<<"xmlns">>, _attrs) of
 +      <<"">>
 +        when __TopXMLNS ==
 +               <<"http://jabber.org/protocol/muc#user">> ->
 +        decode_muc_user_invite_els(__TopXMLNS, __IgnoreEls,
 +                                   _els,
 +                                   decode_muc_user_continue(__TopXMLNS,
 +                                                            __IgnoreEls, _el),
 +                                   Reason);
 +      <<"http://jabber.org/protocol/muc#user">> ->
 +        decode_muc_user_invite_els(__TopXMLNS, __IgnoreEls,
 +                                   _els,
 +                                   decode_muc_user_continue(<<"http://jabber.org/protocol/muc#user">>,
 +                                                            __IgnoreEls, _el),
 +                                   Reason);
 +      _ ->
 +        decode_muc_user_invite_els(__TopXMLNS, __IgnoreEls,
 +                                   _els, Continue, Reason)
 +    end;
 +decode_muc_user_invite_els(__TopXMLNS, __IgnoreEls,
 +                         [_ | _els], Continue, Reason) ->
 +    decode_muc_user_invite_els(__TopXMLNS, __IgnoreEls,
 +                             _els, Continue, Reason).
 +
 +decode_muc_user_invite_attrs(__TopXMLNS,
 +                           [{<<"to">>, _val} | _attrs], _To, From) ->
 +    decode_muc_user_invite_attrs(__TopXMLNS, _attrs, _val,
 +                               From);
 +decode_muc_user_invite_attrs(__TopXMLNS,
 +                           [{<<"from">>, _val} | _attrs], To, _From) ->
 +    decode_muc_user_invite_attrs(__TopXMLNS, _attrs, To,
 +                               _val);
 +decode_muc_user_invite_attrs(__TopXMLNS, [_ | _attrs],
 +                           To, From) ->
 +    decode_muc_user_invite_attrs(__TopXMLNS, _attrs, To,
 +                               From);
 +decode_muc_user_invite_attrs(__TopXMLNS, [], To,
 +                           From) ->
 +    {decode_muc_user_invite_attr_to(__TopXMLNS, To),
 +     decode_muc_user_invite_attr_from(__TopXMLNS, From)}.
 +
 +encode_muc_user_invite({muc_invite, Reason, From, To,
 +                      Continue},
 +                     __TopXMLNS) ->
 +    __NewTopXMLNS =
 +      choose_top_xmlns(<<"http://jabber.org/protocol/muc#user">>,
 +                       [], __TopXMLNS),
 +    _els =
 +      lists:reverse('encode_muc_user_invite_$continue'(Continue,
 +                                                       __NewTopXMLNS,
 +                                                       'encode_muc_user_invite_$reason'(Reason,
 +                                                                                        __NewTopXMLNS,
 +                                                                                        []))),
 +    _attrs = encode_muc_user_invite_attr_from(From,
 +                                            encode_muc_user_invite_attr_to(To,
 +                                                                           enc_xmlns_attrs(__NewTopXMLNS,
 +                                                                                           __TopXMLNS))),
 +    {xmlel, <<"invite">>, _attrs, _els}.
 +
 +'encode_muc_user_invite_$continue'(undefined,
 +                                 __TopXMLNS, _acc) ->
 +    _acc;
 +'encode_muc_user_invite_$continue'(Continue, __TopXMLNS,
 +                                 _acc) ->
 +    [encode_muc_user_continue(Continue, __TopXMLNS) | _acc].
 +
 +'encode_muc_user_invite_$reason'(<<>>, __TopXMLNS,
 +                               _acc) ->
 +    _acc;
 +'encode_muc_user_invite_$reason'(Reason, __TopXMLNS,
 +                               _acc) ->
 +    [encode_muc_reason(Reason, __TopXMLNS) | _acc].
 +
 +decode_muc_user_invite_attr_to(__TopXMLNS, undefined) ->
 +    undefined;
 +decode_muc_user_invite_attr_to(__TopXMLNS, _val) ->
 +    case catch dec_jid(_val) of
 +      {'EXIT', _} ->
 +        erlang:error({xmpp_codec,
 +                      {bad_attr_value, <<"to">>, <<"invite">>, __TopXMLNS}});
 +      _res -> _res
 +    end.
 +
 +encode_muc_user_invite_attr_to(undefined, _acc) -> _acc;
 +encode_muc_user_invite_attr_to(_val, _acc) ->
 +    [{<<"to">>, enc_jid(_val)} | _acc].
 +
 +decode_muc_user_invite_attr_from(__TopXMLNS,
 +                               undefined) ->
 +    undefined;
 +decode_muc_user_invite_attr_from(__TopXMLNS, _val) ->
 +    case catch dec_jid(_val) of
 +      {'EXIT', _} ->
 +        erlang:error({xmpp_codec,
 +                      {bad_attr_value, <<"from">>, <<"invite">>,
 +                       __TopXMLNS}});
 +      _res -> _res
 +    end.
 +
 +encode_muc_user_invite_attr_from(undefined, _acc) ->
 +    _acc;
 +encode_muc_user_invite_attr_from(_val, _acc) ->
 +    [{<<"from">>, enc_jid(_val)} | _acc].
 +
 +decode_muc_destroy(__TopXMLNS, __IgnoreEls,
 +                 {xmlel, <<"destroy">>, _attrs, _els}) ->
 +    {Password, Reason} = decode_muc_destroy_els(__TopXMLNS,
 +                                              __IgnoreEls, _els, undefined,
 +                                              <<>>),
 +    {Jid, Xmlns} = decode_muc_destroy_attrs(__TopXMLNS,
 +                                          _attrs, undefined, undefined),
 +    {muc_destroy, Xmlns, Jid, Reason, Password}.
 +
 +decode_muc_destroy_els(__TopXMLNS, __IgnoreEls, [],
 +                     Password, Reason) ->
 +    {Password, Reason};
 +decode_muc_destroy_els(__TopXMLNS, __IgnoreEls,
 +                     [{xmlel, <<"reason">>, _attrs, _} = _el | _els],
 +                     Password, Reason) ->
 +    case get_attr(<<"xmlns">>, _attrs) of
 +      <<"">>
 +        when __TopXMLNS ==
 +               <<"http://jabber.org/protocol/muc#user">>;
 +             __TopXMLNS ==
 +               <<"http://jabber.org/protocol/muc#owner">> ->
 +        decode_muc_destroy_els(__TopXMLNS, __IgnoreEls, _els,
 +                               Password,
 +                               decode_muc_reason(__TopXMLNS, __IgnoreEls,
 +                                                 _el));
 +      <<"http://jabber.org/protocol/muc#user">> ->
 +        decode_muc_destroy_els(__TopXMLNS, __IgnoreEls, _els,
 +                               Password,
 +                               decode_muc_reason(<<"http://jabber.org/protocol/muc#user">>,
 +                                                 __IgnoreEls, _el));
 +      <<"http://jabber.org/protocol/muc#admin">> ->
 +        decode_muc_destroy_els(__TopXMLNS, __IgnoreEls, _els,
 +                               Password,
 +                               decode_muc_reason(<<"http://jabber.org/protocol/muc#admin">>,
 +                                                 __IgnoreEls, _el));
 +      <<"http://jabber.org/protocol/muc#owner">> ->
 +        decode_muc_destroy_els(__TopXMLNS, __IgnoreEls, _els,
 +                               Password,
 +                               decode_muc_reason(<<"http://jabber.org/protocol/muc#owner">>,
 +                                                 __IgnoreEls, _el));
 +      _ ->
 +        decode_muc_destroy_els(__TopXMLNS, __IgnoreEls, _els,
 +                               Password, Reason)
 +    end;
 +decode_muc_destroy_els(__TopXMLNS, __IgnoreEls,
 +                     [{xmlel, <<"password">>, _attrs, _} = _el | _els],
 +                     Password, Reason) ->
 +    case get_attr(<<"xmlns">>, _attrs) of
 +      <<"">>
 +        when __TopXMLNS ==
 +               <<"http://jabber.org/protocol/muc#user">>;
 +             __TopXMLNS ==
 +               <<"http://jabber.org/protocol/muc#owner">> ->
 +        decode_muc_destroy_els(__TopXMLNS, __IgnoreEls, _els,
 +                               decode_muc_password(__TopXMLNS, __IgnoreEls,
 +                                                   _el),
 +                               Reason);
 +      <<"http://jabber.org/protocol/muc#owner">> ->
 +        decode_muc_destroy_els(__TopXMLNS, __IgnoreEls, _els,
 +                               decode_muc_password(<<"http://jabber.org/protocol/muc#owner">>,
 +                                                   __IgnoreEls, _el),
 +                               Reason);
 +      <<"http://jabber.org/protocol/muc#user">> ->
 +        decode_muc_destroy_els(__TopXMLNS, __IgnoreEls, _els,
 +                               decode_muc_password(<<"http://jabber.org/protocol/muc#user">>,
 +                                                   __IgnoreEls, _el),
 +                               Reason);
 +      <<"http://jabber.org/protocol/muc">> ->
 +        decode_muc_destroy_els(__TopXMLNS, __IgnoreEls, _els,
 +                               decode_muc_password(<<"http://jabber.org/protocol/muc">>,
 +                                                   __IgnoreEls, _el),
 +                               Reason);
 +      _ ->
 +        decode_muc_destroy_els(__TopXMLNS, __IgnoreEls, _els,
 +                               Password, Reason)
 +    end;
 +decode_muc_destroy_els(__TopXMLNS, __IgnoreEls,
 +                     [_ | _els], Password, Reason) ->
 +    decode_muc_destroy_els(__TopXMLNS, __IgnoreEls, _els,
 +                         Password, Reason).
 +
 +decode_muc_destroy_attrs(__TopXMLNS,
 +                       [{<<"jid">>, _val} | _attrs], _Jid, Xmlns) ->
 +    decode_muc_destroy_attrs(__TopXMLNS, _attrs, _val,
 +                           Xmlns);
 +decode_muc_destroy_attrs(__TopXMLNS,
 +                       [{<<"xmlns">>, _val} | _attrs], Jid, _Xmlns) ->
 +    decode_muc_destroy_attrs(__TopXMLNS, _attrs, Jid, _val);
 +decode_muc_destroy_attrs(__TopXMLNS, [_ | _attrs], Jid,
 +                       Xmlns) ->
 +    decode_muc_destroy_attrs(__TopXMLNS, _attrs, Jid,
 +                           Xmlns);
 +decode_muc_destroy_attrs(__TopXMLNS, [], Jid, Xmlns) ->
 +    {decode_muc_destroy_attr_jid(__TopXMLNS, Jid),
 +     decode_muc_destroy_attr_xmlns(__TopXMLNS, Xmlns)}.
 +
 +encode_muc_destroy({muc_destroy, Xmlns, Jid, Reason,
 +                  Password},
 +                 __TopXMLNS) ->
 +    __NewTopXMLNS = choose_top_xmlns(Xmlns,
 +                                   [<<"http://jabber.org/protocol/muc#user">>,
 +                                    <<"http://jabber.org/protocol/muc#owner">>],
 +                                   __TopXMLNS),
 +    _els =
 +      lists:reverse('encode_muc_destroy_$password'(Password,
 +                                                   __NewTopXMLNS,
 +                                                   'encode_muc_destroy_$reason'(Reason,
 +                                                                                __NewTopXMLNS,
 +                                                                                []))),
 +    _attrs = encode_muc_destroy_attr_jid(Jid,
 +                                       enc_xmlns_attrs(__NewTopXMLNS,
 +                                                       __TopXMLNS)),
 +    {xmlel, <<"destroy">>, _attrs, _els}.
 +
 +'encode_muc_destroy_$password'(undefined, __TopXMLNS,
 +                             _acc) ->
 +    _acc;
 +'encode_muc_destroy_$password'(Password, __TopXMLNS,
 +                             _acc) ->
 +    [encode_muc_password(Password, __TopXMLNS) | _acc].
 +
 +'encode_muc_destroy_$reason'(<<>>, __TopXMLNS, _acc) ->
 +    _acc;
 +'encode_muc_destroy_$reason'(Reason, __TopXMLNS,
 +                           _acc) ->
 +    [encode_muc_reason(Reason, __TopXMLNS) | _acc].
 +
 +decode_muc_destroy_attr_jid(__TopXMLNS, undefined) ->
 +    undefined;
 +decode_muc_destroy_attr_jid(__TopXMLNS, _val) ->
 +    case catch dec_jid(_val) of
 +      {'EXIT', _} ->
 +        erlang:error({xmpp_codec,
 +                      {bad_attr_value, <<"jid">>, <<"destroy">>,
 +                       __TopXMLNS}});
 +      _res -> _res
 +    end.
 +
 +encode_muc_destroy_attr_jid(undefined, _acc) -> _acc;
 +encode_muc_destroy_attr_jid(_val, _acc) ->
 +    [{<<"jid">>, enc_jid(_val)} | _acc].
 +
 +decode_muc_destroy_attr_xmlns(__TopXMLNS, undefined) ->
 +    <<>>;
 +decode_muc_destroy_attr_xmlns(__TopXMLNS, _val) -> _val.
 +
 +decode_muc_user_decline(__TopXMLNS, __IgnoreEls,
 +                      {xmlel, <<"decline">>, _attrs, _els}) ->
 +    Reason = decode_muc_user_decline_els(__TopXMLNS,
 +                                       __IgnoreEls, _els, <<>>),
 +    {To, From} = decode_muc_user_decline_attrs(__TopXMLNS,
 +                                             _attrs, undefined, undefined),
 +    {muc_decline, Reason, From, To}.
 +
 +decode_muc_user_decline_els(__TopXMLNS, __IgnoreEls, [],
 +                          Reason) ->
 +    Reason;
 +decode_muc_user_decline_els(__TopXMLNS, __IgnoreEls,
 +                          [{xmlel, <<"reason">>, _attrs, _} = _el | _els],
 +                          Reason) ->
 +    case get_attr(<<"xmlns">>, _attrs) of
 +      <<"">>
 +        when __TopXMLNS ==
 +               <<"http://jabber.org/protocol/muc#user">> ->
 +        decode_muc_user_decline_els(__TopXMLNS, __IgnoreEls,
 +                                    _els,
 +                                    decode_muc_reason(__TopXMLNS, __IgnoreEls,
 +                                                      _el));
 +      <<"http://jabber.org/protocol/muc#user">> ->
 +        decode_muc_user_decline_els(__TopXMLNS, __IgnoreEls,
 +                                    _els,
 +                                    decode_muc_reason(<<"http://jabber.org/protocol/muc#user">>,
 +                                                      __IgnoreEls, _el));
 +      <<"http://jabber.org/protocol/muc#admin">> ->
 +        decode_muc_user_decline_els(__TopXMLNS, __IgnoreEls,
 +                                    _els,
 +                                    decode_muc_reason(<<"http://jabber.org/protocol/muc#admin">>,
 +                                                      __IgnoreEls, _el));
 +      <<"http://jabber.org/protocol/muc#owner">> ->
 +        decode_muc_user_decline_els(__TopXMLNS, __IgnoreEls,
 +                                    _els,
 +                                    decode_muc_reason(<<"http://jabber.org/protocol/muc#owner">>,
 +                                                      __IgnoreEls, _el));
 +      _ ->
 +        decode_muc_user_decline_els(__TopXMLNS, __IgnoreEls,
 +                                    _els, Reason)
 +    end;
 +decode_muc_user_decline_els(__TopXMLNS, __IgnoreEls,
 +                          [_ | _els], Reason) ->
 +    decode_muc_user_decline_els(__TopXMLNS, __IgnoreEls,
 +                              _els, Reason).
 +
 +decode_muc_user_decline_attrs(__TopXMLNS,
 +                            [{<<"to">>, _val} | _attrs], _To, From) ->
 +    decode_muc_user_decline_attrs(__TopXMLNS, _attrs, _val,
 +                                From);
 +decode_muc_user_decline_attrs(__TopXMLNS,
 +                            [{<<"from">>, _val} | _attrs], To, _From) ->
 +    decode_muc_user_decline_attrs(__TopXMLNS, _attrs, To,
 +                                _val);
 +decode_muc_user_decline_attrs(__TopXMLNS, [_ | _attrs],
 +                            To, From) ->
 +    decode_muc_user_decline_attrs(__TopXMLNS, _attrs, To,
 +                                From);
 +decode_muc_user_decline_attrs(__TopXMLNS, [], To,
 +                            From) ->
 +    {decode_muc_user_decline_attr_to(__TopXMLNS, To),
 +     decode_muc_user_decline_attr_from(__TopXMLNS, From)}.
 +
 +encode_muc_user_decline({muc_decline, Reason, From, To},
 +                      __TopXMLNS) ->
 +    __NewTopXMLNS =
 +      choose_top_xmlns(<<"http://jabber.org/protocol/muc#user">>,
 +                       [], __TopXMLNS),
 +    _els =
 +      lists:reverse('encode_muc_user_decline_$reason'(Reason,
 +                                                      __NewTopXMLNS, [])),
 +    _attrs = encode_muc_user_decline_attr_from(From,
 +                                             encode_muc_user_decline_attr_to(To,
 +                                                                             enc_xmlns_attrs(__NewTopXMLNS,
 +                                                                                             __TopXMLNS))),
 +    {xmlel, <<"decline">>, _attrs, _els}.
 +
 +'encode_muc_user_decline_$reason'(<<>>, __TopXMLNS,
 +                                _acc) ->
 +    _acc;
 +'encode_muc_user_decline_$reason'(Reason, __TopXMLNS,
 +                                _acc) ->
 +    [encode_muc_reason(Reason, __TopXMLNS) | _acc].
 +
 +decode_muc_user_decline_attr_to(__TopXMLNS,
 +                              undefined) ->
 +    undefined;
 +decode_muc_user_decline_attr_to(__TopXMLNS, _val) ->
 +    case catch dec_jid(_val) of
 +      {'EXIT', _} ->
 +        erlang:error({xmpp_codec,
 +                      {bad_attr_value, <<"to">>, <<"decline">>, __TopXMLNS}});
 +      _res -> _res
 +    end.
 +
 +encode_muc_user_decline_attr_to(undefined, _acc) ->
 +    _acc;
 +encode_muc_user_decline_attr_to(_val, _acc) ->
 +    [{<<"to">>, enc_jid(_val)} | _acc].
 +
 +decode_muc_user_decline_attr_from(__TopXMLNS,
 +                                undefined) ->
 +    undefined;
 +decode_muc_user_decline_attr_from(__TopXMLNS, _val) ->
 +    case catch dec_jid(_val) of
 +      {'EXIT', _} ->
 +        erlang:error({xmpp_codec,
 +                      {bad_attr_value, <<"from">>, <<"decline">>,
 +                       __TopXMLNS}});
 +      _res -> _res
 +    end.
 +
 +encode_muc_user_decline_attr_from(undefined, _acc) ->
 +    _acc;
 +encode_muc_user_decline_attr_from(_val, _acc) ->
 +    [{<<"from">>, enc_jid(_val)} | _acc].
 +
 +decode_muc_reason(__TopXMLNS, __IgnoreEls,
 +                {xmlel, <<"reason">>, _attrs, _els}) ->
 +    Cdata = decode_muc_reason_els(__TopXMLNS, __IgnoreEls,
 +                                _els, <<>>),
 +    Cdata.
 +
 +decode_muc_reason_els(__TopXMLNS, __IgnoreEls, [],
 +                    Cdata) ->
 +    decode_muc_reason_cdata(__TopXMLNS, Cdata);
 +decode_muc_reason_els(__TopXMLNS, __IgnoreEls,
 +                    [{xmlcdata, _data} | _els], Cdata) ->
 +    decode_muc_reason_els(__TopXMLNS, __IgnoreEls, _els,
 +                        <<Cdata/binary, _data/binary>>);
 +decode_muc_reason_els(__TopXMLNS, __IgnoreEls,
 +                    [_ | _els], Cdata) ->
 +    decode_muc_reason_els(__TopXMLNS, __IgnoreEls, _els,
 +                        Cdata).
 +
 +encode_muc_reason(Cdata, __TopXMLNS) ->
 +    __NewTopXMLNS = choose_top_xmlns(<<>>,
 +                                   [<<"http://jabber.org/protocol/muc#user">>,
 +                                    <<"http://jabber.org/protocol/muc#admin">>,
 +                                    <<"http://jabber.org/protocol/muc#owner">>],
 +                                   __TopXMLNS),
 +    _els = encode_muc_reason_cdata(Cdata, []),
 +    _attrs = enc_xmlns_attrs(__NewTopXMLNS, __TopXMLNS),
 +    {xmlel, <<"reason">>, _attrs, _els}.
 +
 +decode_muc_reason_cdata(__TopXMLNS, <<>>) -> <<>>;
 +decode_muc_reason_cdata(__TopXMLNS, _val) -> _val.
 +
 +encode_muc_reason_cdata(<<>>, _acc) -> _acc;
 +encode_muc_reason_cdata(_val, _acc) ->
 +    [{xmlcdata, _val} | _acc].
 +
 +decode_muc_history(__TopXMLNS, __IgnoreEls,
 +                 {xmlel, <<"history">>, _attrs, _els}) ->
 +    {Maxchars, Maxstanzas, Seconds, Since} =
 +      decode_muc_history_attrs(__TopXMLNS, _attrs, undefined,
 +                               undefined, undefined, undefined),
 +    {muc_history, Maxchars, Maxstanzas, Seconds, Since}.
 +
 +decode_muc_history_attrs(__TopXMLNS,
 +                       [{<<"maxchars">>, _val} | _attrs], _Maxchars,
 +                       Maxstanzas, Seconds, Since) ->
 +    decode_muc_history_attrs(__TopXMLNS, _attrs, _val,
 +                           Maxstanzas, Seconds, Since);
 +decode_muc_history_attrs(__TopXMLNS,
 +                       [{<<"maxstanzas">>, _val} | _attrs], Maxchars,
 +                       _Maxstanzas, Seconds, Since) ->
 +    decode_muc_history_attrs(__TopXMLNS, _attrs, Maxchars,
 +                           _val, Seconds, Since);
 +decode_muc_history_attrs(__TopXMLNS,
 +                       [{<<"seconds">>, _val} | _attrs], Maxchars, Maxstanzas,
 +                       _Seconds, Since) ->
 +    decode_muc_history_attrs(__TopXMLNS, _attrs, Maxchars,
 +                           Maxstanzas, _val, Since);
 +decode_muc_history_attrs(__TopXMLNS,
 +                       [{<<"since">>, _val} | _attrs], Maxchars, Maxstanzas,
 +                       Seconds, _Since) ->
 +    decode_muc_history_attrs(__TopXMLNS, _attrs, Maxchars,
 +                           Maxstanzas, Seconds, _val);
 +decode_muc_history_attrs(__TopXMLNS, [_ | _attrs],
 +                       Maxchars, Maxstanzas, Seconds, Since) ->
 +    decode_muc_history_attrs(__TopXMLNS, _attrs, Maxchars,
 +                           Maxstanzas, Seconds, Since);
 +decode_muc_history_attrs(__TopXMLNS, [], Maxchars,
 +                       Maxstanzas, Seconds, Since) ->
 +    {decode_muc_history_attr_maxchars(__TopXMLNS, Maxchars),
 +     decode_muc_history_attr_maxstanzas(__TopXMLNS,
 +                                      Maxstanzas),
 +     decode_muc_history_attr_seconds(__TopXMLNS, Seconds),
 +     decode_muc_history_attr_since(__TopXMLNS, Since)}.
 +
 +encode_muc_history({muc_history, Maxchars, Maxstanzas,
 +                  Seconds, Since},
 +                 __TopXMLNS) ->
 +    __NewTopXMLNS =
 +      choose_top_xmlns(<<"http://jabber.org/protocol/muc">>,
 +                       [], __TopXMLNS),
 +    _els = [],
 +    _attrs = encode_muc_history_attr_since(Since,
 +                                         encode_muc_history_attr_seconds(Seconds,
 +                                                                         encode_muc_history_attr_maxstanzas(Maxstanzas,
 +                                                                                                            encode_muc_history_attr_maxchars(Maxchars,
 +                                                                                                                                             enc_xmlns_attrs(__NewTopXMLNS,
 +                                                                                                                                                             __TopXMLNS))))),
 +    {xmlel, <<"history">>, _attrs, _els}.
 +
 +decode_muc_history_attr_maxchars(__TopXMLNS,
 +                               undefined) ->
 +    undefined;
 +decode_muc_history_attr_maxchars(__TopXMLNS, _val) ->
 +    case catch dec_int(_val, 0, infinity) of
 +      {'EXIT', _} ->
 +        erlang:error({xmpp_codec,
 +                      {bad_attr_value, <<"maxchars">>, <<"history">>,
 +                       __TopXMLNS}});
 +      _res -> _res
 +    end.
 +
 +encode_muc_history_attr_maxchars(undefined, _acc) ->
 +    _acc;
 +encode_muc_history_attr_maxchars(_val, _acc) ->
 +    [{<<"maxchars">>, enc_int(_val)} | _acc].
 +
 +decode_muc_history_attr_maxstanzas(__TopXMLNS,
 +                                 undefined) ->
 +    undefined;
 +decode_muc_history_attr_maxstanzas(__TopXMLNS, _val) ->
 +    case catch dec_int(_val, 0, infinity) of
 +      {'EXIT', _} ->
 +        erlang:error({xmpp_codec,
 +                      {bad_attr_value, <<"maxstanzas">>, <<"history">>,
 +                       __TopXMLNS}});
 +      _res -> _res
 +    end.
 +
 +encode_muc_history_attr_maxstanzas(undefined, _acc) ->
 +    _acc;
 +encode_muc_history_attr_maxstanzas(_val, _acc) ->
 +    [{<<"maxstanzas">>, enc_int(_val)} | _acc].
 +
 +decode_muc_history_attr_seconds(__TopXMLNS,
 +                              undefined) ->
 +    undefined;
 +decode_muc_history_attr_seconds(__TopXMLNS, _val) ->
 +    case catch dec_int(_val, 0, infinity) of
 +      {'EXIT', _} ->
 +        erlang:error({xmpp_codec,
 +                      {bad_attr_value, <<"seconds">>, <<"history">>,
 +                       __TopXMLNS}});
 +      _res -> _res
 +    end.
 +
 +encode_muc_history_attr_seconds(undefined, _acc) ->
 +    _acc;
 +encode_muc_history_attr_seconds(_val, _acc) ->
 +    [{<<"seconds">>, enc_int(_val)} | _acc].
 +
 +decode_muc_history_attr_since(__TopXMLNS, undefined) ->
 +    undefined;
 +decode_muc_history_attr_since(__TopXMLNS, _val) ->
 +    case catch dec_utc(_val) of
 +      {'EXIT', _} ->
 +        erlang:error({xmpp_codec,
 +                      {bad_attr_value, <<"since">>, <<"history">>,
 +                       __TopXMLNS}});
 +      _res -> _res
 +    end.
 +
 +encode_muc_history_attr_since(undefined, _acc) -> _acc;
 +encode_muc_history_attr_since(_val, _acc) ->
 +    [{<<"since">>, enc_utc(_val)} | _acc].
 +
 +decode_bytestreams(__TopXMLNS, __IgnoreEls,
 +                 {xmlel, <<"query">>, _attrs, _els}) ->
 +    {Hosts, Used, Activate} =
 +      decode_bytestreams_els(__TopXMLNS, __IgnoreEls, _els,
 +                             [], undefined, undefined),
 +    {Dstaddr, Sid, Mode} =
 +      decode_bytestreams_attrs(__TopXMLNS, _attrs, undefined,
 +                               undefined, undefined),
 +    {bytestreams, Hosts, Used, Activate, Dstaddr, Mode,
 +     Sid}.
 +
 +decode_bytestreams_els(__TopXMLNS, __IgnoreEls, [],
 +                     Hosts, Used, Activate) ->
 +    {lists:reverse(Hosts), Used, Activate};
 +decode_bytestreams_els(__TopXMLNS, __IgnoreEls,
 +                     [{xmlel, <<"streamhost">>, _attrs, _} = _el | _els],
 +                     Hosts, Used, Activate) ->
 +    case get_attr(<<"xmlns">>, _attrs) of
 +      <<"">>
 +        when __TopXMLNS ==
 +               <<"http://jabber.org/protocol/bytestreams">> ->
 +        decode_bytestreams_els(__TopXMLNS, __IgnoreEls, _els,
 +                               [decode_bytestreams_streamhost(__TopXMLNS,
 +                                                              __IgnoreEls,
 +                                                              _el)
 +                                | Hosts],
 +                               Used, Activate);
 +      <<"http://jabber.org/protocol/bytestreams">> ->
 +        decode_bytestreams_els(__TopXMLNS, __IgnoreEls, _els,
 +                               [decode_bytestreams_streamhost(<<"http://jabber.org/protocol/bytestreams">>,
 +                                                              __IgnoreEls,
 +                                                              _el)
 +                                | Hosts],
 +                               Used, Activate);
 +      _ ->
 +        decode_bytestreams_els(__TopXMLNS, __IgnoreEls, _els,
 +                               Hosts, Used, Activate)
 +    end;
 +decode_bytestreams_els(__TopXMLNS, __IgnoreEls,
 +                     [{xmlel, <<"streamhost-used">>, _attrs, _} = _el
 +                      | _els],
 +                     Hosts, Used, Activate) ->
 +    case get_attr(<<"xmlns">>, _attrs) of
 +      <<"">>
 +        when __TopXMLNS ==
 +               <<"http://jabber.org/protocol/bytestreams">> ->
 +        decode_bytestreams_els(__TopXMLNS, __IgnoreEls, _els,
 +                               Hosts,
 +                               decode_bytestreams_streamhost_used(__TopXMLNS,
 +                                                                  __IgnoreEls,
 +                                                                  _el),
 +                               Activate);
 +      <<"http://jabber.org/protocol/bytestreams">> ->
 +        decode_bytestreams_els(__TopXMLNS, __IgnoreEls, _els,
 +                               Hosts,
 +                               decode_bytestreams_streamhost_used(<<"http://jabber.org/protocol/bytestreams">>,
 +                                                                  __IgnoreEls,
 +                                                                  _el),
 +                               Activate);
 +      _ ->
 +        decode_bytestreams_els(__TopXMLNS, __IgnoreEls, _els,
 +                               Hosts, Used, Activate)
 +    end;
 +decode_bytestreams_els(__TopXMLNS, __IgnoreEls,
 +                     [{xmlel, <<"activate">>, _attrs, _} = _el | _els],
 +                     Hosts, Used, Activate) ->
 +    case get_attr(<<"xmlns">>, _attrs) of
 +      <<"">>
 +        when __TopXMLNS ==
 +               <<"http://jabber.org/protocol/bytestreams">> ->
 +        decode_bytestreams_els(__TopXMLNS, __IgnoreEls, _els,
 +                               Hosts, Used,
 +                               decode_bytestreams_activate(__TopXMLNS,
 +                                                           __IgnoreEls, _el));
 +      <<"http://jabber.org/protocol/bytestreams">> ->
 +        decode_bytestreams_els(__TopXMLNS, __IgnoreEls, _els,
 +                               Hosts, Used,
 +                               decode_bytestreams_activate(<<"http://jabber.org/protocol/bytestreams">>,
 +                                                           __IgnoreEls, _el));
 +      _ ->
 +        decode_bytestreams_els(__TopXMLNS, __IgnoreEls, _els,
 +                               Hosts, Used, Activate)
 +    end;
 +decode_bytestreams_els(__TopXMLNS, __IgnoreEls,
 +                     [_ | _els], Hosts, Used, Activate) ->
 +    decode_bytestreams_els(__TopXMLNS, __IgnoreEls, _els,
 +                         Hosts, Used, Activate).
 +
 +decode_bytestreams_attrs(__TopXMLNS,
 +                       [{<<"dstaddr">>, _val} | _attrs], _Dstaddr, Sid,
 +                       Mode) ->
 +    decode_bytestreams_attrs(__TopXMLNS, _attrs, _val, Sid,
 +                           Mode);
 +decode_bytestreams_attrs(__TopXMLNS,
 +                       [{<<"sid">>, _val} | _attrs], Dstaddr, _Sid, Mode) ->
 +    decode_bytestreams_attrs(__TopXMLNS, _attrs, Dstaddr,
 +                           _val, Mode);
 +decode_bytestreams_attrs(__TopXMLNS,
 +                       [{<<"mode">>, _val} | _attrs], Dstaddr, Sid, _Mode) ->
 +    decode_bytestreams_attrs(__TopXMLNS, _attrs, Dstaddr,
 +                           Sid, _val);
 +decode_bytestreams_attrs(__TopXMLNS, [_ | _attrs],
 +                       Dstaddr, Sid, Mode) ->
 +    decode_bytestreams_attrs(__TopXMLNS, _attrs, Dstaddr,
 +                           Sid, Mode);
 +decode_bytestreams_attrs(__TopXMLNS, [], Dstaddr, Sid,
 +                       Mode) ->
 +    {decode_bytestreams_attr_dstaddr(__TopXMLNS, Dstaddr),
 +     decode_bytestreams_attr_sid(__TopXMLNS, Sid),
 +     decode_bytestreams_attr_mode(__TopXMLNS, Mode)}.
 +
 +encode_bytestreams({bytestreams, Hosts, Used, Activate,
 +                  Dstaddr, Mode, Sid},
 +                 __TopXMLNS) ->
 +    __NewTopXMLNS =
 +      choose_top_xmlns(<<"http://jabber.org/protocol/bytestreams">>,
 +                       [], __TopXMLNS),
 +    _els = lists:reverse('encode_bytestreams_$hosts'(Hosts,
 +                                                   __NewTopXMLNS,
 +                                                   'encode_bytestreams_$used'(Used,
 +                                                                              __NewTopXMLNS,
 +                                                                              'encode_bytestreams_$activate'(Activate,
 +                                                                                                             __NewTopXMLNS,
 +                                                                                                             [])))),
 +    _attrs = encode_bytestreams_attr_mode(Mode,
 +                                        encode_bytestreams_attr_sid(Sid,
 +                                                                    encode_bytestreams_attr_dstaddr(Dstaddr,
 +                                                                                                    enc_xmlns_attrs(__NewTopXMLNS,
 +                                                                                                                    __TopXMLNS)))),
 +    {xmlel, <<"query">>, _attrs, _els}.
 +
 +'encode_bytestreams_$hosts'([], __TopXMLNS, _acc) ->
 +    _acc;
 +'encode_bytestreams_$hosts'([Hosts | _els], __TopXMLNS,
 +                          _acc) ->
 +    'encode_bytestreams_$hosts'(_els, __TopXMLNS,
 +                              [encode_bytestreams_streamhost(Hosts,
 +                                                             __TopXMLNS)
 +                               | _acc]).
 +
 +'encode_bytestreams_$used'(undefined, __TopXMLNS,
 +                         _acc) ->
 +    _acc;
 +'encode_bytestreams_$used'(Used, __TopXMLNS, _acc) ->
 +    [encode_bytestreams_streamhost_used(Used, __TopXMLNS)
 +     | _acc].
 +
 +'encode_bytestreams_$activate'(undefined, __TopXMLNS,
 +                             _acc) ->
 +    _acc;
 +'encode_bytestreams_$activate'(Activate, __TopXMLNS,
 +                             _acc) ->
 +    [encode_bytestreams_activate(Activate, __TopXMLNS)
 +     | _acc].
 +
 +decode_bytestreams_attr_dstaddr(__TopXMLNS,
 +                              undefined) ->
 +    <<>>;
 +decode_bytestreams_attr_dstaddr(__TopXMLNS, _val) ->
 +    _val.
 +
 +encode_bytestreams_attr_dstaddr(<<>>, _acc) -> _acc;
 +encode_bytestreams_attr_dstaddr(_val, _acc) ->
 +    [{<<"dstaddr">>, _val} | _acc].
 +
 +decode_bytestreams_attr_sid(__TopXMLNS, undefined) ->
 +    <<>>;
 +decode_bytestreams_attr_sid(__TopXMLNS, _val) -> _val.
 +
 +encode_bytestreams_attr_sid(<<>>, _acc) -> _acc;
 +encode_bytestreams_attr_sid(_val, _acc) ->
 +    [{<<"sid">>, _val} | _acc].
 +
 +decode_bytestreams_attr_mode(__TopXMLNS, undefined) ->
 +    tcp;
 +decode_bytestreams_attr_mode(__TopXMLNS, _val) ->
 +    case catch dec_enum(_val, [tcp, udp]) of
 +      {'EXIT', _} ->
 +        erlang:error({xmpp_codec,
 +                      {bad_attr_value, <<"mode">>, <<"query">>, __TopXMLNS}});
 +      _res -> _res
 +    end.
 +
 +encode_bytestreams_attr_mode(tcp, _acc) -> _acc;
 +encode_bytestreams_attr_mode(_val, _acc) ->
 +    [{<<"mode">>, enc_enum(_val)} | _acc].
 +
 +decode_bytestreams_activate(__TopXMLNS, __IgnoreEls,
 +                          {xmlel, <<"activate">>, _attrs, _els}) ->
 +    Cdata = decode_bytestreams_activate_els(__TopXMLNS,
 +                                          __IgnoreEls, _els, <<>>),
 +    Cdata.
 +
 +decode_bytestreams_activate_els(__TopXMLNS, __IgnoreEls,
 +                              [], Cdata) ->
 +    decode_bytestreams_activate_cdata(__TopXMLNS, Cdata);
 +decode_bytestreams_activate_els(__TopXMLNS, __IgnoreEls,
 +                              [{xmlcdata, _data} | _els], Cdata) ->
 +    decode_bytestreams_activate_els(__TopXMLNS, __IgnoreEls,
 +                                  _els, <<Cdata/binary, _data/binary>>);
 +decode_bytestreams_activate_els(__TopXMLNS, __IgnoreEls,
 +                              [_ | _els], Cdata) ->
 +    decode_bytestreams_activate_els(__TopXMLNS, __IgnoreEls,
 +                                  _els, Cdata).
 +
 +encode_bytestreams_activate(Cdata, __TopXMLNS) ->
 +    __NewTopXMLNS =
 +      choose_top_xmlns(<<"http://jabber.org/protocol/bytestreams">>,
 +                       [], __TopXMLNS),
 +    _els = encode_bytestreams_activate_cdata(Cdata, []),
 +    _attrs = enc_xmlns_attrs(__NewTopXMLNS, __TopXMLNS),
 +    {xmlel, <<"activate">>, _attrs, _els}.
 +
 +decode_bytestreams_activate_cdata(__TopXMLNS, <<>>) ->
 +    undefined;
 +decode_bytestreams_activate_cdata(__TopXMLNS, _val) ->
 +    case catch dec_jid(_val) of
 +      {'EXIT', _} ->
 +        erlang:error({xmpp_codec,
 +                      {bad_cdata_value, <<>>, <<"activate">>, __TopXMLNS}});
 +      _res -> _res
 +    end.
 +
 +encode_bytestreams_activate_cdata(undefined, _acc) ->
 +    _acc;
 +encode_bytestreams_activate_cdata(_val, _acc) ->
 +    [{xmlcdata, enc_jid(_val)} | _acc].
 +
 +decode_bytestreams_streamhost_used(__TopXMLNS,
 +                                 __IgnoreEls,
 +                                 {xmlel, <<"streamhost-used">>, _attrs,
 +                                  _els}) ->
 +    Jid =
 +      decode_bytestreams_streamhost_used_attrs(__TopXMLNS,
 +                                               _attrs, undefined),
 +    Jid.
 +
 +decode_bytestreams_streamhost_used_attrs(__TopXMLNS,
 +                                       [{<<"jid">>, _val} | _attrs], _Jid) ->
 +    decode_bytestreams_streamhost_used_attrs(__TopXMLNS,
 +                                           _attrs, _val);
 +decode_bytestreams_streamhost_used_attrs(__TopXMLNS,
 +                                       [_ | _attrs], Jid) ->
 +    decode_bytestreams_streamhost_used_attrs(__TopXMLNS,
 +                                           _attrs, Jid);
 +decode_bytestreams_streamhost_used_attrs(__TopXMLNS, [],
 +                                       Jid) ->
 +    decode_bytestreams_streamhost_used_attr_jid(__TopXMLNS,
 +                                              Jid).
 +
 +encode_bytestreams_streamhost_used(Jid, __TopXMLNS) ->
 +    __NewTopXMLNS =
 +      choose_top_xmlns(<<"http://jabber.org/protocol/bytestreams">>,
 +                       [], __TopXMLNS),
 +    _els = [],
 +    _attrs =
 +      encode_bytestreams_streamhost_used_attr_jid(Jid,
 +                                                  enc_xmlns_attrs(__NewTopXMLNS,
 +                                                                  __TopXMLNS)),
 +    {xmlel, <<"streamhost-used">>, _attrs, _els}.
 +
 +decode_bytestreams_streamhost_used_attr_jid(__TopXMLNS,
 +                                          undefined) ->
 +    erlang:error({xmpp_codec,
 +                {missing_attr, <<"jid">>, <<"streamhost-used">>,
 +                 __TopXMLNS}});
 +decode_bytestreams_streamhost_used_attr_jid(__TopXMLNS,
 +                                          _val) ->
 +    case catch dec_jid(_val) of
 +      {'EXIT', _} ->
 +        erlang:error({xmpp_codec,
 +                      {bad_attr_value, <<"jid">>, <<"streamhost-used">>,
 +                       __TopXMLNS}});
 +      _res -> _res
 +    end.
 +
 +encode_bytestreams_streamhost_used_attr_jid(_val,
 +                                          _acc) ->
 +    [{<<"jid">>, enc_jid(_val)} | _acc].
 +
 +decode_bytestreams_streamhost(__TopXMLNS, __IgnoreEls,
 +                            {xmlel, <<"streamhost">>, _attrs, _els}) ->
 +    {Jid, Host, Port} =
 +      decode_bytestreams_streamhost_attrs(__TopXMLNS, _attrs,
 +                                          undefined, undefined, undefined),
 +    {streamhost, Jid, Host, Port}.
 +
 +decode_bytestreams_streamhost_attrs(__TopXMLNS,
 +                                  [{<<"jid">>, _val} | _attrs], _Jid, Host,
 +                                  Port) ->
 +    decode_bytestreams_streamhost_attrs(__TopXMLNS, _attrs,
 +                                      _val, Host, Port);
 +decode_bytestreams_streamhost_attrs(__TopXMLNS,
 +                                  [{<<"host">>, _val} | _attrs], Jid, _Host,
 +                                  Port) ->
 +    decode_bytestreams_streamhost_attrs(__TopXMLNS, _attrs,
 +                                      Jid, _val, Port);
 +decode_bytestreams_streamhost_attrs(__TopXMLNS,
 +                                  [{<<"port">>, _val} | _attrs], Jid, Host,
 +                                  _Port) ->
 +    decode_bytestreams_streamhost_attrs(__TopXMLNS, _attrs,
 +                                      Jid, Host, _val);
 +decode_bytestreams_streamhost_attrs(__TopXMLNS,
 +                                  [_ | _attrs], Jid, Host, Port) ->
 +    decode_bytestreams_streamhost_attrs(__TopXMLNS, _attrs,
 +                                      Jid, Host, Port);
 +decode_bytestreams_streamhost_attrs(__TopXMLNS, [], Jid,
 +                                  Host, Port) ->
 +    {decode_bytestreams_streamhost_attr_jid(__TopXMLNS,
 +                                          Jid),
 +     decode_bytestreams_streamhost_attr_host(__TopXMLNS,
 +                                           Host),
 +     decode_bytestreams_streamhost_attr_port(__TopXMLNS,
 +                                           Port)}.
 +
 +encode_bytestreams_streamhost({streamhost, Jid, Host,
 +                             Port},
 +                            __TopXMLNS) ->
 +    __NewTopXMLNS =
 +      choose_top_xmlns(<<"http://jabber.org/protocol/bytestreams">>,
 +                       [], __TopXMLNS),
 +    _els = [],
 +    _attrs = encode_bytestreams_streamhost_attr_port(Port,
 +                                                   encode_bytestreams_streamhost_attr_host(Host,
 +                                                                                           encode_bytestreams_streamhost_attr_jid(Jid,
 +                                                                                                                                  enc_xmlns_attrs(__NewTopXMLNS,
 +                                                                                                                                                  __TopXMLNS)))),
 +    {xmlel, <<"streamhost">>, _attrs, _els}.
 +
 +decode_bytestreams_streamhost_attr_jid(__TopXMLNS,
 +                                     undefined) ->
 +    erlang:error({xmpp_codec,
 +                {missing_attr, <<"jid">>, <<"streamhost">>,
 +                 __TopXMLNS}});
 +decode_bytestreams_streamhost_attr_jid(__TopXMLNS,
 +                                     _val) ->
 +    case catch dec_jid(_val) of
 +      {'EXIT', _} ->
 +        erlang:error({xmpp_codec,
 +                      {bad_attr_value, <<"jid">>, <<"streamhost">>,
 +                       __TopXMLNS}});
 +      _res -> _res
 +    end.
 +
 +encode_bytestreams_streamhost_attr_jid(_val, _acc) ->
 +    [{<<"jid">>, enc_jid(_val)} | _acc].
 +
 +decode_bytestreams_streamhost_attr_host(__TopXMLNS,
 +                                      undefined) ->
 +    erlang:error({xmpp_codec,
 +                {missing_attr, <<"host">>, <<"streamhost">>,
 +                 __TopXMLNS}});
 +decode_bytestreams_streamhost_attr_host(__TopXMLNS,
 +                                      _val) ->
 +    _val.
 +
 +encode_bytestreams_streamhost_attr_host(_val, _acc) ->
 +    [{<<"host">>, _val} | _acc].
 +
 +decode_bytestreams_streamhost_attr_port(__TopXMLNS,
 +                                      undefined) ->
 +    1080;
 +decode_bytestreams_streamhost_attr_port(__TopXMLNS,
 +                                      _val) ->
 +    case catch dec_int(_val, 0, 65535) of
 +      {'EXIT', _} ->
 +        erlang:error({xmpp_codec,
 +                      {bad_attr_value, <<"port">>, <<"streamhost">>,
 +                       __TopXMLNS}});
 +      _res -> _res
 +    end.
 +
 +encode_bytestreams_streamhost_attr_port(1080, _acc) ->
 +    _acc;
 +encode_bytestreams_streamhost_attr_port(_val, _acc) ->
 +    [{<<"port">>, enc_int(_val)} | _acc].
 +
 +decode_delay(__TopXMLNS, __IgnoreEls,
 +           {xmlel, <<"delay">>, _attrs, _els}) ->
 +    Desc = decode_delay_els(__TopXMLNS, __IgnoreEls, _els,
 +                          <<>>),
 +    {Stamp, From} = decode_delay_attrs(__TopXMLNS, _attrs,
 +                                     undefined, undefined),
 +    {delay, Stamp, From, Desc}.
 +
 +decode_delay_els(__TopXMLNS, __IgnoreEls, [], Desc) ->
 +    decode_delay_cdata(__TopXMLNS, Desc);
 +decode_delay_els(__TopXMLNS, __IgnoreEls,
 +               [{xmlcdata, _data} | _els], Desc) ->
 +    decode_delay_els(__TopXMLNS, __IgnoreEls, _els,
 +                   <<Desc/binary, _data/binary>>);
 +decode_delay_els(__TopXMLNS, __IgnoreEls, [_ | _els],
 +               Desc) ->
 +    decode_delay_els(__TopXMLNS, __IgnoreEls, _els, Desc).
 +
 +decode_delay_attrs(__TopXMLNS,
 +                 [{<<"stamp">>, _val} | _attrs], _Stamp, From) ->
 +    decode_delay_attrs(__TopXMLNS, _attrs, _val, From);
 +decode_delay_attrs(__TopXMLNS,
 +                 [{<<"from">>, _val} | _attrs], Stamp, _From) ->
 +    decode_delay_attrs(__TopXMLNS, _attrs, Stamp, _val);
 +decode_delay_attrs(__TopXMLNS, [_ | _attrs], Stamp,
 +                 From) ->
 +    decode_delay_attrs(__TopXMLNS, _attrs, Stamp, From);
 +decode_delay_attrs(__TopXMLNS, [], Stamp, From) ->
 +    {decode_delay_attr_stamp(__TopXMLNS, Stamp),
 +     decode_delay_attr_from(__TopXMLNS, From)}.
 +
 +encode_delay({delay, Stamp, From, Desc}, __TopXMLNS) ->
 +    __NewTopXMLNS = choose_top_xmlns(<<"urn:xmpp:delay">>,
 +                                   [], __TopXMLNS),
 +    _els = encode_delay_cdata(Desc, []),
 +    _attrs = encode_delay_attr_from(From,
 +                                  encode_delay_attr_stamp(Stamp,
 +                                                          enc_xmlns_attrs(__NewTopXMLNS,
 +                                                                          __TopXMLNS))),
 +    {xmlel, <<"delay">>, _attrs, _els}.
 +
 +decode_delay_attr_stamp(__TopXMLNS, undefined) ->
 +    erlang:error({xmpp_codec,
 +                {missing_attr, <<"stamp">>, <<"delay">>, __TopXMLNS}});
 +decode_delay_attr_stamp(__TopXMLNS, _val) ->
 +    case catch dec_utc(_val) of
 +      {'EXIT', _} ->
 +        erlang:error({xmpp_codec,
 +                      {bad_attr_value, <<"stamp">>, <<"delay">>,
 +                       __TopXMLNS}});
 +      _res -> _res
 +    end.
 +
 +encode_delay_attr_stamp(_val, _acc) ->
 +    [{<<"stamp">>, enc_utc(_val)} | _acc].
 +
 +decode_delay_attr_from(__TopXMLNS, undefined) ->
 +    undefined;
 +decode_delay_attr_from(__TopXMLNS, _val) ->
 +    case catch dec_jid(_val) of
 +      {'EXIT', _} ->
 +        erlang:error({xmpp_codec,
 +                      {bad_attr_value, <<"from">>, <<"delay">>, __TopXMLNS}});
 +      _res -> _res
 +    end.
 +
 +encode_delay_attr_from(undefined, _acc) -> _acc;
 +encode_delay_attr_from(_val, _acc) ->
 +    [{<<"from">>, enc_jid(_val)} | _acc].
 +
 +decode_delay_cdata(__TopXMLNS, <<>>) -> <<>>;
 +decode_delay_cdata(__TopXMLNS, _val) -> _val.
 +
 +encode_delay_cdata(<<>>, _acc) -> _acc;
 +encode_delay_cdata(_val, _acc) ->
 +    [{xmlcdata, _val} | _acc].
 +
 +decode_chatstate_paused(__TopXMLNS, __IgnoreEls,
 +                      {xmlel, <<"paused">>, _attrs, _els}) ->
 +    {chatstate, paused}.
 +
 +encode_chatstate_paused({chatstate, paused},
 +                      __TopXMLNS) ->
 +    __NewTopXMLNS =
 +      choose_top_xmlns(<<"http://jabber.org/protocol/chatstates">>,
 +                       [], __TopXMLNS),
 +    _els = [],
 +    _attrs = enc_xmlns_attrs(__NewTopXMLNS, __TopXMLNS),
 +    {xmlel, <<"paused">>, _attrs, _els}.
 +
 +decode_chatstate_inactive(__TopXMLNS, __IgnoreEls,
 +                        {xmlel, <<"inactive">>, _attrs, _els}) ->
 +    {chatstate, inactive}.
 +
 +encode_chatstate_inactive({chatstate, inactive},
 +                        __TopXMLNS) ->
 +    __NewTopXMLNS =
 +      choose_top_xmlns(<<"http://jabber.org/protocol/chatstates">>,
 +                       [], __TopXMLNS),
 +    _els = [],
 +    _attrs = enc_xmlns_attrs(__NewTopXMLNS, __TopXMLNS),
 +    {xmlel, <<"inactive">>, _attrs, _els}.
 +
 +decode_chatstate_gone(__TopXMLNS, __IgnoreEls,
 +                    {xmlel, <<"gone">>, _attrs, _els}) ->
 +    {chatstate, gone}.
 +
 +encode_chatstate_gone({chatstate, gone}, __TopXMLNS) ->
 +    __NewTopXMLNS =
 +      choose_top_xmlns(<<"http://jabber.org/protocol/chatstates">>,
 +                       [], __TopXMLNS),
 +    _els = [],
 +    _attrs = enc_xmlns_attrs(__NewTopXMLNS, __TopXMLNS),
 +    {xmlel, <<"gone">>, _attrs, _els}.
 +
 +decode_chatstate_composing(__TopXMLNS, __IgnoreEls,
 +                         {xmlel, <<"composing">>, _attrs, _els}) ->
 +    {chatstate, composing}.
 +
 +encode_chatstate_composing({chatstate, composing},
 +                         __TopXMLNS) ->
 +    __NewTopXMLNS =
 +      choose_top_xmlns(<<"http://jabber.org/protocol/chatstates">>,
 +                       [], __TopXMLNS),
 +    _els = [],
 +    _attrs = enc_xmlns_attrs(__NewTopXMLNS, __TopXMLNS),
 +    {xmlel, <<"composing">>, _attrs, _els}.
 +
 +decode_chatstate_active(__TopXMLNS, __IgnoreEls,
 +                      {xmlel, <<"active">>, _attrs, _els}) ->
 +    {chatstate, active}.
 +
 +encode_chatstate_active({chatstate, active},
 +                      __TopXMLNS) ->
 +    __NewTopXMLNS =
 +      choose_top_xmlns(<<"http://jabber.org/protocol/chatstates">>,
 +                       [], __TopXMLNS),
 +    _els = [],
 +    _attrs = enc_xmlns_attrs(__NewTopXMLNS, __TopXMLNS),
 +    {xmlel, <<"active">>, _attrs, _els}.
 +
 +decode_shim_headers(__TopXMLNS, __IgnoreEls,
 +                  {xmlel, <<"headers">>, _attrs, _els}) ->
 +    Headers = decode_shim_headers_els(__TopXMLNS,
 +                                    __IgnoreEls, _els, []),
 +    {shim, Headers}.
 +
 +decode_shim_headers_els(__TopXMLNS, __IgnoreEls, [],
 +                      Headers) ->
 +    lists:reverse(Headers);
 +decode_shim_headers_els(__TopXMLNS, __IgnoreEls,
 +                      [{xmlel, <<"header">>, _attrs, _} = _el | _els],
 +                      Headers) ->
 +    case get_attr(<<"xmlns">>, _attrs) of
 +      <<"">>
 +        when __TopXMLNS ==
 +               <<"http://jabber.org/protocol/shim">> ->
 +        decode_shim_headers_els(__TopXMLNS, __IgnoreEls, _els,
 +                                [decode_shim_header(__TopXMLNS, __IgnoreEls,
 +                                                    _el)
 +                                 | Headers]);
 +      <<"http://jabber.org/protocol/shim">> ->
 +        decode_shim_headers_els(__TopXMLNS, __IgnoreEls, _els,
 +                                [decode_shim_header(<<"http://jabber.org/protocol/shim">>,
 +                                                    __IgnoreEls, _el)
 +                                 | Headers]);
 +      _ ->
 +        decode_shim_headers_els(__TopXMLNS, __IgnoreEls, _els,
 +                                Headers)
 +    end;
 +decode_shim_headers_els(__TopXMLNS, __IgnoreEls,
 +                      [_ | _els], Headers) ->
 +    decode_shim_headers_els(__TopXMLNS, __IgnoreEls, _els,
 +                          Headers).
 +
 +encode_shim_headers({shim, Headers}, __TopXMLNS) ->
 +    __NewTopXMLNS =
 +      choose_top_xmlns(<<"http://jabber.org/protocol/shim">>,
 +                       [], __TopXMLNS),
 +    _els =
 +      lists:reverse('encode_shim_headers_$headers'(Headers,
 +                                                   __NewTopXMLNS, [])),
 +    _attrs = enc_xmlns_attrs(__NewTopXMLNS, __TopXMLNS),
 +    {xmlel, <<"headers">>, _attrs, _els}.
 +
 +'encode_shim_headers_$headers'([], __TopXMLNS, _acc) ->
 +    _acc;
 +'encode_shim_headers_$headers'([Headers | _els],
 +                             __TopXMLNS, _acc) ->
 +    'encode_shim_headers_$headers'(_els, __TopXMLNS,
 +                                 [encode_shim_header(Headers, __TopXMLNS)
 +                                  | _acc]).
 +
 +decode_shim_header(__TopXMLNS, __IgnoreEls,
 +                 {xmlel, <<"header">>, _attrs, _els}) ->
 +    Cdata = decode_shim_header_els(__TopXMLNS, __IgnoreEls,
 +                                 _els, <<>>),
 +    Name = decode_shim_header_attrs(__TopXMLNS, _attrs,
 +                                  undefined),
 +    {Name, Cdata}.
 +
 +decode_shim_header_els(__TopXMLNS, __IgnoreEls, [],
 +                     Cdata) ->
 +    decode_shim_header_cdata(__TopXMLNS, Cdata);
 +decode_shim_header_els(__TopXMLNS, __IgnoreEls,
 +                     [{xmlcdata, _data} | _els], Cdata) ->
 +    decode_shim_header_els(__TopXMLNS, __IgnoreEls, _els,
 +                         <<Cdata/binary, _data/binary>>);
 +decode_shim_header_els(__TopXMLNS, __IgnoreEls,
 +                     [_ | _els], Cdata) ->
 +    decode_shim_header_els(__TopXMLNS, __IgnoreEls, _els,
 +                         Cdata).
 +
 +decode_shim_header_attrs(__TopXMLNS,
 +                       [{<<"name">>, _val} | _attrs], _Name) ->
 +    decode_shim_header_attrs(__TopXMLNS, _attrs, _val);
 +decode_shim_header_attrs(__TopXMLNS, [_ | _attrs],
 +                       Name) ->
 +    decode_shim_header_attrs(__TopXMLNS, _attrs, Name);
 +decode_shim_header_attrs(__TopXMLNS, [], Name) ->
 +    decode_shim_header_attr_name(__TopXMLNS, Name).
 +
 +encode_shim_header({Name, Cdata}, __TopXMLNS) ->
 +    __NewTopXMLNS =
 +      choose_top_xmlns(<<"http://jabber.org/protocol/shim">>,
 +                       [], __TopXMLNS),
 +    _els = encode_shim_header_cdata(Cdata, []),
 +    _attrs = encode_shim_header_attr_name(Name,
 +                                        enc_xmlns_attrs(__NewTopXMLNS,
 +                                                        __TopXMLNS)),
 +    {xmlel, <<"header">>, _attrs, _els}.
 +
 +decode_shim_header_attr_name(__TopXMLNS, undefined) ->
 +    erlang:error({xmpp_codec,
 +                {missing_attr, <<"name">>, <<"header">>, __TopXMLNS}});
 +decode_shim_header_attr_name(__TopXMLNS, _val) -> _val.
 +
 +encode_shim_header_attr_name(_val, _acc) ->
 +    [{<<"name">>, _val} | _acc].
 +
 +decode_shim_header_cdata(__TopXMLNS, <<>>) -> <<>>;
 +decode_shim_header_cdata(__TopXMLNS, _val) -> _val.
 +
 +encode_shim_header_cdata(<<>>, _acc) -> _acc;
 +encode_shim_header_cdata(_val, _acc) ->
 +    [{xmlcdata, _val} | _acc].
 +
 +decode_pubsub_error_unsupported_access_model(__TopXMLNS,
 +                                           __IgnoreEls,
 +                                           {xmlel,
 +                                            <<"unsupported-access-model">>,
 +                                            _attrs, _els}) ->
 +    {ps_error, 'unsupported-access-model', undefined}.
 +
 +encode_pubsub_error_unsupported_access_model({ps_error,
 +                                            'unsupported-access-model', _},
 +                                           __TopXMLNS) ->
 +    __NewTopXMLNS =
 +      choose_top_xmlns(<<"http://jabber.org/protocol/pubsub#errors">>,
 +                       [], __TopXMLNS),
 +    _els = [],
 +    _attrs = enc_xmlns_attrs(__NewTopXMLNS, __TopXMLNS),
 +    {xmlel, <<"unsupported-access-model">>, _attrs, _els}.
 +
 +decode_pubsub_error_unsupported(__TopXMLNS, __IgnoreEls,
 +                              {xmlel, <<"unsupported">>, _attrs, _els}) ->
 +    Feature =
 +      decode_pubsub_error_unsupported_attrs(__TopXMLNS,
 +                                            _attrs, undefined),
 +    {ps_error, unsupported, Feature}.
 +
 +decode_pubsub_error_unsupported_attrs(__TopXMLNS,
 +                                    [{<<"feature">>, _val} | _attrs],
 +                                    _Feature) ->
 +    decode_pubsub_error_unsupported_attrs(__TopXMLNS,
 +                                        _attrs, _val);
 +decode_pubsub_error_unsupported_attrs(__TopXMLNS,
 +                                    [_ | _attrs], Feature) ->
 +    decode_pubsub_error_unsupported_attrs(__TopXMLNS,
 +                                        _attrs, Feature);
 +decode_pubsub_error_unsupported_attrs(__TopXMLNS, [],
 +                                    Feature) ->
 +    decode_pubsub_error_unsupported_attr_feature(__TopXMLNS,
 +                                               Feature).
 +
 +encode_pubsub_error_unsupported({ps_error, unsupported,
 +                               Feature},
 +                              __TopXMLNS) ->
 +    __NewTopXMLNS =
 +      choose_top_xmlns(<<"http://jabber.org/protocol/pubsub#errors">>,
 +                       [], __TopXMLNS),
 +    _els = [],
 +    _attrs =
 +      encode_pubsub_error_unsupported_attr_feature(Feature,
 +                                                   enc_xmlns_attrs(__NewTopXMLNS,
 +                                                                   __TopXMLNS)),
 +    {xmlel, <<"unsupported">>, _attrs, _els}.
 +
 +decode_pubsub_error_unsupported_attr_feature(__TopXMLNS,
 +                                           undefined) ->
 +    erlang:error({xmpp_codec,
 +                {missing_attr, <<"feature">>, <<"unsupported">>,
 +                 __TopXMLNS}});
 +decode_pubsub_error_unsupported_attr_feature(__TopXMLNS,
 +                                           _val) ->
 +    case catch dec_enum(_val,
 +                      ['access-authorize', 'access-open', 'access-presence',
 +                       'access-roster', 'access-whitelist', 'auto-create',
 +                       'auto-subscribe', collections, 'config-node',
 +                       'create-and-configure', 'create-nodes', 'delete-items',
 +                       'delete-nodes', 'filtered-notifications',
 +                       'get-pending', 'instant-nodes', 'item-ids',
 +                       'last-published', 'leased-subscription',
 +                       'manage-subscriptions', 'member-affiliation',
 +                       'meta-data', 'modify-affiliations', 'multi-collection',
 +                       'multi-subscribe', 'outcast-affiliation',
 +                       'persistent-items', 'presence-notifications',
 +                       'presence-subscribe', publish, 'publish-options',
 +                       'publish-only-affiliation', 'publisher-affiliation',
 +                       'purge-nodes', 'retract-items',
 +                       'retrieve-affiliations', 'retrieve-default',
 +                       'retrieve-items', 'retrieve-subscriptions', subscribe,
 +                       'subscription-options', 'subscription-notifications'])
 +      of
 +      {'EXIT', _} ->
 +        erlang:error({xmpp_codec,
 +                      {bad_attr_value, <<"feature">>, <<"unsupported">>,
 +                       __TopXMLNS}});
 +      _res -> _res
 +    end.
 +
 +encode_pubsub_error_unsupported_attr_feature(_val,
 +                                           _acc) ->
 +    [{<<"feature">>, enc_enum(_val)} | _acc].
 +
 +decode_pubsub_error_too_many_subscriptions(__TopXMLNS,
 +                                         __IgnoreEls,
 +                                         {xmlel, <<"too-many-subscriptions">>,
 +                                          _attrs, _els}) ->
 +    {ps_error, 'too-many-subscriptions', undefined}.
 +
 +encode_pubsub_error_too_many_subscriptions({ps_error,
 +                                          'too-many-subscriptions', _},
 +                                         __TopXMLNS) ->
 +    __NewTopXMLNS =
 +      choose_top_xmlns(<<"http://jabber.org/protocol/pubsub#errors">>,
 +                       [], __TopXMLNS),
 +    _els = [],
 +    _attrs = enc_xmlns_attrs(__NewTopXMLNS, __TopXMLNS),
 +    {xmlel, <<"too-many-subscriptions">>, _attrs, _els}.
 +
 +decode_pubsub_error_subid_required(__TopXMLNS,
 +                                 __IgnoreEls,
 +                                 {xmlel, <<"subid-required">>, _attrs,
 +                                  _els}) ->
 +    {ps_error, 'subid-required', undefined}.
 +
 +encode_pubsub_error_subid_required({ps_error,
 +                                  'subid-required', _},
 +                                 __TopXMLNS) ->
 +    __NewTopXMLNS =
 +      choose_top_xmlns(<<"http://jabber.org/protocol/pubsub#errors">>,
 +                       [], __TopXMLNS),
 +    _els = [],
 +    _attrs = enc_xmlns_attrs(__NewTopXMLNS, __TopXMLNS),
 +    {xmlel, <<"subid-required">>, _attrs, _els}.
 +
 +decode_pubsub_error_presence_subscription_required(__TopXMLNS,
 +                                                 __IgnoreEls,
 +                                                 {xmlel,
 +                                                  <<"presence-subscription-required">>,
 +                                                  _attrs, _els}) ->
 +    {ps_error, 'presence-subscription-required', undefined}.
 +
 +encode_pubsub_error_presence_subscription_required({ps_error,
 +                                                  'presence-subscription-required',
 +                                                  _},
 +                                                 __TopXMLNS) ->
 +    __NewTopXMLNS =
 +      choose_top_xmlns(<<"http://jabber.org/protocol/pubsub#errors">>,
 +                       [], __TopXMLNS),
 +    _els = [],
 +    _attrs = enc_xmlns_attrs(__NewTopXMLNS, __TopXMLNS),
 +    {xmlel, <<"presence-subscription-required">>, _attrs,
 +     _els}.
 +
 +decode_pubsub_error_pending_subscription(__TopXMLNS,
 +                                       __IgnoreEls,
 +                                       {xmlel, <<"pending-subscription">>,
 +                                        _attrs, _els}) ->
 +    {ps_error, 'pending-subscription', undefined}.
 +
 +encode_pubsub_error_pending_subscription({ps_error,
 +                                        'pending-subscription', _},
 +                                       __TopXMLNS) ->
 +    __NewTopXMLNS =
 +      choose_top_xmlns(<<"http://jabber.org/protocol/pubsub#errors">>,
 +                       [], __TopXMLNS),
 +    _els = [],
 +    _attrs = enc_xmlns_attrs(__NewTopXMLNS, __TopXMLNS),
 +    {xmlel, <<"pending-subscription">>, _attrs, _els}.
 +
 +decode_pubsub_error_payload_required(__TopXMLNS,
 +                                   __IgnoreEls,
 +                                   {xmlel, <<"payload-required">>, _attrs,
 +                                    _els}) ->
 +    {ps_error, 'payload-required', undefined}.
 +
 +encode_pubsub_error_payload_required({ps_error,
 +                                    'payload-required', _},
 +                                   __TopXMLNS) ->
 +    __NewTopXMLNS =
 +      choose_top_xmlns(<<"http://jabber.org/protocol/pubsub#errors">>,
 +                       [], __TopXMLNS),
 +    _els = [],
 +    _attrs = enc_xmlns_attrs(__NewTopXMLNS, __TopXMLNS),
 +    {xmlel, <<"payload-required">>, _attrs, _els}.
 +
 +decode_pubsub_error_payload_too_big(__TopXMLNS,
 +                                  __IgnoreEls,
 +                                  {xmlel, <<"payload-too-big">>, _attrs,
 +                                   _els}) ->
 +    {ps_error, 'payload-too-big', undefined}.
 +
 +encode_pubsub_error_payload_too_big({ps_error,
 +                                   'payload-too-big', _},
 +                                  __TopXMLNS) ->
 +    __NewTopXMLNS =
 +      choose_top_xmlns(<<"http://jabber.org/protocol/pubsub#errors">>,
 +                       [], __TopXMLNS),
 +    _els = [],
 +    _attrs = enc_xmlns_attrs(__NewTopXMLNS, __TopXMLNS),
 +    {xmlel, <<"payload-too-big">>, _attrs, _els}.
 +
 +decode_pubsub_error_not_subscribed(__TopXMLNS,
 +                                 __IgnoreEls,
 +                                 {xmlel, <<"not-subscribed">>, _attrs,
 +                                  _els}) ->
 +    {ps_error, 'not-subscribed', undefined}.
 +
 +encode_pubsub_error_not_subscribed({ps_error,
 +                                  'not-subscribed', _},
 +                                 __TopXMLNS) ->
 +    __NewTopXMLNS =
 +      choose_top_xmlns(<<"http://jabber.org/protocol/pubsub#errors">>,
 +                       [], __TopXMLNS),
 +    _els = [],
 +    _attrs = enc_xmlns_attrs(__NewTopXMLNS, __TopXMLNS),
 +    {xmlel, <<"not-subscribed">>, _attrs, _els}.
 +
 +decode_pubsub_error_not_in_roster_group(__TopXMLNS,
 +                                      __IgnoreEls,
 +                                      {xmlel, <<"not-in-roster-group">>,
 +                                       _attrs, _els}) ->
 +    {ps_error, 'not-in-roster-group', undefined}.
 +
 +encode_pubsub_error_not_in_roster_group({ps_error,
 +                                       'not-in-roster-group', _},
 +                                      __TopXMLNS) ->
 +    __NewTopXMLNS =
 +      choose_top_xmlns(<<"http://jabber.org/protocol/pubsub#errors">>,
 +                       [], __TopXMLNS),
 +    _els = [],
 +    _attrs = enc_xmlns_attrs(__NewTopXMLNS, __TopXMLNS),
 +    {xmlel, <<"not-in-roster-group">>, _attrs, _els}.
 +
 +decode_pubsub_error_nodeid_required(__TopXMLNS,
 +                                  __IgnoreEls,
 +                                  {xmlel, <<"nodeid-required">>, _attrs,
 +                                   _els}) ->
 +    {ps_error, 'nodeid-required', undefined}.
 +
 +encode_pubsub_error_nodeid_required({ps_error,
 +                                   'nodeid-required', _},
 +                                  __TopXMLNS) ->
 +    __NewTopXMLNS =
 +      choose_top_xmlns(<<"http://jabber.org/protocol/pubsub#errors">>,
 +                       [], __TopXMLNS),
 +    _els = [],
 +    _attrs = enc_xmlns_attrs(__NewTopXMLNS, __TopXMLNS),
 +    {xmlel, <<"nodeid-required">>, _attrs, _els}.
 +
 +decode_pubsub_error_max_nodes_exceeded(__TopXMLNS,
 +                                     __IgnoreEls,
 +                                     {xmlel, <<"max-nodes-exceeded">>, _attrs,
 +                                      _els}) ->
 +    {ps_error, 'max-nodes-exceeded', undefined}.
 +
 +encode_pubsub_error_max_nodes_exceeded({ps_error,
 +                                      'max-nodes-exceeded', _},
 +                                     __TopXMLNS) ->
 +    __NewTopXMLNS =
 +      choose_top_xmlns(<<"http://jabber.org/protocol/pubsub#errors">>,
 +                       [], __TopXMLNS),
 +    _els = [],
 +    _attrs = enc_xmlns_attrs(__NewTopXMLNS, __TopXMLNS),
 +    {xmlel, <<"max-nodes-exceeded">>, _attrs, _els}.
 +
 +decode_pubsub_error_max_items_exceeded(__TopXMLNS,
 +                                     __IgnoreEls,
 +                                     {xmlel, <<"max-items-exceeded">>, _attrs,
 +                                      _els}) ->
 +    {ps_error, 'max-items-exceeded', undefined}.
 +
 +encode_pubsub_error_max_items_exceeded({ps_error,
 +                                      'max-items-exceeded', _},
 +                                     __TopXMLNS) ->
 +    __NewTopXMLNS =
 +      choose_top_xmlns(<<"http://jabber.org/protocol/pubsub#errors">>,
 +                       [], __TopXMLNS),
 +    _els = [],
 +    _attrs = enc_xmlns_attrs(__NewTopXMLNS, __TopXMLNS),
 +    {xmlel, <<"max-items-exceeded">>, _attrs, _els}.
 +
 +decode_pubsub_error_jid_required(__TopXMLNS,
 +                               __IgnoreEls,
 +                               {xmlel, <<"jid-required">>, _attrs, _els}) ->
 +    {ps_error, 'jid-required', undefined}.
 +
 +encode_pubsub_error_jid_required({ps_error,
 +                                'jid-required', _},
 +                               __TopXMLNS) ->
 +    __NewTopXMLNS =
 +      choose_top_xmlns(<<"http://jabber.org/protocol/pubsub#errors">>,
 +                       [], __TopXMLNS),
 +    _els = [],
 +    _attrs = enc_xmlns_attrs(__NewTopXMLNS, __TopXMLNS),
 +    {xmlel, <<"jid-required">>, _attrs, _els}.
 +
 +decode_pubsub_error_item_required(__TopXMLNS,
 +                                __IgnoreEls,
 +                                {xmlel, <<"item-required">>, _attrs, _els}) ->
 +    {ps_error, 'item-required', undefined}.
 +
 +encode_pubsub_error_item_required({ps_error,
 +                                 'item-required', _},
 +                                __TopXMLNS) ->
 +    __NewTopXMLNS =
 +      choose_top_xmlns(<<"http://jabber.org/protocol/pubsub#errors">>,
 +                       [], __TopXMLNS),
 +    _els = [],
 +    _attrs = enc_xmlns_attrs(__NewTopXMLNS, __TopXMLNS),
 +    {xmlel, <<"item-required">>, _attrs, _els}.
 +
 +decode_pubsub_error_item_forbidden(__TopXMLNS,
 +                                 __IgnoreEls,
 +                                 {xmlel, <<"item-forbidden">>, _attrs,
 +                                  _els}) ->
 +    {ps_error, 'item-forbidden', undefined}.
 +
 +encode_pubsub_error_item_forbidden({ps_error,
 +                                  'item-forbidden', _},
 +                                 __TopXMLNS) ->
 +    __NewTopXMLNS =
 +      choose_top_xmlns(<<"http://jabber.org/protocol/pubsub#errors">>,
 +                       [], __TopXMLNS),
 +    _els = [],
 +    _attrs = enc_xmlns_attrs(__NewTopXMLNS, __TopXMLNS),
 +    {xmlel, <<"item-forbidden">>, _attrs, _els}.
 +
 +decode_pubsub_error_invalid_subid(__TopXMLNS,
 +                                __IgnoreEls,
 +                                {xmlel, <<"invalid-subid">>, _attrs, _els}) ->
 +    {ps_error, 'invalid-subid', undefined}.
 +
 +encode_pubsub_error_invalid_subid({ps_error,
 +                                 'invalid-subid', _},
 +                                __TopXMLNS) ->
 +    __NewTopXMLNS =
 +      choose_top_xmlns(<<"http://jabber.org/protocol/pubsub#errors">>,
 +                       [], __TopXMLNS),
 +    _els = [],
 +    _attrs = enc_xmlns_attrs(__NewTopXMLNS, __TopXMLNS),
 +    {xmlel, <<"invalid-subid">>, _attrs, _els}.
 +
 +decode_pubsub_error_invalid_payload(__TopXMLNS,
 +                                  __IgnoreEls,
 +                                  {xmlel, <<"invalid-payload">>, _attrs,
 +                                   _els}) ->
 +    {ps_error, 'invalid-payload', undefined}.
 +
 +encode_pubsub_error_invalid_payload({ps_error,
 +                                   'invalid-payload', _},
 +                                  __TopXMLNS) ->
 +    __NewTopXMLNS =
 +      choose_top_xmlns(<<"http://jabber.org/protocol/pubsub#errors">>,
 +                       [], __TopXMLNS),
 +    _els = [],
 +    _attrs = enc_xmlns_attrs(__NewTopXMLNS, __TopXMLNS),
 +    {xmlel, <<"invalid-payload">>, _attrs, _els}.
 +
 +decode_pubsub_error_invalid_options(__TopXMLNS,
 +                                  __IgnoreEls,
 +                                  {xmlel, <<"invalid-options">>, _attrs,
 +                                   _els}) ->
 +    {ps_error, 'invalid-options', undefined}.
 +
 +encode_pubsub_error_invalid_options({ps_error,
 +                                   'invalid-options', _},
 +                                  __TopXMLNS) ->
 +    __NewTopXMLNS =
 +      choose_top_xmlns(<<"http://jabber.org/protocol/pubsub#errors">>,
 +                       [], __TopXMLNS),
 +    _els = [],
 +    _attrs = enc_xmlns_attrs(__NewTopXMLNS, __TopXMLNS),
 +    {xmlel, <<"invalid-options">>, _attrs, _els}.
 +
 +decode_pubsub_error_invalid_jid(__TopXMLNS, __IgnoreEls,
 +                              {xmlel, <<"invalid-jid">>, _attrs, _els}) ->
 +    {ps_error, 'invalid-jid', undefined}.
 +
 +encode_pubsub_error_invalid_jid({ps_error,
 +                               'invalid-jid', _},
 +                              __TopXMLNS) ->
 +    __NewTopXMLNS =
 +      choose_top_xmlns(<<"http://jabber.org/protocol/pubsub#errors">>,
 +                       [], __TopXMLNS),
 +    _els = [],
 +    _attrs = enc_xmlns_attrs(__NewTopXMLNS, __TopXMLNS),
 +    {xmlel, <<"invalid-jid">>, _attrs, _els}.
 +
 +decode_pubsub_error_configuration_required(__TopXMLNS,
 +                                         __IgnoreEls,
 +                                         {xmlel, <<"configuration-required">>,
 +                                          _attrs, _els}) ->
 +    {ps_error, 'configuration-required', undefined}.
 +
 +encode_pubsub_error_configuration_required({ps_error,
 +                                          'configuration-required', _},
 +                                         __TopXMLNS) ->
 +    __NewTopXMLNS =
 +      choose_top_xmlns(<<"http://jabber.org/protocol/pubsub#errors">>,
 +                       [], __TopXMLNS),
 +    _els = [],
 +    _attrs = enc_xmlns_attrs(__NewTopXMLNS, __TopXMLNS),
 +    {xmlel, <<"configuration-required">>, _attrs, _els}.
 +
 +decode_pubsub_error_closed_node(__TopXMLNS, __IgnoreEls,
 +                              {xmlel, <<"closed-node">>, _attrs, _els}) ->
 +    {ps_error, 'closed-node', undefined}.
 +
 +encode_pubsub_error_closed_node({ps_error,
 +                               'closed-node', _},
 +                              __TopXMLNS) ->
 +    __NewTopXMLNS =
 +      choose_top_xmlns(<<"http://jabber.org/protocol/pubsub#errors">>,
 +                       [], __TopXMLNS),
 +    _els = [],
 +    _attrs = enc_xmlns_attrs(__NewTopXMLNS, __TopXMLNS),
 +    {xmlel, <<"closed-node">>, _attrs, _els}.
 +
 +decode_pubsub_owner(__TopXMLNS, __IgnoreEls,
 +                  {xmlel, <<"pubsub">>, _attrs, _els}) ->
 +    {Subscriptions, Affiliations, Default, Purge, Delete,
 +     Configure} =
 +      decode_pubsub_owner_els(__TopXMLNS, __IgnoreEls, _els,
 +                              undefined, undefined, undefined, undefined,
 +                              undefined, undefined),
 +    {pubsub_owner, Affiliations, Configure, Default, Delete,
 +     Purge, Subscriptions}.
 +
 +decode_pubsub_owner_els(__TopXMLNS, __IgnoreEls, [],
 +                      Subscriptions, Affiliations, Default, Purge, Delete,
 +                      Configure) ->
 +    {Subscriptions, Affiliations, Default, Purge, Delete,
 +     Configure};
 +decode_pubsub_owner_els(__TopXMLNS, __IgnoreEls,
 +                      [{xmlel, <<"affiliations">>, _attrs, _} = _el | _els],
 +                      Subscriptions, Affiliations, Default, Purge, Delete,
 +                      Configure) ->
 +    case get_attr(<<"xmlns">>, _attrs) of
 +      <<"">>
 +        when __TopXMLNS ==
 +               <<"http://jabber.org/protocol/pubsub#owner">> ->
 +        decode_pubsub_owner_els(__TopXMLNS, __IgnoreEls, _els,
 +                                Subscriptions,
 +                                decode_pubsub_owner_affiliations(__TopXMLNS,
 +                                                                 __IgnoreEls,
 +                                                                 _el),
 +                                Default, Purge, Delete, Configure);
 +      <<"http://jabber.org/protocol/pubsub#owner">> ->
 +        decode_pubsub_owner_els(__TopXMLNS, __IgnoreEls, _els,
 +                                Subscriptions,
 +                                decode_pubsub_owner_affiliations(<<"http://jabber.org/protocol/pubsub#owner">>,
 +                                                                 __IgnoreEls,
 +                                                                 _el),
 +                                Default, Purge, Delete, Configure);
 +      _ ->
 +        decode_pubsub_owner_els(__TopXMLNS, __IgnoreEls, _els,
 +                                Subscriptions, Affiliations, Default, Purge,
 +                                Delete, Configure)
 +    end;
 +decode_pubsub_owner_els(__TopXMLNS, __IgnoreEls,
 +                      [{xmlel, <<"configure">>, _attrs, _} = _el | _els],
 +                      Subscriptions, Affiliations, Default, Purge, Delete,
 +                      Configure) ->
 +    case get_attr(<<"xmlns">>, _attrs) of
 +      <<"">>
 +        when __TopXMLNS ==
 +               <<"http://jabber.org/protocol/pubsub#owner">> ->
 +        decode_pubsub_owner_els(__TopXMLNS, __IgnoreEls, _els,
 +                                Subscriptions, Affiliations, Default, Purge,
 +                                Delete,
 +                                decode_pubsub_configure(__TopXMLNS,
 +                                                        __IgnoreEls, _el));
 +      <<"http://jabber.org/protocol/pubsub">> ->
 +        decode_pubsub_owner_els(__TopXMLNS, __IgnoreEls, _els,
 +                                Subscriptions, Affiliations, Default, Purge,
 +                                Delete,
 +                                decode_pubsub_configure(<<"http://jabber.org/protocol/pubsub">>,
 +                                                        __IgnoreEls, _el));
 +      <<"http://jabber.org/protocol/pubsub#owner">> ->
 +        decode_pubsub_owner_els(__TopXMLNS, __IgnoreEls, _els,
 +                                Subscriptions, Affiliations, Default, Purge,
 +                                Delete,
 +                                decode_pubsub_configure(<<"http://jabber.org/protocol/pubsub#owner">>,
 +                                                        __IgnoreEls, _el));
 +      _ ->
 +        decode_pubsub_owner_els(__TopXMLNS, __IgnoreEls, _els,
 +                                Subscriptions, Affiliations, Default, Purge,
 +                                Delete, Configure)
 +    end;
 +decode_pubsub_owner_els(__TopXMLNS, __IgnoreEls,
 +                      [{xmlel, <<"default">>, _attrs, _} = _el | _els],
 +                      Subscriptions, Affiliations, Default, Purge, Delete,
 +                      Configure) ->
 +    case get_attr(<<"xmlns">>, _attrs) of
 +      <<"">>
 +        when __TopXMLNS ==
 +               <<"http://jabber.org/protocol/pubsub#owner">> ->
 +        decode_pubsub_owner_els(__TopXMLNS, __IgnoreEls, _els,
 +                                Subscriptions, Affiliations,
 +                                decode_pubsub_default(__TopXMLNS, __IgnoreEls,
 +                                                      _el),
 +                                Purge, Delete, Configure);
 +      <<"http://jabber.org/protocol/pubsub">> ->
 +        decode_pubsub_owner_els(__TopXMLNS, __IgnoreEls, _els,
 +                                Subscriptions, Affiliations,
 +                                decode_pubsub_default(<<"http://jabber.org/protocol/pubsub">>,
 +                                                      __IgnoreEls, _el),
 +                                Purge, Delete, Configure);
 +      <<"http://jabber.org/protocol/pubsub#owner">> ->
 +        decode_pubsub_owner_els(__TopXMLNS, __IgnoreEls, _els,
 +                                Subscriptions, Affiliations,
 +                                decode_pubsub_default(<<"http://jabber.org/protocol/pubsub#owner">>,
 +                                                      __IgnoreEls, _el),
 +                                Purge, Delete, Configure);
 +      _ ->
 +        decode_pubsub_owner_els(__TopXMLNS, __IgnoreEls, _els,
 +                                Subscriptions, Affiliations, Default, Purge,
 +                                Delete, Configure)
 +    end;
 +decode_pubsub_owner_els(__TopXMLNS, __IgnoreEls,
 +                      [{xmlel, <<"delete">>, _attrs, _} = _el | _els],
 +                      Subscriptions, Affiliations, Default, Purge, Delete,
 +                      Configure) ->
 +    case get_attr(<<"xmlns">>, _attrs) of
 +      <<"">>
 +        when __TopXMLNS ==
 +               <<"http://jabber.org/protocol/pubsub#owner">> ->
 +        decode_pubsub_owner_els(__TopXMLNS, __IgnoreEls, _els,
 +                                Subscriptions, Affiliations, Default, Purge,
 +                                decode_pubsub_delete(__TopXMLNS, __IgnoreEls,
 +                                                     _el),
 +                                Configure);
 +      <<"http://jabber.org/protocol/pubsub">> ->
 +        decode_pubsub_owner_els(__TopXMLNS, __IgnoreEls, _els,
 +                                Subscriptions, Affiliations, Default, Purge,
 +                                decode_pubsub_delete(<<"http://jabber.org/protocol/pubsub">>,
 +                                                     __IgnoreEls, _el),
 +                                Configure);
 +      <<"http://jabber.org/protocol/pubsub#owner">> ->
 +        decode_pubsub_owner_els(__TopXMLNS, __IgnoreEls, _els,
 +                                Subscriptions, Affiliations, Default, Purge,
 +                                decode_pubsub_delete(<<"http://jabber.org/protocol/pubsub#owner">>,
 +                                                     __IgnoreEls, _el),
 +                                Configure);
 +      <<"http://jabber.org/protocol/pubsub#event">> ->
 +        decode_pubsub_owner_els(__TopXMLNS, __IgnoreEls, _els,
 +                                Subscriptions, Affiliations, Default, Purge,
 +                                decode_pubsub_delete(<<"http://jabber.org/protocol/pubsub#event">>,
 +                                                     __IgnoreEls, _el),
 +                                Configure);
 +      _ ->
 +        decode_pubsub_owner_els(__TopXMLNS, __IgnoreEls, _els,
 +                                Subscriptions, Affiliations, Default, Purge,
 +                                Delete, Configure)
 +    end;
 +decode_pubsub_owner_els(__TopXMLNS, __IgnoreEls,
 +                      [{xmlel, <<"purge">>, _attrs, _} = _el | _els],
 +                      Subscriptions, Affiliations, Default, Purge, Delete,
 +                      Configure) ->
 +    case get_attr(<<"xmlns">>, _attrs) of
 +      <<"">>
 +        when __TopXMLNS ==
 +               <<"http://jabber.org/protocol/pubsub#owner">> ->
 +        decode_pubsub_owner_els(__TopXMLNS, __IgnoreEls, _els,
 +                                Subscriptions, Affiliations, Default,
 +                                decode_pubsub_purge(__TopXMLNS, __IgnoreEls,
 +                                                    _el),
 +                                Delete, Configure);
 +      <<"http://jabber.org/protocol/pubsub">> ->
 +        decode_pubsub_owner_els(__TopXMLNS, __IgnoreEls, _els,
 +                                Subscriptions, Affiliations, Default,
 +                                decode_pubsub_purge(<<"http://jabber.org/protocol/pubsub">>,
 +                                                    __IgnoreEls, _el),
 +                                Delete, Configure);
 +      <<"http://jabber.org/protocol/pubsub#owner">> ->
 +        decode_pubsub_owner_els(__TopXMLNS, __IgnoreEls, _els,
 +                                Subscriptions, Affiliations, Default,
 +                                decode_pubsub_purge(<<"http://jabber.org/protocol/pubsub#owner">>,
 +                                                    __IgnoreEls, _el),
 +                                Delete, Configure);
 +      <<"http://jabber.org/protocol/pubsub#event">> ->
 +        decode_pubsub_owner_els(__TopXMLNS, __IgnoreEls, _els,
 +                                Subscriptions, Affiliations, Default,
 +                                decode_pubsub_purge(<<"http://jabber.org/protocol/pubsub#event">>,
 +                                                    __IgnoreEls, _el),
 +                                Delete, Configure);
 +      _ ->
 +        decode_pubsub_owner_els(__TopXMLNS, __IgnoreEls, _els,
 +                                Subscriptions, Affiliations, Default, Purge,
 +                                Delete, Configure)
 +    end;
 +decode_pubsub_owner_els(__TopXMLNS, __IgnoreEls,
 +                      [{xmlel, <<"subscriptions">>, _attrs, _} = _el | _els],
 +                      Subscriptions, Affiliations, Default, Purge, Delete,
 +                      Configure) ->
 +    case get_attr(<<"xmlns">>, _attrs) of
 +      <<"">>
 +        when __TopXMLNS ==
 +               <<"http://jabber.org/protocol/pubsub#owner">> ->
 +        decode_pubsub_owner_els(__TopXMLNS, __IgnoreEls, _els,
 +                                decode_pubsub_subscriptions(__TopXMLNS,
 +                                                            __IgnoreEls, _el),
 +                                Affiliations, Default, Purge, Delete,
 +                                Configure);
 +      <<"http://jabber.org/protocol/pubsub">> ->
 +        decode_pubsub_owner_els(__TopXMLNS, __IgnoreEls, _els,
 +                                decode_pubsub_subscriptions(<<"http://jabber.org/protocol/pubsub">>,
 +                                                            __IgnoreEls, _el),
 +                                Affiliations, Default, Purge, Delete,
 +                                Configure);
 +      <<"http://jabber.org/protocol/pubsub#owner">> ->
 +        decode_pubsub_owner_els(__TopXMLNS, __IgnoreEls, _els,
 +                                decode_pubsub_subscriptions(<<"http://jabber.org/protocol/pubsub#owner">>,
 +                                                            __IgnoreEls, _el),
 +                                Affiliations, Default, Purge, Delete,
 +                                Configure);
 +      _ ->
 +        decode_pubsub_owner_els(__TopXMLNS, __IgnoreEls, _els,
 +                                Subscriptions, Affiliations, Default, Purge,
 +                                Delete, Configure)
 +    end;
 +decode_pubsub_owner_els(__TopXMLNS, __IgnoreEls,
 +                      [_ | _els], Subscriptions, Affiliations, Default, Purge,
 +                      Delete, Configure) ->
 +    decode_pubsub_owner_els(__TopXMLNS, __IgnoreEls, _els,
 +                          Subscriptions, Affiliations, Default, Purge, Delete,
 +                          Configure).
 +
 +encode_pubsub_owner({pubsub_owner, Affiliations,
 +                   Configure, Default, Delete, Purge, Subscriptions},
 +                  __TopXMLNS) ->
 +    __NewTopXMLNS =
 +      choose_top_xmlns(<<"http://jabber.org/protocol/pubsub#owner">>,
 +                       [], __TopXMLNS),
 +    _els =
 +      lists:reverse('encode_pubsub_owner_$subscriptions'(Subscriptions,
 +                                                         __NewTopXMLNS,
 +                                                         'encode_pubsub_owner_$affiliations'(Affiliations,
 +                                                                                             __NewTopXMLNS,
 +                                                                                             'encode_pubsub_owner_$default'(Default,
 +                                                                                                                            __NewTopXMLNS,
 +                                                                                                                            'encode_pubsub_owner_$purge'(Purge,
 +                                                                                                                                                         __NewTopXMLNS,
 +                                                                                                                                                         'encode_pubsub_owner_$delete'(Delete,
 +                                                                                                                                                                                       __NewTopXMLNS,
 +                                                                                                                                                                                       'encode_pubsub_owner_$configure'(Configure,
 +                                                                                                                                                                                                                        __NewTopXMLNS,
 +                                                                                                                                                                                                                        []))))))),
 +    _attrs = enc_xmlns_attrs(__NewTopXMLNS, __TopXMLNS),
 +    {xmlel, <<"pubsub">>, _attrs, _els}.
 +
 +'encode_pubsub_owner_$subscriptions'(undefined,
 +                                   __TopXMLNS, _acc) ->
 +    _acc;
 +'encode_pubsub_owner_$subscriptions'(Subscriptions,
 +                                   __TopXMLNS, _acc) ->
 +    [encode_pubsub_subscriptions(Subscriptions, __TopXMLNS)
 +     | _acc].
 +
 +'encode_pubsub_owner_$affiliations'(undefined,
 +                                  __TopXMLNS, _acc) ->
 +    _acc;
 +'encode_pubsub_owner_$affiliations'(Affiliations,
 +                                  __TopXMLNS, _acc) ->
 +    [encode_pubsub_owner_affiliations(Affiliations,
 +                                    __TopXMLNS)
 +     | _acc].
 +
 +'encode_pubsub_owner_$default'(undefined, __TopXMLNS,
 +                             _acc) ->
 +    _acc;
 +'encode_pubsub_owner_$default'(Default, __TopXMLNS,
 +                             _acc) ->
 +    [encode_pubsub_default(Default, __TopXMLNS) | _acc].
 +
 +'encode_pubsub_owner_$purge'(undefined, __TopXMLNS,
 +                           _acc) ->
 +    _acc;
 +'encode_pubsub_owner_$purge'(Purge, __TopXMLNS, _acc) ->
 +    [encode_pubsub_purge(Purge, __TopXMLNS) | _acc].
 +
 +'encode_pubsub_owner_$delete'(undefined, __TopXMLNS,
 +                            _acc) ->
 +    _acc;
 +'encode_pubsub_owner_$delete'(Delete, __TopXMLNS,
 +                            _acc) ->
 +    [encode_pubsub_delete(Delete, __TopXMLNS) | _acc].
 +
 +'encode_pubsub_owner_$configure'(undefined, __TopXMLNS,
 +                               _acc) ->
 +    _acc;
 +'encode_pubsub_owner_$configure'(Configure, __TopXMLNS,
 +                               _acc) ->
 +    [encode_pubsub_configure(Configure, __TopXMLNS) | _acc].
 +
 +decode_pubsub(__TopXMLNS, __IgnoreEls,
 +            {xmlel, <<"pubsub">>, _attrs, _els}) ->
 +    {Publish_options, Items, Options, Affiliations,
 +     Subscriptions, Default, Retract, Purge, Delete,
 +     Configure, Create, Unsubscribe, Subscribe, Publish, Rsm,
 +     Subscription} =
 +      decode_pubsub_els(__TopXMLNS, __IgnoreEls, _els,
 +                        undefined, undefined, undefined, undefined, undefined,
 +                        undefined, undefined, undefined, undefined, undefined,
 +                        undefined, undefined, undefined, undefined, undefined,
 +                        undefined),
 +    {pubsub, Subscriptions, Subscription, Affiliations,
 +     Publish, Publish_options, Subscribe, Unsubscribe,
 +     Options, Items, Retract, Create, Configure, Default,
 +     Delete, Purge, Rsm}.
 +
 +decode_pubsub_els(__TopXMLNS, __IgnoreEls, [],
 +                Publish_options, Items, Options, Affiliations,
 +                Subscriptions, Default, Retract, Purge, Delete,
 +                Configure, Create, Unsubscribe, Subscribe, Publish, Rsm,
 +                Subscription) ->
 +    {Publish_options, Items, Options, Affiliations,
 +     Subscriptions, Default, Retract, Purge, Delete,
 +     Configure, Create, Unsubscribe, Subscribe, Publish, Rsm,
 +     Subscription};
 +decode_pubsub_els(__TopXMLNS, __IgnoreEls,
 +                [{xmlel, <<"subscriptions">>, _attrs, _} = _el | _els],
 +                Publish_options, Items, Options, Affiliations,
 +                Subscriptions, Default, Retract, Purge, Delete,
 +                Configure, Create, Unsubscribe, Subscribe, Publish, Rsm,
 +                Subscription) ->
 +    case get_attr(<<"xmlns">>, _attrs) of
 +      <<"">>
 +        when __TopXMLNS ==
 +               <<"http://jabber.org/protocol/pubsub">> ->
 +        decode_pubsub_els(__TopXMLNS, __IgnoreEls, _els,
 +                          Publish_options, Items, Options, Affiliations,
 +                          decode_pubsub_subscriptions(__TopXMLNS, __IgnoreEls,
 +                                                      _el),
 +                          Default, Retract, Purge, Delete, Configure, Create,
 +                          Unsubscribe, Subscribe, Publish, Rsm, Subscription);
 +      <<"http://jabber.org/protocol/pubsub">> ->
 +        decode_pubsub_els(__TopXMLNS, __IgnoreEls, _els,
 +                          Publish_options, Items, Options, Affiliations,
 +                          decode_pubsub_subscriptions(<<"http://jabber.org/protocol/pubsub">>,
 +                                                      __IgnoreEls, _el),
 +                          Default, Retract, Purge, Delete, Configure, Create,
 +                          Unsubscribe, Subscribe, Publish, Rsm, Subscription);
 +      <<"http://jabber.org/protocol/pubsub#owner">> ->
 +        decode_pubsub_els(__TopXMLNS, __IgnoreEls, _els,
 +                          Publish_options, Items, Options, Affiliations,
 +                          decode_pubsub_subscriptions(<<"http://jabber.org/protocol/pubsub#owner">>,
 +                                                      __IgnoreEls, _el),
 +                          Default, Retract, Purge, Delete, Configure, Create,
 +                          Unsubscribe, Subscribe, Publish, Rsm, Subscription);
 +      _ ->
 +        decode_pubsub_els(__TopXMLNS, __IgnoreEls, _els,
 +                          Publish_options, Items, Options, Affiliations,
 +                          Subscriptions, Default, Retract, Purge, Delete,
 +                          Configure, Create, Unsubscribe, Subscribe, Publish,
 +                          Rsm, Subscription)
 +    end;
 +decode_pubsub_els(__TopXMLNS, __IgnoreEls,
 +                [{xmlel, <<"affiliations">>, _attrs, _} = _el | _els],
 +                Publish_options, Items, Options, Affiliations,
 +                Subscriptions, Default, Retract, Purge, Delete,
 +                Configure, Create, Unsubscribe, Subscribe, Publish, Rsm,
 +                Subscription) ->
 +    case get_attr(<<"xmlns">>, _attrs) of
 +      <<"">>
 +        when __TopXMLNS ==
 +               <<"http://jabber.org/protocol/pubsub">> ->
 +        decode_pubsub_els(__TopXMLNS, __IgnoreEls, _els,
 +                          Publish_options, Items, Options,
 +                          decode_pubsub_affiliations(__TopXMLNS, __IgnoreEls,
 +                                                     _el),
 +                          Subscriptions, Default, Retract, Purge, Delete,
 +                          Configure, Create, Unsubscribe, Subscribe, Publish,
 +                          Rsm, Subscription);
 +      <<"http://jabber.org/protocol/pubsub">> ->
 +        decode_pubsub_els(__TopXMLNS, __IgnoreEls, _els,
 +                          Publish_options, Items, Options,
 +                          decode_pubsub_affiliations(<<"http://jabber.org/protocol/pubsub">>,
 +                                                     __IgnoreEls, _el),
 +                          Subscriptions, Default, Retract, Purge, Delete,
 +                          Configure, Create, Unsubscribe, Subscribe, Publish,
 +                          Rsm, Subscription);
 +      _ ->
 +        decode_pubsub_els(__TopXMLNS, __IgnoreEls, _els,
 +                          Publish_options, Items, Options, Affiliations,
 +                          Subscriptions, Default, Retract, Purge, Delete,
 +                          Configure, Create, Unsubscribe, Subscribe, Publish,
 +                          Rsm, Subscription)
 +    end;
 +decode_pubsub_els(__TopXMLNS, __IgnoreEls,
 +                [{xmlel, <<"subscribe">>, _attrs, _} = _el | _els],
 +                Publish_options, Items, Options, Affiliations,
 +                Subscriptions, Default, Retract, Purge, Delete,
 +                Configure, Create, Unsubscribe, Subscribe, Publish, Rsm,
 +                Subscription) ->
 +    case get_attr(<<"xmlns">>, _attrs) of
 +      <<"">>
 +        when __TopXMLNS ==
 +               <<"http://jabber.org/protocol/pubsub">> ->
 +        decode_pubsub_els(__TopXMLNS, __IgnoreEls, _els,
 +                          Publish_options, Items, Options, Affiliations,
 +                          Subscriptions, Default, Retract, Purge, Delete,
 +                          Configure, Create, Unsubscribe,
 +                          decode_pubsub_subscribe(__TopXMLNS, __IgnoreEls,
 +                                                  _el),
 +                          Publish, Rsm, Subscription);
 +      <<"http://jabber.org/protocol/pubsub">> ->
 +        decode_pubsub_els(__TopXMLNS, __IgnoreEls, _els,
 +                          Publish_options, Items, Options, Affiliations,
 +                          Subscriptions, Default, Retract, Purge, Delete,
 +                          Configure, Create, Unsubscribe,
 +                          decode_pubsub_subscribe(<<"http://jabber.org/protocol/pubsub">>,
 +                                                  __IgnoreEls, _el),
 +                          Publish, Rsm, Subscription);
 +      _ ->
 +        decode_pubsub_els(__TopXMLNS, __IgnoreEls, _els,
 +                          Publish_options, Items, Options, Affiliations,
 +                          Subscriptions, Default, Retract, Purge, Delete,
 +                          Configure, Create, Unsubscribe, Subscribe, Publish,
 +                          Rsm, Subscription)
 +    end;
 +decode_pubsub_els(__TopXMLNS, __IgnoreEls,
 +                [{xmlel, <<"unsubscribe">>, _attrs, _} = _el | _els],
 +                Publish_options, Items, Options, Affiliations,
 +                Subscriptions, Default, Retract, Purge, Delete,
 +                Configure, Create, Unsubscribe, Subscribe, Publish, Rsm,
 +                Subscription) ->
 +    case get_attr(<<"xmlns">>, _attrs) of
 +      <<"">>
 +        when __TopXMLNS ==
 +               <<"http://jabber.org/protocol/pubsub">> ->
 +        decode_pubsub_els(__TopXMLNS, __IgnoreEls, _els,
 +                          Publish_options, Items, Options, Affiliations,
 +                          Subscriptions, Default, Retract, Purge, Delete,
 +                          Configure, Create,
 +                          decode_pubsub_unsubscribe(__TopXMLNS, __IgnoreEls,
 +                                                    _el),
 +                          Subscribe, Publish, Rsm, Subscription);
 +      <<"http://jabber.org/protocol/pubsub">> ->
 +        decode_pubsub_els(__TopXMLNS, __IgnoreEls, _els,
 +                          Publish_options, Items, Options, Affiliations,
 +                          Subscriptions, Default, Retract, Purge, Delete,
 +                          Configure, Create,
 +                          decode_pubsub_unsubscribe(<<"http://jabber.org/protocol/pubsub">>,
 +                                                    __IgnoreEls, _el),
 +                          Subscribe, Publish, Rsm, Subscription);
 +      _ ->
 +        decode_pubsub_els(__TopXMLNS, __IgnoreEls, _els,
 +                          Publish_options, Items, Options, Affiliations,
 +                          Subscriptions, Default, Retract, Purge, Delete,
 +                          Configure, Create, Unsubscribe, Subscribe, Publish,
 +                          Rsm, Subscription)
 +    end;
 +decode_pubsub_els(__TopXMLNS, __IgnoreEls,
 +                [{xmlel, <<"options">>, _attrs, _} = _el | _els],
 +                Publish_options, Items, Options, Affiliations,
 +                Subscriptions, Default, Retract, Purge, Delete,
 +                Configure, Create, Unsubscribe, Subscribe, Publish, Rsm,
 +                Subscription) ->
 +    case get_attr(<<"xmlns">>, _attrs) of
 +      <<"">>
 +        when __TopXMLNS ==
 +               <<"http://jabber.org/protocol/pubsub">> ->
 +        decode_pubsub_els(__TopXMLNS, __IgnoreEls, _els,
 +                          Publish_options, Items,
 +                          decode_pubsub_options(__TopXMLNS, __IgnoreEls, _el),
 +                          Affiliations, Subscriptions, Default, Retract,
 +                          Purge, Delete, Configure, Create, Unsubscribe,
 +                          Subscribe, Publish, Rsm, Subscription);
 +      <<"http://jabber.org/protocol/pubsub">> ->
 +        decode_pubsub_els(__TopXMLNS, __IgnoreEls, _els,
 +                          Publish_options, Items,
 +                          decode_pubsub_options(<<"http://jabber.org/protocol/pubsub">>,
 +                                                __IgnoreEls, _el),
 +                          Affiliations, Subscriptions, Default, Retract,
 +                          Purge, Delete, Configure, Create, Unsubscribe,
 +                          Subscribe, Publish, Rsm, Subscription);
 +      _ ->
 +        decode_pubsub_els(__TopXMLNS, __IgnoreEls, _els,
 +                          Publish_options, Items, Options, Affiliations,
 +                          Subscriptions, Default, Retract, Purge, Delete,
 +                          Configure, Create, Unsubscribe, Subscribe, Publish,
 +                          Rsm, Subscription)
 +    end;
 +decode_pubsub_els(__TopXMLNS, __IgnoreEls,
 +                [{xmlel, <<"items">>, _attrs, _} = _el | _els],
 +                Publish_options, Items, Options, Affiliations,
 +                Subscriptions, Default, Retract, Purge, Delete,
 +                Configure, Create, Unsubscribe, Subscribe, Publish, Rsm,
 +                Subscription) ->
 +    case get_attr(<<"xmlns">>, _attrs) of
 +      <<"">>
 +        when __TopXMLNS ==
 +               <<"http://jabber.org/protocol/pubsub">> ->
 +        decode_pubsub_els(__TopXMLNS, __IgnoreEls, _els,
 +                          Publish_options,
 +                          decode_pubsub_items(__TopXMLNS, __IgnoreEls, _el),
 +                          Options, Affiliations, Subscriptions, Default,
 +                          Retract, Purge, Delete, Configure, Create,
 +                          Unsubscribe, Subscribe, Publish, Rsm, Subscription);
 +      <<"http://jabber.org/protocol/pubsub">> ->
 +        decode_pubsub_els(__TopXMLNS, __IgnoreEls, _els,
 +                          Publish_options,
 +                          decode_pubsub_items(<<"http://jabber.org/protocol/pubsub">>,
 +                                              __IgnoreEls, _el),
 +                          Options, Affiliations, Subscriptions, Default,
 +                          Retract, Purge, Delete, Configure, Create,
 +                          Unsubscribe, Subscribe, Publish, Rsm, Subscription);
 +      <<"http://jabber.org/protocol/pubsub#event">> ->
 +        decode_pubsub_els(__TopXMLNS, __IgnoreEls, _els,
 +                          Publish_options,
 +                          decode_pubsub_items(<<"http://jabber.org/protocol/pubsub#event">>,
 +                                              __IgnoreEls, _el),
 +                          Options, Affiliations, Subscriptions, Default,
 +                          Retract, Purge, Delete, Configure, Create,
 +                          Unsubscribe, Subscribe, Publish, Rsm, Subscription);
 +      _ ->
 +        decode_pubsub_els(__TopXMLNS, __IgnoreEls, _els,
 +                          Publish_options, Items, Options, Affiliations,
 +                          Subscriptions, Default, Retract, Purge, Delete,
 +                          Configure, Create, Unsubscribe, Subscribe, Publish,
 +                          Rsm, Subscription)
 +    end;
 +decode_pubsub_els(__TopXMLNS, __IgnoreEls,
 +                [{xmlel, <<"retract">>, _attrs, _} = _el | _els],
 +                Publish_options, Items, Options, Affiliations,
 +                Subscriptions, Default, Retract, Purge, Delete,
 +                Configure, Create, Unsubscribe, Subscribe, Publish, Rsm,
 +                Subscription) ->
 +    case get_attr(<<"xmlns">>, _attrs) of
 +      <<"">>
 +        when __TopXMLNS ==
 +               <<"http://jabber.org/protocol/pubsub">> ->
 +        decode_pubsub_els(__TopXMLNS, __IgnoreEls, _els,
 +                          Publish_options, Items, Options, Affiliations,
 +                          Subscriptions, Default,
 +                          decode_pubsub_retract(__TopXMLNS, __IgnoreEls, _el),
 +                          Purge, Delete, Configure, Create, Unsubscribe,
 +                          Subscribe, Publish, Rsm, Subscription);
 +      <<"http://jabber.org/protocol/pubsub">> ->
 +        decode_pubsub_els(__TopXMLNS, __IgnoreEls, _els,
 +                          Publish_options, Items, Options, Affiliations,
 +                          Subscriptions, Default,
 +                          decode_pubsub_retract(<<"http://jabber.org/protocol/pubsub">>,
 +                                                __IgnoreEls, _el),
 +                          Purge, Delete, Configure, Create, Unsubscribe,
 +                          Subscribe, Publish, Rsm, Subscription);
 +      _ ->
 +        decode_pubsub_els(__TopXMLNS, __IgnoreEls, _els,
 +                          Publish_options, Items, Options, Affiliations,
 +                          Subscriptions, Default, Retract, Purge, Delete,
 +                          Configure, Create, Unsubscribe, Subscribe, Publish,
 +                          Rsm, Subscription)
 +    end;
 +decode_pubsub_els(__TopXMLNS, __IgnoreEls,
 +                [{xmlel, <<"create">>, _attrs, _} = _el | _els],
 +                Publish_options, Items, Options, Affiliations,
 +                Subscriptions, Default, Retract, Purge, Delete,
 +                Configure, Create, Unsubscribe, Subscribe, Publish, Rsm,
 +                Subscription) ->
 +    case get_attr(<<"xmlns">>, _attrs) of
 +      <<"">>
 +        when __TopXMLNS ==
 +               <<"http://jabber.org/protocol/pubsub">> ->
 +        decode_pubsub_els(__TopXMLNS, __IgnoreEls, _els,
 +                          Publish_options, Items, Options, Affiliations,
 +                          Subscriptions, Default, Retract, Purge, Delete,
 +                          Configure,
 +                          decode_pubsub_create(__TopXMLNS, __IgnoreEls, _el),
 +                          Unsubscribe, Subscribe, Publish, Rsm, Subscription);
 +      <<"http://jabber.org/protocol/pubsub">> ->
 +        decode_pubsub_els(__TopXMLNS, __IgnoreEls, _els,
 +                          Publish_options, Items, Options, Affiliations,
 +                          Subscriptions, Default, Retract, Purge, Delete,
 +                          Configure,
 +                          decode_pubsub_create(<<"http://jabber.org/protocol/pubsub">>,
 +                                               __IgnoreEls, _el),
 +                          Unsubscribe, Subscribe, Publish, Rsm, Subscription);
 +      <<"http://jabber.org/protocol/pubsub#event">> ->
 +        decode_pubsub_els(__TopXMLNS, __IgnoreEls, _els,
 +                          Publish_options, Items, Options, Affiliations,
 +                          Subscriptions, Default, Retract, Purge, Delete,
 +                          Configure,
 +                          decode_pubsub_create(<<"http://jabber.org/protocol/pubsub#event">>,
 +                                               __IgnoreEls, _el),
 +                          Unsubscribe, Subscribe, Publish, Rsm, Subscription);
 +      _ ->
 +        decode_pubsub_els(__TopXMLNS, __IgnoreEls, _els,
 +                          Publish_options, Items, Options, Affiliations,
 +                          Subscriptions, Default, Retract, Purge, Delete,
 +                          Configure, Create, Unsubscribe, Subscribe, Publish,
 +                          Rsm, Subscription)
 +    end;
 +decode_pubsub_els(__TopXMLNS, __IgnoreEls,
 +                [{xmlel, <<"configure">>, _attrs, _} = _el | _els],
 +                Publish_options, Items, Options, Affiliations,
 +                Subscriptions, Default, Retract, Purge, Delete,
 +                Configure, Create, Unsubscribe, Subscribe, Publish, Rsm,
 +                Subscription) ->
 +    case get_attr(<<"xmlns">>, _attrs) of
 +      <<"">>
 +        when __TopXMLNS ==
 +               <<"http://jabber.org/protocol/pubsub">> ->
 +        decode_pubsub_els(__TopXMLNS, __IgnoreEls, _els,
 +                          Publish_options, Items, Options, Affiliations,
 +                          Subscriptions, Default, Retract, Purge, Delete,
 +                          decode_pubsub_configure(__TopXMLNS, __IgnoreEls,
 +                                                  _el),
 +                          Create, Unsubscribe, Subscribe, Publish, Rsm,
 +                          Subscription);
 +      <<"http://jabber.org/protocol/pubsub">> ->
 +        decode_pubsub_els(__TopXMLNS, __IgnoreEls, _els,
 +                          Publish_options, Items, Options, Affiliations,
 +                          Subscriptions, Default, Retract, Purge, Delete,
 +                          decode_pubsub_configure(<<"http://jabber.org/protocol/pubsub">>,
 +                                                  __IgnoreEls, _el),
 +                          Create, Unsubscribe, Subscribe, Publish, Rsm,
 +                          Subscription);
 +      <<"http://jabber.org/protocol/pubsub#owner">> ->
 +        decode_pubsub_els(__TopXMLNS, __IgnoreEls, _els,
 +                          Publish_options, Items, Options, Affiliations,
 +                          Subscriptions, Default, Retract, Purge, Delete,
 +                          decode_pubsub_configure(<<"http://jabber.org/protocol/pubsub#owner">>,
 +                                                  __IgnoreEls, _el),
 +                          Create, Unsubscribe, Subscribe, Publish, Rsm,
 +                          Subscription);
 +      _ ->
 +        decode_pubsub_els(__TopXMLNS, __IgnoreEls, _els,
 +                          Publish_options, Items, Options, Affiliations,
 +                          Subscriptions, Default, Retract, Purge, Delete,
 +                          Configure, Create, Unsubscribe, Subscribe, Publish,
 +                          Rsm, Subscription)
 +    end;
 +decode_pubsub_els(__TopXMLNS, __IgnoreEls,
 +                [{xmlel, <<"publish-options">>, _attrs, _} = _el
 +                 | _els],
 +                Publish_options, Items, Options, Affiliations,
 +                Subscriptions, Default, Retract, Purge, Delete,
 +                Configure, Create, Unsubscribe, Subscribe, Publish, Rsm,
 +                Subscription) ->
 +    case get_attr(<<"xmlns">>, _attrs) of
 +      <<"">>
 +        when __TopXMLNS ==
 +               <<"http://jabber.org/protocol/pubsub">> ->
 +        decode_pubsub_els(__TopXMLNS, __IgnoreEls, _els,
 +                          decode_pubsub_publish_options(__TopXMLNS,
 +                                                        __IgnoreEls, _el),
 +                          Items, Options, Affiliations, Subscriptions,
 +                          Default, Retract, Purge, Delete, Configure, Create,
 +                          Unsubscribe, Subscribe, Publish, Rsm, Subscription);
 +      <<"http://jabber.org/protocol/pubsub">> ->
 +        decode_pubsub_els(__TopXMLNS, __IgnoreEls, _els,
 +                          decode_pubsub_publish_options(<<"http://jabber.org/protocol/pubsub">>,
 +                                                        __IgnoreEls, _el),
 +                          Items, Options, Affiliations, Subscriptions,
 +                          Default, Retract, Purge, Delete, Configure, Create,
 +                          Unsubscribe, Subscribe, Publish, Rsm, Subscription);
 +      _ ->
 +        decode_pubsub_els(__TopXMLNS, __IgnoreEls, _els,
 +                          Publish_options, Items, Options, Affiliations,
 +                          Subscriptions, Default, Retract, Purge, Delete,
 +                          Configure, Create, Unsubscribe, Subscribe, Publish,
 +                          Rsm, Subscription)
 +    end;
 +decode_pubsub_els(__TopXMLNS, __IgnoreEls,
 +                [{xmlel, <<"default">>, _attrs, _} = _el | _els],
 +                Publish_options, Items, Options, Affiliations,
 +                Subscriptions, Default, Retract, Purge, Delete,
 +                Configure, Create, Unsubscribe, Subscribe, Publish, Rsm,
 +                Subscription) ->
 +    case get_attr(<<"xmlns">>, _attrs) of
 +      <<"">>
 +        when __TopXMLNS ==
 +               <<"http://jabber.org/protocol/pubsub">> ->
 +        decode_pubsub_els(__TopXMLNS, __IgnoreEls, _els,
 +                          Publish_options, Items, Options, Affiliations,
 +                          Subscriptions,
 +                          decode_pubsub_default(__TopXMLNS, __IgnoreEls, _el),
 +                          Retract, Purge, Delete, Configure, Create,
 +                          Unsubscribe, Subscribe, Publish, Rsm, Subscription);
 +      <<"http://jabber.org/protocol/pubsub">> ->
 +        decode_pubsub_els(__TopXMLNS, __IgnoreEls, _els,
 +                          Publish_options, Items, Options, Affiliations,
 +                          Subscriptions,
 +                          decode_pubsub_default(<<"http://jabber.org/protocol/pubsub">>,
 +                                                __IgnoreEls, _el),
 +                          Retract, Purge, Delete, Configure, Create,
 +                          Unsubscribe, Subscribe, Publish, Rsm, Subscription);
 +      <<"http://jabber.org/protocol/pubsub#owner">> ->
 +        decode_pubsub_els(__TopXMLNS, __IgnoreEls, _els,
 +                          Publish_options, Items, Options, Affiliations,
 +                          Subscriptions,
 +                          decode_pubsub_default(<<"http://jabber.org/protocol/pubsub#owner">>,
 +                                                __IgnoreEls, _el),
 +                          Retract, Purge, Delete, Configure, Create,
 +                          Unsubscribe, Subscribe, Publish, Rsm, Subscription);
 +      _ ->
 +        decode_pubsub_els(__TopXMLNS, __IgnoreEls, _els,
 +                          Publish_options, Items, Options, Affiliations,
 +                          Subscriptions, Default, Retract, Purge, Delete,
 +                          Configure, Create, Unsubscribe, Subscribe, Publish,
 +                          Rsm, Subscription)
 +    end;
 +decode_pubsub_els(__TopXMLNS, __IgnoreEls,
 +                [{xmlel, <<"delete">>, _attrs, _} = _el | _els],
 +                Publish_options, Items, Options, Affiliations,
 +                Subscriptions, Default, Retract, Purge, Delete,
 +                Configure, Create, Unsubscribe, Subscribe, Publish, Rsm,
 +                Subscription) ->
 +    case get_attr(<<"xmlns">>, _attrs) of
 +      <<"">>
 +        when __TopXMLNS ==
 +               <<"http://jabber.org/protocol/pubsub">> ->
 +        decode_pubsub_els(__TopXMLNS, __IgnoreEls, _els,
 +                          Publish_options, Items, Options, Affiliations,
 +                          Subscriptions, Default, Retract, Purge,
 +                          decode_pubsub_delete(__TopXMLNS, __IgnoreEls, _el),
 +                          Configure, Create, Unsubscribe, Subscribe, Publish,
 +                          Rsm, Subscription);
 +      <<"http://jabber.org/protocol/pubsub">> ->
 +        decode_pubsub_els(__TopXMLNS, __IgnoreEls, _els,
 +                          Publish_options, Items, Options, Affiliations,
 +                          Subscriptions, Default, Retract, Purge,
 +                          decode_pubsub_delete(<<"http://jabber.org/protocol/pubsub">>,
 +                                               __IgnoreEls, _el),
 +                          Configure, Create, Unsubscribe, Subscribe, Publish,
 +                          Rsm, Subscription);
 +      <<"http://jabber.org/protocol/pubsub#owner">> ->
 +        decode_pubsub_els(__TopXMLNS, __IgnoreEls, _els,
 +                          Publish_options, Items, Options, Affiliations,
 +                          Subscriptions, Default, Retract, Purge,
 +                          decode_pubsub_delete(<<"http://jabber.org/protocol/pubsub#owner">>,
 +                                               __IgnoreEls, _el),
 +                          Configure, Create, Unsubscribe, Subscribe, Publish,
 +                          Rsm, Subscription);
 +      <<"http://jabber.org/protocol/pubsub#event">> ->
 +        decode_pubsub_els(__TopXMLNS, __IgnoreEls, _els,
 +                          Publish_options, Items, Options, Affiliations,
 +                          Subscriptions, Default, Retract, Purge,
 +                          decode_pubsub_delete(<<"http://jabber.org/protocol/pubsub#event">>,
 +                                               __IgnoreEls, _el),
 +                          Configure, Create, Unsubscribe, Subscribe, Publish,
 +                          Rsm, Subscription);
 +      _ ->
 +        decode_pubsub_els(__TopXMLNS, __IgnoreEls, _els,
 +                          Publish_options, Items, Options, Affiliations,
 +                          Subscriptions, Default, Retract, Purge, Delete,
 +                          Configure, Create, Unsubscribe, Subscribe, Publish,
 +                          Rsm, Subscription)
 +    end;
 +decode_pubsub_els(__TopXMLNS, __IgnoreEls,
 +                [{xmlel, <<"purge">>, _attrs, _} = _el | _els],
 +                Publish_options, Items, Options, Affiliations,
 +                Subscriptions, Default, Retract, Purge, Delete,
 +                Configure, Create, Unsubscribe, Subscribe, Publish, Rsm,
 +                Subscription) ->
 +    case get_attr(<<"xmlns">>, _attrs) of
 +      <<"">>
 +        when __TopXMLNS ==
 +               <<"http://jabber.org/protocol/pubsub">> ->
 +        decode_pubsub_els(__TopXMLNS, __IgnoreEls, _els,
 +                          Publish_options, Items, Options, Affiliations,
 +                          Subscriptions, Default, Retract,
 +                          decode_pubsub_purge(__TopXMLNS, __IgnoreEls, _el),
 +                          Delete, Configure, Create, Unsubscribe, Subscribe,
 +                          Publish, Rsm, Subscription);
 +      <<"http://jabber.org/protocol/pubsub">> ->
 +        decode_pubsub_els(__TopXMLNS, __IgnoreEls, _els,
 +                          Publish_options, Items, Options, Affiliations,
 +                          Subscriptions, Default, Retract,
 +                          decode_pubsub_purge(<<"http://jabber.org/protocol/pubsub">>,
 +                                              __IgnoreEls, _el),
 +                          Delete, Configure, Create, Unsubscribe, Subscribe,
 +                          Publish, Rsm, Subscription);
 +      <<"http://jabber.org/protocol/pubsub#owner">> ->
 +        decode_pubsub_els(__TopXMLNS, __IgnoreEls, _els,
 +                          Publish_options, Items, Options, Affiliations,
 +                          Subscriptions, Default, Retract,
 +                          decode_pubsub_purge(<<"http://jabber.org/protocol/pubsub#owner">>,
 +                                              __IgnoreEls, _el),
 +                          Delete, Configure, Create, Unsubscribe, Subscribe,
 +                          Publish, Rsm, Subscription);
 +      <<"http://jabber.org/protocol/pubsub#event">> ->
 +        decode_pubsub_els(__TopXMLNS, __IgnoreEls, _els,
 +                          Publish_options, Items, Options, Affiliations,
 +                          Subscriptions, Default, Retract,
 +                          decode_pubsub_purge(<<"http://jabber.org/protocol/pubsub#event">>,
 +                                              __IgnoreEls, _el),
 +                          Delete, Configure, Create, Unsubscribe, Subscribe,
 +                          Publish, Rsm, Subscription);
 +      _ ->
 +        decode_pubsub_els(__TopXMLNS, __IgnoreEls, _els,
 +                          Publish_options, Items, Options, Affiliations,
 +                          Subscriptions, Default, Retract, Purge, Delete,
 +                          Configure, Create, Unsubscribe, Subscribe, Publish,
 +                          Rsm, Subscription)
 +    end;
 +decode_pubsub_els(__TopXMLNS, __IgnoreEls,
 +                [{xmlel, <<"subscription">>, _attrs, _} = _el | _els],
 +                Publish_options, Items, Options, Affiliations,
 +                Subscriptions, Default, Retract, Purge, Delete,
 +                Configure, Create, Unsubscribe, Subscribe, Publish, Rsm,
 +                Subscription) ->
 +    case get_attr(<<"xmlns">>, _attrs) of
 +      <<"">>
 +        when __TopXMLNS ==
 +               <<"http://jabber.org/protocol/pubsub">> ->
 +        decode_pubsub_els(__TopXMLNS, __IgnoreEls, _els,
 +                          Publish_options, Items, Options, Affiliations,
 +                          Subscriptions, Default, Retract, Purge, Delete,
 +                          Configure, Create, Unsubscribe, Subscribe, Publish,
 +                          Rsm,
 +                          decode_pubsub_subscription(__TopXMLNS, __IgnoreEls,
 +                                                     _el));
 +      <<"http://jabber.org/protocol/pubsub">> ->
 +        decode_pubsub_els(__TopXMLNS, __IgnoreEls, _els,
 +                          Publish_options, Items, Options, Affiliations,
 +                          Subscriptions, Default, Retract, Purge, Delete,
 +                          Configure, Create, Unsubscribe, Subscribe, Publish,
 +                          Rsm,
 +                          decode_pubsub_subscription(<<"http://jabber.org/protocol/pubsub">>,
 +                                                     __IgnoreEls, _el));
 +      <<"http://jabber.org/protocol/pubsub#owner">> ->
 +        decode_pubsub_els(__TopXMLNS, __IgnoreEls, _els,
 +                          Publish_options, Items, Options, Affiliations,
 +                          Subscriptions, Default, Retract, Purge, Delete,
 +                          Configure, Create, Unsubscribe, Subscribe, Publish,
 +                          Rsm,
 +                          decode_pubsub_subscription(<<"http://jabber.org/protocol/pubsub#owner">>,
 +                                                     __IgnoreEls, _el));
 +      <<"http://jabber.org/protocol/pubsub#event">> ->
 +        decode_pubsub_els(__TopXMLNS, __IgnoreEls, _els,
 +                          Publish_options, Items, Options, Affiliations,
 +                          Subscriptions, Default, Retract, Purge, Delete,
 +                          Configure, Create, Unsubscribe, Subscribe, Publish,
 +                          Rsm,
 +                          decode_pubsub_subscription(<<"http://jabber.org/protocol/pubsub#event">>,
 +                                                     __IgnoreEls, _el));
 +      _ ->
 +        decode_pubsub_els(__TopXMLNS, __IgnoreEls, _els,
 +                          Publish_options, Items, Options, Affiliations,
 +                          Subscriptions, Default, Retract, Purge, Delete,
 +                          Configure, Create, Unsubscribe, Subscribe, Publish,
 +                          Rsm, Subscription)
 +    end;
 +decode_pubsub_els(__TopXMLNS, __IgnoreEls,
 +                [{xmlel, <<"set">>, _attrs, _} = _el | _els],
 +                Publish_options, Items, Options, Affiliations,
 +                Subscriptions, Default, Retract, Purge, Delete,
 +                Configure, Create, Unsubscribe, Subscribe, Publish, Rsm,
 +                Subscription) ->
 +    case get_attr(<<"xmlns">>, _attrs) of
 +      <<"http://jabber.org/protocol/rsm">> ->
 +        decode_pubsub_els(__TopXMLNS, __IgnoreEls, _els,
 +                          Publish_options, Items, Options, Affiliations,
 +                          Subscriptions, Default, Retract, Purge, Delete,
 +                          Configure, Create, Unsubscribe, Subscribe, Publish,
 +                          decode_rsm_set(<<"http://jabber.org/protocol/rsm">>,
 +                                         __IgnoreEls, _el),
 +                          Subscription);
 +      _ ->
 +        decode_pubsub_els(__TopXMLNS, __IgnoreEls, _els,
 +                          Publish_options, Items, Options, Affiliations,
 +                          Subscriptions, Default, Retract, Purge, Delete,
 +                          Configure, Create, Unsubscribe, Subscribe, Publish,
 +                          Rsm, Subscription)
 +    end;
 +decode_pubsub_els(__TopXMLNS, __IgnoreEls,
 +                [{xmlel, <<"publish">>, _attrs, _} = _el | _els],
 +                Publish_options, Items, Options, Affiliations,
 +                Subscriptions, Default, Retract, Purge, Delete,
 +                Configure, Create, Unsubscribe, Subscribe, Publish, Rsm,
 +                Subscription) ->
 +    case get_attr(<<"xmlns">>, _attrs) of
 +      <<"">>
 +        when __TopXMLNS ==
 +               <<"http://jabber.org/protocol/pubsub">> ->
 +        decode_pubsub_els(__TopXMLNS, __IgnoreEls, _els,
 +                          Publish_options, Items, Options, Affiliations,
 +                          Subscriptions, Default, Retract, Purge, Delete,
 +                          Configure, Create, Unsubscribe, Subscribe,
 +                          decode_pubsub_publish(__TopXMLNS, __IgnoreEls, _el),
 +                          Rsm, Subscription);
 +      <<"http://jabber.org/protocol/pubsub">> ->
 +        decode_pubsub_els(__TopXMLNS, __IgnoreEls, _els,
 +                          Publish_options, Items, Options, Affiliations,
 +                          Subscriptions, Default, Retract, Purge, Delete,
 +                          Configure, Create, Unsubscribe, Subscribe,
 +                          decode_pubsub_publish(<<"http://jabber.org/protocol/pubsub">>,
 +                                                __IgnoreEls, _el),
 +                          Rsm, Subscription);
 +      _ ->
 +        decode_pubsub_els(__TopXMLNS, __IgnoreEls, _els,
 +                          Publish_options, Items, Options, Affiliations,
 +                          Subscriptions, Default, Retract, Purge, Delete,
 +                          Configure, Create, Unsubscribe, Subscribe, Publish,
 +                          Rsm, Subscription)
 +    end;
 +decode_pubsub_els(__TopXMLNS, __IgnoreEls, [_ | _els],
 +                Publish_options, Items, Options, Affiliations,
 +                Subscriptions, Default, Retract, Purge, Delete,
 +                Configure, Create, Unsubscribe, Subscribe, Publish, Rsm,
 +                Subscription) ->
 +    decode_pubsub_els(__TopXMLNS, __IgnoreEls, _els,
 +                    Publish_options, Items, Options, Affiliations,
 +                    Subscriptions, Default, Retract, Purge, Delete,
 +                    Configure, Create, Unsubscribe, Subscribe, Publish, Rsm,
 +                    Subscription).
 +
 +encode_pubsub({pubsub, Subscriptions, Subscription,
 +             Affiliations, Publish, Publish_options, Subscribe,
 +             Unsubscribe, Options, Items, Retract, Create, Configure,
 +             Default, Delete, Purge, Rsm},
 +            __TopXMLNS) ->
 +    __NewTopXMLNS =
 +      choose_top_xmlns(<<"http://jabber.org/protocol/pubsub">>,
 +                       [], __TopXMLNS),
 +    _els =
 +      lists:reverse('encode_pubsub_$publish_options'(Publish_options,
 +                                                     __NewTopXMLNS,
 +                                                     'encode_pubsub_$items'(Items,
 +                                                                            __NewTopXMLNS,
 +                                                                            'encode_pubsub_$options'(Options,
 +                                                                                                     __NewTopXMLNS,
 +                                                                                                     'encode_pubsub_$affiliations'(Affiliations,
 +                                                                                                                                   __NewTopXMLNS,
 +                                                                                                                                   'encode_pubsub_$subscriptions'(Subscriptions,
 +                                                                                                                                                                  __NewTopXMLNS,
 +                                                                                                                                                                  'encode_pubsub_$default'(Default,
 +                                                                                                                                                                                           __NewTopXMLNS,
 +                                                                                                                                                                                           'encode_pubsub_$retract'(Retract,
 +                                                                                                                                                                                                                    __NewTopXMLNS,
 +                                                                                                                                                                                                                    'encode_pubsub_$purge'(Purge,
 +                                                                                                                                                                                                                                           __NewTopXMLNS,
 +                                                                                                                                                                                                                                           'encode_pubsub_$delete'(Delete,
 +                                                                                                                                                                                                                                                                   __NewTopXMLNS,
 +                                                                                                                                                                                                                                                                   'encode_pubsub_$configure'(Configure,
 +                                                                                                                                                                                                                                                                                              __NewTopXMLNS,
 +                                                                                                                                                                                                                                                                                              'encode_pubsub_$create'(Create,
 +                                                                                                                                                                                                                                                                                                                      __NewTopXMLNS,
 +                                                                                                                                                                                                                                                                                                                      'encode_pubsub_$unsubscribe'(Unsubscribe,
 +                                                                                                                                                                                                                                                                                                                                                   __NewTopXMLNS,
 +                                                                                                                                                                                                                                                                                                                                                   'encode_pubsub_$subscribe'(Subscribe,
 +                                                                                                                                                                                                                                                                                                                                                                              __NewTopXMLNS,
 +                                                                                                                                                                                                                                                                                                                                                                              'encode_pubsub_$publish'(Publish,
 +                                                                                                                                                                                                                                                                                                                                                                                                       __NewTopXMLNS,
 +                                                                                                                                                                                                                                                                                                                                                                                                       'encode_pubsub_$rsm'(Rsm,
 +                                                                                                                                                                                                                                                                                                                                                                                                                            __NewTopXMLNS,
 +                                                                                                                                                                                                                                                                                                                                                                                                                            'encode_pubsub_$subscription'(Subscription,
 +                                                                                                                                                                                                                                                                                                                                                                                                                                                          __NewTopXMLNS,
 +                                                                                                                                                                                                                                                                                                                                                                                                                                                          []))))))))))))))))),
 +    _attrs = enc_xmlns_attrs(__NewTopXMLNS, __TopXMLNS),
 +    {xmlel, <<"pubsub">>, _attrs, _els}.
 +
 +'encode_pubsub_$publish_options'(undefined, __TopXMLNS,
 +                               _acc) ->
 +    _acc;
 +'encode_pubsub_$publish_options'(Publish_options,
 +                               __TopXMLNS, _acc) ->
 +    [encode_pubsub_publish_options(Publish_options,
 +                                 __TopXMLNS)
 +     | _acc].
 +
 +'encode_pubsub_$items'(undefined, __TopXMLNS, _acc) ->
 +    _acc;
 +'encode_pubsub_$items'(Items, __TopXMLNS, _acc) ->
 +    [encode_pubsub_items(Items, __TopXMLNS) | _acc].
 +
 +'encode_pubsub_$options'(undefined, __TopXMLNS, _acc) ->
 +    _acc;
 +'encode_pubsub_$options'(Options, __TopXMLNS, _acc) ->
 +    [encode_pubsub_options(Options, __TopXMLNS) | _acc].
 +
 +'encode_pubsub_$affiliations'(undefined, __TopXMLNS,
 +                            _acc) ->
 +    _acc;
 +'encode_pubsub_$affiliations'(Affiliations, __TopXMLNS,
 +                            _acc) ->
 +    [encode_pubsub_affiliations(Affiliations, __TopXMLNS)
 +     | _acc].
 +
 +'encode_pubsub_$subscriptions'(undefined, __TopXMLNS,
 +                             _acc) ->
 +    _acc;
 +'encode_pubsub_$subscriptions'(Subscriptions,
 +                             __TopXMLNS, _acc) ->
 +    [encode_pubsub_subscriptions(Subscriptions, __TopXMLNS)
 +     | _acc].
 +
 +'encode_pubsub_$default'(undefined, __TopXMLNS, _acc) ->
 +    _acc;
 +'encode_pubsub_$default'(Default, __TopXMLNS, _acc) ->
 +    [encode_pubsub_default(Default, __TopXMLNS) | _acc].
 +
 +'encode_pubsub_$retract'(undefined, __TopXMLNS, _acc) ->
 +    _acc;
 +'encode_pubsub_$retract'(Retract, __TopXMLNS, _acc) ->
 +    [encode_pubsub_retract(Retract, __TopXMLNS) | _acc].
 +
 +'encode_pubsub_$purge'(undefined, __TopXMLNS, _acc) ->
 +    _acc;
 +'encode_pubsub_$purge'(Purge, __TopXMLNS, _acc) ->
 +    [encode_pubsub_purge(Purge, __TopXMLNS) | _acc].
 +
 +'encode_pubsub_$delete'(undefined, __TopXMLNS, _acc) ->
 +    _acc;
 +'encode_pubsub_$delete'(Delete, __TopXMLNS, _acc) ->
 +    [encode_pubsub_delete(Delete, __TopXMLNS) | _acc].
 +
 +'encode_pubsub_$configure'(undefined, __TopXMLNS,
 +                         _acc) ->
 +    _acc;
 +'encode_pubsub_$configure'(Configure, __TopXMLNS,
 +                         _acc) ->
 +    [encode_pubsub_configure(Configure, __TopXMLNS) | _acc].
 +
 +'encode_pubsub_$create'(undefined, __TopXMLNS, _acc) ->
 +    _acc;
 +'encode_pubsub_$create'(Create, __TopXMLNS, _acc) ->
 +    [encode_pubsub_create(Create, __TopXMLNS) | _acc].
 +
 +'encode_pubsub_$unsubscribe'(undefined, __TopXMLNS,
 +                           _acc) ->
 +    _acc;
 +'encode_pubsub_$unsubscribe'(Unsubscribe, __TopXMLNS,
 +                           _acc) ->
 +    [encode_pubsub_unsubscribe(Unsubscribe, __TopXMLNS)
 +     | _acc].
 +
 +'encode_pubsub_$subscribe'(undefined, __TopXMLNS,
 +                         _acc) ->
 +    _acc;
 +'encode_pubsub_$subscribe'(Subscribe, __TopXMLNS,
 +                         _acc) ->
 +    [encode_pubsub_subscribe(Subscribe, __TopXMLNS) | _acc].
 +
 +'encode_pubsub_$publish'(undefined, __TopXMLNS, _acc) ->
 +    _acc;
 +'encode_pubsub_$publish'(Publish, __TopXMLNS, _acc) ->
 +    [encode_pubsub_publish(Publish, __TopXMLNS) | _acc].
 +
 +'encode_pubsub_$rsm'(undefined, __TopXMLNS, _acc) ->
 +    _acc;
 +'encode_pubsub_$rsm'(Rsm, __TopXMLNS, _acc) ->
 +    [encode_rsm_set(Rsm, __TopXMLNS) | _acc].
 +
 +'encode_pubsub_$subscription'(undefined, __TopXMLNS,
 +                            _acc) ->
 +    _acc;
 +'encode_pubsub_$subscription'(Subscription, __TopXMLNS,
 +                            _acc) ->
 +    [encode_pubsub_subscription(Subscription, __TopXMLNS)
 +     | _acc].
 +
 +decode_pubsub_purge(__TopXMLNS, __IgnoreEls,
 +                  {xmlel, <<"purge">>, _attrs, _els}) ->
 +    Node = decode_pubsub_purge_attrs(__TopXMLNS, _attrs,
 +                                   undefined),
 +    Node.
 +
 +decode_pubsub_purge_attrs(__TopXMLNS,
 +                        [{<<"node">>, _val} | _attrs], _Node) ->
 +    decode_pubsub_purge_attrs(__TopXMLNS, _attrs, _val);
 +decode_pubsub_purge_attrs(__TopXMLNS, [_ | _attrs],
 +                        Node) ->
 +    decode_pubsub_purge_attrs(__TopXMLNS, _attrs, Node);
 +decode_pubsub_purge_attrs(__TopXMLNS, [], Node) ->
 +    decode_pubsub_purge_attr_node(__TopXMLNS, Node).
 +
 +encode_pubsub_purge(Node, __TopXMLNS) ->
 +    __NewTopXMLNS = choose_top_xmlns(<<>>,
 +                                   [<<"http://jabber.org/protocol/pubsub">>,
 +                                    <<"http://jabber.org/protocol/pubsub#owner">>,
 +                                    <<"http://jabber.org/protocol/pubsub#event">>],
 +                                   __TopXMLNS),
 +    _els = [],
 +    _attrs = encode_pubsub_purge_attr_node(Node,
 +                                         enc_xmlns_attrs(__NewTopXMLNS,
 +                                                         __TopXMLNS)),
 +    {xmlel, <<"purge">>, _attrs, _els}.
 +
 +decode_pubsub_purge_attr_node(__TopXMLNS, undefined) ->
 +    erlang:error({xmpp_codec,
 +                {missing_attr, <<"node">>, <<"purge">>, __TopXMLNS}});
 +decode_pubsub_purge_attr_node(__TopXMLNS, _val) -> _val.
 +
 +encode_pubsub_purge_attr_node(_val, _acc) ->
 +    [{<<"node">>, _val} | _acc].
 +
 +decode_pubsub_delete(__TopXMLNS, __IgnoreEls,
 +                   {xmlel, <<"delete">>, _attrs, _els}) ->
 +    Uri = decode_pubsub_delete_els(__TopXMLNS, __IgnoreEls,
 +                                 _els, <<>>),
 +    Node = decode_pubsub_delete_attrs(__TopXMLNS, _attrs,
 +                                    undefined),
 +    {Node, Uri}.
 +
 +decode_pubsub_delete_els(__TopXMLNS, __IgnoreEls, [],
 +                       Uri) ->
 +    Uri;
 +decode_pubsub_delete_els(__TopXMLNS, __IgnoreEls,
 +                       [{xmlel, <<"redirect">>, _attrs, _} = _el | _els],
 +                       Uri) ->
 +    case get_attr(<<"xmlns">>, _attrs) of
 +      <<"">>
 +        when __TopXMLNS ==
 +               <<"http://jabber.org/protocol/pubsub">>;
 +             __TopXMLNS ==
 +               <<"http://jabber.org/protocol/pubsub#owner">>;
 +             __TopXMLNS ==
 +               <<"http://jabber.org/protocol/pubsub#event">> ->
 +        decode_pubsub_delete_els(__TopXMLNS, __IgnoreEls, _els,
 +                                 decode_pubsub_redirect(__TopXMLNS,
 +                                                        __IgnoreEls, _el));
 +      <<"http://jabber.org/protocol/pubsub">> ->
 +        decode_pubsub_delete_els(__TopXMLNS, __IgnoreEls, _els,
 +                                 decode_pubsub_redirect(<<"http://jabber.org/protocol/pubsub">>,
 +                                                        __IgnoreEls, _el));
 +      <<"http://jabber.org/protocol/pubsub#owner">> ->
 +        decode_pubsub_delete_els(__TopXMLNS, __IgnoreEls, _els,
 +                                 decode_pubsub_redirect(<<"http://jabber.org/protocol/pubsub#owner">>,
 +                                                        __IgnoreEls, _el));
 +      <<"http://jabber.org/protocol/pubsub#event">> ->
 +        decode_pubsub_delete_els(__TopXMLNS, __IgnoreEls, _els,
 +                                 decode_pubsub_redirect(<<"http://jabber.org/protocol/pubsub#event">>,
 +                                                        __IgnoreEls, _el));
 +      _ ->
 +        decode_pubsub_delete_els(__TopXMLNS, __IgnoreEls, _els,
 +                                 Uri)
 +    end;
 +decode_pubsub_delete_els(__TopXMLNS, __IgnoreEls,
 +                       [_ | _els], Uri) ->
 +    decode_pubsub_delete_els(__TopXMLNS, __IgnoreEls, _els,
 +                           Uri).
 +
 +decode_pubsub_delete_attrs(__TopXMLNS,
 +                         [{<<"node">>, _val} | _attrs], _Node) ->
 +    decode_pubsub_delete_attrs(__TopXMLNS, _attrs, _val);
 +decode_pubsub_delete_attrs(__TopXMLNS, [_ | _attrs],
 +                         Node) ->
 +    decode_pubsub_delete_attrs(__TopXMLNS, _attrs, Node);
 +decode_pubsub_delete_attrs(__TopXMLNS, [], Node) ->
 +    decode_pubsub_delete_attr_node(__TopXMLNS, Node).
 +
 +encode_pubsub_delete({Node, Uri}, __TopXMLNS) ->
 +    __NewTopXMLNS = choose_top_xmlns(<<>>,
 +                                   [<<"http://jabber.org/protocol/pubsub">>,
 +                                    <<"http://jabber.org/protocol/pubsub#owner">>,
 +                                    <<"http://jabber.org/protocol/pubsub#event">>],
 +                                   __TopXMLNS),
 +    _els = lists:reverse('encode_pubsub_delete_$uri'(Uri,
 +                                                   __NewTopXMLNS, [])),
 +    _attrs = encode_pubsub_delete_attr_node(Node,
 +                                          enc_xmlns_attrs(__NewTopXMLNS,
 +                                                          __TopXMLNS)),
 +    {xmlel, <<"delete">>, _attrs, _els}.
 +
 +'encode_pubsub_delete_$uri'(<<>>, __TopXMLNS, _acc) ->
 +    _acc;
 +'encode_pubsub_delete_$uri'(Uri, __TopXMLNS, _acc) ->
 +    [encode_pubsub_redirect(Uri, __TopXMLNS) | _acc].
 +
 +decode_pubsub_delete_attr_node(__TopXMLNS, undefined) ->
 +    erlang:error({xmpp_codec,
 +                {missing_attr, <<"node">>, <<"delete">>, __TopXMLNS}});
 +decode_pubsub_delete_attr_node(__TopXMLNS, _val) ->
 +    _val.
 +
 +encode_pubsub_delete_attr_node(_val, _acc) ->
 +    [{<<"node">>, _val} | _acc].
 +
 +decode_pubsub_redirect(__TopXMLNS, __IgnoreEls,
 +                     {xmlel, <<"redirect">>, _attrs, _els}) ->
 +    Uri = decode_pubsub_redirect_attrs(__TopXMLNS, _attrs,
 +                                     undefined),
 +    Uri.
 +
 +decode_pubsub_redirect_attrs(__TopXMLNS,
 +                           [{<<"uri">>, _val} | _attrs], _Uri) ->
 +    decode_pubsub_redirect_attrs(__TopXMLNS, _attrs, _val);
 +decode_pubsub_redirect_attrs(__TopXMLNS, [_ | _attrs],
 +                           Uri) ->
 +    decode_pubsub_redirect_attrs(__TopXMLNS, _attrs, Uri);
 +decode_pubsub_redirect_attrs(__TopXMLNS, [], Uri) ->
 +    decode_pubsub_redirect_attr_uri(__TopXMLNS, Uri).
 +
 +encode_pubsub_redirect(Uri, __TopXMLNS) ->
 +    __NewTopXMLNS = choose_top_xmlns(<<>>,
 +                                   [<<"http://jabber.org/protocol/pubsub">>,
 +                                    <<"http://jabber.org/protocol/pubsub#owner">>,
 +                                    <<"http://jabber.org/protocol/pubsub#event">>],
 +                                   __TopXMLNS),
 +    _els = [],
 +    _attrs = encode_pubsub_redirect_attr_uri(Uri,
 +                                           enc_xmlns_attrs(__NewTopXMLNS,
 +                                                           __TopXMLNS)),
 +    {xmlel, <<"redirect">>, _attrs, _els}.
 +
 +decode_pubsub_redirect_attr_uri(__TopXMLNS,
 +                              undefined) ->
 +    erlang:error({xmpp_codec,
 +                {missing_attr, <<"uri">>, <<"redirect">>, __TopXMLNS}});
 +decode_pubsub_redirect_attr_uri(__TopXMLNS, _val) ->
 +    _val.
 +
 +encode_pubsub_redirect_attr_uri(_val, _acc) ->
 +    [{<<"uri">>, _val} | _acc].
 +
 +decode_pubsub_default(__TopXMLNS, __IgnoreEls,
 +                    {xmlel, <<"default">>, _attrs, _els}) ->
 +    Xdata = decode_pubsub_default_els(__TopXMLNS,
 +                                    __IgnoreEls, _els, undefined),
 +    Node = decode_pubsub_default_attrs(__TopXMLNS, _attrs,
 +                                     undefined),
 +    {Node, Xdata}.
 +
 +decode_pubsub_default_els(__TopXMLNS, __IgnoreEls, [],
 +                        Xdata) ->
 +    Xdata;
 +decode_pubsub_default_els(__TopXMLNS, __IgnoreEls,
 +                        [{xmlel, <<"x">>, _attrs, _} = _el | _els], Xdata) ->
 +    case get_attr(<<"xmlns">>, _attrs) of
 +      <<"jabber:x:data">> ->
 +        decode_pubsub_default_els(__TopXMLNS, __IgnoreEls, _els,
 +                                  decode_xdata(<<"jabber:x:data">>,
 +                                               __IgnoreEls, _el));
 +      _ ->
 +        decode_pubsub_default_els(__TopXMLNS, __IgnoreEls, _els,
 +                                  Xdata)
 +    end;
 +decode_pubsub_default_els(__TopXMLNS, __IgnoreEls,
 +                        [_ | _els], Xdata) ->
 +    decode_pubsub_default_els(__TopXMLNS, __IgnoreEls, _els,
 +                            Xdata).
 +
 +decode_pubsub_default_attrs(__TopXMLNS,
 +                          [{<<"node">>, _val} | _attrs], _Node) ->
 +    decode_pubsub_default_attrs(__TopXMLNS, _attrs, _val);
 +decode_pubsub_default_attrs(__TopXMLNS, [_ | _attrs],
 +                          Node) ->
 +    decode_pubsub_default_attrs(__TopXMLNS, _attrs, Node);
 +decode_pubsub_default_attrs(__TopXMLNS, [], Node) ->
 +    decode_pubsub_default_attr_node(__TopXMLNS, Node).
 +
 +encode_pubsub_default({Node, Xdata}, __TopXMLNS) ->
 +    __NewTopXMLNS = choose_top_xmlns(<<>>,
 +                                   [<<"http://jabber.org/protocol/pubsub">>,
 +                                    <<"http://jabber.org/protocol/pubsub#owner">>],
 +                                   __TopXMLNS),
 +    _els =
 +      lists:reverse('encode_pubsub_default_$xdata'(Xdata,
 +                                                   __NewTopXMLNS, [])),
 +    _attrs = encode_pubsub_default_attr_node(Node,
 +                                           enc_xmlns_attrs(__NewTopXMLNS,
 +                                                           __TopXMLNS)),
 +    {xmlel, <<"default">>, _attrs, _els}.
 +
 +'encode_pubsub_default_$xdata'(undefined, __TopXMLNS,
 +                             _acc) ->
 +    _acc;
 +'encode_pubsub_default_$xdata'(Xdata, __TopXMLNS,
 +                             _acc) ->
 +    [encode_xdata(Xdata, __TopXMLNS) | _acc].
 +
 +decode_pubsub_default_attr_node(__TopXMLNS,
 +                              undefined) ->
 +    <<>>;
 +decode_pubsub_default_attr_node(__TopXMLNS, _val) ->
 +    _val.
 +
 +encode_pubsub_default_attr_node(<<>>, _acc) -> _acc;
 +encode_pubsub_default_attr_node(_val, _acc) ->
 +    [{<<"node">>, _val} | _acc].
 +
 +decode_pubsub_publish_options(__TopXMLNS, __IgnoreEls,
 +                            {xmlel, <<"publish-options">>, _attrs, _els}) ->
 +    Xdata = decode_pubsub_publish_options_els(__TopXMLNS,
 +                                            __IgnoreEls, _els, undefined),
 +    Xdata.
 +
 +decode_pubsub_publish_options_els(__TopXMLNS,
 +                                __IgnoreEls, [], Xdata) ->
 +    Xdata;
 +decode_pubsub_publish_options_els(__TopXMLNS,
 +                                __IgnoreEls,
 +                                [{xmlel, <<"x">>, _attrs, _} = _el | _els],
 +                                Xdata) ->
 +    case get_attr(<<"xmlns">>, _attrs) of
 +      <<"jabber:x:data">> ->
 +        decode_pubsub_publish_options_els(__TopXMLNS,
 +                                          __IgnoreEls, _els,
 +                                          decode_xdata(<<"jabber:x:data">>,
 +                                                       __IgnoreEls, _el));
 +      _ ->
 +        decode_pubsub_publish_options_els(__TopXMLNS,
 +                                          __IgnoreEls, _els, Xdata)
 +    end;
 +decode_pubsub_publish_options_els(__TopXMLNS,
 +                                __IgnoreEls, [_ | _els], Xdata) ->
 +    decode_pubsub_publish_options_els(__TopXMLNS,
 +                                    __IgnoreEls, _els, Xdata).
 +
 +encode_pubsub_publish_options(Xdata, __TopXMLNS) ->
 +    __NewTopXMLNS =
 +      choose_top_xmlns(<<"http://jabber.org/protocol/pubsub">>,
 +                       [], __TopXMLNS),
 +    _els =
 +      lists:reverse('encode_pubsub_publish_options_$xdata'(Xdata,
 +                                                           __NewTopXMLNS,
 +                                                           [])),
 +    _attrs = enc_xmlns_attrs(__NewTopXMLNS, __TopXMLNS),
 +    {xmlel, <<"publish-options">>, _attrs, _els}.
 +
 +'encode_pubsub_publish_options_$xdata'(undefined,
 +                                     __TopXMLNS, _acc) ->
 +    _acc;
 +'encode_pubsub_publish_options_$xdata'(Xdata,
 +                                     __TopXMLNS, _acc) ->
 +    [encode_xdata(Xdata, __TopXMLNS) | _acc].
 +
 +decode_pubsub_configure(__TopXMLNS, __IgnoreEls,
 +                      {xmlel, <<"configure">>, _attrs, _els}) ->
 +    Xdata = decode_pubsub_configure_els(__TopXMLNS,
 +                                      __IgnoreEls, _els, undefined),
 +    Node = decode_pubsub_configure_attrs(__TopXMLNS, _attrs,
 +                                       undefined),
 +    {Node, Xdata}.
 +
 +decode_pubsub_configure_els(__TopXMLNS, __IgnoreEls, [],
 +                          Xdata) ->
 +    Xdata;
 +decode_pubsub_configure_els(__TopXMLNS, __IgnoreEls,
 +                          [{xmlel, <<"x">>, _attrs, _} = _el | _els],
 +                          Xdata) ->
 +    case get_attr(<<"xmlns">>, _attrs) of
 +      <<"jabber:x:data">> ->
 +        decode_pubsub_configure_els(__TopXMLNS, __IgnoreEls,
 +                                    _els,
 +                                    decode_xdata(<<"jabber:x:data">>,
 +                                                 __IgnoreEls, _el));
 +      _ ->
 +        decode_pubsub_configure_els(__TopXMLNS, __IgnoreEls,
 +                                    _els, Xdata)
 +    end;
 +decode_pubsub_configure_els(__TopXMLNS, __IgnoreEls,
 +                          [_ | _els], Xdata) ->
 +    decode_pubsub_configure_els(__TopXMLNS, __IgnoreEls,
 +                              _els, Xdata).
 +
 +decode_pubsub_configure_attrs(__TopXMLNS,
 +                            [{<<"node">>, _val} | _attrs], _Node) ->
 +    decode_pubsub_configure_attrs(__TopXMLNS, _attrs, _val);
 +decode_pubsub_configure_attrs(__TopXMLNS, [_ | _attrs],
 +                            Node) ->
 +    decode_pubsub_configure_attrs(__TopXMLNS, _attrs, Node);
 +decode_pubsub_configure_attrs(__TopXMLNS, [], Node) ->
 +    decode_pubsub_configure_attr_node(__TopXMLNS, Node).
 +
 +encode_pubsub_configure({Node, Xdata}, __TopXMLNS) ->
 +    __NewTopXMLNS = choose_top_xmlns(<<>>,
 +                                   [<<"http://jabber.org/protocol/pubsub">>,
 +                                    <<"http://jabber.org/protocol/pubsub#owner">>],
 +                                   __TopXMLNS),
 +    _els =
 +      lists:reverse('encode_pubsub_configure_$xdata'(Xdata,
 +                                                     __NewTopXMLNS, [])),
 +    _attrs = encode_pubsub_configure_attr_node(Node,
 +                                             enc_xmlns_attrs(__NewTopXMLNS,
 +                                                             __TopXMLNS)),
 +    {xmlel, <<"configure">>, _attrs, _els}.
 +
 +'encode_pubsub_configure_$xdata'(undefined, __TopXMLNS,
 +                               _acc) ->
 +    _acc;
 +'encode_pubsub_configure_$xdata'(Xdata, __TopXMLNS,
 +                               _acc) ->
 +    [encode_xdata(Xdata, __TopXMLNS) | _acc].
 +
 +decode_pubsub_configure_attr_node(__TopXMLNS,
 +                                undefined) ->
 +    <<>>;
 +decode_pubsub_configure_attr_node(__TopXMLNS, _val) ->
 +    _val.
 +
 +encode_pubsub_configure_attr_node(<<>>, _acc) -> _acc;
 +encode_pubsub_configure_attr_node(_val, _acc) ->
 +    [{<<"node">>, _val} | _acc].
 +
 +decode_pubsub_create(__TopXMLNS, __IgnoreEls,
 +                   {xmlel, <<"create">>, _attrs, _els}) ->
 +    Node = decode_pubsub_create_attrs(__TopXMLNS, _attrs,
 +                                    undefined),
 +    Node.
 +
 +decode_pubsub_create_attrs(__TopXMLNS,
 +                         [{<<"node">>, _val} | _attrs], _Node) ->
 +    decode_pubsub_create_attrs(__TopXMLNS, _attrs, _val);
 +decode_pubsub_create_attrs(__TopXMLNS, [_ | _attrs],
 +                         Node) ->
 +    decode_pubsub_create_attrs(__TopXMLNS, _attrs, Node);
 +decode_pubsub_create_attrs(__TopXMLNS, [], Node) ->
 +    decode_pubsub_create_attr_node(__TopXMLNS, Node).
 +
 +encode_pubsub_create(Node, __TopXMLNS) ->
 +    __NewTopXMLNS = choose_top_xmlns(<<>>,
 +                                   [<<"http://jabber.org/protocol/pubsub">>,
 +                                    <<"http://jabber.org/protocol/pubsub#event">>],
 +                                   __TopXMLNS),
 +    _els = [],
 +    _attrs = encode_pubsub_create_attr_node(Node,
 +                                          enc_xmlns_attrs(__NewTopXMLNS,
 +                                                          __TopXMLNS)),
 +    {xmlel, <<"create">>, _attrs, _els}.
 +
 +decode_pubsub_create_attr_node(__TopXMLNS, undefined) ->
 +    <<>>;
 +decode_pubsub_create_attr_node(__TopXMLNS, _val) ->
 +    _val.
 +
 +encode_pubsub_create_attr_node(<<>>, _acc) -> _acc;
 +encode_pubsub_create_attr_node(_val, _acc) ->
 +    [{<<"node">>, _val} | _acc].
 +
 +decode_pubsub_retract(__TopXMLNS, __IgnoreEls,
 +                    {xmlel, <<"retract">>, _attrs, _els}) ->
 +    Items = decode_pubsub_retract_els(__TopXMLNS,
 +                                    __IgnoreEls, _els, []),
 +    {Node, Notify} = decode_pubsub_retract_attrs(__TopXMLNS,
 +                                               _attrs, undefined, undefined),
 +    {ps_retract, Node, Notify, Items}.
 +
 +decode_pubsub_retract_els(__TopXMLNS, __IgnoreEls, [],
 +                        Items) ->
 +    lists:reverse(Items);
 +decode_pubsub_retract_els(__TopXMLNS, __IgnoreEls,
 +                        [{xmlel, <<"item">>, _attrs, _} = _el | _els],
 +                        Items) ->
 +    case get_attr(<<"xmlns">>, _attrs) of
 +      <<"">>
 +        when __TopXMLNS ==
 +               <<"http://jabber.org/protocol/pubsub">> ->
 +        decode_pubsub_retract_els(__TopXMLNS, __IgnoreEls, _els,
 +                                  [decode_pubsub_item(__TopXMLNS, __IgnoreEls,
 +                                                      _el)
 +                                   | Items]);
 +      <<"http://jabber.org/protocol/pubsub">> ->
 +        decode_pubsub_retract_els(__TopXMLNS, __IgnoreEls, _els,
 +                                  [decode_pubsub_item(<<"http://jabber.org/protocol/pubsub">>,
 +                                                      __IgnoreEls, _el)
 +                                   | Items]);
 +      <<"http://jabber.org/protocol/pubsub#event">> ->
 +        decode_pubsub_retract_els(__TopXMLNS, __IgnoreEls, _els,
 +                                  [decode_pubsub_item(<<"http://jabber.org/protocol/pubsub#event">>,
 +                                                      __IgnoreEls, _el)
 +                                   | Items]);
 +      _ ->
 +        decode_pubsub_retract_els(__TopXMLNS, __IgnoreEls, _els,
 +                                  Items)
 +    end;
 +decode_pubsub_retract_els(__TopXMLNS, __IgnoreEls,
 +                        [_ | _els], Items) ->
 +    decode_pubsub_retract_els(__TopXMLNS, __IgnoreEls, _els,
 +                            Items).
 +
 +decode_pubsub_retract_attrs(__TopXMLNS,
 +                          [{<<"node">>, _val} | _attrs], _Node, Notify) ->
 +    decode_pubsub_retract_attrs(__TopXMLNS, _attrs, _val,
 +                              Notify);
 +decode_pubsub_retract_attrs(__TopXMLNS,
 +                          [{<<"notify">>, _val} | _attrs], Node, _Notify) ->
 +    decode_pubsub_retract_attrs(__TopXMLNS, _attrs, Node,
 +                              _val);
 +decode_pubsub_retract_attrs(__TopXMLNS, [_ | _attrs],
 +                          Node, Notify) ->
 +    decode_pubsub_retract_attrs(__TopXMLNS, _attrs, Node,
 +                              Notify);
 +decode_pubsub_retract_attrs(__TopXMLNS, [], Node,
 +                          Notify) ->
 +    {decode_pubsub_retract_attr_node(__TopXMLNS, Node),
 +     decode_pubsub_retract_attr_notify(__TopXMLNS, Notify)}.
 +
 +encode_pubsub_retract({ps_retract, Node, Notify, Items},
 +                    __TopXMLNS) ->
 +    __NewTopXMLNS =
 +      choose_top_xmlns(<<"http://jabber.org/protocol/pubsub">>,
 +                       [], __TopXMLNS),
 +    _els =
 +      lists:reverse('encode_pubsub_retract_$items'(Items,
 +                                                   __NewTopXMLNS, [])),
 +    _attrs = encode_pubsub_retract_attr_notify(Notify,
 +                                             encode_pubsub_retract_attr_node(Node,
 +                                                                             enc_xmlns_attrs(__NewTopXMLNS,
 +                                                                                             __TopXMLNS))),
 +    {xmlel, <<"retract">>, _attrs, _els}.
 +
 +'encode_pubsub_retract_$items'([], __TopXMLNS, _acc) ->
 +    _acc;
 +'encode_pubsub_retract_$items'([Items | _els],
 +                             __TopXMLNS, _acc) ->
 +    'encode_pubsub_retract_$items'(_els, __TopXMLNS,
 +                                 [encode_pubsub_item(Items, __TopXMLNS)
 +                                  | _acc]).
 +
 +decode_pubsub_retract_attr_node(__TopXMLNS,
 +                              undefined) ->
 +    erlang:error({xmpp_codec,
 +                {missing_attr, <<"node">>, <<"retract">>, __TopXMLNS}});
 +decode_pubsub_retract_attr_node(__TopXMLNS, _val) ->
 +    _val.
 +
 +encode_pubsub_retract_attr_node(_val, _acc) ->
 +    [{<<"node">>, _val} | _acc].
 +
 +decode_pubsub_retract_attr_notify(__TopXMLNS,
 +                                undefined) ->
 +    false;
 +decode_pubsub_retract_attr_notify(__TopXMLNS, _val) ->
 +    case catch dec_bool(_val) of
 +      {'EXIT', _} ->
 +        erlang:error({xmpp_codec,
 +                      {bad_attr_value, <<"notify">>, <<"retract">>,
 +                       __TopXMLNS}});
 +      _res -> _res
 +    end.
 +
 +encode_pubsub_retract_attr_notify(false, _acc) -> _acc;
 +encode_pubsub_retract_attr_notify(_val, _acc) ->
 +    [{<<"notify">>, enc_bool(_val)} | _acc].
 +
 +decode_pubsub_options(__TopXMLNS, __IgnoreEls,
 +                    {xmlel, <<"options">>, _attrs, _els}) ->
 +    Xdata = decode_pubsub_options_els(__TopXMLNS,
 +                                    __IgnoreEls, _els, undefined),
 +    {Node, Subid, Jid} =
 +      decode_pubsub_options_attrs(__TopXMLNS, _attrs,
 +                                  undefined, undefined, undefined),
 +    {ps_options, Node, Jid, Subid, Xdata}.
 +
 +decode_pubsub_options_els(__TopXMLNS, __IgnoreEls, [],
 +                        Xdata) ->
 +    Xdata;
 +decode_pubsub_options_els(__TopXMLNS, __IgnoreEls,
 +                        [{xmlel, <<"x">>, _attrs, _} = _el | _els], Xdata) ->
 +    case get_attr(<<"xmlns">>, _attrs) of
 +      <<"jabber:x:data">> ->
 +        decode_pubsub_options_els(__TopXMLNS, __IgnoreEls, _els,
 +                                  decode_xdata(<<"jabber:x:data">>,
 +                                               __IgnoreEls, _el));
 +      _ ->
 +        decode_pubsub_options_els(__TopXMLNS, __IgnoreEls, _els,
 +                                  Xdata)
 +    end;
 +decode_pubsub_options_els(__TopXMLNS, __IgnoreEls,
 +                        [_ | _els], Xdata) ->
 +    decode_pubsub_options_els(__TopXMLNS, __IgnoreEls, _els,
 +                            Xdata).
 +
 +decode_pubsub_options_attrs(__TopXMLNS,
 +                          [{<<"node">>, _val} | _attrs], _Node, Subid, Jid) ->
 +    decode_pubsub_options_attrs(__TopXMLNS, _attrs, _val,
 +                              Subid, Jid);
 +decode_pubsub_options_attrs(__TopXMLNS,
 +                          [{<<"subid">>, _val} | _attrs], Node, _Subid,
 +                          Jid) ->
 +    decode_pubsub_options_attrs(__TopXMLNS, _attrs, Node,
 +                              _val, Jid);
 +decode_pubsub_options_attrs(__TopXMLNS,
 +                          [{<<"jid">>, _val} | _attrs], Node, Subid, _Jid) ->
 +    decode_pubsub_options_attrs(__TopXMLNS, _attrs, Node,
 +                              Subid, _val);
 +decode_pubsub_options_attrs(__TopXMLNS, [_ | _attrs],
 +                          Node, Subid, Jid) ->
 +    decode_pubsub_options_attrs(__TopXMLNS, _attrs, Node,
 +                              Subid, Jid);
 +decode_pubsub_options_attrs(__TopXMLNS, [], Node, Subid,
 +                          Jid) ->
 +    {decode_pubsub_options_attr_node(__TopXMLNS, Node),
 +     decode_pubsub_options_attr_subid(__TopXMLNS, Subid),
 +     decode_pubsub_options_attr_jid(__TopXMLNS, Jid)}.
 +
 +encode_pubsub_options({ps_options, Node, Jid, Subid,
 +                     Xdata},
 +                    __TopXMLNS) ->
 +    __NewTopXMLNS =
 +      choose_top_xmlns(<<"http://jabber.org/protocol/pubsub">>,
 +                       [], __TopXMLNS),
 +    _els =
 +      lists:reverse('encode_pubsub_options_$xdata'(Xdata,
 +                                                   __NewTopXMLNS, [])),
 +    _attrs = encode_pubsub_options_attr_jid(Jid,
 +                                          encode_pubsub_options_attr_subid(Subid,
 +                                                                           encode_pubsub_options_attr_node(Node,
 +                                                                                                           enc_xmlns_attrs(__NewTopXMLNS,
 +                                                                                                                           __TopXMLNS)))),
 +    {xmlel, <<"options">>, _attrs, _els}.
 +
 +'encode_pubsub_options_$xdata'(undefined, __TopXMLNS,
 +                             _acc) ->
 +    _acc;
 +'encode_pubsub_options_$xdata'(Xdata, __TopXMLNS,
 +                             _acc) ->
 +    [encode_xdata(Xdata, __TopXMLNS) | _acc].
 +
 +decode_pubsub_options_attr_node(__TopXMLNS,
 +                              undefined) ->
 +    <<>>;
 +decode_pubsub_options_attr_node(__TopXMLNS, _val) ->
 +    _val.
 +
 +encode_pubsub_options_attr_node(<<>>, _acc) -> _acc;
 +encode_pubsub_options_attr_node(_val, _acc) ->
 +    [{<<"node">>, _val} | _acc].
 +
 +decode_pubsub_options_attr_subid(__TopXMLNS,
 +                               undefined) ->
 +    <<>>;
 +decode_pubsub_options_attr_subid(__TopXMLNS, _val) ->
 +    _val.
 +
 +encode_pubsub_options_attr_subid(<<>>, _acc) -> _acc;
 +encode_pubsub_options_attr_subid(_val, _acc) ->
 +    [{<<"subid">>, _val} | _acc].
 +
 +decode_pubsub_options_attr_jid(__TopXMLNS, undefined) ->
 +    erlang:error({xmpp_codec,
 +                {missing_attr, <<"jid">>, <<"options">>, __TopXMLNS}});
 +decode_pubsub_options_attr_jid(__TopXMLNS, _val) ->
 +    case catch dec_jid(_val) of
 +      {'EXIT', _} ->
 +        erlang:error({xmpp_codec,
 +                      {bad_attr_value, <<"jid">>, <<"options">>,
 +                       __TopXMLNS}});
 +      _res -> _res
 +    end.
 +
 +encode_pubsub_options_attr_jid(_val, _acc) ->
 +    [{<<"jid">>, enc_jid(_val)} | _acc].
 +
 +decode_pubsub_publish(__TopXMLNS, __IgnoreEls,
 +                    {xmlel, <<"publish">>, _attrs, _els}) ->
 +    Items = decode_pubsub_publish_els(__TopXMLNS,
 +                                    __IgnoreEls, _els, []),
 +    Node = decode_pubsub_publish_attrs(__TopXMLNS, _attrs,
 +                                     undefined),
 +    {ps_publish, Node, Items}.
 +
 +decode_pubsub_publish_els(__TopXMLNS, __IgnoreEls, [],
 +                        Items) ->
 +    lists:reverse(Items);
 +decode_pubsub_publish_els(__TopXMLNS, __IgnoreEls,
 +                        [{xmlel, <<"item">>, _attrs, _} = _el | _els],
 +                        Items) ->
 +    case get_attr(<<"xmlns">>, _attrs) of
 +      <<"">>
 +        when __TopXMLNS ==
 +               <<"http://jabber.org/protocol/pubsub">> ->
 +        decode_pubsub_publish_els(__TopXMLNS, __IgnoreEls, _els,
 +                                  [decode_pubsub_item(__TopXMLNS, __IgnoreEls,
 +                                                      _el)
 +                                   | Items]);
 +      <<"http://jabber.org/protocol/pubsub">> ->
 +        decode_pubsub_publish_els(__TopXMLNS, __IgnoreEls, _els,
 +                                  [decode_pubsub_item(<<"http://jabber.org/protocol/pubsub">>,
 +                                                      __IgnoreEls, _el)
 +                                   | Items]);
 +      <<"http://jabber.org/protocol/pubsub#event">> ->
 +        decode_pubsub_publish_els(__TopXMLNS, __IgnoreEls, _els,
 +                                  [decode_pubsub_item(<<"http://jabber.org/protocol/pubsub#event">>,
 +                                                      __IgnoreEls, _el)
 +                                   | Items]);
 +      _ ->
 +        decode_pubsub_publish_els(__TopXMLNS, __IgnoreEls, _els,
 +                                  Items)
 +    end;
 +decode_pubsub_publish_els(__TopXMLNS, __IgnoreEls,
 +                        [_ | _els], Items) ->
 +    decode_pubsub_publish_els(__TopXMLNS, __IgnoreEls, _els,
 +                            Items).
 +
 +decode_pubsub_publish_attrs(__TopXMLNS,
 +                          [{<<"node">>, _val} | _attrs], _Node) ->
 +    decode_pubsub_publish_attrs(__TopXMLNS, _attrs, _val);
 +decode_pubsub_publish_attrs(__TopXMLNS, [_ | _attrs],
 +                          Node) ->
 +    decode_pubsub_publish_attrs(__TopXMLNS, _attrs, Node);
 +decode_pubsub_publish_attrs(__TopXMLNS, [], Node) ->
 +    decode_pubsub_publish_attr_node(__TopXMLNS, Node).
 +
 +encode_pubsub_publish({ps_publish, Node, Items},
 +                    __TopXMLNS) ->
 +    __NewTopXMLNS =
 +      choose_top_xmlns(<<"http://jabber.org/protocol/pubsub">>,
 +                       [], __TopXMLNS),
 +    _els =
 +      lists:reverse('encode_pubsub_publish_$items'(Items,
 +                                                   __NewTopXMLNS, [])),
 +    _attrs = encode_pubsub_publish_attr_node(Node,
 +                                           enc_xmlns_attrs(__NewTopXMLNS,
 +                                                           __TopXMLNS)),
 +    {xmlel, <<"publish">>, _attrs, _els}.
 +
 +'encode_pubsub_publish_$items'([], __TopXMLNS, _acc) ->
 +    _acc;
 +'encode_pubsub_publish_$items'([Items | _els],
 +                             __TopXMLNS, _acc) ->
 +    'encode_pubsub_publish_$items'(_els, __TopXMLNS,
 +                                 [encode_pubsub_item(Items, __TopXMLNS)
 +                                  | _acc]).
 +
 +decode_pubsub_publish_attr_node(__TopXMLNS,
 +                              undefined) ->
 +    erlang:error({xmpp_codec,
 +                {missing_attr, <<"node">>, <<"publish">>, __TopXMLNS}});
 +decode_pubsub_publish_attr_node(__TopXMLNS, _val) ->
 +    _val.
 +
 +encode_pubsub_publish_attr_node(_val, _acc) ->
 +    [{<<"node">>, _val} | _acc].
 +
 +decode_pubsub_unsubscribe(__TopXMLNS, __IgnoreEls,
 +                        {xmlel, <<"unsubscribe">>, _attrs, _els}) ->
 +    {Node, Subid, Jid} =
 +      decode_pubsub_unsubscribe_attrs(__TopXMLNS, _attrs,
 +                                      undefined, undefined, undefined),
 +    {ps_unsubscribe, Node, Jid, Subid}.
 +
 +decode_pubsub_unsubscribe_attrs(__TopXMLNS,
 +                              [{<<"node">>, _val} | _attrs], _Node, Subid,
 +                              Jid) ->
 +    decode_pubsub_unsubscribe_attrs(__TopXMLNS, _attrs,
 +                                  _val, Subid, Jid);
 +decode_pubsub_unsubscribe_attrs(__TopXMLNS,
 +                              [{<<"subid">>, _val} | _attrs], Node, _Subid,
 +                              Jid) ->
 +    decode_pubsub_unsubscribe_attrs(__TopXMLNS, _attrs,
 +                                  Node, _val, Jid);
 +decode_pubsub_unsubscribe_attrs(__TopXMLNS,
 +                              [{<<"jid">>, _val} | _attrs], Node, Subid,
 +                              _Jid) ->
 +    decode_pubsub_unsubscribe_attrs(__TopXMLNS, _attrs,
 +                                  Node, Subid, _val);
 +decode_pubsub_unsubscribe_attrs(__TopXMLNS,
 +                              [_ | _attrs], Node, Subid, Jid) ->
 +    decode_pubsub_unsubscribe_attrs(__TopXMLNS, _attrs,
 +                                  Node, Subid, Jid);
 +decode_pubsub_unsubscribe_attrs(__TopXMLNS, [], Node,
 +                              Subid, Jid) ->
 +    {decode_pubsub_unsubscribe_attr_node(__TopXMLNS, Node),
 +     decode_pubsub_unsubscribe_attr_subid(__TopXMLNS, Subid),
 +     decode_pubsub_unsubscribe_attr_jid(__TopXMLNS, Jid)}.
 +
 +encode_pubsub_unsubscribe({ps_unsubscribe, Node, Jid,
 +                         Subid},
 +                        __TopXMLNS) ->
 +    __NewTopXMLNS =
 +      choose_top_xmlns(<<"http://jabber.org/protocol/pubsub">>,
 +                       [], __TopXMLNS),
 +    _els = [],
 +    _attrs = encode_pubsub_unsubscribe_attr_jid(Jid,
 +                                              encode_pubsub_unsubscribe_attr_subid(Subid,
 +                                                                                   encode_pubsub_unsubscribe_attr_node(Node,
 +                                                                                                                       enc_xmlns_attrs(__NewTopXMLNS,
 +                                                                                                                                       __TopXMLNS)))),
 +    {xmlel, <<"unsubscribe">>, _attrs, _els}.
 +
 +decode_pubsub_unsubscribe_attr_node(__TopXMLNS,
 +                                  undefined) ->
 +    <<>>;
 +decode_pubsub_unsubscribe_attr_node(__TopXMLNS, _val) ->
 +    _val.
 +
 +encode_pubsub_unsubscribe_attr_node(<<>>, _acc) -> _acc;
 +encode_pubsub_unsubscribe_attr_node(_val, _acc) ->
 +    [{<<"node">>, _val} | _acc].
 +
 +decode_pubsub_unsubscribe_attr_subid(__TopXMLNS,
 +                                   undefined) ->
 +    <<>>;
 +decode_pubsub_unsubscribe_attr_subid(__TopXMLNS,
 +                                   _val) ->
 +    _val.
 +
 +encode_pubsub_unsubscribe_attr_subid(<<>>, _acc) ->
 +    _acc;
 +encode_pubsub_unsubscribe_attr_subid(_val, _acc) ->
 +    [{<<"subid">>, _val} | _acc].
 +
 +decode_pubsub_unsubscribe_attr_jid(__TopXMLNS,
 +                                 undefined) ->
 +    erlang:error({xmpp_codec,
 +                {missing_attr, <<"jid">>, <<"unsubscribe">>,
 +                 __TopXMLNS}});
 +decode_pubsub_unsubscribe_attr_jid(__TopXMLNS, _val) ->
 +    case catch dec_jid(_val) of
 +      {'EXIT', _} ->
 +        erlang:error({xmpp_codec,
 +                      {bad_attr_value, <<"jid">>, <<"unsubscribe">>,
 +                       __TopXMLNS}});
 +      _res -> _res
 +    end.
 +
 +encode_pubsub_unsubscribe_attr_jid(_val, _acc) ->
 +    [{<<"jid">>, enc_jid(_val)} | _acc].
 +
 +decode_pubsub_subscribe(__TopXMLNS, __IgnoreEls,
 +                      {xmlel, <<"subscribe">>, _attrs, _els}) ->
 +    {Node, Jid} = decode_pubsub_subscribe_attrs(__TopXMLNS,
 +                                              _attrs, undefined, undefined),
 +    {ps_subscribe, Node, Jid}.
 +
 +decode_pubsub_subscribe_attrs(__TopXMLNS,
 +                            [{<<"node">>, _val} | _attrs], _Node, Jid) ->
 +    decode_pubsub_subscribe_attrs(__TopXMLNS, _attrs, _val,
 +                                Jid);
 +decode_pubsub_subscribe_attrs(__TopXMLNS,
 +                            [{<<"jid">>, _val} | _attrs], Node, _Jid) ->
 +    decode_pubsub_subscribe_attrs(__TopXMLNS, _attrs, Node,
 +                                _val);
 +decode_pubsub_subscribe_attrs(__TopXMLNS, [_ | _attrs],
 +                            Node, Jid) ->
 +    decode_pubsub_subscribe_attrs(__TopXMLNS, _attrs, Node,
 +                                Jid);
 +decode_pubsub_subscribe_attrs(__TopXMLNS, [], Node,
 +                            Jid) ->
 +    {decode_pubsub_subscribe_attr_node(__TopXMLNS, Node),
 +     decode_pubsub_subscribe_attr_jid(__TopXMLNS, Jid)}.
 +
 +encode_pubsub_subscribe({ps_subscribe, Node, Jid},
 +                      __TopXMLNS) ->
 +    __NewTopXMLNS =
 +      choose_top_xmlns(<<"http://jabber.org/protocol/pubsub">>,
 +                       [], __TopXMLNS),
 +    _els = [],
 +    _attrs = encode_pubsub_subscribe_attr_jid(Jid,
 +                                            encode_pubsub_subscribe_attr_node(Node,
 +                                                                              enc_xmlns_attrs(__NewTopXMLNS,
 +                                                                                              __TopXMLNS))),
 +    {xmlel, <<"subscribe">>, _attrs, _els}.
 +
 +decode_pubsub_subscribe_attr_node(__TopXMLNS,
 +                                undefined) ->
 +    <<>>;
 +decode_pubsub_subscribe_attr_node(__TopXMLNS, _val) ->
 +    _val.
 +
 +encode_pubsub_subscribe_attr_node(<<>>, _acc) -> _acc;
 +encode_pubsub_subscribe_attr_node(_val, _acc) ->
 +    [{<<"node">>, _val} | _acc].
 +
 +decode_pubsub_subscribe_attr_jid(__TopXMLNS,
 +                               undefined) ->
 +    erlang:error({xmpp_codec,
 +                {missing_attr, <<"jid">>, <<"subscribe">>,
 +                 __TopXMLNS}});
 +decode_pubsub_subscribe_attr_jid(__TopXMLNS, _val) ->
 +    case catch dec_jid(_val) of
 +      {'EXIT', _} ->
 +        erlang:error({xmpp_codec,
 +                      {bad_attr_value, <<"jid">>, <<"subscribe">>,
 +                       __TopXMLNS}});
 +      _res -> _res
 +    end.
 +
 +encode_pubsub_subscribe_attr_jid(_val, _acc) ->
 +    [{<<"jid">>, enc_jid(_val)} | _acc].
 +
 +decode_pubsub_owner_affiliations(__TopXMLNS,
 +                               __IgnoreEls,
 +                               {xmlel, <<"affiliations">>, _attrs, _els}) ->
 +    Affiliations =
 +      decode_pubsub_owner_affiliations_els(__TopXMLNS,
 +                                           __IgnoreEls, _els, []),
 +    Node =
 +      decode_pubsub_owner_affiliations_attrs(__TopXMLNS,
 +                                             _attrs, undefined),
 +    {Node, Affiliations}.
 +
 +decode_pubsub_owner_affiliations_els(__TopXMLNS,
 +                                   __IgnoreEls, [], Affiliations) ->
 +    lists:reverse(Affiliations);
 +decode_pubsub_owner_affiliations_els(__TopXMLNS,
 +                                   __IgnoreEls,
 +                                   [{xmlel, <<"affiliation">>, _attrs, _} =
 +                                        _el
 +                                    | _els],
 +                                   Affiliations) ->
 +    case get_attr(<<"xmlns">>, _attrs) of
 +      <<"">>
 +        when __TopXMLNS ==
 +               <<"http://jabber.org/protocol/pubsub#owner">> ->
 +        decode_pubsub_owner_affiliations_els(__TopXMLNS,
 +                                             __IgnoreEls, _els,
 +                                             [decode_pubsub_owner_affiliation(__TopXMLNS,
 +                                                                              __IgnoreEls,
 +                                                                              _el)
 +                                              | Affiliations]);
 +      <<"http://jabber.org/protocol/pubsub#owner">> ->
 +        decode_pubsub_owner_affiliations_els(__TopXMLNS,
 +                                             __IgnoreEls, _els,
 +                                             [decode_pubsub_owner_affiliation(<<"http://jabber.org/protocol/pubsub#owner">>,
 +                                                                              __IgnoreEls,
 +                                                                              _el)
 +                                              | Affiliations]);
 +      _ ->
 +        decode_pubsub_owner_affiliations_els(__TopXMLNS,
 +                                             __IgnoreEls, _els, Affiliations)
 +    end;
 +decode_pubsub_owner_affiliations_els(__TopXMLNS,
 +                                   __IgnoreEls, [_ | _els], Affiliations) ->
 +    decode_pubsub_owner_affiliations_els(__TopXMLNS,
 +                                       __IgnoreEls, _els, Affiliations).
 +
 +decode_pubsub_owner_affiliations_attrs(__TopXMLNS,
 +                                     [{<<"node">>, _val} | _attrs], _Node) ->
 +    decode_pubsub_owner_affiliations_attrs(__TopXMLNS,
 +                                         _attrs, _val);
 +decode_pubsub_owner_affiliations_attrs(__TopXMLNS,
 +                                     [_ | _attrs], Node) ->
 +    decode_pubsub_owner_affiliations_attrs(__TopXMLNS,
 +                                         _attrs, Node);
 +decode_pubsub_owner_affiliations_attrs(__TopXMLNS, [],
 +                                     Node) ->
 +    decode_pubsub_owner_affiliations_attr_node(__TopXMLNS,
 +                                             Node).
 +
 +encode_pubsub_owner_affiliations({Node, Affiliations},
 +                               __TopXMLNS) ->
 +    __NewTopXMLNS =
 +      choose_top_xmlns(<<"http://jabber.org/protocol/pubsub#owner">>,
 +                       [], __TopXMLNS),
 +    _els =
 +      lists:reverse('encode_pubsub_owner_affiliations_$affiliations'(Affiliations,
 +                                                                     __NewTopXMLNS,
 +                                                                     [])),
 +    _attrs =
 +      encode_pubsub_owner_affiliations_attr_node(Node,
 +                                                 enc_xmlns_attrs(__NewTopXMLNS,
 +                                                                 __TopXMLNS)),
 +    {xmlel, <<"affiliations">>, _attrs, _els}.
 +
 +'encode_pubsub_owner_affiliations_$affiliations'([],
 +                                               __TopXMLNS, _acc) ->
 +    _acc;
 +'encode_pubsub_owner_affiliations_$affiliations'([Affiliations
 +                                                | _els],
 +                                               __TopXMLNS, _acc) ->
 +    'encode_pubsub_owner_affiliations_$affiliations'(_els,
 +                                                   __TopXMLNS,
 +                                                   [encode_pubsub_owner_affiliation(Affiliations,
 +                                                                                    __TopXMLNS)
 +                                                    | _acc]).
 +
 +decode_pubsub_owner_affiliations_attr_node(__TopXMLNS,
 +                                         undefined) ->
 +    <<>>;
 +decode_pubsub_owner_affiliations_attr_node(__TopXMLNS,
 +                                         _val) ->
 +    _val.
 +
 +encode_pubsub_owner_affiliations_attr_node(<<>>,
 +                                         _acc) ->
 +    _acc;
 +encode_pubsub_owner_affiliations_attr_node(_val,
 +                                         _acc) ->
 +    [{<<"node">>, _val} | _acc].
 +
 +decode_pubsub_affiliations(__TopXMLNS, __IgnoreEls,
 +                         {xmlel, <<"affiliations">>, _attrs, _els}) ->
 +    Affiliations =
 +      decode_pubsub_affiliations_els(__TopXMLNS, __IgnoreEls,
 +                                     _els, []),
 +    Node = decode_pubsub_affiliations_attrs(__TopXMLNS,
 +                                          _attrs, undefined),
 +    {Node, Affiliations}.
 +
 +decode_pubsub_affiliations_els(__TopXMLNS, __IgnoreEls,
 +                             [], Affiliations) ->
 +    lists:reverse(Affiliations);
 +decode_pubsub_affiliations_els(__TopXMLNS, __IgnoreEls,
 +                             [{xmlel, <<"affiliation">>, _attrs, _} = _el
 +                              | _els],
 +                             Affiliations) ->
 +    case get_attr(<<"xmlns">>, _attrs) of
 +      <<"">>
 +        when __TopXMLNS ==
 +               <<"http://jabber.org/protocol/pubsub">> ->
 +        decode_pubsub_affiliations_els(__TopXMLNS, __IgnoreEls,
 +                                       _els,
 +                                       [decode_pubsub_affiliation(__TopXMLNS,
 +                                                                  __IgnoreEls,
 +                                                                  _el)
 +                                        | Affiliations]);
 +      <<"http://jabber.org/protocol/pubsub">> ->
 +        decode_pubsub_affiliations_els(__TopXMLNS, __IgnoreEls,
 +                                       _els,
 +                                       [decode_pubsub_affiliation(<<"http://jabber.org/protocol/pubsub">>,
 +                                                                  __IgnoreEls,
 +                                                                  _el)
 +                                        | Affiliations]);
 +      _ ->
 +        decode_pubsub_affiliations_els(__TopXMLNS, __IgnoreEls,
 +                                       _els, Affiliations)
 +    end;
 +decode_pubsub_affiliations_els(__TopXMLNS, __IgnoreEls,
 +                             [_ | _els], Affiliations) ->
 +    decode_pubsub_affiliations_els(__TopXMLNS, __IgnoreEls,
 +                                 _els, Affiliations).
 +
 +decode_pubsub_affiliations_attrs(__TopXMLNS,
 +                               [{<<"node">>, _val} | _attrs], _Node) ->
 +    decode_pubsub_affiliations_attrs(__TopXMLNS, _attrs,
 +                                   _val);
 +decode_pubsub_affiliations_attrs(__TopXMLNS,
 +                               [_ | _attrs], Node) ->
 +    decode_pubsub_affiliations_attrs(__TopXMLNS, _attrs,
 +                                   Node);
 +decode_pubsub_affiliations_attrs(__TopXMLNS, [],
 +                               Node) ->
 +    decode_pubsub_affiliations_attr_node(__TopXMLNS, Node).
 +
 +encode_pubsub_affiliations({Node, Affiliations},
 +                         __TopXMLNS) ->
 +    __NewTopXMLNS =
 +      choose_top_xmlns(<<"http://jabber.org/protocol/pubsub">>,
 +                       [], __TopXMLNS),
 +    _els =
 +      lists:reverse('encode_pubsub_affiliations_$affiliations'(Affiliations,
 +                                                               __NewTopXMLNS,
 +                                                               [])),
 +    _attrs = encode_pubsub_affiliations_attr_node(Node,
 +                                                enc_xmlns_attrs(__NewTopXMLNS,
 +                                                                __TopXMLNS)),
 +    {xmlel, <<"affiliations">>, _attrs, _els}.
 +
 +'encode_pubsub_affiliations_$affiliations'([],
 +                                         __TopXMLNS, _acc) ->
 +    _acc;
 +'encode_pubsub_affiliations_$affiliations'([Affiliations
 +                                          | _els],
 +                                         __TopXMLNS, _acc) ->
 +    'encode_pubsub_affiliations_$affiliations'(_els,
 +                                             __TopXMLNS,
 +                                             [encode_pubsub_affiliation(Affiliations,
 +                                                                        __TopXMLNS)
 +                                              | _acc]).
 +
 +decode_pubsub_affiliations_attr_node(__TopXMLNS,
 +                                   undefined) ->
 +    <<>>;
 +decode_pubsub_affiliations_attr_node(__TopXMLNS,
 +                                   _val) ->
 +    _val.
 +
 +encode_pubsub_affiliations_attr_node(<<>>, _acc) ->
 +    _acc;
 +encode_pubsub_affiliations_attr_node(_val, _acc) ->
 +    [{<<"node">>, _val} | _acc].
 +
 +decode_pubsub_subscriptions(__TopXMLNS, __IgnoreEls,
 +                          {xmlel, <<"subscriptions">>, _attrs, _els}) ->
 +    Subscriptions =
 +      decode_pubsub_subscriptions_els(__TopXMLNS, __IgnoreEls,
 +                                      _els, []),
 +    Node = decode_pubsub_subscriptions_attrs(__TopXMLNS,
 +                                           _attrs, undefined),
 +    {Node, Subscriptions}.
 +
 +decode_pubsub_subscriptions_els(__TopXMLNS, __IgnoreEls,
 +                              [], Subscriptions) ->
 +    lists:reverse(Subscriptions);
 +decode_pubsub_subscriptions_els(__TopXMLNS, __IgnoreEls,
 +                              [{xmlel, <<"subscription">>, _attrs, _} = _el
 +                               | _els],
 +                              Subscriptions) ->
 +    case get_attr(<<"xmlns">>, _attrs) of
 +      <<"">>
 +        when __TopXMLNS ==
 +               <<"http://jabber.org/protocol/pubsub">>;
 +             __TopXMLNS ==
 +               <<"http://jabber.org/protocol/pubsub#owner">> ->
 +        decode_pubsub_subscriptions_els(__TopXMLNS, __IgnoreEls,
 +                                        _els,
 +                                        [decode_pubsub_subscription(__TopXMLNS,
 +                                                                    __IgnoreEls,
 +                                                                    _el)
 +                                         | Subscriptions]);
 +      <<"http://jabber.org/protocol/pubsub">> ->
 +        decode_pubsub_subscriptions_els(__TopXMLNS, __IgnoreEls,
 +                                        _els,
 +                                        [decode_pubsub_subscription(<<"http://jabber.org/protocol/pubsub">>,
 +                                                                    __IgnoreEls,
 +                                                                    _el)
 +                                         | Subscriptions]);
 +      <<"http://jabber.org/protocol/pubsub#owner">> ->
 +        decode_pubsub_subscriptions_els(__TopXMLNS, __IgnoreEls,
 +                                        _els,
 +                                        [decode_pubsub_subscription(<<"http://jabber.org/protocol/pubsub#owner">>,
 +                                                                    __IgnoreEls,
 +                                                                    _el)
 +                                         | Subscriptions]);
 +      <<"http://jabber.org/protocol/pubsub#event">> ->
 +        decode_pubsub_subscriptions_els(__TopXMLNS, __IgnoreEls,
 +                                        _els,
 +                                        [decode_pubsub_subscription(<<"http://jabber.org/protocol/pubsub#event">>,
 +                                                                    __IgnoreEls,
 +                                                                    _el)
 +                                         | Subscriptions]);
 +      _ ->
 +        decode_pubsub_subscriptions_els(__TopXMLNS, __IgnoreEls,
 +                                        _els, Subscriptions)
 +    end;
 +decode_pubsub_subscriptions_els(__TopXMLNS, __IgnoreEls,
 +                              [_ | _els], Subscriptions) ->
 +    decode_pubsub_subscriptions_els(__TopXMLNS, __IgnoreEls,
 +                                  _els, Subscriptions).
 +
 +decode_pubsub_subscriptions_attrs(__TopXMLNS,
 +                                [{<<"node">>, _val} | _attrs], _Node) ->
 +    decode_pubsub_subscriptions_attrs(__TopXMLNS, _attrs,
 +                                    _val);
 +decode_pubsub_subscriptions_attrs(__TopXMLNS,
 +                                [_ | _attrs], Node) ->
 +    decode_pubsub_subscriptions_attrs(__TopXMLNS, _attrs,
 +                                    Node);
 +decode_pubsub_subscriptions_attrs(__TopXMLNS, [],
 +                                Node) ->
 +    decode_pubsub_subscriptions_attr_node(__TopXMLNS, Node).
 +
 +encode_pubsub_subscriptions({Node, Subscriptions},
 +                          __TopXMLNS) ->
 +    __NewTopXMLNS = choose_top_xmlns(<<>>,
 +                                   [<<"http://jabber.org/protocol/pubsub">>,
 +                                    <<"http://jabber.org/protocol/pubsub#owner">>],
 +                                   __TopXMLNS),
 +    _els =
 +      lists:reverse('encode_pubsub_subscriptions_$subscriptions'(Subscriptions,
 +                                                                 __NewTopXMLNS,
 +                                                                 [])),
 +    _attrs = encode_pubsub_subscriptions_attr_node(Node,
 +                                                 enc_xmlns_attrs(__NewTopXMLNS,
 +                                                                 __TopXMLNS)),
 +    {xmlel, <<"subscriptions">>, _attrs, _els}.
 +
 +'encode_pubsub_subscriptions_$subscriptions'([],
 +                                           __TopXMLNS, _acc) ->
 +    _acc;
 +'encode_pubsub_subscriptions_$subscriptions'([Subscriptions
 +                                            | _els],
 +                                           __TopXMLNS, _acc) ->
 +    'encode_pubsub_subscriptions_$subscriptions'(_els,
 +                                               __TopXMLNS,
 +                                               [encode_pubsub_subscription(Subscriptions,
 +                                                                           __TopXMLNS)
 +                                                | _acc]).
 +
 +decode_pubsub_subscriptions_attr_node(__TopXMLNS,
 +                                    undefined) ->
 +    <<>>;
 +decode_pubsub_subscriptions_attr_node(__TopXMLNS,
 +                                    _val) ->
 +    _val.
 +
 +encode_pubsub_subscriptions_attr_node(<<>>, _acc) ->
 +    _acc;
 +encode_pubsub_subscriptions_attr_node(_val, _acc) ->
 +    [{<<"node">>, _val} | _acc].
 +
 +decode_pubsub_event(__TopXMLNS, __IgnoreEls,
 +                  {xmlel, <<"event">>, _attrs, _els}) ->
 +    {Items, Create, Delete, Purge, Configuration,
 +     Subscription} =
 +      decode_pubsub_event_els(__TopXMLNS, __IgnoreEls, _els,
 +                              undefined, undefined, undefined, undefined,
 +                              undefined, undefined),
 +    {ps_event, Items, Purge, Subscription, Delete, Create,
 +     Configuration}.
 +
 +decode_pubsub_event_els(__TopXMLNS, __IgnoreEls, [],
 +                      Items, Create, Delete, Purge, Configuration,
 +                      Subscription) ->
 +    {Items, Create, Delete, Purge, Configuration,
 +     Subscription};
 +decode_pubsub_event_els(__TopXMLNS, __IgnoreEls,
 +                      [{xmlel, <<"items">>, _attrs, _} = _el | _els], Items,
 +                      Create, Delete, Purge, Configuration, Subscription) ->
 +    case get_attr(<<"xmlns">>, _attrs) of
 +      <<"">>
 +        when __TopXMLNS ==
 +               <<"http://jabber.org/protocol/pubsub#event">> ->
 +        decode_pubsub_event_els(__TopXMLNS, __IgnoreEls, _els,
 +                                decode_pubsub_items(__TopXMLNS, __IgnoreEls,
 +                                                    _el),
 +                                Create, Delete, Purge, Configuration,
 +                                Subscription);
 +      <<"http://jabber.org/protocol/pubsub">> ->
 +        decode_pubsub_event_els(__TopXMLNS, __IgnoreEls, _els,
 +                                decode_pubsub_items(<<"http://jabber.org/protocol/pubsub">>,
 +                                                    __IgnoreEls, _el),
 +                                Create, Delete, Purge, Configuration,
 +                                Subscription);
 +      <<"http://jabber.org/protocol/pubsub#event">> ->
 +        decode_pubsub_event_els(__TopXMLNS, __IgnoreEls, _els,
 +                                decode_pubsub_items(<<"http://jabber.org/protocol/pubsub#event">>,
 +                                                    __IgnoreEls, _el),
 +                                Create, Delete, Purge, Configuration,
 +                                Subscription);
 +      _ ->
 +        decode_pubsub_event_els(__TopXMLNS, __IgnoreEls, _els,
 +                                Items, Create, Delete, Purge, Configuration,
 +                                Subscription)
 +    end;
 +decode_pubsub_event_els(__TopXMLNS, __IgnoreEls,
 +                      [{xmlel, <<"subscription">>, _attrs, _} = _el | _els],
 +                      Items, Create, Delete, Purge, Configuration,
 +                      Subscription) ->
 +    case get_attr(<<"xmlns">>, _attrs) of
 +      <<"">>
 +        when __TopXMLNS ==
 +               <<"http://jabber.org/protocol/pubsub#event">> ->
 +        decode_pubsub_event_els(__TopXMLNS, __IgnoreEls, _els,
 +                                Items, Create, Delete, Purge, Configuration,
 +                                decode_pubsub_subscription(__TopXMLNS,
 +                                                           __IgnoreEls, _el));
 +      <<"http://jabber.org/protocol/pubsub">> ->
 +        decode_pubsub_event_els(__TopXMLNS, __IgnoreEls, _els,
 +                                Items, Create, Delete, Purge, Configuration,
 +                                decode_pubsub_subscription(<<"http://jabber.org/protocol/pubsub">>,
 +                                                           __IgnoreEls, _el));
 +      <<"http://jabber.org/protocol/pubsub#owner">> ->
 +        decode_pubsub_event_els(__TopXMLNS, __IgnoreEls, _els,
 +                                Items, Create, Delete, Purge, Configuration,
 +                                decode_pubsub_subscription(<<"http://jabber.org/protocol/pubsub#owner">>,
 +                                                           __IgnoreEls, _el));
 +      <<"http://jabber.org/protocol/pubsub#event">> ->
 +        decode_pubsub_event_els(__TopXMLNS, __IgnoreEls, _els,
 +                                Items, Create, Delete, Purge, Configuration,
 +                                decode_pubsub_subscription(<<"http://jabber.org/protocol/pubsub#event">>,
 +                                                           __IgnoreEls, _el));
 +      _ ->
 +        decode_pubsub_event_els(__TopXMLNS, __IgnoreEls, _els,
 +                                Items, Create, Delete, Purge, Configuration,
 +                                Subscription)
 +    end;
 +decode_pubsub_event_els(__TopXMLNS, __IgnoreEls,
 +                      [{xmlel, <<"purge">>, _attrs, _} = _el | _els], Items,
 +                      Create, Delete, Purge, Configuration, Subscription) ->
 +    case get_attr(<<"xmlns">>, _attrs) of
 +      <<"">>
 +        when __TopXMLNS ==
 +               <<"http://jabber.org/protocol/pubsub#event">> ->
 +        decode_pubsub_event_els(__TopXMLNS, __IgnoreEls, _els,
 +                                Items, Create, Delete,
 +                                decode_pubsub_purge(__TopXMLNS, __IgnoreEls,
 +                                                    _el),
 +                                Configuration, Subscription);
 +      <<"http://jabber.org/protocol/pubsub">> ->
 +        decode_pubsub_event_els(__TopXMLNS, __IgnoreEls, _els,
 +                                Items, Create, Delete,
 +                                decode_pubsub_purge(<<"http://jabber.org/protocol/pubsub">>,
 +                                                    __IgnoreEls, _el),
 +                                Configuration, Subscription);
 +      <<"http://jabber.org/protocol/pubsub#owner">> ->
 +        decode_pubsub_event_els(__TopXMLNS, __IgnoreEls, _els,
 +                                Items, Create, Delete,
 +                                decode_pubsub_purge(<<"http://jabber.org/protocol/pubsub#owner">>,
 +                                                    __IgnoreEls, _el),
 +                                Configuration, Subscription);
 +      <<"http://jabber.org/protocol/pubsub#event">> ->
 +        decode_pubsub_event_els(__TopXMLNS, __IgnoreEls, _els,
 +                                Items, Create, Delete,
 +                                decode_pubsub_purge(<<"http://jabber.org/protocol/pubsub#event">>,
 +                                                    __IgnoreEls, _el),
 +                                Configuration, Subscription);
 +      _ ->
 +        decode_pubsub_event_els(__TopXMLNS, __IgnoreEls, _els,
 +                                Items, Create, Delete, Purge, Configuration,
 +                                Subscription)
 +    end;
 +decode_pubsub_event_els(__TopXMLNS, __IgnoreEls,
 +                      [{xmlel, <<"delete">>, _attrs, _} = _el | _els], Items,
 +                      Create, Delete, Purge, Configuration, Subscription) ->
 +    case get_attr(<<"xmlns">>, _attrs) of
 +      <<"">>
 +        when __TopXMLNS ==
 +               <<"http://jabber.org/protocol/pubsub#event">> ->
 +        decode_pubsub_event_els(__TopXMLNS, __IgnoreEls, _els,
 +                                Items, Create,
 +                                decode_pubsub_delete(__TopXMLNS, __IgnoreEls,
 +                                                     _el),
 +                                Purge, Configuration, Subscription);
 +      <<"http://jabber.org/protocol/pubsub">> ->
 +        decode_pubsub_event_els(__TopXMLNS, __IgnoreEls, _els,
 +                                Items, Create,
 +                                decode_pubsub_delete(<<"http://jabber.org/protocol/pubsub">>,
 +                                                     __IgnoreEls, _el),
 +                                Purge, Configuration, Subscription);
 +      <<"http://jabber.org/protocol/pubsub#owner">> ->
 +        decode_pubsub_event_els(__TopXMLNS, __IgnoreEls, _els,
 +                                Items, Create,
 +                                decode_pubsub_delete(<<"http://jabber.org/protocol/pubsub#owner">>,
 +                                                     __IgnoreEls, _el),
 +                                Purge, Configuration, Subscription);
 +      <<"http://jabber.org/protocol/pubsub#event">> ->
 +        decode_pubsub_event_els(__TopXMLNS, __IgnoreEls, _els,
 +                                Items, Create,
 +                                decode_pubsub_delete(<<"http://jabber.org/protocol/pubsub#event">>,
 +                                                     __IgnoreEls, _el),
 +                                Purge, Configuration, Subscription);
 +      _ ->
 +        decode_pubsub_event_els(__TopXMLNS, __IgnoreEls, _els,
 +                                Items, Create, Delete, Purge, Configuration,
 +                                Subscription)
 +    end;
 +decode_pubsub_event_els(__TopXMLNS, __IgnoreEls,
 +                      [{xmlel, <<"create">>, _attrs, _} = _el | _els], Items,
 +                      Create, Delete, Purge, Configuration, Subscription) ->
 +    case get_attr(<<"xmlns">>, _attrs) of
 +      <<"">>
 +        when __TopXMLNS ==
 +               <<"http://jabber.org/protocol/pubsub#event">> ->
 +        decode_pubsub_event_els(__TopXMLNS, __IgnoreEls, _els,
 +                                Items,
 +                                decode_pubsub_create(__TopXMLNS, __IgnoreEls,
 +                                                     _el),
 +                                Delete, Purge, Configuration, Subscription);
 +      <<"http://jabber.org/protocol/pubsub">> ->
 +        decode_pubsub_event_els(__TopXMLNS, __IgnoreEls, _els,
 +                                Items,
 +                                decode_pubsub_create(<<"http://jabber.org/protocol/pubsub">>,
 +                                                     __IgnoreEls, _el),
 +                                Delete, Purge, Configuration, Subscription);
 +      <<"http://jabber.org/protocol/pubsub#event">> ->
 +        decode_pubsub_event_els(__TopXMLNS, __IgnoreEls, _els,
 +                                Items,
 +                                decode_pubsub_create(<<"http://jabber.org/protocol/pubsub#event">>,
 +                                                     __IgnoreEls, _el),
 +                                Delete, Purge, Configuration, Subscription);
 +      _ ->
 +        decode_pubsub_event_els(__TopXMLNS, __IgnoreEls, _els,
 +                                Items, Create, Delete, Purge, Configuration,
 +                                Subscription)
 +    end;
 +decode_pubsub_event_els(__TopXMLNS, __IgnoreEls,
 +                      [{xmlel, <<"configuration">>, _attrs, _} = _el | _els],
 +                      Items, Create, Delete, Purge, Configuration,
 +                      Subscription) ->
 +    case get_attr(<<"xmlns">>, _attrs) of
 +      <<"">>
 +        when __TopXMLNS ==
 +               <<"http://jabber.org/protocol/pubsub#event">> ->
 +        decode_pubsub_event_els(__TopXMLNS, __IgnoreEls, _els,
 +                                Items, Create, Delete, Purge,
 +                                decode_pubsub_event_configuration(__TopXMLNS,
 +                                                                  __IgnoreEls,
 +                                                                  _el),
 +                                Subscription);
 +      <<"http://jabber.org/protocol/pubsub#event">> ->
 +        decode_pubsub_event_els(__TopXMLNS, __IgnoreEls, _els,
 +                                Items, Create, Delete, Purge,
 +                                decode_pubsub_event_configuration(<<"http://jabber.org/protocol/pubsub#event">>,
 +                                                                  __IgnoreEls,
 +                                                                  _el),
 +                                Subscription);
 +      _ ->
 +        decode_pubsub_event_els(__TopXMLNS, __IgnoreEls, _els,
 +                                Items, Create, Delete, Purge, Configuration,
 +                                Subscription)
 +    end;
 +decode_pubsub_event_els(__TopXMLNS, __IgnoreEls,
 +                      [_ | _els], Items, Create, Delete, Purge, Configuration,
 +                      Subscription) ->
 +    decode_pubsub_event_els(__TopXMLNS, __IgnoreEls, _els,
 +                          Items, Create, Delete, Purge, Configuration,
 +                          Subscription).
 +
 +encode_pubsub_event({ps_event, Items, Purge,
 +                   Subscription, Delete, Create, Configuration},
 +                  __TopXMLNS) ->
 +    __NewTopXMLNS =
 +      choose_top_xmlns(<<"http://jabber.org/protocol/pubsub#event">>,
 +                       [], __TopXMLNS),
 +    _els = lists:reverse('encode_pubsub_event_$items'(Items,
 +                                                    __NewTopXMLNS,
 +                                                    'encode_pubsub_event_$create'(Create,
 +                                                                                  __NewTopXMLNS,
 +                                                                                  'encode_pubsub_event_$delete'(Delete,
 +                                                                                                                __NewTopXMLNS,
 +                                                                                                                'encode_pubsub_event_$purge'(Purge,
 +                                                                                                                                             __NewTopXMLNS,
 +                                                                                                                                             'encode_pubsub_event_$configuration'(Configuration,
 +                                                                                                                                                                                  __NewTopXMLNS,
 +                                                                                                                                                                                  'encode_pubsub_event_$subscription'(Subscription,
 +                                                                                                                                                                                                                      __NewTopXMLNS,
 +                                                                                                                                                                                                                      []))))))),
 +    _attrs = enc_xmlns_attrs(__NewTopXMLNS, __TopXMLNS),
 +    {xmlel, <<"event">>, _attrs, _els}.
 +
 +'encode_pubsub_event_$items'(undefined, __TopXMLNS,
 +                           _acc) ->
 +    _acc;
 +'encode_pubsub_event_$items'(Items, __TopXMLNS, _acc) ->
 +    [encode_pubsub_items(Items, __TopXMLNS) | _acc].
 +
 +'encode_pubsub_event_$create'(undefined, __TopXMLNS,
 +                            _acc) ->
 +    _acc;
 +'encode_pubsub_event_$create'(Create, __TopXMLNS,
 +                            _acc) ->
 +    [encode_pubsub_create(Create, __TopXMLNS) | _acc].
 +
 +'encode_pubsub_event_$delete'(undefined, __TopXMLNS,
 +                            _acc) ->
 +    _acc;
 +'encode_pubsub_event_$delete'(Delete, __TopXMLNS,
 +                            _acc) ->
 +    [encode_pubsub_delete(Delete, __TopXMLNS) | _acc].
 +
 +'encode_pubsub_event_$purge'(undefined, __TopXMLNS,
 +                           _acc) ->
 +    _acc;
 +'encode_pubsub_event_$purge'(Purge, __TopXMLNS, _acc) ->
 +    [encode_pubsub_purge(Purge, __TopXMLNS) | _acc].
 +
 +'encode_pubsub_event_$configuration'(undefined,
 +                                   __TopXMLNS, _acc) ->
 +    _acc;
 +'encode_pubsub_event_$configuration'(Configuration,
 +                                   __TopXMLNS, _acc) ->
 +    [encode_pubsub_event_configuration(Configuration,
 +                                     __TopXMLNS)
 +     | _acc].
 +
 +'encode_pubsub_event_$subscription'(undefined,
 +                                  __TopXMLNS, _acc) ->
 +    _acc;
 +'encode_pubsub_event_$subscription'(Subscription,
 +                                  __TopXMLNS, _acc) ->
 +    [encode_pubsub_subscription(Subscription, __TopXMLNS)
 +     | _acc].
 +
 +decode_pubsub_items(__TopXMLNS, __IgnoreEls,
 +                  {xmlel, <<"items">>, _attrs, _els}) ->
 +    {Items, Retract} = decode_pubsub_items_els(__TopXMLNS,
 +                                             __IgnoreEls, _els, [],
 +                                             undefined),
 +    {Xmlns, Max_items, Node, Subid} =
 +      decode_pubsub_items_attrs(__TopXMLNS, _attrs, undefined,
 +                                undefined, undefined, undefined),
 +    {ps_items, Xmlns, Node, Items, Max_items, Subid,
 +     Retract}.
 +
 +decode_pubsub_items_els(__TopXMLNS, __IgnoreEls, [],
 +                      Items, Retract) ->
 +    {lists:reverse(Items), Retract};
 +decode_pubsub_items_els(__TopXMLNS, __IgnoreEls,
 +                      [{xmlel, <<"retract">>, _attrs, _} = _el | _els], Items,
 +                      Retract) ->
 +    case get_attr(<<"xmlns">>, _attrs) of
 +      <<"">>
 +        when __TopXMLNS ==
 +               <<"http://jabber.org/protocol/pubsub#event">> ->
 +        decode_pubsub_items_els(__TopXMLNS, __IgnoreEls, _els,
 +                                Items,
 +                                decode_pubsub_event_retract(__TopXMLNS,
 +                                                            __IgnoreEls,
 +                                                            _el));
 +      <<"http://jabber.org/protocol/pubsub#event">> ->
 +        decode_pubsub_items_els(__TopXMLNS, __IgnoreEls, _els,
 +                                Items,
 +                                decode_pubsub_event_retract(<<"http://jabber.org/protocol/pubsub#event">>,
 +                                                            __IgnoreEls,
 +                                                            _el));
 +      _ ->
 +        decode_pubsub_items_els(__TopXMLNS, __IgnoreEls, _els,
 +                                Items, Retract)
 +    end;
 +decode_pubsub_items_els(__TopXMLNS, __IgnoreEls,
 +                      [{xmlel, <<"item">>, _attrs, _} = _el | _els], Items,
 +                      Retract) ->
 +    case get_attr(<<"xmlns">>, _attrs) of
 +      <<"">>
 +        when __TopXMLNS ==
 +               <<"http://jabber.org/protocol/pubsub">>;
 +             __TopXMLNS ==
 +               <<"http://jabber.org/protocol/pubsub#event">> ->
 +        decode_pubsub_items_els(__TopXMLNS, __IgnoreEls, _els,
 +                                [decode_pubsub_item(__TopXMLNS, __IgnoreEls,
 +                                                    _el)
 +                                 | Items],
 +                                Retract);
 +      <<"http://jabber.org/protocol/pubsub">> ->
 +        decode_pubsub_items_els(__TopXMLNS, __IgnoreEls, _els,
 +                                [decode_pubsub_item(<<"http://jabber.org/protocol/pubsub">>,
 +                                                    __IgnoreEls, _el)
 +                                 | Items],
 +                                Retract);
 +      <<"http://jabber.org/protocol/pubsub#event">> ->
 +        decode_pubsub_items_els(__TopXMLNS, __IgnoreEls, _els,
 +                                [decode_pubsub_item(<<"http://jabber.org/protocol/pubsub#event">>,
 +                                                    __IgnoreEls, _el)
 +                                 | Items],
 +                                Retract);
 +      _ ->
 +        decode_pubsub_items_els(__TopXMLNS, __IgnoreEls, _els,
 +                                Items, Retract)
 +    end;
 +decode_pubsub_items_els(__TopXMLNS, __IgnoreEls,
 +                      [_ | _els], Items, Retract) ->
 +    decode_pubsub_items_els(__TopXMLNS, __IgnoreEls, _els,
 +                          Items, Retract).
 +
 +decode_pubsub_items_attrs(__TopXMLNS,
 +                        [{<<"xmlns">>, _val} | _attrs], _Xmlns, Max_items,
 +                        Node, Subid) ->
 +    decode_pubsub_items_attrs(__TopXMLNS, _attrs, _val,
 +                            Max_items, Node, Subid);
 +decode_pubsub_items_attrs(__TopXMLNS,
 +                        [{<<"max_items">>, _val} | _attrs], Xmlns, _Max_items,
 +                        Node, Subid) ->
 +    decode_pubsub_items_attrs(__TopXMLNS, _attrs, Xmlns,
 +                            _val, Node, Subid);
 +decode_pubsub_items_attrs(__TopXMLNS,
 +                        [{<<"node">>, _val} | _attrs], Xmlns, Max_items,
 +                        _Node, Subid) ->
 +    decode_pubsub_items_attrs(__TopXMLNS, _attrs, Xmlns,
 +                            Max_items, _val, Subid);
 +decode_pubsub_items_attrs(__TopXMLNS,
 +                        [{<<"subid">>, _val} | _attrs], Xmlns, Max_items,
 +                        Node, _Subid) ->
 +    decode_pubsub_items_attrs(__TopXMLNS, _attrs, Xmlns,
 +                            Max_items, Node, _val);
 +decode_pubsub_items_attrs(__TopXMLNS, [_ | _attrs],
 +                        Xmlns, Max_items, Node, Subid) ->
 +    decode_pubsub_items_attrs(__TopXMLNS, _attrs, Xmlns,
 +                            Max_items, Node, Subid);
 +decode_pubsub_items_attrs(__TopXMLNS, [], Xmlns,
 +                        Max_items, Node, Subid) ->
 +    {decode_pubsub_items_attr_xmlns(__TopXMLNS, Xmlns),
 +     decode_pubsub_items_attr_max_items(__TopXMLNS,
 +                                      Max_items),
 +     decode_pubsub_items_attr_node(__TopXMLNS, Node),
 +     decode_pubsub_items_attr_subid(__TopXMLNS, Subid)}.
 +
 +encode_pubsub_items({ps_items, Xmlns, Node, Items,
 +                   Max_items, Subid, Retract},
 +                  __TopXMLNS) ->
 +    __NewTopXMLNS = choose_top_xmlns(Xmlns,
 +                                   [<<"http://jabber.org/protocol/pubsub">>,
 +                                    <<"http://jabber.org/protocol/pubsub#event">>],
 +                                   __TopXMLNS),
 +    _els = lists:reverse('encode_pubsub_items_$items'(Items,
 +                                                    __NewTopXMLNS,
 +                                                    'encode_pubsub_items_$retract'(Retract,
 +                                                                                   __NewTopXMLNS,
 +                                                                                   []))),
 +    _attrs = encode_pubsub_items_attr_subid(Subid,
 +                                          encode_pubsub_items_attr_node(Node,
 +                                                                        encode_pubsub_items_attr_max_items(Max_items,
 +                                                                                                           enc_xmlns_attrs(__NewTopXMLNS,
 +                                                                                                                           __TopXMLNS)))),
 +    {xmlel, <<"items">>, _attrs, _els}.
 +
 +'encode_pubsub_items_$items'([], __TopXMLNS, _acc) ->
 +    _acc;
 +'encode_pubsub_items_$items'([Items | _els], __TopXMLNS,
 +                           _acc) ->
 +    'encode_pubsub_items_$items'(_els, __TopXMLNS,
 +                               [encode_pubsub_item(Items, __TopXMLNS)
 +                                | _acc]).
 +
 +'encode_pubsub_items_$retract'(undefined, __TopXMLNS,
 +                             _acc) ->
 +    _acc;
 +'encode_pubsub_items_$retract'(Retract, __TopXMLNS,
 +                             _acc) ->
 +    [encode_pubsub_event_retract(Retract, __TopXMLNS)
 +     | _acc].
 +
 +decode_pubsub_items_attr_xmlns(__TopXMLNS, undefined) ->
 +    <<>>;
 +decode_pubsub_items_attr_xmlns(__TopXMLNS, _val) ->
 +    _val.
 +
 +decode_pubsub_items_attr_max_items(__TopXMLNS,
 +                                 undefined) ->
 +    undefined;
 +decode_pubsub_items_attr_max_items(__TopXMLNS, _val) ->
 +    case catch dec_int(_val, 0, infinity) of
 +      {'EXIT', _} ->
 +        erlang:error({xmpp_codec,
 +                      {bad_attr_value, <<"max_items">>, <<"items">>,
 +                       __TopXMLNS}});
 +      _res -> _res
 +    end.
 +
 +encode_pubsub_items_attr_max_items(undefined, _acc) ->
 +    _acc;
 +encode_pubsub_items_attr_max_items(_val, _acc) ->
 +    [{<<"max_items">>, enc_int(_val)} | _acc].
 +
 +decode_pubsub_items_attr_node(__TopXMLNS, undefined) ->
 +    erlang:error({xmpp_codec,
 +                {missing_attr, <<"node">>, <<"items">>, __TopXMLNS}});
 +decode_pubsub_items_attr_node(__TopXMLNS, _val) -> _val.
 +
 +encode_pubsub_items_attr_node(_val, _acc) ->
 +    [{<<"node">>, _val} | _acc].
 +
 +decode_pubsub_items_attr_subid(__TopXMLNS, undefined) ->
 +    <<>>;
 +decode_pubsub_items_attr_subid(__TopXMLNS, _val) ->
 +    _val.
 +
 +encode_pubsub_items_attr_subid(<<>>, _acc) -> _acc;
 +encode_pubsub_items_attr_subid(_val, _acc) ->
 +    [{<<"subid">>, _val} | _acc].
 +
 +decode_pubsub_item(__TopXMLNS, __IgnoreEls,
 +                 {xmlel, <<"item">>, _attrs, _els}) ->
 +    __Xmls = decode_pubsub_item_els(__TopXMLNS, __IgnoreEls,
 +                                  _els, []),
 +    {Id, Xmlns, Node, Publisher} =
 +      decode_pubsub_item_attrs(__TopXMLNS, _attrs, undefined,
 +                               undefined, undefined, undefined),
 +    {ps_item, Xmlns, Id, __Xmls, Node, Publisher}.
 +
 +decode_pubsub_item_els(__TopXMLNS, __IgnoreEls, [],
 +                     __Xmls) ->
 +    lists:reverse(__Xmls);
 +decode_pubsub_item_els(__TopXMLNS, __IgnoreEls,
 +                     [{xmlel, _, _, _} = _el | _els], __Xmls) ->
 +    decode_pubsub_item_els(__TopXMLNS, __IgnoreEls, _els,
 +                         [_el | __Xmls]);
 +decode_pubsub_item_els(__TopXMLNS, __IgnoreEls,
 +                     [_ | _els], __Xmls) ->
 +    decode_pubsub_item_els(__TopXMLNS, __IgnoreEls, _els,
 +                         __Xmls).
 +
 +decode_pubsub_item_attrs(__TopXMLNS,
 +                       [{<<"id">>, _val} | _attrs], _Id, Xmlns, Node,
 +                       Publisher) ->
 +    decode_pubsub_item_attrs(__TopXMLNS, _attrs, _val,
 +                           Xmlns, Node, Publisher);
 +decode_pubsub_item_attrs(__TopXMLNS,
 +                       [{<<"xmlns">>, _val} | _attrs], Id, _Xmlns, Node,
 +                       Publisher) ->
 +    decode_pubsub_item_attrs(__TopXMLNS, _attrs, Id, _val,
 +                           Node, Publisher);
 +decode_pubsub_item_attrs(__TopXMLNS,
 +                       [{<<"node">>, _val} | _attrs], Id, Xmlns, _Node,
 +                       Publisher) ->
 +    decode_pubsub_item_attrs(__TopXMLNS, _attrs, Id, Xmlns,
 +                           _val, Publisher);
 +decode_pubsub_item_attrs(__TopXMLNS,
 +                       [{<<"publisher">>, _val} | _attrs], Id, Xmlns, Node,
 +                       _Publisher) ->
 +    decode_pubsub_item_attrs(__TopXMLNS, _attrs, Id, Xmlns,
 +                           Node, _val);
 +decode_pubsub_item_attrs(__TopXMLNS, [_ | _attrs], Id,
 +                       Xmlns, Node, Publisher) ->
 +    decode_pubsub_item_attrs(__TopXMLNS, _attrs, Id, Xmlns,
 +                           Node, Publisher);
 +decode_pubsub_item_attrs(__TopXMLNS, [], Id, Xmlns,
 +                       Node, Publisher) ->
 +    {decode_pubsub_item_attr_id(__TopXMLNS, Id),
 +     decode_pubsub_item_attr_xmlns(__TopXMLNS, Xmlns),
 +     decode_pubsub_item_attr_node(__TopXMLNS, Node),
 +     decode_pubsub_item_attr_publisher(__TopXMLNS,
 +                                     Publisher)}.
 +
 +encode_pubsub_item({ps_item, Xmlns, Id, __Xmls, Node,
 +                  Publisher},
 +                 __TopXMLNS) ->
 +    __NewTopXMLNS = choose_top_xmlns(Xmlns,
 +                                   [<<"http://jabber.org/protocol/pubsub">>,
 +                                    <<"http://jabber.org/protocol/pubsub#event">>],
 +                                   __TopXMLNS),
 +    _els = __Xmls,
 +    _attrs = encode_pubsub_item_attr_publisher(Publisher,
 +                                             encode_pubsub_item_attr_node(Node,
 +                                                                          encode_pubsub_item_attr_id(Id,
 +                                                                                                     enc_xmlns_attrs(__NewTopXMLNS,
 +                                                                                                                     __TopXMLNS)))),
 +    {xmlel, <<"item">>, _attrs, _els}.
 +
 +decode_pubsub_item_attr_id(__TopXMLNS, undefined) ->
 +    <<>>;
 +decode_pubsub_item_attr_id(__TopXMLNS, _val) -> _val.
 +
 +encode_pubsub_item_attr_id(<<>>, _acc) -> _acc;
 +encode_pubsub_item_attr_id(_val, _acc) ->
 +    [{<<"id">>, _val} | _acc].
 +
 +decode_pubsub_item_attr_xmlns(__TopXMLNS, undefined) ->
 +    <<>>;
 +decode_pubsub_item_attr_xmlns(__TopXMLNS, _val) -> _val.
 +
 +decode_pubsub_item_attr_node(__TopXMLNS, undefined) ->
 +    <<>>;
 +decode_pubsub_item_attr_node(__TopXMLNS, _val) -> _val.
 +
 +encode_pubsub_item_attr_node(<<>>, _acc) -> _acc;
 +encode_pubsub_item_attr_node(_val, _acc) ->
 +    [{<<"node">>, _val} | _acc].
 +
 +decode_pubsub_item_attr_publisher(__TopXMLNS,
 +                                undefined) ->
 +    <<>>;
 +decode_pubsub_item_attr_publisher(__TopXMLNS, _val) ->
 +    _val.
 +
 +encode_pubsub_item_attr_publisher(<<>>, _acc) -> _acc;
 +encode_pubsub_item_attr_publisher(_val, _acc) ->
 +    [{<<"publisher">>, _val} | _acc].
 +
 +decode_pubsub_event_retract(__TopXMLNS, __IgnoreEls,
 +                          {xmlel, <<"retract">>, _attrs, _els}) ->
 +    Id = decode_pubsub_event_retract_attrs(__TopXMLNS,
 +                                         _attrs, undefined),
 +    Id.
 +
 +decode_pubsub_event_retract_attrs(__TopXMLNS,
 +                                [{<<"id">>, _val} | _attrs], _Id) ->
 +    decode_pubsub_event_retract_attrs(__TopXMLNS, _attrs,
 +                                    _val);
 +decode_pubsub_event_retract_attrs(__TopXMLNS,
 +                                [_ | _attrs], Id) ->
 +    decode_pubsub_event_retract_attrs(__TopXMLNS, _attrs,
 +                                    Id);
 +decode_pubsub_event_retract_attrs(__TopXMLNS, [], Id) ->
 +    decode_pubsub_event_retract_attr_id(__TopXMLNS, Id).
 +
 +encode_pubsub_event_retract(Id, __TopXMLNS) ->
 +    __NewTopXMLNS =
 +      choose_top_xmlns(<<"http://jabber.org/protocol/pubsub#event">>,
 +                       [], __TopXMLNS),
 +    _els = [],
 +    _attrs = encode_pubsub_event_retract_attr_id(Id,
 +                                               enc_xmlns_attrs(__NewTopXMLNS,
 +                                                               __TopXMLNS)),
 +    {xmlel, <<"retract">>, _attrs, _els}.
 +
 +decode_pubsub_event_retract_attr_id(__TopXMLNS,
 +                                  undefined) ->
 +    erlang:error({xmpp_codec,
 +                {missing_attr, <<"id">>, <<"retract">>, __TopXMLNS}});
 +decode_pubsub_event_retract_attr_id(__TopXMLNS, _val) ->
 +    _val.
 +
 +encode_pubsub_event_retract_attr_id(_val, _acc) ->
 +    [{<<"id">>, _val} | _acc].
 +
 +decode_pubsub_event_configuration(__TopXMLNS,
 +                                __IgnoreEls,
 +                                {xmlel, <<"configuration">>, _attrs, _els}) ->
 +    Xdata =
 +      decode_pubsub_event_configuration_els(__TopXMLNS,
 +                                            __IgnoreEls, _els, undefined),
 +    Node =
 +      decode_pubsub_event_configuration_attrs(__TopXMLNS,
 +                                              _attrs, undefined),
 +    {Node, Xdata}.
 +
 +decode_pubsub_event_configuration_els(__TopXMLNS,
 +                                    __IgnoreEls, [], Xdata) ->
 +    Xdata;
 +decode_pubsub_event_configuration_els(__TopXMLNS,
 +                                    __IgnoreEls,
 +                                    [{xmlel, <<"x">>, _attrs, _} = _el
 +                                     | _els],
 +                                    Xdata) ->
 +    case get_attr(<<"xmlns">>, _attrs) of
 +      <<"jabber:x:data">> ->
 +        decode_pubsub_event_configuration_els(__TopXMLNS,
 +                                              __IgnoreEls, _els,
 +                                              decode_xdata(<<"jabber:x:data">>,
 +                                                           __IgnoreEls, _el));
 +      _ ->
 +        decode_pubsub_event_configuration_els(__TopXMLNS,
 +                                              __IgnoreEls, _els, Xdata)
 +    end;
 +decode_pubsub_event_configuration_els(__TopXMLNS,
 +                                    __IgnoreEls, [_ | _els], Xdata) ->
 +    decode_pubsub_event_configuration_els(__TopXMLNS,
 +                                        __IgnoreEls, _els, Xdata).
 +
 +decode_pubsub_event_configuration_attrs(__TopXMLNS,
 +                                      [{<<"node">>, _val} | _attrs], _Node) ->
 +    decode_pubsub_event_configuration_attrs(__TopXMLNS,
 +                                          _attrs, _val);
 +decode_pubsub_event_configuration_attrs(__TopXMLNS,
 +                                      [_ | _attrs], Node) ->
 +    decode_pubsub_event_configuration_attrs(__TopXMLNS,
 +                                          _attrs, Node);
 +decode_pubsub_event_configuration_attrs(__TopXMLNS, [],
 +                                      Node) ->
 +    decode_pubsub_event_configuration_attr_node(__TopXMLNS,
 +                                              Node).
 +
 +encode_pubsub_event_configuration({Node, Xdata},
 +                                __TopXMLNS) ->
 +    __NewTopXMLNS =
 +      choose_top_xmlns(<<"http://jabber.org/protocol/pubsub#event">>,
 +                       [], __TopXMLNS),
 +    _els =
 +      lists:reverse('encode_pubsub_event_configuration_$xdata'(Xdata,
 +                                                               __NewTopXMLNS,
 +                                                               [])),
 +    _attrs =
 +      encode_pubsub_event_configuration_attr_node(Node,
 +                                                  enc_xmlns_attrs(__NewTopXMLNS,
 +                                                                  __TopXMLNS)),
 +    {xmlel, <<"configuration">>, _attrs, _els}.
 +
 +'encode_pubsub_event_configuration_$xdata'(undefined,
 +                                         __TopXMLNS, _acc) ->
 +    _acc;
 +'encode_pubsub_event_configuration_$xdata'(Xdata,
 +                                         __TopXMLNS, _acc) ->
 +    [encode_xdata(Xdata, __TopXMLNS) | _acc].
 +
 +decode_pubsub_event_configuration_attr_node(__TopXMLNS,
 +                                          undefined) ->
 +    erlang:error({xmpp_codec,
 +                {missing_attr, <<"node">>, <<"configuration">>,
 +                 __TopXMLNS}});
 +decode_pubsub_event_configuration_attr_node(__TopXMLNS,
 +                                          _val) ->
 +    _val.
 +
 +encode_pubsub_event_configuration_attr_node(_val,
 +                                          _acc) ->
 +    [{<<"node">>, _val} | _acc].
 +
 +decode_pubsub_owner_affiliation(__TopXMLNS, __IgnoreEls,
 +                              {xmlel, <<"affiliation">>, _attrs, _els}) ->
 +    {Jid, Xmlns, Type} =
 +      decode_pubsub_owner_affiliation_attrs(__TopXMLNS,
 +                                            _attrs, undefined, undefined,
 +                                            undefined),
 +    {ps_affiliation, Xmlns, <<>>, Type, Jid}.
 +
 +decode_pubsub_owner_affiliation_attrs(__TopXMLNS,
 +                                    [{<<"jid">>, _val} | _attrs], _Jid, Xmlns,
 +                                    Type) ->
 +    decode_pubsub_owner_affiliation_attrs(__TopXMLNS,
 +                                        _attrs, _val, Xmlns, Type);
 +decode_pubsub_owner_affiliation_attrs(__TopXMLNS,
 +                                    [{<<"xmlns">>, _val} | _attrs], Jid,
 +                                    _Xmlns, Type) ->
 +    decode_pubsub_owner_affiliation_attrs(__TopXMLNS,
 +                                        _attrs, Jid, _val, Type);
 +decode_pubsub_owner_affiliation_attrs(__TopXMLNS,
 +                                    [{<<"affiliation">>, _val} | _attrs], Jid,
 +                                    Xmlns, _Type) ->
 +    decode_pubsub_owner_affiliation_attrs(__TopXMLNS,
 +                                        _attrs, Jid, Xmlns, _val);
 +decode_pubsub_owner_affiliation_attrs(__TopXMLNS,
 +                                    [_ | _attrs], Jid, Xmlns, Type) ->
 +    decode_pubsub_owner_affiliation_attrs(__TopXMLNS,
 +                                        _attrs, Jid, Xmlns, Type);
 +decode_pubsub_owner_affiliation_attrs(__TopXMLNS, [],
 +                                    Jid, Xmlns, Type) ->
 +    {decode_pubsub_owner_affiliation_attr_jid(__TopXMLNS,
 +                                            Jid),
 +     decode_pubsub_owner_affiliation_attr_xmlns(__TopXMLNS,
 +                                              Xmlns),
 +     decode_pubsub_owner_affiliation_attr_affiliation(__TopXMLNS,
 +                                                    Type)}.
 +
 +encode_pubsub_owner_affiliation({ps_affiliation, Xmlns,
 +                               _, Type, Jid},
 +                              __TopXMLNS) ->
 +    __NewTopXMLNS = choose_top_xmlns(Xmlns,
 +                                   [<<"http://jabber.org/protocol/pubsub#owner">>],
 +                                   __TopXMLNS),
 +    _els = [],
 +    _attrs =
 +      encode_pubsub_owner_affiliation_attr_affiliation(Type,
 +                                                       encode_pubsub_owner_affiliation_attr_jid(Jid,
 +                                                                                                enc_xmlns_attrs(__NewTopXMLNS,
 +                                                                                                                __TopXMLNS))),
 +    {xmlel, <<"affiliation">>, _attrs, _els}.
 +
 +decode_pubsub_owner_affiliation_attr_jid(__TopXMLNS,
 +                                       undefined) ->
 +    erlang:error({xmpp_codec,
 +                {missing_attr, <<"jid">>, <<"affiliation">>,
 +                 __TopXMLNS}});
 +decode_pubsub_owner_affiliation_attr_jid(__TopXMLNS,
 +                                       _val) ->
 +    case catch dec_jid(_val) of
 +      {'EXIT', _} ->
 +        erlang:error({xmpp_codec,
 +                      {bad_attr_value, <<"jid">>, <<"affiliation">>,
 +                       __TopXMLNS}});
 +      _res -> _res
 +    end.
 +
 +encode_pubsub_owner_affiliation_attr_jid(_val, _acc) ->
 +    [{<<"jid">>, enc_jid(_val)} | _acc].
 +
 +decode_pubsub_owner_affiliation_attr_xmlns(__TopXMLNS,
 +                                         undefined) ->
 +    <<>>;
 +decode_pubsub_owner_affiliation_attr_xmlns(__TopXMLNS,
 +                                         _val) ->
 +    _val.
 +
 +decode_pubsub_owner_affiliation_attr_affiliation(__TopXMLNS,
 +                                               undefined) ->
 +    erlang:error({xmpp_codec,
 +                {missing_attr, <<"affiliation">>, <<"affiliation">>,
 +                 __TopXMLNS}});
 +decode_pubsub_owner_affiliation_attr_affiliation(__TopXMLNS,
 +                                               _val) ->
 +    case catch dec_ps_aff(_val) of
 +      {'EXIT', _} ->
 +        erlang:error({xmpp_codec,
 +                      {bad_attr_value, <<"affiliation">>, <<"affiliation">>,
 +                       __TopXMLNS}});
 +      _res -> _res
 +    end.
 +
 +encode_pubsub_owner_affiliation_attr_affiliation(_val,
 +                                               _acc) ->
 +    [{<<"affiliation">>, enc_ps_aff(_val)} | _acc].
 +
 +decode_pubsub_affiliation(__TopXMLNS, __IgnoreEls,
 +                        {xmlel, <<"affiliation">>, _attrs, _els}) ->
 +    {Node, Xmlns, Type} =
 +      decode_pubsub_affiliation_attrs(__TopXMLNS, _attrs,
 +                                      undefined, undefined, undefined),
 +    {ps_affiliation, Xmlns, Node, Type, undefined}.
 +
 +decode_pubsub_affiliation_attrs(__TopXMLNS,
 +                              [{<<"node">>, _val} | _attrs], _Node, Xmlns,
 +                              Type) ->
 +    decode_pubsub_affiliation_attrs(__TopXMLNS, _attrs,
 +                                  _val, Xmlns, Type);
 +decode_pubsub_affiliation_attrs(__TopXMLNS,
 +                              [{<<"xmlns">>, _val} | _attrs], Node, _Xmlns,
 +                              Type) ->
 +    decode_pubsub_affiliation_attrs(__TopXMLNS, _attrs,
 +                                  Node, _val, Type);
 +decode_pubsub_affiliation_attrs(__TopXMLNS,
 +                              [{<<"affiliation">>, _val} | _attrs], Node,
 +                              Xmlns, _Type) ->
 +    decode_pubsub_affiliation_attrs(__TopXMLNS, _attrs,
 +                                  Node, Xmlns, _val);
 +decode_pubsub_affiliation_attrs(__TopXMLNS,
 +                              [_ | _attrs], Node, Xmlns, Type) ->
 +    decode_pubsub_affiliation_attrs(__TopXMLNS, _attrs,
 +                                  Node, Xmlns, Type);
 +decode_pubsub_affiliation_attrs(__TopXMLNS, [], Node,
 +                              Xmlns, Type) ->
 +    {decode_pubsub_affiliation_attr_node(__TopXMLNS, Node),
 +     decode_pubsub_affiliation_attr_xmlns(__TopXMLNS, Xmlns),
 +     decode_pubsub_affiliation_attr_affiliation(__TopXMLNS,
 +                                              Type)}.
 +
 +encode_pubsub_affiliation({ps_affiliation, Xmlns, Node,
 +                         Type, _},
 +                        __TopXMLNS) ->
 +    __NewTopXMLNS = choose_top_xmlns(Xmlns,
 +                                   [<<"http://jabber.org/protocol/pubsub">>],
 +                                   __TopXMLNS),
 +    _els = [],
 +    _attrs =
 +      encode_pubsub_affiliation_attr_affiliation(Type,
 +                                                 encode_pubsub_affiliation_attr_node(Node,
 +                                                                                     enc_xmlns_attrs(__NewTopXMLNS,
 +                                                                                                     __TopXMLNS))),
 +    {xmlel, <<"affiliation">>, _attrs, _els}.
 +
 +decode_pubsub_affiliation_attr_node(__TopXMLNS,
 +                                  undefined) ->
 +    erlang:error({xmpp_codec,
 +                {missing_attr, <<"node">>, <<"affiliation">>,
 +                 __TopXMLNS}});
 +decode_pubsub_affiliation_attr_node(__TopXMLNS, _val) ->
 +    _val.
 +
 +encode_pubsub_affiliation_attr_node(_val, _acc) ->
 +    [{<<"node">>, _val} | _acc].
 +
 +decode_pubsub_affiliation_attr_xmlns(__TopXMLNS,
 +                                   undefined) ->
 +    <<>>;
 +decode_pubsub_affiliation_attr_xmlns(__TopXMLNS,
 +                                   _val) ->
 +    _val.
 +
 +decode_pubsub_affiliation_attr_affiliation(__TopXMLNS,
 +                                         undefined) ->
 +    erlang:error({xmpp_codec,
 +                {missing_attr, <<"affiliation">>, <<"affiliation">>,
 +                 __TopXMLNS}});
 +decode_pubsub_affiliation_attr_affiliation(__TopXMLNS,
 +                                         _val) ->
 +    case catch dec_ps_aff(_val) of
 +      {'EXIT', _} ->
 +        erlang:error({xmpp_codec,
 +                      {bad_attr_value, <<"affiliation">>, <<"affiliation">>,
 +                       __TopXMLNS}});
 +      _res -> _res
 +    end.
 +
 +encode_pubsub_affiliation_attr_affiliation(_val,
 +                                         _acc) ->
 +    [{<<"affiliation">>, enc_ps_aff(_val)} | _acc].
 +
 +decode_pubsub_subscription(__TopXMLNS, __IgnoreEls,
 +                         {xmlel, <<"subscription">>, _attrs, _els}) ->
 +    {Xmlns, Jid, Node, Subid, Type, Expiry} =
 +      decode_pubsub_subscription_attrs(__TopXMLNS, _attrs,
 +                                       undefined, undefined, undefined,
 +                                       undefined, undefined, undefined),
 +    {ps_subscription, Xmlns, Jid, Type, Node, Subid,
 +     Expiry}.
 +
 +decode_pubsub_subscription_attrs(__TopXMLNS,
 +                               [{<<"xmlns">>, _val} | _attrs], _Xmlns, Jid,
 +                               Node, Subid, Type, Expiry) ->
 +    decode_pubsub_subscription_attrs(__TopXMLNS, _attrs,
 +                                   _val, Jid, Node, Subid, Type, Expiry);
 +decode_pubsub_subscription_attrs(__TopXMLNS,
 +                               [{<<"jid">>, _val} | _attrs], Xmlns, _Jid,
 +                               Node, Subid, Type, Expiry) ->
 +    decode_pubsub_subscription_attrs(__TopXMLNS, _attrs,
 +                                   Xmlns, _val, Node, Subid, Type, Expiry);
 +decode_pubsub_subscription_attrs(__TopXMLNS,
 +                               [{<<"node">>, _val} | _attrs], Xmlns, Jid,
 +                               _Node, Subid, Type, Expiry) ->
 +    decode_pubsub_subscription_attrs(__TopXMLNS, _attrs,
 +                                   Xmlns, Jid, _val, Subid, Type, Expiry);
 +decode_pubsub_subscription_attrs(__TopXMLNS,
 +                               [{<<"subid">>, _val} | _attrs], Xmlns, Jid,
 +                               Node, _Subid, Type, Expiry) ->
 +    decode_pubsub_subscription_attrs(__TopXMLNS, _attrs,
 +                                   Xmlns, Jid, Node, _val, Type, Expiry);
 +decode_pubsub_subscription_attrs(__TopXMLNS,
 +                               [{<<"subscription">>, _val} | _attrs], Xmlns,
 +                               Jid, Node, Subid, _Type, Expiry) ->
 +    decode_pubsub_subscription_attrs(__TopXMLNS, _attrs,
 +                                   Xmlns, Jid, Node, Subid, _val, Expiry);
 +decode_pubsub_subscription_attrs(__TopXMLNS,
 +                               [{<<"expiry">>, _val} | _attrs], Xmlns, Jid,
 +                               Node, Subid, Type, _Expiry) ->
 +    decode_pubsub_subscription_attrs(__TopXMLNS, _attrs,
 +                                   Xmlns, Jid, Node, Subid, Type, _val);
 +decode_pubsub_subscription_attrs(__TopXMLNS,
 +                               [_ | _attrs], Xmlns, Jid, Node, Subid, Type,
 +                               Expiry) ->
 +    decode_pubsub_subscription_attrs(__TopXMLNS, _attrs,
 +                                   Xmlns, Jid, Node, Subid, Type, Expiry);
 +decode_pubsub_subscription_attrs(__TopXMLNS, [], Xmlns,
 +                               Jid, Node, Subid, Type, Expiry) ->
 +    {decode_pubsub_subscription_attr_xmlns(__TopXMLNS,
 +                                         Xmlns),
 +     decode_pubsub_subscription_attr_jid(__TopXMLNS, Jid),
 +     decode_pubsub_subscription_attr_node(__TopXMLNS, Node),
 +     decode_pubsub_subscription_attr_subid(__TopXMLNS,
 +                                         Subid),
 +     decode_pubsub_subscription_attr_subscription(__TopXMLNS,
 +                                                Type),
 +     decode_pubsub_subscription_attr_expiry(__TopXMLNS,
 +                                          Expiry)}.
 +
 +encode_pubsub_subscription({ps_subscription, Xmlns, Jid,
 +                          Type, Node, Subid, Expiry},
 +                         __TopXMLNS) ->
 +    __NewTopXMLNS = choose_top_xmlns(Xmlns,
 +                                   [<<"http://jabber.org/protocol/pubsub">>,
 +                                    <<"http://jabber.org/protocol/pubsub#owner">>,
 +                                    <<"http://jabber.org/protocol/pubsub#event">>],
 +                                   __TopXMLNS),
 +    _els = [],
 +    _attrs = encode_pubsub_subscription_attr_expiry(Expiry,
 +                                                  encode_pubsub_subscription_attr_subscription(Type,
 +                                                                                               encode_pubsub_subscription_attr_subid(Subid,
 +                                                                                                                                     encode_pubsub_subscription_attr_node(Node,
 +                                                                                                                                                                          encode_pubsub_subscription_attr_jid(Jid,
 +                                                                                                                                                                                                              enc_xmlns_attrs(__NewTopXMLNS,
 +                                                                                                                                                                                                                              __TopXMLNS)))))),
 +    {xmlel, <<"subscription">>, _attrs, _els}.
 +
 +decode_pubsub_subscription_attr_xmlns(__TopXMLNS,
 +                                    undefined) ->
 +    <<>>;
 +decode_pubsub_subscription_attr_xmlns(__TopXMLNS,
 +                                    _val) ->
 +    _val.
 +
 +decode_pubsub_subscription_attr_jid(__TopXMLNS,
 +                                  undefined) ->
 +    erlang:error({xmpp_codec,
 +                {missing_attr, <<"jid">>, <<"subscription">>,
 +                 __TopXMLNS}});
 +decode_pubsub_subscription_attr_jid(__TopXMLNS, _val) ->
 +    case catch dec_jid(_val) of
 +      {'EXIT', _} ->
 +        erlang:error({xmpp_codec,
 +                      {bad_attr_value, <<"jid">>, <<"subscription">>,
 +                       __TopXMLNS}});
 +      _res -> _res
 +    end.
 +
 +encode_pubsub_subscription_attr_jid(_val, _acc) ->
 +    [{<<"jid">>, enc_jid(_val)} | _acc].
 +
 +decode_pubsub_subscription_attr_node(__TopXMLNS,
 +                                   undefined) ->
 +    <<>>;
 +decode_pubsub_subscription_attr_node(__TopXMLNS,
 +                                   _val) ->
 +    _val.
 +
 +encode_pubsub_subscription_attr_node(<<>>, _acc) ->
 +    _acc;
 +encode_pubsub_subscription_attr_node(_val, _acc) ->
 +    [{<<"node">>, _val} | _acc].
 +
 +decode_pubsub_subscription_attr_subid(__TopXMLNS,
 +                                    undefined) ->
 +    <<>>;
 +decode_pubsub_subscription_attr_subid(__TopXMLNS,
 +                                    _val) ->
 +    _val.
 +
 +encode_pubsub_subscription_attr_subid(<<>>, _acc) ->
 +    _acc;
 +encode_pubsub_subscription_attr_subid(_val, _acc) ->
 +    [{<<"subid">>, _val} | _acc].
 +
 +decode_pubsub_subscription_attr_subscription(__TopXMLNS,
 +                                           undefined) ->
 +    undefined;
 +decode_pubsub_subscription_attr_subscription(__TopXMLNS,
 +                                           _val) ->
 +    case catch dec_enum(_val,
 +                      [none, pending, subscribed, unconfigured])
 +      of
 +      {'EXIT', _} ->
 +        erlang:error({xmpp_codec,
 +                      {bad_attr_value, <<"subscription">>, <<"subscription">>,
 +                       __TopXMLNS}});
 +      _res -> _res
 +    end.
 +
 +encode_pubsub_subscription_attr_subscription(undefined,
 +                                           _acc) ->
 +    _acc;
 +encode_pubsub_subscription_attr_subscription(_val,
 +                                           _acc) ->
 +    [{<<"subscription">>, enc_enum(_val)} | _acc].
 +
 +decode_pubsub_subscription_attr_expiry(__TopXMLNS,
 +                                     undefined) ->
 +    undefined;
 +decode_pubsub_subscription_attr_expiry(__TopXMLNS,
 +                                     _val) ->
 +    case catch dec_utc(_val) of
 +      {'EXIT', _} ->
 +        erlang:error({xmpp_codec,
 +                      {bad_attr_value, <<"expiry">>, <<"subscription">>,
 +                       __TopXMLNS}});
 +      _res -> _res
 +    end.
 +
 +encode_pubsub_subscription_attr_expiry(undefined,
 +                                     _acc) ->
 +    _acc;
 +encode_pubsub_subscription_attr_expiry(_val, _acc) ->
 +    [{<<"expiry">>, enc_utc(_val)} | _acc].
 +
 +decode_xdata(__TopXMLNS, __IgnoreEls,
 +           {xmlel, <<"x">>, _attrs, _els}) ->
 +    {Fields, Items, Instructions, Reported, Title} =
 +      decode_xdata_els(__TopXMLNS, __IgnoreEls, _els, [], [],
 +                       [], undefined, undefined),
 +    Type = decode_xdata_attrs(__TopXMLNS, _attrs,
 +                            undefined),
 +    {xdata, Type, Instructions, Title, Reported, Items,
 +     Fields}.
 +
 +decode_xdata_els(__TopXMLNS, __IgnoreEls, [], Fields,
 +               Items, Instructions, Reported, Title) ->
 +    {lists:reverse(Fields), lists:reverse(Items),
 +     lists:reverse(Instructions), Reported, Title};
 +decode_xdata_els(__TopXMLNS, __IgnoreEls,
 +               [{xmlel, <<"instructions">>, _attrs, _} = _el | _els],
 +               Fields, Items, Instructions, Reported, Title) ->
 +    case get_attr(<<"xmlns">>, _attrs) of
 +      <<"">> when __TopXMLNS == <<"jabber:x:data">> ->
 +        decode_xdata_els(__TopXMLNS, __IgnoreEls, _els, Fields,
 +                         Items,
 +                         [decode_xdata_instructions(__TopXMLNS, __IgnoreEls,
 +                                                    _el)
 +                          | Instructions],
 +                         Reported, Title);
 +      <<"jabber:x:data">> ->
 +        decode_xdata_els(__TopXMLNS, __IgnoreEls, _els, Fields,
 +                         Items,
 +                         [decode_xdata_instructions(<<"jabber:x:data">>,
 +                                                    __IgnoreEls, _el)
 +                          | Instructions],
 +                         Reported, Title);
 +      _ ->
 +        decode_xdata_els(__TopXMLNS, __IgnoreEls, _els, Fields,
 +                         Items, Instructions, Reported, Title)
 +    end;
 +decode_xdata_els(__TopXMLNS, __IgnoreEls,
 +               [{xmlel, <<"title">>, _attrs, _} = _el | _els], Fields,
 +               Items, Instructions, Reported, Title) ->
 +    case get_attr(<<"xmlns">>, _attrs) of
 +      <<"">> when __TopXMLNS == <<"jabber:x:data">> ->
 +        decode_xdata_els(__TopXMLNS, __IgnoreEls, _els, Fields,
 +                         Items, Instructions, Reported,
 +                         decode_xdata_title(__TopXMLNS, __IgnoreEls, _el));
 +      <<"jabber:x:data">> ->
 +        decode_xdata_els(__TopXMLNS, __IgnoreEls, _els, Fields,
 +                         Items, Instructions, Reported,
 +                         decode_xdata_title(<<"jabber:x:data">>, __IgnoreEls,
 +                                            _el));
 +      _ ->
 +        decode_xdata_els(__TopXMLNS, __IgnoreEls, _els, Fields,
 +                         Items, Instructions, Reported, Title)
 +    end;
 +decode_xdata_els(__TopXMLNS, __IgnoreEls,
 +               [{xmlel, <<"reported">>, _attrs, _} = _el | _els],
 +               Fields, Items, Instructions, Reported, Title) ->
 +    case get_attr(<<"xmlns">>, _attrs) of
 +      <<"">> when __TopXMLNS == <<"jabber:x:data">> ->
 +        decode_xdata_els(__TopXMLNS, __IgnoreEls, _els, Fields,
 +                         Items, Instructions,
 +                         decode_xdata_reported(__TopXMLNS, __IgnoreEls, _el),
 +                         Title);
 +      <<"jabber:x:data">> ->
 +        decode_xdata_els(__TopXMLNS, __IgnoreEls, _els, Fields,
 +                         Items, Instructions,
 +                         decode_xdata_reported(<<"jabber:x:data">>,
 +                                               __IgnoreEls, _el),
 +                         Title);
 +      _ ->
 +        decode_xdata_els(__TopXMLNS, __IgnoreEls, _els, Fields,
 +                         Items, Instructions, Reported, Title)
 +    end;
 +decode_xdata_els(__TopXMLNS, __IgnoreEls,
 +               [{xmlel, <<"item">>, _attrs, _} = _el | _els], Fields,
 +               Items, Instructions, Reported, Title) ->
 +    case get_attr(<<"xmlns">>, _attrs) of
 +      <<"">> when __TopXMLNS == <<"jabber:x:data">> ->
 +        decode_xdata_els(__TopXMLNS, __IgnoreEls, _els, Fields,
 +                         [decode_xdata_item(__TopXMLNS, __IgnoreEls, _el)
 +                          | Items],
 +                         Instructions, Reported, Title);
 +      <<"jabber:x:data">> ->
 +        decode_xdata_els(__TopXMLNS, __IgnoreEls, _els, Fields,
 +                         [decode_xdata_item(<<"jabber:x:data">>, __IgnoreEls,
 +                                            _el)
 +                          | Items],
 +                         Instructions, Reported, Title);
 +      _ ->
 +        decode_xdata_els(__TopXMLNS, __IgnoreEls, _els, Fields,
 +                         Items, Instructions, Reported, Title)
 +    end;
 +decode_xdata_els(__TopXMLNS, __IgnoreEls,
 +               [{xmlel, <<"field">>, _attrs, _} = _el | _els], Fields,
 +               Items, Instructions, Reported, Title) ->
 +    case get_attr(<<"xmlns">>, _attrs) of
 +      <<"">> when __TopXMLNS == <<"jabber:x:data">> ->
 +        decode_xdata_els(__TopXMLNS, __IgnoreEls, _els,
 +                         [decode_xdata_field(__TopXMLNS, __IgnoreEls, _el)
 +                          | Fields],
 +                         Items, Instructions, Reported, Title);
 +      <<"jabber:x:data">> ->
 +        decode_xdata_els(__TopXMLNS, __IgnoreEls, _els,
 +                         [decode_xdata_field(<<"jabber:x:data">>, __IgnoreEls,
 +                                             _el)
 +                          | Fields],
 +                         Items, Instructions, Reported, Title);
 +      _ ->
 +        decode_xdata_els(__TopXMLNS, __IgnoreEls, _els, Fields,
 +                         Items, Instructions, Reported, Title)
 +    end;
 +decode_xdata_els(__TopXMLNS, __IgnoreEls, [_ | _els],
 +               Fields, Items, Instructions, Reported, Title) ->
 +    decode_xdata_els(__TopXMLNS, __IgnoreEls, _els, Fields,
 +                   Items, Instructions, Reported, Title).
 +
 +decode_xdata_attrs(__TopXMLNS,
 +                 [{<<"type">>, _val} | _attrs], _Type) ->
 +    decode_xdata_attrs(__TopXMLNS, _attrs, _val);
 +decode_xdata_attrs(__TopXMLNS, [_ | _attrs], Type) ->
 +    decode_xdata_attrs(__TopXMLNS, _attrs, Type);
 +decode_xdata_attrs(__TopXMLNS, [], Type) ->
 +    decode_xdata_attr_type(__TopXMLNS, Type).
 +
 +encode_xdata({xdata, Type, Instructions, Title,
 +            Reported, Items, Fields},
 +           __TopXMLNS) ->
 +    __NewTopXMLNS = choose_top_xmlns(<<"jabber:x:data">>,
 +                                   [], __TopXMLNS),
 +    _els = lists:reverse('encode_xdata_$fields'(Fields,
 +                                              __NewTopXMLNS,
 +                                              'encode_xdata_$items'(Items,
 +                                                                    __NewTopXMLNS,
 +                                                                    'encode_xdata_$instructions'(Instructions,
 +                                                                                                 __NewTopXMLNS,
 +                                                                                                 'encode_xdata_$reported'(Reported,
 +                                                                                                                          __NewTopXMLNS,
 +                                                                                                                          'encode_xdata_$title'(Title,
 +                                                                                                                                                __NewTopXMLNS,
 +                                                                                                                                                [])))))),
 +    _attrs = encode_xdata_attr_type(Type,
 +                                  enc_xmlns_attrs(__NewTopXMLNS, __TopXMLNS)),
 +    {xmlel, <<"x">>, _attrs, _els}.
 +
 +'encode_xdata_$fields'([], __TopXMLNS, _acc) -> _acc;
 +'encode_xdata_$fields'([Fields | _els], __TopXMLNS,
 +                     _acc) ->
 +    'encode_xdata_$fields'(_els, __TopXMLNS,
 +                         [encode_xdata_field(Fields, __TopXMLNS) | _acc]).
 +
 +'encode_xdata_$items'([], __TopXMLNS, _acc) -> _acc;
 +'encode_xdata_$items'([Items | _els], __TopXMLNS,
 +                    _acc) ->
 +    'encode_xdata_$items'(_els, __TopXMLNS,
 +                        [encode_xdata_item(Items, __TopXMLNS) | _acc]).
 +
 +'encode_xdata_$instructions'([], __TopXMLNS, _acc) ->
 +    _acc;
 +'encode_xdata_$instructions'([Instructions | _els],
 +                           __TopXMLNS, _acc) ->
 +    'encode_xdata_$instructions'(_els, __TopXMLNS,
 +                               [encode_xdata_instructions(Instructions,
 +                                                          __TopXMLNS)
 +                                | _acc]).
 +
 +'encode_xdata_$reported'(undefined, __TopXMLNS, _acc) ->
 +    _acc;
 +'encode_xdata_$reported'(Reported, __TopXMLNS, _acc) ->
 +    [encode_xdata_reported(Reported, __TopXMLNS) | _acc].
 +
 +'encode_xdata_$title'(undefined, __TopXMLNS, _acc) ->
 +    _acc;
 +'encode_xdata_$title'(Title, __TopXMLNS, _acc) ->
 +    [encode_xdata_title(Title, __TopXMLNS) | _acc].
 +
 +decode_xdata_attr_type(__TopXMLNS, undefined) ->
 +    erlang:error({xmpp_codec,
 +                {missing_attr, <<"type">>, <<"x">>, __TopXMLNS}});
 +decode_xdata_attr_type(__TopXMLNS, _val) ->
 +    case catch dec_enum(_val,
 +                      [cancel, form, result, submit])
 +      of
 +      {'EXIT', _} ->
 +        erlang:error({xmpp_codec,
 +                      {bad_attr_value, <<"type">>, <<"x">>, __TopXMLNS}});
 +      _res -> _res
 +    end.
 +
 +encode_xdata_attr_type(_val, _acc) ->
 +    [{<<"type">>, enc_enum(_val)} | _acc].
 +
 +decode_xdata_item(__TopXMLNS, __IgnoreEls,
 +                {xmlel, <<"item">>, _attrs, _els}) ->
 +    Fields = decode_xdata_item_els(__TopXMLNS, __IgnoreEls,
 +                                 _els, []),
 +    Fields.
 +
 +decode_xdata_item_els(__TopXMLNS, __IgnoreEls, [],
 +                    Fields) ->
 +    lists:reverse(Fields);
 +decode_xdata_item_els(__TopXMLNS, __IgnoreEls,
 +                    [{xmlel, <<"field">>, _attrs, _} = _el | _els],
 +                    Fields) ->
 +    case get_attr(<<"xmlns">>, _attrs) of
 +      <<"">> when __TopXMLNS == <<"jabber:x:data">> ->
 +        decode_xdata_item_els(__TopXMLNS, __IgnoreEls, _els,
 +                              [decode_xdata_field(__TopXMLNS, __IgnoreEls,
 +                                                  _el)
 +                               | Fields]);
 +      <<"jabber:x:data">> ->
 +        decode_xdata_item_els(__TopXMLNS, __IgnoreEls, _els,
 +                              [decode_xdata_field(<<"jabber:x:data">>,
 +                                                  __IgnoreEls, _el)
 +                               | Fields]);
 +      _ ->
 +        decode_xdata_item_els(__TopXMLNS, __IgnoreEls, _els,
 +                              Fields)
 +    end;
 +decode_xdata_item_els(__TopXMLNS, __IgnoreEls,
 +                    [_ | _els], Fields) ->
 +    decode_xdata_item_els(__TopXMLNS, __IgnoreEls, _els,
 +                        Fields).
 +
 +encode_xdata_item(Fields, __TopXMLNS) ->
 +    __NewTopXMLNS = choose_top_xmlns(<<"jabber:x:data">>,
 +                                   [], __TopXMLNS),
 +    _els = lists:reverse('encode_xdata_item_$fields'(Fields,
 +                                                   __NewTopXMLNS, [])),
 +    _attrs = enc_xmlns_attrs(__NewTopXMLNS, __TopXMLNS),
 +    {xmlel, <<"item">>, _attrs, _els}.
 +
 +'encode_xdata_item_$fields'([], __TopXMLNS, _acc) ->
 +    _acc;
 +'encode_xdata_item_$fields'([Fields | _els], __TopXMLNS,
 +                          _acc) ->
 +    'encode_xdata_item_$fields'(_els, __TopXMLNS,
 +                              [encode_xdata_field(Fields, __TopXMLNS)
 +                               | _acc]).
 +
 +decode_xdata_reported(__TopXMLNS, __IgnoreEls,
 +                    {xmlel, <<"reported">>, _attrs, _els}) ->
 +    Fields = decode_xdata_reported_els(__TopXMLNS,
 +                                     __IgnoreEls, _els, []),
 +    Fields.
 +
 +decode_xdata_reported_els(__TopXMLNS, __IgnoreEls, [],
 +                        Fields) ->
 +    lists:reverse(Fields);
 +decode_xdata_reported_els(__TopXMLNS, __IgnoreEls,
 +                        [{xmlel, <<"field">>, _attrs, _} = _el | _els],
 +                        Fields) ->
 +    case get_attr(<<"xmlns">>, _attrs) of
 +      <<"">> when __TopXMLNS == <<"jabber:x:data">> ->
 +        decode_xdata_reported_els(__TopXMLNS, __IgnoreEls, _els,
 +                                  [decode_xdata_field(__TopXMLNS, __IgnoreEls,
 +                                                      _el)
 +                                   | Fields]);
 +      <<"jabber:x:data">> ->
 +        decode_xdata_reported_els(__TopXMLNS, __IgnoreEls, _els,
 +                                  [decode_xdata_field(<<"jabber:x:data">>,
 +                                                      __IgnoreEls, _el)
 +                                   | Fields]);
 +      _ ->
 +        decode_xdata_reported_els(__TopXMLNS, __IgnoreEls, _els,
 +                                  Fields)
 +    end;
 +decode_xdata_reported_els(__TopXMLNS, __IgnoreEls,
 +                        [_ | _els], Fields) ->
 +    decode_xdata_reported_els(__TopXMLNS, __IgnoreEls, _els,
 +                            Fields).
 +
 +encode_xdata_reported(Fields, __TopXMLNS) ->
 +    __NewTopXMLNS = choose_top_xmlns(<<"jabber:x:data">>,
 +                                   [], __TopXMLNS),
 +    _els =
 +      lists:reverse('encode_xdata_reported_$fields'(Fields,
 +                                                    __NewTopXMLNS, [])),
 +    _attrs = enc_xmlns_attrs(__NewTopXMLNS, __TopXMLNS),
 +    {xmlel, <<"reported">>, _attrs, _els}.
 +
 +'encode_xdata_reported_$fields'([], __TopXMLNS, _acc) ->
 +    _acc;
 +'encode_xdata_reported_$fields'([Fields | _els],
 +                              __TopXMLNS, _acc) ->
 +    'encode_xdata_reported_$fields'(_els, __TopXMLNS,
 +                                  [encode_xdata_field(Fields, __TopXMLNS)
 +                                   | _acc]).
 +
 +decode_xdata_title(__TopXMLNS, __IgnoreEls,
 +                 {xmlel, <<"title">>, _attrs, _els}) ->
 +    Cdata = decode_xdata_title_els(__TopXMLNS, __IgnoreEls,
 +                                 _els, <<>>),
 +    Cdata.
 +
 +decode_xdata_title_els(__TopXMLNS, __IgnoreEls, [],
 +                     Cdata) ->
 +    decode_xdata_title_cdata(__TopXMLNS, Cdata);
 +decode_xdata_title_els(__TopXMLNS, __IgnoreEls,
 +                     [{xmlcdata, _data} | _els], Cdata) ->
 +    decode_xdata_title_els(__TopXMLNS, __IgnoreEls, _els,
 +                         <<Cdata/binary, _data/binary>>);
 +decode_xdata_title_els(__TopXMLNS, __IgnoreEls,
 +                     [_ | _els], Cdata) ->
 +    decode_xdata_title_els(__TopXMLNS, __IgnoreEls, _els,
 +                         Cdata).
 +
 +encode_xdata_title(Cdata, __TopXMLNS) ->
 +    __NewTopXMLNS = choose_top_xmlns(<<"jabber:x:data">>,
 +                                   [], __TopXMLNS),
 +    _els = encode_xdata_title_cdata(Cdata, []),
 +    _attrs = enc_xmlns_attrs(__NewTopXMLNS, __TopXMLNS),
 +    {xmlel, <<"title">>, _attrs, _els}.
 +
 +decode_xdata_title_cdata(__TopXMLNS, <<>>) -> <<>>;
 +decode_xdata_title_cdata(__TopXMLNS, _val) -> _val.
 +
 +encode_xdata_title_cdata(<<>>, _acc) -> _acc;
 +encode_xdata_title_cdata(_val, _acc) ->
 +    [{xmlcdata, _val} | _acc].
 +
 +decode_xdata_instructions(__TopXMLNS, __IgnoreEls,
 +                        {xmlel, <<"instructions">>, _attrs, _els}) ->
 +    Cdata = decode_xdata_instructions_els(__TopXMLNS,
 +                                        __IgnoreEls, _els, <<>>),
 +    Cdata.
 +
 +decode_xdata_instructions_els(__TopXMLNS, __IgnoreEls,
 +                            [], Cdata) ->
 +    decode_xdata_instructions_cdata(__TopXMLNS, Cdata);
 +decode_xdata_instructions_els(__TopXMLNS, __IgnoreEls,
 +                            [{xmlcdata, _data} | _els], Cdata) ->
 +    decode_xdata_instructions_els(__TopXMLNS, __IgnoreEls,
 +                                _els, <<Cdata/binary, _data/binary>>);
 +decode_xdata_instructions_els(__TopXMLNS, __IgnoreEls,
 +                            [_ | _els], Cdata) ->
 +    decode_xdata_instructions_els(__TopXMLNS, __IgnoreEls,
 +                                _els, Cdata).
 +
 +encode_xdata_instructions(Cdata, __TopXMLNS) ->
 +    __NewTopXMLNS = choose_top_xmlns(<<"jabber:x:data">>,
 +                                   [], __TopXMLNS),
 +    _els = encode_xdata_instructions_cdata(Cdata, []),
 +    _attrs = enc_xmlns_attrs(__NewTopXMLNS, __TopXMLNS),
 +    {xmlel, <<"instructions">>, _attrs, _els}.
 +
 +decode_xdata_instructions_cdata(__TopXMLNS, <<>>) ->
 +    <<>>;
 +decode_xdata_instructions_cdata(__TopXMLNS, _val) ->
 +    _val.
 +
 +encode_xdata_instructions_cdata(<<>>, _acc) -> _acc;
 +encode_xdata_instructions_cdata(_val, _acc) ->
 +    [{xmlcdata, _val} | _acc].
 +
 +decode_xdata_field(__TopXMLNS, __IgnoreEls,
 +                 {xmlel, <<"field">>, _attrs, _els}) ->
 +    {Options, Values, Desc, Required, __Els} =
 +      decode_xdata_field_els(__TopXMLNS, __IgnoreEls, _els,
 +                             [], [], <<>>, false, []),
 +    {Label, Type, Var} =
 +      decode_xdata_field_attrs(__TopXMLNS, _attrs, undefined,
 +                               undefined, undefined),
 +    {xdata_field, Label, Type, Var, Required, Desc, Values,
 +     Options, __Els}.
 +
 +decode_xdata_field_els(__TopXMLNS, __IgnoreEls, [],
 +                     Options, Values, Desc, Required, __Els) ->
 +    {lists:reverse(Options), lists:reverse(Values), Desc,
 +     Required, lists:reverse(__Els)};
 +decode_xdata_field_els(__TopXMLNS, __IgnoreEls,
 +                     [{xmlel, <<"required">>, _attrs, _} = _el | _els],
 +                     Options, Values, Desc, Required, __Els) ->
 +    case get_attr(<<"xmlns">>, _attrs) of
 +      <<"">> when __TopXMLNS == <<"jabber:x:data">> ->
 +        decode_xdata_field_els(__TopXMLNS, __IgnoreEls, _els,
 +                               Options, Values, Desc,
 +                               decode_xdata_field_required(__TopXMLNS,
 +                                                           __IgnoreEls, _el),
 +                               __Els);
 +      <<"jabber:x:data">> ->
 +        decode_xdata_field_els(__TopXMLNS, __IgnoreEls, _els,
 +                               Options, Values, Desc,
 +                               decode_xdata_field_required(<<"jabber:x:data">>,
 +                                                           __IgnoreEls, _el),
 +                               __Els);
 +      _ ->
 +        decode_xdata_field_els(__TopXMLNS, __IgnoreEls, _els,
 +                               Options, Values, Desc, Required, __Els)
 +    end;
 +decode_xdata_field_els(__TopXMLNS, __IgnoreEls,
 +                     [{xmlel, <<"desc">>, _attrs, _} = _el | _els], Options,
 +                     Values, Desc, Required, __Els) ->
 +    case get_attr(<<"xmlns">>, _attrs) of
 +      <<"">> when __TopXMLNS == <<"jabber:x:data">> ->
 +        decode_xdata_field_els(__TopXMLNS, __IgnoreEls, _els,
 +                               Options, Values,
 +                               decode_xdata_field_desc(__TopXMLNS,
 +                                                       __IgnoreEls, _el),
 +                               Required, __Els);
 +      <<"jabber:x:data">> ->
 +        decode_xdata_field_els(__TopXMLNS, __IgnoreEls, _els,
 +                               Options, Values,
 +                               decode_xdata_field_desc(<<"jabber:x:data">>,
 +                                                       __IgnoreEls, _el),
 +                               Required, __Els);
 +      _ ->
 +        decode_xdata_field_els(__TopXMLNS, __IgnoreEls, _els,
 +                               Options, Values, Desc, Required, __Els)
 +    end;
 +decode_xdata_field_els(__TopXMLNS, __IgnoreEls,
 +                     [{xmlel, <<"value">>, _attrs, _} = _el | _els], Options,
 +                     Values, Desc, Required, __Els) ->
 +    case get_attr(<<"xmlns">>, _attrs) of
 +      <<"">> when __TopXMLNS == <<"jabber:x:data">> ->
 +        decode_xdata_field_els(__TopXMLNS, __IgnoreEls, _els,
 +                               Options,
 +                               [decode_xdata_field_value(__TopXMLNS,
 +                                                         __IgnoreEls, _el)
 +                                | Values],
 +                               Desc, Required, __Els);
 +      <<"jabber:x:data">> ->
 +        decode_xdata_field_els(__TopXMLNS, __IgnoreEls, _els,
 +                               Options,
 +                               [decode_xdata_field_value(<<"jabber:x:data">>,
 +                                                         __IgnoreEls, _el)
 +                                | Values],
 +                               Desc, Required, __Els);
 +      _ ->
 +        decode_xdata_field_els(__TopXMLNS, __IgnoreEls, _els,
 +                               Options, Values, Desc, Required, __Els)
 +    end;
 +decode_xdata_field_els(__TopXMLNS, __IgnoreEls,
 +                     [{xmlel, <<"option">>, _attrs, _} = _el | _els],
 +                     Options, Values, Desc, Required, __Els) ->
 +    case get_attr(<<"xmlns">>, _attrs) of
 +      <<"">> when __TopXMLNS == <<"jabber:x:data">> ->
 +        decode_xdata_field_els(__TopXMLNS, __IgnoreEls, _els,
 +                               [decode_xdata_field_option(__TopXMLNS,
 +                                                          __IgnoreEls, _el)
 +                                | Options],
 +                               Values, Desc, Required, __Els);
 +      <<"jabber:x:data">> ->
 +        decode_xdata_field_els(__TopXMLNS, __IgnoreEls, _els,
 +                               [decode_xdata_field_option(<<"jabber:x:data">>,
 +                                                          __IgnoreEls, _el)
 +                                | Options],
 +                               Values, Desc, Required, __Els);
 +      _ ->
 +        decode_xdata_field_els(__TopXMLNS, __IgnoreEls, _els,
 +                               Options, Values, Desc, Required, __Els)
 +    end;
 +decode_xdata_field_els(__TopXMLNS, __IgnoreEls,
 +                     [{xmlel, _, _, _} = _el | _els], Options, Values, Desc,
 +                     Required, __Els) ->
 +    if __IgnoreEls ->
 +         decode_xdata_field_els(__TopXMLNS, __IgnoreEls, _els,
 +                                Options, Values, Desc, Required,
 +                                [_el | __Els]);
 +       true ->
 +         case is_known_tag(_el, __TopXMLNS) of
 +           true ->
 +               decode_xdata_field_els(__TopXMLNS, __IgnoreEls, _els,
 +                                      Options, Values, Desc, Required,
 +                                      [decode(_el, __TopXMLNS, []) | __Els]);
 +           false ->
 +               decode_xdata_field_els(__TopXMLNS, __IgnoreEls, _els,
 +                                      Options, Values, Desc, Required, __Els)
 +         end
 +    end;
 +decode_xdata_field_els(__TopXMLNS, __IgnoreEls,
 +                     [_ | _els], Options, Values, Desc, Required, __Els) ->
 +    decode_xdata_field_els(__TopXMLNS, __IgnoreEls, _els,
 +                         Options, Values, Desc, Required, __Els).
 +
 +decode_xdata_field_attrs(__TopXMLNS,
 +                       [{<<"label">>, _val} | _attrs], _Label, Type, Var) ->
 +    decode_xdata_field_attrs(__TopXMLNS, _attrs, _val, Type,
 +                           Var);
 +decode_xdata_field_attrs(__TopXMLNS,
 +                       [{<<"type">>, _val} | _attrs], Label, _Type, Var) ->
 +    decode_xdata_field_attrs(__TopXMLNS, _attrs, Label,
 +                           _val, Var);
 +decode_xdata_field_attrs(__TopXMLNS,
 +                       [{<<"var">>, _val} | _attrs], Label, Type, _Var) ->
 +    decode_xdata_field_attrs(__TopXMLNS, _attrs, Label,
 +                           Type, _val);
 +decode_xdata_field_attrs(__TopXMLNS, [_ | _attrs],
 +                       Label, Type, Var) ->
 +    decode_xdata_field_attrs(__TopXMLNS, _attrs, Label,
 +                           Type, Var);
 +decode_xdata_field_attrs(__TopXMLNS, [], Label, Type,
 +                       Var) ->
 +    {decode_xdata_field_attr_label(__TopXMLNS, Label),
 +     decode_xdata_field_attr_type(__TopXMLNS, Type),
 +     decode_xdata_field_attr_var(__TopXMLNS, Var)}.
 +
 +encode_xdata_field({xdata_field, Label, Type, Var,
 +                  Required, Desc, Values, Options, __Els},
 +                 __TopXMLNS) ->
 +    __NewTopXMLNS = choose_top_xmlns(<<"jabber:x:data">>,
 +                                   [], __TopXMLNS),
 +    _els = [encode(_el, __NewTopXMLNS) || _el <- __Els] ++
 +           lists:reverse('encode_xdata_field_$options'(Options,
 +                                                       __NewTopXMLNS,
 +                                                       'encode_xdata_field_$values'(Values,
 +                                                                                    __NewTopXMLNS,
 +                                                                                    'encode_xdata_field_$desc'(Desc,
 +                                                                                                               __NewTopXMLNS,
 +                                                                                                               'encode_xdata_field_$required'(Required,
 +                                                                                                                                              __NewTopXMLNS,
 +                                                                                                                                              []))))),
 +    _attrs = encode_xdata_field_attr_var(Var,
 +                                       encode_xdata_field_attr_type(Type,
 +                                                                    encode_xdata_field_attr_label(Label,
 +                                                                                                  enc_xmlns_attrs(__NewTopXMLNS,
 +                                                                                                                  __TopXMLNS)))),
 +    {xmlel, <<"field">>, _attrs, _els}.
 +
 +'encode_xdata_field_$options'([], __TopXMLNS, _acc) ->
 +    _acc;
 +'encode_xdata_field_$options'([Options | _els],
 +                            __TopXMLNS, _acc) ->
 +    'encode_xdata_field_$options'(_els, __TopXMLNS,
 +                                [encode_xdata_field_option(Options,
 +                                                           __TopXMLNS)
 +                                 | _acc]).
 +
 +'encode_xdata_field_$values'([], __TopXMLNS, _acc) ->
 +    _acc;
 +'encode_xdata_field_$values'([Values | _els],
 +                           __TopXMLNS, _acc) ->
 +    'encode_xdata_field_$values'(_els, __TopXMLNS,
 +                               [encode_xdata_field_value(Values, __TopXMLNS)
 +                                | _acc]).
 +
 +'encode_xdata_field_$desc'(<<>>, __TopXMLNS, _acc) ->
 +    _acc;
 +'encode_xdata_field_$desc'(Desc, __TopXMLNS, _acc) ->
 +    [encode_xdata_field_desc(Desc, __TopXMLNS) | _acc].
 +
 +'encode_xdata_field_$required'(false, __TopXMLNS,
 +                             _acc) ->
 +    _acc;
 +'encode_xdata_field_$required'(Required, __TopXMLNS,
 +                             _acc) ->
 +    [encode_xdata_field_required(Required, __TopXMLNS)
 +     | _acc].
 +
 +decode_xdata_field_attr_label(__TopXMLNS, undefined) ->
 +    <<>>;
 +decode_xdata_field_attr_label(__TopXMLNS, _val) -> _val.
 +
 +encode_xdata_field_attr_label(<<>>, _acc) -> _acc;
 +encode_xdata_field_attr_label(_val, _acc) ->
 +    [{<<"label">>, _val} | _acc].
 +
 +decode_xdata_field_attr_type(__TopXMLNS, undefined) ->
 +    undefined;
 +decode_xdata_field_attr_type(__TopXMLNS, _val) ->
 +    case catch dec_enum(_val,
 +                      [boolean, fixed, hidden, 'jid-multi', 'jid-single',
 +                       'list-multi', 'list-single', 'text-multi',
 +                       'text-private', 'text-single'])
 +      of
 +      {'EXIT', _} ->
 +        erlang:error({xmpp_codec,
 +                      {bad_attr_value, <<"type">>, <<"field">>, __TopXMLNS}});
 +      _res -> _res
 +    end.
 +
 +encode_xdata_field_attr_type(undefined, _acc) -> _acc;
 +encode_xdata_field_attr_type(_val, _acc) ->
 +    [{<<"type">>, enc_enum(_val)} | _acc].
 +
 +decode_xdata_field_attr_var(__TopXMLNS, undefined) ->
 +    <<>>;
 +decode_xdata_field_attr_var(__TopXMLNS, _val) -> _val.
 +
 +encode_xdata_field_attr_var(<<>>, _acc) -> _acc;
 +encode_xdata_field_attr_var(_val, _acc) ->
 +    [{<<"var">>, _val} | _acc].
 +
 +decode_xdata_field_option(__TopXMLNS, __IgnoreEls,
 +                        {xmlel, <<"option">>, _attrs, _els}) ->
 +    Value = decode_xdata_field_option_els(__TopXMLNS,
 +                                        __IgnoreEls, _els, error),
 +    Label = decode_xdata_field_option_attrs(__TopXMLNS,
 +                                          _attrs, undefined),
 +    {xdata_option, Label, Value}.
 +
 +decode_xdata_field_option_els(__TopXMLNS, __IgnoreEls,
 +                            [], Value) ->
 +    case Value of
 +      error ->
 +        erlang:error({xmpp_codec,
 +                      {missing_tag, <<"value">>, __TopXMLNS}});
 +      {value, Value1} -> Value1
 +    end;
 +decode_xdata_field_option_els(__TopXMLNS, __IgnoreEls,
 +                            [{xmlel, <<"value">>, _attrs, _} = _el | _els],
 +                            Value) ->
 +    case get_attr(<<"xmlns">>, _attrs) of
 +      <<"">> when __TopXMLNS == <<"jabber:x:data">> ->
 +        decode_xdata_field_option_els(__TopXMLNS, __IgnoreEls,
 +                                      _els,
 +                                      {value,
 +                                       decode_xdata_field_value(__TopXMLNS,
 +                                                                __IgnoreEls,
 +                                                                _el)});
 +      <<"jabber:x:data">> ->
 +        decode_xdata_field_option_els(__TopXMLNS, __IgnoreEls,
 +                                      _els,
 +                                      {value,
 +                                       decode_xdata_field_value(<<"jabber:x:data">>,
 +                                                                __IgnoreEls,
 +                                                                _el)});
 +      _ ->
 +        decode_xdata_field_option_els(__TopXMLNS, __IgnoreEls,
 +                                      _els, Value)
 +    end;
 +decode_xdata_field_option_els(__TopXMLNS, __IgnoreEls,
 +                            [_ | _els], Value) ->
 +    decode_xdata_field_option_els(__TopXMLNS, __IgnoreEls,
 +                                _els, Value).
 +
 +decode_xdata_field_option_attrs(__TopXMLNS,
 +                              [{<<"label">>, _val} | _attrs], _Label) ->
 +    decode_xdata_field_option_attrs(__TopXMLNS, _attrs,
 +                                  _val);
 +decode_xdata_field_option_attrs(__TopXMLNS,
 +                              [_ | _attrs], Label) ->
 +    decode_xdata_field_option_attrs(__TopXMLNS, _attrs,
 +                                  Label);
 +decode_xdata_field_option_attrs(__TopXMLNS, [],
 +                              Label) ->
 +    decode_xdata_field_option_attr_label(__TopXMLNS, Label).
 +
 +encode_xdata_field_option({xdata_option, Label, Value},
 +                        __TopXMLNS) ->
 +    __NewTopXMLNS = choose_top_xmlns(<<"jabber:x:data">>,
 +                                   [], __TopXMLNS),
 +    _els =
 +      lists:reverse('encode_xdata_field_option_$value'(Value,
 +                                                       __NewTopXMLNS, [])),
 +    _attrs = encode_xdata_field_option_attr_label(Label,
 +                                                enc_xmlns_attrs(__NewTopXMLNS,
 +                                                                __TopXMLNS)),
 +    {xmlel, <<"option">>, _attrs, _els}.
 +
 +'encode_xdata_field_option_$value'(Value, __TopXMLNS,
 +                                 _acc) ->
 +    [encode_xdata_field_value(Value, __TopXMLNS) | _acc].
 +
 +decode_xdata_field_option_attr_label(__TopXMLNS,
 +                                   undefined) ->
 +    <<>>;
 +decode_xdata_field_option_attr_label(__TopXMLNS,
 +                                   _val) ->
 +    _val.
 +
 +encode_xdata_field_option_attr_label(<<>>, _acc) ->
 +    _acc;
 +encode_xdata_field_option_attr_label(_val, _acc) ->
 +    [{<<"label">>, _val} | _acc].
 +
 +decode_xdata_field_value(__TopXMLNS, __IgnoreEls,
 +                       {xmlel, <<"value">>, _attrs, _els}) ->
 +    Cdata = decode_xdata_field_value_els(__TopXMLNS,
 +                                       __IgnoreEls, _els, <<>>),
 +    Cdata.
 +
 +decode_xdata_field_value_els(__TopXMLNS, __IgnoreEls,
 +                           [], Cdata) ->
 +    decode_xdata_field_value_cdata(__TopXMLNS, Cdata);
 +decode_xdata_field_value_els(__TopXMLNS, __IgnoreEls,
 +                           [{xmlcdata, _data} | _els], Cdata) ->
 +    decode_xdata_field_value_els(__TopXMLNS, __IgnoreEls,
 +                               _els, <<Cdata/binary, _data/binary>>);
 +decode_xdata_field_value_els(__TopXMLNS, __IgnoreEls,
 +                           [_ | _els], Cdata) ->
 +    decode_xdata_field_value_els(__TopXMLNS, __IgnoreEls,
 +                               _els, Cdata).
 +
 +encode_xdata_field_value(Cdata, __TopXMLNS) ->
 +    __NewTopXMLNS = choose_top_xmlns(<<"jabber:x:data">>,
 +                                   [], __TopXMLNS),
 +    _els = encode_xdata_field_value_cdata(Cdata, []),
 +    _attrs = enc_xmlns_attrs(__NewTopXMLNS, __TopXMLNS),
 +    {xmlel, <<"value">>, _attrs, _els}.
 +
 +decode_xdata_field_value_cdata(__TopXMLNS, <<>>) ->
 +    <<>>;
 +decode_xdata_field_value_cdata(__TopXMLNS, _val) ->
 +    _val.
 +
 +encode_xdata_field_value_cdata(<<>>, _acc) -> _acc;
 +encode_xdata_field_value_cdata(_val, _acc) ->
 +    [{xmlcdata, _val} | _acc].
 +
 +decode_xdata_field_desc(__TopXMLNS, __IgnoreEls,
 +                      {xmlel, <<"desc">>, _attrs, _els}) ->
 +    Cdata = decode_xdata_field_desc_els(__TopXMLNS,
 +                                      __IgnoreEls, _els, <<>>),
 +    Cdata.
 +
 +decode_xdata_field_desc_els(__TopXMLNS, __IgnoreEls, [],
 +                          Cdata) ->
 +    decode_xdata_field_desc_cdata(__TopXMLNS, Cdata);
 +decode_xdata_field_desc_els(__TopXMLNS, __IgnoreEls,
 +                          [{xmlcdata, _data} | _els], Cdata) ->
 +    decode_xdata_field_desc_els(__TopXMLNS, __IgnoreEls,
 +                              _els, <<Cdata/binary, _data/binary>>);
 +decode_xdata_field_desc_els(__TopXMLNS, __IgnoreEls,
 +                          [_ | _els], Cdata) ->
 +    decode_xdata_field_desc_els(__TopXMLNS, __IgnoreEls,
 +                              _els, Cdata).
 +
 +encode_xdata_field_desc(Cdata, __TopXMLNS) ->
 +    __NewTopXMLNS = choose_top_xmlns(<<"jabber:x:data">>,
 +                                   [], __TopXMLNS),
 +    _els = encode_xdata_field_desc_cdata(Cdata, []),
 +    _attrs = enc_xmlns_attrs(__NewTopXMLNS, __TopXMLNS),
 +    {xmlel, <<"desc">>, _attrs, _els}.
 +
 +decode_xdata_field_desc_cdata(__TopXMLNS, <<>>) -> <<>>;
 +decode_xdata_field_desc_cdata(__TopXMLNS, _val) -> _val.
 +
 +encode_xdata_field_desc_cdata(<<>>, _acc) -> _acc;
 +encode_xdata_field_desc_cdata(_val, _acc) ->
 +    [{xmlcdata, _val} | _acc].
 +
 +decode_xdata_field_required(__TopXMLNS, __IgnoreEls,
 +                          {xmlel, <<"required">>, _attrs, _els}) ->
 +    true.
 +
 +encode_xdata_field_required(true, __TopXMLNS) ->
 +    __NewTopXMLNS = choose_top_xmlns(<<"jabber:x:data">>,
 +                                   [], __TopXMLNS),
 +    _els = [],
 +    _attrs = enc_xmlns_attrs(__NewTopXMLNS, __TopXMLNS),
 +    {xmlel, <<"required">>, _attrs, _els}.
 +
 +decode_vcard_xupdate(__TopXMLNS, __IgnoreEls,
 +                   {xmlel, <<"x">>, _attrs, _els}) ->
 +    Hash = decode_vcard_xupdate_els(__TopXMLNS, __IgnoreEls,
 +                                  _els, undefined),
 +    {vcard_xupdate, {<<>>, <<>>}, Hash}.
 +
 +decode_vcard_xupdate_els(__TopXMLNS, __IgnoreEls, [],
 +                       Hash) ->
 +    Hash;
 +decode_vcard_xupdate_els(__TopXMLNS, __IgnoreEls,
 +                       [{xmlel, <<"photo">>, _attrs, _} = _el | _els],
 +                       Hash) ->
 +    case get_attr(<<"xmlns">>, _attrs) of
 +      <<"">> when __TopXMLNS == <<"vcard-temp:x:update">> ->
 +        decode_vcard_xupdate_els(__TopXMLNS, __IgnoreEls, _els,
 +                                 decode_vcard_xupdate_photo(__TopXMLNS,
 +                                                            __IgnoreEls,
 +                                                            _el));
 +      <<"vcard-temp:x:update">> ->
 +        decode_vcard_xupdate_els(__TopXMLNS, __IgnoreEls, _els,
 +                                 decode_vcard_xupdate_photo(<<"vcard-temp:x:update">>,
 +                                                            __IgnoreEls,
 +                                                            _el));
 +      _ ->
 +        decode_vcard_xupdate_els(__TopXMLNS, __IgnoreEls, _els,
 +                                 Hash)
 +    end;
 +decode_vcard_xupdate_els(__TopXMLNS, __IgnoreEls,
 +                       [_ | _els], Hash) ->
 +    decode_vcard_xupdate_els(__TopXMLNS, __IgnoreEls, _els,
 +                           Hash).
 +
 +encode_vcard_xupdate({vcard_xupdate, _, Hash},
 +                   __TopXMLNS) ->
 +    __NewTopXMLNS =
 +      choose_top_xmlns(<<"vcard-temp:x:update">>, [],
 +                       __TopXMLNS),
 +    _els = lists:reverse('encode_vcard_xupdate_$hash'(Hash,
 +                                                    __NewTopXMLNS, [])),
 +    _attrs = enc_xmlns_attrs(__NewTopXMLNS, __TopXMLNS),
 +    {xmlel, <<"x">>, _attrs, _els}.
 +
 +'encode_vcard_xupdate_$hash'(undefined, __TopXMLNS,
 +                           _acc) ->
 +    _acc;
 +'encode_vcard_xupdate_$hash'(Hash, __TopXMLNS, _acc) ->
 +    [encode_vcard_xupdate_photo(Hash, __TopXMLNS) | _acc].
 +
 +decode_vcard_xupdate_photo(__TopXMLNS, __IgnoreEls,
 +                         {xmlel, <<"photo">>, _attrs, _els}) ->
 +    Cdata = decode_vcard_xupdate_photo_els(__TopXMLNS,
 +                                         __IgnoreEls, _els, <<>>),
 +    Cdata.
 +
 +decode_vcard_xupdate_photo_els(__TopXMLNS, __IgnoreEls,
 +                             [], Cdata) ->
 +    decode_vcard_xupdate_photo_cdata(__TopXMLNS, Cdata);
 +decode_vcard_xupdate_photo_els(__TopXMLNS, __IgnoreEls,
 +                             [{xmlcdata, _data} | _els], Cdata) ->
 +    decode_vcard_xupdate_photo_els(__TopXMLNS, __IgnoreEls,
 +                                 _els, <<Cdata/binary, _data/binary>>);
 +decode_vcard_xupdate_photo_els(__TopXMLNS, __IgnoreEls,
 +                             [_ | _els], Cdata) ->
 +    decode_vcard_xupdate_photo_els(__TopXMLNS, __IgnoreEls,
 +                                 _els, Cdata).
 +
 +encode_vcard_xupdate_photo(Cdata, __TopXMLNS) ->
 +    __NewTopXMLNS =
 +      choose_top_xmlns(<<"vcard-temp:x:update">>, [],
 +                       __TopXMLNS),
 +    _els = encode_vcard_xupdate_photo_cdata(Cdata, []),
 +    _attrs = enc_xmlns_attrs(__NewTopXMLNS, __TopXMLNS),
 +    {xmlel, <<"photo">>, _attrs, _els}.
 +
 +decode_vcard_xupdate_photo_cdata(__TopXMLNS, <<>>) ->
 +    <<>>;
 +decode_vcard_xupdate_photo_cdata(__TopXMLNS, _val) ->
 +    _val.
 +
 +encode_vcard_xupdate_photo_cdata(<<>>, _acc) -> _acc;
 +encode_vcard_xupdate_photo_cdata(_val, _acc) ->
 +    [{xmlcdata, _val} | _acc].
 +
 +decode_vcard_temp(__TopXMLNS, __IgnoreEls,
 +                {xmlel, <<"vCard">>, _attrs, _els}) ->
 +    {Mailer, Adr, Class, Categories, Desc, Uid, Prodid,
 +     Jabberid, Sound, Note, Role, Title, Nickname, Rev,
 +     Sort_string, Org, Bday, Key, Tz, Url, Email, Tel, Label,
 +     Fn, Version, N, Photo, Logo, Geo} =
 +      decode_vcard_temp_els(__TopXMLNS, __IgnoreEls, _els,
 +                            undefined, [], undefined, [], undefined,
 +                            undefined, undefined, undefined, undefined,
 +                            undefined, undefined, undefined, undefined,
 +                            undefined, undefined, undefined, undefined,
 +                            undefined, undefined, undefined, [], [], [],
 +                            undefined, undefined, undefined, undefined,
 +                            undefined, undefined),
 +    {vcard_temp, Version, Fn, N, Nickname, Photo, Bday, Adr,
 +     Label, Tel, Email, Jabberid, Mailer, Tz, Geo, Title,
 +     Role, Logo, Org, Categories, Note, Prodid, Rev,
 +     Sort_string, Sound, Uid, Url, Class, Key, Desc}.
 +
 +decode_vcard_temp_els(__TopXMLNS, __IgnoreEls, [],
 +                    Mailer, Adr, Class, Categories, Desc, Uid, Prodid,
 +                    Jabberid, Sound, Note, Role, Title, Nickname, Rev,
 +                    Sort_string, Org, Bday, Key, Tz, Url, Email, Tel, Label,
 +                    Fn, Version, N, Photo, Logo, Geo) ->
 +    {Mailer, lists:reverse(Adr), Class, Categories, Desc,
 +     Uid, Prodid, Jabberid, Sound, Note, Role, Title,
 +     Nickname, Rev, Sort_string, Org, Bday, Key, Tz, Url,
 +     lists:reverse(Email), lists:reverse(Tel),
 +     lists:reverse(Label), Fn, Version, N, Photo, Logo, Geo};
 +decode_vcard_temp_els(__TopXMLNS, __IgnoreEls,
 +                    [{xmlel, <<"N">>, _attrs, _} = _el | _els], Mailer, Adr,
 +                    Class, Categories, Desc, Uid, Prodid, Jabberid, Sound,
 +                    Note, Role, Title, Nickname, Rev, Sort_string, Org,
 +                    Bday, Key, Tz, Url, Email, Tel, Label, Fn, Version, N,
 +                    Photo, Logo, Geo) ->
 +    case get_attr(<<"xmlns">>, _attrs) of
 +      <<"">> when __TopXMLNS == <<"vcard-temp">> ->
 +        decode_vcard_temp_els(__TopXMLNS, __IgnoreEls, _els,
 +                              Mailer, Adr, Class, Categories, Desc, Uid,
 +                              Prodid, Jabberid, Sound, Note, Role, Title,
 +                              Nickname, Rev, Sort_string, Org, Bday, Key, Tz,
 +                              Url, Email, Tel, Label, Fn, Version,
 +                              decode_vcard_N(__TopXMLNS, __IgnoreEls, _el),
 +                              Photo, Logo, Geo);
 +      <<"vcard-temp">> ->
 +        decode_vcard_temp_els(__TopXMLNS, __IgnoreEls, _els,
 +                              Mailer, Adr, Class, Categories, Desc, Uid,
 +                              Prodid, Jabberid, Sound, Note, Role, Title,
 +                              Nickname, Rev, Sort_string, Org, Bday, Key, Tz,
 +                              Url, Email, Tel, Label, Fn, Version,
 +                              decode_vcard_N(<<"vcard-temp">>, __IgnoreEls,
 +                                             _el),
 +                              Photo, Logo, Geo);
 +      _ ->
 +        decode_vcard_temp_els(__TopXMLNS, __IgnoreEls, _els,
 +                              Mailer, Adr, Class, Categories, Desc, Uid,
 +                              Prodid, Jabberid, Sound, Note, Role, Title,
 +                              Nickname, Rev, Sort_string, Org, Bday, Key, Tz,
 +                              Url, Email, Tel, Label, Fn, Version, N, Photo,
 +                              Logo, Geo)
 +    end;
 +decode_vcard_temp_els(__TopXMLNS, __IgnoreEls,
 +                    [{xmlel, <<"ADR">>, _attrs, _} = _el | _els], Mailer,
 +                    Adr, Class, Categories, Desc, Uid, Prodid, Jabberid,
 +                    Sound, Note, Role, Title, Nickname, Rev, Sort_string,
 +                    Org, Bday, Key, Tz, Url, Email, Tel, Label, Fn, Version,
 +                    N, Photo, Logo, Geo) ->
 +    case get_attr(<<"xmlns">>, _attrs) of
 +      <<"">> when __TopXMLNS == <<"vcard-temp">> ->
 +        decode_vcard_temp_els(__TopXMLNS, __IgnoreEls, _els,
 +                              Mailer,
 +                              [decode_vcard_ADR(__TopXMLNS, __IgnoreEls, _el)
 +                               | Adr],
 +                              Class, Categories, Desc, Uid, Prodid, Jabberid,
 +                              Sound, Note, Role, Title, Nickname, Rev,
 +                              Sort_string, Org, Bday, Key, Tz, Url, Email,
 +                              Tel, Label, Fn, Version, N, Photo, Logo, Geo);
 +      <<"vcard-temp">> ->
 +        decode_vcard_temp_els(__TopXMLNS, __IgnoreEls, _els,
 +                              Mailer,
 +                              [decode_vcard_ADR(<<"vcard-temp">>, __IgnoreEls,
 +                                                _el)
 +                               | Adr],
 +                              Class, Categories, Desc, Uid, Prodid, Jabberid,
 +                              Sound, Note, Role, Title, Nickname, Rev,
 +                              Sort_string, Org, Bday, Key, Tz, Url, Email,
 +                              Tel, Label, Fn, Version, N, Photo, Logo, Geo);
 +      _ ->
 +        decode_vcard_temp_els(__TopXMLNS, __IgnoreEls, _els,
 +                              Mailer, Adr, Class, Categories, Desc, Uid,
 +                              Prodid, Jabberid, Sound, Note, Role, Title,
 +                              Nickname, Rev, Sort_string, Org, Bday, Key, Tz,
 +                              Url, Email, Tel, Label, Fn, Version, N, Photo,
 +                              Logo, Geo)
 +    end;
 +decode_vcard_temp_els(__TopXMLNS, __IgnoreEls,
 +                    [{xmlel, <<"LABEL">>, _attrs, _} = _el | _els], Mailer,
 +                    Adr, Class, Categories, Desc, Uid, Prodid, Jabberid,
 +                    Sound, Note, Role, Title, Nickname, Rev, Sort_string,
 +                    Org, Bday, Key, Tz, Url, Email, Tel, Label, Fn, Version,
 +                    N, Photo, Logo, Geo) ->
 +    case get_attr(<<"xmlns">>, _attrs) of
 +      <<"">> when __TopXMLNS == <<"vcard-temp">> ->
 +        decode_vcard_temp_els(__TopXMLNS, __IgnoreEls, _els,
 +                              Mailer, Adr, Class, Categories, Desc, Uid,
 +                              Prodid, Jabberid, Sound, Note, Role, Title,
 +                              Nickname, Rev, Sort_string, Org, Bday, Key, Tz,
 +                              Url, Email, Tel,
 +                              [decode_vcard_LABEL(__TopXMLNS, __IgnoreEls,
 +                                                  _el)
 +                               | Label],
 +                              Fn, Version, N, Photo, Logo, Geo);
 +      <<"vcard-temp">> ->
 +        decode_vcard_temp_els(__TopXMLNS, __IgnoreEls, _els,
 +                              Mailer, Adr, Class, Categories, Desc, Uid,
 +                              Prodid, Jabberid, Sound, Note, Role, Title,
 +                              Nickname, Rev, Sort_string, Org, Bday, Key, Tz,
 +                              Url, Email, Tel,
 +                              [decode_vcard_LABEL(<<"vcard-temp">>,
 +                                                  __IgnoreEls, _el)
 +                               | Label],
 +                              Fn, Version, N, Photo, Logo, Geo);
 +      _ ->
 +        decode_vcard_temp_els(__TopXMLNS, __IgnoreEls, _els,
 +                              Mailer, Adr, Class, Categories, Desc, Uid,
 +                              Prodid, Jabberid, Sound, Note, Role, Title,
 +                              Nickname, Rev, Sort_string, Org, Bday, Key, Tz,
 +                              Url, Email, Tel, Label, Fn, Version, N, Photo,
 +                              Logo, Geo)
 +    end;
 +decode_vcard_temp_els(__TopXMLNS, __IgnoreEls,
 +                    [{xmlel, <<"TEL">>, _attrs, _} = _el | _els], Mailer,
 +                    Adr, Class, Categories, Desc, Uid, Prodid, Jabberid,
 +                    Sound, Note, Role, Title, Nickname, Rev, Sort_string,
 +                    Org, Bday, Key, Tz, Url, Email, Tel, Label, Fn, Version,
 +                    N, Photo, Logo, Geo) ->
 +    case get_attr(<<"xmlns">>, _attrs) of
 +      <<"">> when __TopXMLNS == <<"vcard-temp">> ->
 +        decode_vcard_temp_els(__TopXMLNS, __IgnoreEls, _els,
 +                              Mailer, Adr, Class, Categories, Desc, Uid,
 +                              Prodid, Jabberid, Sound, Note, Role, Title,
 +                              Nickname, Rev, Sort_string, Org, Bday, Key, Tz,
 +                              Url, Email,
 +                              [decode_vcard_TEL(__TopXMLNS, __IgnoreEls, _el)
 +                               | Tel],
 +                              Label, Fn, Version, N, Photo, Logo, Geo);
 +      <<"vcard-temp">> ->
 +        decode_vcard_temp_els(__TopXMLNS, __IgnoreEls, _els,
 +                              Mailer, Adr, Class, Categories, Desc, Uid,
 +                              Prodid, Jabberid, Sound, Note, Role, Title,
 +                              Nickname, Rev, Sort_string, Org, Bday, Key, Tz,
 +                              Url, Email,
 +                              [decode_vcard_TEL(<<"vcard-temp">>, __IgnoreEls,
 +                                                _el)
 +                               | Tel],
 +                              Label, Fn, Version, N, Photo, Logo, Geo);
 +      _ ->
 +        decode_vcard_temp_els(__TopXMLNS, __IgnoreEls, _els,
 +                              Mailer, Adr, Class, Categories, Desc, Uid,
 +                              Prodid, Jabberid, Sound, Note, Role, Title,
 +                              Nickname, Rev, Sort_string, Org, Bday, Key, Tz,
 +                              Url, Email, Tel, Label, Fn, Version, N, Photo,
 +                              Logo, Geo)
 +    end;
 +decode_vcard_temp_els(__TopXMLNS, __IgnoreEls,
 +                    [{xmlel, <<"EMAIL">>, _attrs, _} = _el | _els], Mailer,
 +                    Adr, Class, Categories, Desc, Uid, Prodid, Jabberid,
 +                    Sound, Note, Role, Title, Nickname, Rev, Sort_string,
 +                    Org, Bday, Key, Tz, Url, Email, Tel, Label, Fn, Version,
 +                    N, Photo, Logo, Geo) ->
 +    case get_attr(<<"xmlns">>, _attrs) of
 +      <<"">> when __TopXMLNS == <<"vcard-temp">> ->
 +        decode_vcard_temp_els(__TopXMLNS, __IgnoreEls, _els,
 +                              Mailer, Adr, Class, Categories, Desc, Uid,
 +                              Prodid, Jabberid, Sound, Note, Role, Title,
 +                              Nickname, Rev, Sort_string, Org, Bday, Key, Tz,
 +                              Url,
 +                              [decode_vcard_EMAIL(__TopXMLNS, __IgnoreEls,
 +                                                  _el)
 +                               | Email],
 +                              Tel, Label, Fn, Version, N, Photo, Logo, Geo);
 +      <<"vcard-temp">> ->
 +        decode_vcard_temp_els(__TopXMLNS, __IgnoreEls, _els,
 +                              Mailer, Adr, Class, Categories, Desc, Uid,
 +                              Prodid, Jabberid, Sound, Note, Role, Title,
 +                              Nickname, Rev, Sort_string, Org, Bday, Key, Tz,
 +                              Url,
 +                              [decode_vcard_EMAIL(<<"vcard-temp">>,
 +                                                  __IgnoreEls, _el)
 +                               | Email],
 +                              Tel, Label, Fn, Version, N, Photo, Logo, Geo);
 +      _ ->
 +        decode_vcard_temp_els(__TopXMLNS, __IgnoreEls, _els,
 +                              Mailer, Adr, Class, Categories, Desc, Uid,
 +                              Prodid, Jabberid, Sound, Note, Role, Title,
 +                              Nickname, Rev, Sort_string, Org, Bday, Key, Tz,
 +                              Url, Email, Tel, Label, Fn, Version, N, Photo,
 +                              Logo, Geo)
 +    end;
 +decode_vcard_temp_els(__TopXMLNS, __IgnoreEls,
 +                    [{xmlel, <<"GEO">>, _attrs, _} = _el | _els], Mailer,
 +                    Adr, Class, Categories, Desc, Uid, Prodid, Jabberid,
 +                    Sound, Note, Role, Title, Nickname, Rev, Sort_string,
 +                    Org, Bday, Key, Tz, Url, Email, Tel, Label, Fn, Version,
 +                    N, Photo, Logo, Geo) ->
 +    case get_attr(<<"xmlns">>, _attrs) of
 +      <<"">> when __TopXMLNS == <<"vcard-temp">> ->
 +        decode_vcard_temp_els(__TopXMLNS, __IgnoreEls, _els,
 +                              Mailer, Adr, Class, Categories, Desc, Uid,
 +                              Prodid, Jabberid, Sound, Note, Role, Title,
 +                              Nickname, Rev, Sort_string, Org, Bday, Key, Tz,
 +                              Url, Email, Tel, Label, Fn, Version, N, Photo,
 +                              Logo,
 +                              decode_vcard_GEO(__TopXMLNS, __IgnoreEls, _el));
 +      <<"vcard-temp">> ->
 +        decode_vcard_temp_els(__TopXMLNS, __IgnoreEls, _els,
 +                              Mailer, Adr, Class, Categories, Desc, Uid,
 +                              Prodid, Jabberid, Sound, Note, Role, Title,
 +                              Nickname, Rev, Sort_string, Org, Bday, Key, Tz,
 +                              Url, Email, Tel, Label, Fn, Version, N, Photo,
 +                              Logo,
 +                              decode_vcard_GEO(<<"vcard-temp">>, __IgnoreEls,
 +                                               _el));
 +      _ ->
 +        decode_vcard_temp_els(__TopXMLNS, __IgnoreEls, _els,
 +                              Mailer, Adr, Class, Categories, Desc, Uid,
 +                              Prodid, Jabberid, Sound, Note, Role, Title,
 +                              Nickname, Rev, Sort_string, Org, Bday, Key, Tz,
 +                              Url, Email, Tel, Label, Fn, Version, N, Photo,
 +                              Logo, Geo)
 +    end;
 +decode_vcard_temp_els(__TopXMLNS, __IgnoreEls,
 +                    [{xmlel, <<"LOGO">>, _attrs, _} = _el | _els], Mailer,
 +                    Adr, Class, Categories, Desc, Uid, Prodid, Jabberid,
 +                    Sound, Note, Role, Title, Nickname, Rev, Sort_string,
 +                    Org, Bday, Key, Tz, Url, Email, Tel, Label, Fn, Version,
 +                    N, Photo, Logo, Geo) ->
 +    case get_attr(<<"xmlns">>, _attrs) of
 +      <<"">> when __TopXMLNS == <<"vcard-temp">> ->
 +        decode_vcard_temp_els(__TopXMLNS, __IgnoreEls, _els,
 +                              Mailer, Adr, Class, Categories, Desc, Uid,
 +                              Prodid, Jabberid, Sound, Note, Role, Title,
 +                              Nickname, Rev, Sort_string, Org, Bday, Key, Tz,
 +                              Url, Email, Tel, Label, Fn, Version, N, Photo,
 +                              decode_vcard_LOGO(__TopXMLNS, __IgnoreEls, _el),
 +                              Geo);
 +      <<"vcard-temp">> ->
 +        decode_vcard_temp_els(__TopXMLNS, __IgnoreEls, _els,
 +                              Mailer, Adr, Class, Categories, Desc, Uid,
 +                              Prodid, Jabberid, Sound, Note, Role, Title,
 +                              Nickname, Rev, Sort_string, Org, Bday, Key, Tz,
 +                              Url, Email, Tel, Label, Fn, Version, N, Photo,
 +                              decode_vcard_LOGO(<<"vcard-temp">>, __IgnoreEls,
 +                                                _el),
 +                              Geo);
 +      _ ->
 +        decode_vcard_temp_els(__TopXMLNS, __IgnoreEls, _els,
 +                              Mailer, Adr, Class, Categories, Desc, Uid,
 +                              Prodid, Jabberid, Sound, Note, Role, Title,
 +                              Nickname, Rev, Sort_string, Org, Bday, Key, Tz,
 +                              Url, Email, Tel, Label, Fn, Version, N, Photo,
 +                              Logo, Geo)
 +    end;
 +decode_vcard_temp_els(__TopXMLNS, __IgnoreEls,
 +                    [{xmlel, <<"PHOTO">>, _attrs, _} = _el | _els], Mailer,
 +                    Adr, Class, Categories, Desc, Uid, Prodid, Jabberid,
 +                    Sound, Note, Role, Title, Nickname, Rev, Sort_string,
 +                    Org, Bday, Key, Tz, Url, Email, Tel, Label, Fn, Version,
 +                    N, Photo, Logo, Geo) ->
 +    case get_attr(<<"xmlns">>, _attrs) of
 +      <<"">> when __TopXMLNS == <<"vcard-temp">> ->
 +        decode_vcard_temp_els(__TopXMLNS, __IgnoreEls, _els,
 +                              Mailer, Adr, Class, Categories, Desc, Uid,
 +                              Prodid, Jabberid, Sound, Note, Role, Title,
 +                              Nickname, Rev, Sort_string, Org, Bday, Key, Tz,
 +                              Url, Email, Tel, Label, Fn, Version, N,
 +                              decode_vcard_PHOTO(__TopXMLNS, __IgnoreEls,
 +                                                 _el),
 +                              Logo, Geo);
 +      <<"vcard-temp">> ->
 +        decode_vcard_temp_els(__TopXMLNS, __IgnoreEls, _els,
 +                              Mailer, Adr, Class, Categories, Desc, Uid,
 +                              Prodid, Jabberid, Sound, Note, Role, Title,
 +                              Nickname, Rev, Sort_string, Org, Bday, Key, Tz,
 +                              Url, Email, Tel, Label, Fn, Version, N,
 +                              decode_vcard_PHOTO(<<"vcard-temp">>,
 +                                                 __IgnoreEls, _el),
 +                              Logo, Geo);
 +      _ ->
 +        decode_vcard_temp_els(__TopXMLNS, __IgnoreEls, _els,
 +                              Mailer, Adr, Class, Categories, Desc, Uid,
 +                              Prodid, Jabberid, Sound, Note, Role, Title,
 +                              Nickname, Rev, Sort_string, Org, Bday, Key, Tz,
 +                              Url, Email, Tel, Label, Fn, Version, N, Photo,
 +                              Logo, Geo)
 +    end;
 +decode_vcard_temp_els(__TopXMLNS, __IgnoreEls,
 +                    [{xmlel, <<"ORG">>, _attrs, _} = _el | _els], Mailer,
 +                    Adr, Class, Categories, Desc, Uid, Prodid, Jabberid,
 +                    Sound, Note, Role, Title, Nickname, Rev, Sort_string,
 +                    Org, Bday, Key, Tz, Url, Email, Tel, Label, Fn, Version,
 +                    N, Photo, Logo, Geo) ->
 +    case get_attr(<<"xmlns">>, _attrs) of
 +      <<"">> when __TopXMLNS == <<"vcard-temp">> ->
 +        decode_vcard_temp_els(__TopXMLNS, __IgnoreEls, _els,
 +                              Mailer, Adr, Class, Categories, Desc, Uid,
 +                              Prodid, Jabberid, Sound, Note, Role, Title,
 +                              Nickname, Rev, Sort_string,
 +                              decode_vcard_ORG(__TopXMLNS, __IgnoreEls, _el),
 +                              Bday, Key, Tz, Url, Email, Tel, Label, Fn,
 +                              Version, N, Photo, Logo, Geo);
 +      <<"vcard-temp">> ->
 +        decode_vcard_temp_els(__TopXMLNS, __IgnoreEls, _els,
 +                              Mailer, Adr, Class, Categories, Desc, Uid,
 +                              Prodid, Jabberid, Sound, Note, Role, Title,
 +                              Nickname, Rev, Sort_string,
 +                              decode_vcard_ORG(<<"vcard-temp">>, __IgnoreEls,
 +                                               _el),
 +                              Bday, Key, Tz, Url, Email, Tel, Label, Fn,
 +                              Version, N, Photo, Logo, Geo);
 +      _ ->
 +        decode_vcard_temp_els(__TopXMLNS, __IgnoreEls, _els,
 +                              Mailer, Adr, Class, Categories, Desc, Uid,
 +                              Prodid, Jabberid, Sound, Note, Role, Title,
 +                              Nickname, Rev, Sort_string, Org, Bday, Key, Tz,
 +                              Url, Email, Tel, Label, Fn, Version, N, Photo,
 +                              Logo, Geo)
 +    end;
 +decode_vcard_temp_els(__TopXMLNS, __IgnoreEls,
 +                    [{xmlel, <<"SOUND">>, _attrs, _} = _el | _els], Mailer,
 +                    Adr, Class, Categories, Desc, Uid, Prodid, Jabberid,
 +                    Sound, Note, Role, Title, Nickname, Rev, Sort_string,
 +                    Org, Bday, Key, Tz, Url, Email, Tel, Label, Fn, Version,
 +                    N, Photo, Logo, Geo) ->
 +    case get_attr(<<"xmlns">>, _attrs) of
 +      <<"">> when __TopXMLNS == <<"vcard-temp">> ->
 +        decode_vcard_temp_els(__TopXMLNS, __IgnoreEls, _els,
 +                              Mailer, Adr, Class, Categories, Desc, Uid,
 +                              Prodid, Jabberid,
 +                              decode_vcard_SOUND(__TopXMLNS, __IgnoreEls,
 +                                                 _el),
 +                              Note, Role, Title, Nickname, Rev, Sort_string,
 +                              Org, Bday, Key, Tz, Url, Email, Tel, Label, Fn,
 +                              Version, N, Photo, Logo, Geo);
 +      <<"vcard-temp">> ->
 +        decode_vcard_temp_els(__TopXMLNS, __IgnoreEls, _els,
 +                              Mailer, Adr, Class, Categories, Desc, Uid,
 +                              Prodid, Jabberid,
 +                              decode_vcard_SOUND(<<"vcard-temp">>,
 +                                                 __IgnoreEls, _el),
 +                              Note, Role, Title, Nickname, Rev, Sort_string,
 +                              Org, Bday, Key, Tz, Url, Email, Tel, Label, Fn,
 +                              Version, N, Photo, Logo, Geo);
 +      _ ->
 +        decode_vcard_temp_els(__TopXMLNS, __IgnoreEls, _els,
 +                              Mailer, Adr, Class, Categories, Desc, Uid,
 +                              Prodid, Jabberid, Sound, Note, Role, Title,
 +                              Nickname, Rev, Sort_string, Org, Bday, Key, Tz,
 +                              Url, Email, Tel, Label, Fn, Version, N, Photo,
 +                              Logo, Geo)
 +    end;
 +decode_vcard_temp_els(__TopXMLNS, __IgnoreEls,
 +                    [{xmlel, <<"KEY">>, _attrs, _} = _el | _els], Mailer,
 +                    Adr, Class, Categories, Desc, Uid, Prodid, Jabberid,
 +                    Sound, Note, Role, Title, Nickname, Rev, Sort_string,
 +                    Org, Bday, Key, Tz, Url, Email, Tel, Label, Fn, Version,
 +                    N, Photo, Logo, Geo) ->
 +    case get_attr(<<"xmlns">>, _attrs) of
 +      <<"">> when __TopXMLNS == <<"vcard-temp">> ->
 +        decode_vcard_temp_els(__TopXMLNS, __IgnoreEls, _els,
 +                              Mailer, Adr, Class, Categories, Desc, Uid,
 +                              Prodid, Jabberid, Sound, Note, Role, Title,
 +                              Nickname, Rev, Sort_string, Org, Bday,
 +                              decode_vcard_KEY(__TopXMLNS, __IgnoreEls, _el),
 +                              Tz, Url, Email, Tel, Label, Fn, Version, N,
 +                              Photo, Logo, Geo);
 +      <<"vcard-temp">> ->
 +        decode_vcard_temp_els(__TopXMLNS, __IgnoreEls, _els,
 +                              Mailer, Adr, Class, Categories, Desc, Uid,
 +                              Prodid, Jabberid, Sound, Note, Role, Title,
 +                              Nickname, Rev, Sort_string, Org, Bday,
 +                              decode_vcard_KEY(<<"vcard-temp">>, __IgnoreEls,
 +                                               _el),
 +                              Tz, Url, Email, Tel, Label, Fn, Version, N,
 +                              Photo, Logo, Geo);
 +      _ ->
 +        decode_vcard_temp_els(__TopXMLNS, __IgnoreEls, _els,
 +                              Mailer, Adr, Class, Categories, Desc, Uid,
 +                              Prodid, Jabberid, Sound, Note, Role, Title,
 +                              Nickname, Rev, Sort_string, Org, Bday, Key, Tz,
 +                              Url, Email, Tel, Label, Fn, Version, N, Photo,
 +                              Logo, Geo)
 +    end;
 +decode_vcard_temp_els(__TopXMLNS, __IgnoreEls,
 +                    [{xmlel, <<"VERSION">>, _attrs, _} = _el | _els],
 +                    Mailer, Adr, Class, Categories, Desc, Uid, Prodid,
 +                    Jabberid, Sound, Note, Role, Title, Nickname, Rev,
 +                    Sort_string, Org, Bday, Key, Tz, Url, Email, Tel, Label,
 +                    Fn, Version, N, Photo, Logo, Geo) ->
 +    case get_attr(<<"xmlns">>, _attrs) of
 +      <<"">> when __TopXMLNS == <<"vcard-temp">> ->
 +        decode_vcard_temp_els(__TopXMLNS, __IgnoreEls, _els,
 +                              Mailer, Adr, Class, Categories, Desc, Uid,
 +                              Prodid, Jabberid, Sound, Note, Role, Title,
 +                              Nickname, Rev, Sort_string, Org, Bday, Key, Tz,
 +                              Url, Email, Tel, Label, Fn,
 +                              decode_vcard_VERSION(__TopXMLNS, __IgnoreEls,
 +                                                   _el),
 +                              N, Photo, Logo, Geo);
 +      <<"vcard-temp">> ->
 +        decode_vcard_temp_els(__TopXMLNS, __IgnoreEls, _els,
 +                              Mailer, Adr, Class, Categories, Desc, Uid,
 +                              Prodid, Jabberid, Sound, Note, Role, Title,
 +                              Nickname, Rev, Sort_string, Org, Bday, Key, Tz,
 +                              Url, Email, Tel, Label, Fn,
 +                              decode_vcard_VERSION(<<"vcard-temp">>,
 +                                                   __IgnoreEls, _el),
 +                              N, Photo, Logo, Geo);
 +      _ ->
 +        decode_vcard_temp_els(__TopXMLNS, __IgnoreEls, _els,
 +                              Mailer, Adr, Class, Categories, Desc, Uid,
 +                              Prodid, Jabberid, Sound, Note, Role, Title,
 +                              Nickname, Rev, Sort_string, Org, Bday, Key, Tz,
 +                              Url, Email, Tel, Label, Fn, Version, N, Photo,
 +                              Logo, Geo)
 +    end;
 +decode_vcard_temp_els(__TopXMLNS, __IgnoreEls,
 +                    [{xmlel, <<"FN">>, _attrs, _} = _el | _els], Mailer,
 +                    Adr, Class, Categories, Desc, Uid, Prodid, Jabberid,
 +                    Sound, Note, Role, Title, Nickname, Rev, Sort_string,
 +                    Org, Bday, Key, Tz, Url, Email, Tel, Label, Fn, Version,
 +                    N, Photo, Logo, Geo) ->
 +    case get_attr(<<"xmlns">>, _attrs) of
 +      <<"">> when __TopXMLNS == <<"vcard-temp">> ->
 +        decode_vcard_temp_els(__TopXMLNS, __IgnoreEls, _els,
 +                              Mailer, Adr, Class, Categories, Desc, Uid,
 +                              Prodid, Jabberid, Sound, Note, Role, Title,
 +                              Nickname, Rev, Sort_string, Org, Bday, Key, Tz,
 +                              Url, Email, Tel, Label,
 +                              decode_vcard_FN(__TopXMLNS, __IgnoreEls, _el),
 +                              Version, N, Photo, Logo, Geo);
 +      <<"vcard-temp">> ->
 +        decode_vcard_temp_els(__TopXMLNS, __IgnoreEls, _els,
 +                              Mailer, Adr, Class, Categories, Desc, Uid,
 +                              Prodid, Jabberid, Sound, Note, Role, Title,
 +                              Nickname, Rev, Sort_string, Org, Bday, Key, Tz,
 +                              Url, Email, Tel, Label,
 +                              decode_vcard_FN(<<"vcard-temp">>, __IgnoreEls,
 +                                              _el),
 +                              Version, N, Photo, Logo, Geo);
 +      _ ->
 +        decode_vcard_temp_els(__TopXMLNS, __IgnoreEls, _els,
 +                              Mailer, Adr, Class, Categories, Desc, Uid,
 +                              Prodid, Jabberid, Sound, Note, Role, Title,
 +                              Nickname, Rev, Sort_string, Org, Bday, Key, Tz,
 +                              Url, Email, Tel, Label, Fn, Version, N, Photo,
 +                              Logo, Geo)
 +    end;
 +decode_vcard_temp_els(__TopXMLNS, __IgnoreEls,
 +                    [{xmlel, <<"NICKNAME">>, _attrs, _} = _el | _els],
 +                    Mailer, Adr, Class, Categories, Desc, Uid, Prodid,
 +                    Jabberid, Sound, Note, Role, Title, Nickname, Rev,
 +                    Sort_string, Org, Bday, Key, Tz, Url, Email, Tel, Label,
 +                    Fn, Version, N, Photo, Logo, Geo) ->
 +    case get_attr(<<"xmlns">>, _attrs) of
 +      <<"">> when __TopXMLNS == <<"vcard-temp">> ->
 +        decode_vcard_temp_els(__TopXMLNS, __IgnoreEls, _els,
 +                              Mailer, Adr, Class, Categories, Desc, Uid,
 +                              Prodid, Jabberid, Sound, Note, Role, Title,
 +                              decode_vcard_NICKNAME(__TopXMLNS, __IgnoreEls,
 +                                                    _el),
 +                              Rev, Sort_string, Org, Bday, Key, Tz, Url,
 +                              Email, Tel, Label, Fn, Version, N, Photo, Logo,
 +                              Geo);
 +      <<"vcard-temp">> ->
 +        decode_vcard_temp_els(__TopXMLNS, __IgnoreEls, _els,
 +                              Mailer, Adr, Class, Categories, Desc, Uid,
 +                              Prodid, Jabberid, Sound, Note, Role, Title,
 +                              decode_vcard_NICKNAME(<<"vcard-temp">>,
 +                                                    __IgnoreEls, _el),
 +                              Rev, Sort_string, Org, Bday, Key, Tz, Url,
 +                              Email, Tel, Label, Fn, Version, N, Photo, Logo,
 +                              Geo);
 +      _ ->
 +        decode_vcard_temp_els(__TopXMLNS, __IgnoreEls, _els,
 +                              Mailer, Adr, Class, Categories, Desc, Uid,
 +                              Prodid, Jabberid, Sound, Note, Role, Title,
 +                              Nickname, Rev, Sort_string, Org, Bday, Key, Tz,
 +                              Url, Email, Tel, Label, Fn, Version, N, Photo,
 +                              Logo, Geo)
 +    end;
 +decode_vcard_temp_els(__TopXMLNS, __IgnoreEls,
 +                    [{xmlel, <<"BDAY">>, _attrs, _} = _el | _els], Mailer,
 +                    Adr, Class, Categories, Desc, Uid, Prodid, Jabberid,
 +                    Sound, Note, Role, Title, Nickname, Rev, Sort_string,
 +                    Org, Bday, Key, Tz, Url, Email, Tel, Label, Fn, Version,
 +                    N, Photo, Logo, Geo) ->
 +    case get_attr(<<"xmlns">>, _attrs) of
 +      <<"">> when __TopXMLNS == <<"vcard-temp">> ->
 +        decode_vcard_temp_els(__TopXMLNS, __IgnoreEls, _els,
 +                              Mailer, Adr, Class, Categories, Desc, Uid,
 +                              Prodid, Jabberid, Sound, Note, Role, Title,
 +                              Nickname, Rev, Sort_string, Org,
 +                              decode_vcard_BDAY(__TopXMLNS, __IgnoreEls, _el),
 +                              Key, Tz, Url, Email, Tel, Label, Fn, Version, N,
 +                              Photo, Logo, Geo);
 +      <<"vcard-temp">> ->
 +        decode_vcard_temp_els(__TopXMLNS, __IgnoreEls, _els,
 +                              Mailer, Adr, Class, Categories, Desc, Uid,
 +                              Prodid, Jabberid, Sound, Note, Role, Title,
 +                              Nickname, Rev, Sort_string, Org,
 +                              decode_vcard_BDAY(<<"vcard-temp">>, __IgnoreEls,
 +                                                _el),
 +                              Key, Tz, Url, Email, Tel, Label, Fn, Version, N,
 +                              Photo, Logo, Geo);
 +      _ ->
 +        decode_vcard_temp_els(__TopXMLNS, __IgnoreEls, _els,
 +                              Mailer, Adr, Class, Categories, Desc, Uid,
 +                              Prodid, Jabberid, Sound, Note, Role, Title,
 +                              Nickname, Rev, Sort_string, Org, Bday, Key, Tz,
 +                              Url, Email, Tel, Label, Fn, Version, N, Photo,
 +                              Logo, Geo)
 +    end;
 +decode_vcard_temp_els(__TopXMLNS, __IgnoreEls,
 +                    [{xmlel, <<"JABBERID">>, _attrs, _} = _el | _els],
 +                    Mailer, Adr, Class, Categories, Desc, Uid, Prodid,
 +                    Jabberid, Sound, Note, Role, Title, Nickname, Rev,
 +                    Sort_string, Org, Bday, Key, Tz, Url, Email, Tel, Label,
 +                    Fn, Version, N, Photo, Logo, Geo) ->
 +    case get_attr(<<"xmlns">>, _attrs) of
 +      <<"">> when __TopXMLNS == <<"vcard-temp">> ->
 +        decode_vcard_temp_els(__TopXMLNS, __IgnoreEls, _els,
 +                              Mailer, Adr, Class, Categories, Desc, Uid,
 +                              Prodid,
 +                              decode_vcard_JABBERID(__TopXMLNS, __IgnoreEls,
 +                                                    _el),
 +                              Sound, Note, Role, Title, Nickname, Rev,
 +                              Sort_string, Org, Bday, Key, Tz, Url, Email,
 +                              Tel, Label, Fn, Version, N, Photo, Logo, Geo);
 +      <<"vcard-temp">> ->
 +        decode_vcard_temp_els(__TopXMLNS, __IgnoreEls, _els,
 +                              Mailer, Adr, Class, Categories, Desc, Uid,
 +                              Prodid,
 +                              decode_vcard_JABBERID(<<"vcard-temp">>,
 +                                                    __IgnoreEls, _el),
 +                              Sound, Note, Role, Title, Nickname, Rev,
 +                              Sort_string, Org, Bday, Key, Tz, Url, Email,
 +                              Tel, Label, Fn, Version, N, Photo, Logo, Geo);
 +      _ ->
 +        decode_vcard_temp_els(__TopXMLNS, __IgnoreEls, _els,
 +                              Mailer, Adr, Class, Categories, Desc, Uid,
 +                              Prodid, Jabberid, Sound, Note, Role, Title,
 +                              Nickname, Rev, Sort_string, Org, Bday, Key, Tz,
 +                              Url, Email, Tel, Label, Fn, Version, N, Photo,
 +                              Logo, Geo)
 +    end;
 +decode_vcard_temp_els(__TopXMLNS, __IgnoreEls,
 +                    [{xmlel, <<"MAILER">>, _attrs, _} = _el | _els], Mailer,
 +                    Adr, Class, Categories, Desc, Uid, Prodid, Jabberid,
 +                    Sound, Note, Role, Title, Nickname, Rev, Sort_string,
 +                    Org, Bday, Key, Tz, Url, Email, Tel, Label, Fn, Version,
 +                    N, Photo, Logo, Geo) ->
 +    case get_attr(<<"xmlns">>, _attrs) of
 +      <<"">> when __TopXMLNS == <<"vcard-temp">> ->
 +        decode_vcard_temp_els(__TopXMLNS, __IgnoreEls, _els,
 +                              decode_vcard_MAILER(__TopXMLNS, __IgnoreEls,
 +                                                  _el),
 +                              Adr, Class, Categories, Desc, Uid, Prodid,
 +                              Jabberid, Sound, Note, Role, Title, Nickname,
 +                              Rev, Sort_string, Org, Bday, Key, Tz, Url,
 +                              Email, Tel, Label, Fn, Version, N, Photo, Logo,
 +                              Geo);
 +      <<"vcard-temp">> ->
 +        decode_vcard_temp_els(__TopXMLNS, __IgnoreEls, _els,
 +                              decode_vcard_MAILER(<<"vcard-temp">>,
 +                                                  __IgnoreEls, _el),
 +                              Adr, Class, Categories, Desc, Uid, Prodid,
 +                              Jabberid, Sound, Note, Role, Title, Nickname,
 +                              Rev, Sort_string, Org, Bday, Key, Tz, Url,
 +                              Email, Tel, Label, Fn, Version, N, Photo, Logo,
 +                              Geo);
 +      _ ->
 +        decode_vcard_temp_els(__TopXMLNS, __IgnoreEls, _els,
 +                              Mailer, Adr, Class, Categories, Desc, Uid,
 +                              Prodid, Jabberid, Sound, Note, Role, Title,
 +                              Nickname, Rev, Sort_string, Org, Bday, Key, Tz,
 +                              Url, Email, Tel, Label, Fn, Version, N, Photo,
 +                              Logo, Geo)
 +    end;
 +decode_vcard_temp_els(__TopXMLNS, __IgnoreEls,
 +                    [{xmlel, <<"TZ">>, _attrs, _} = _el | _els], Mailer,
 +                    Adr, Class, Categories, Desc, Uid, Prodid, Jabberid,
 +                    Sound, Note, Role, Title, Nickname, Rev, Sort_string,
 +                    Org, Bday, Key, Tz, Url, Email, Tel, Label, Fn, Version,
 +                    N, Photo, Logo, Geo) ->
 +    case get_attr(<<"xmlns">>, _attrs) of
 +      <<"">> when __TopXMLNS == <<"vcard-temp">> ->
 +        decode_vcard_temp_els(__TopXMLNS, __IgnoreEls, _els,
 +                              Mailer, Adr, Class, Categories, Desc, Uid,
 +                              Prodid, Jabberid, Sound, Note, Role, Title,
 +                              Nickname, Rev, Sort_string, Org, Bday, Key,
 +                              decode_vcard_TZ(__TopXMLNS, __IgnoreEls, _el),
 +                              Url, Email, Tel, Label, Fn, Version, N, Photo,
 +                              Logo, Geo);
 +      <<"vcard-temp">> ->
 +        decode_vcard_temp_els(__TopXMLNS, __IgnoreEls, _els,
 +                              Mailer, Adr, Class, Categories, Desc, Uid,
 +                              Prodid, Jabberid, Sound, Note, Role, Title,
 +                              Nickname, Rev, Sort_string, Org, Bday, Key,
 +                              decode_vcard_TZ(<<"vcard-temp">>, __IgnoreEls,
 +                                              _el),
 +                              Url, Email, Tel, Label, Fn, Version, N, Photo,
 +                              Logo, Geo);
 +      _ ->
 +        decode_vcard_temp_els(__TopXMLNS, __IgnoreEls, _els,
 +                              Mailer, Adr, Class, Categories, Desc, Uid,
 +                              Prodid, Jabberid, Sound, Note, Role, Title,
 +                              Nickname, Rev, Sort_string, Org, Bday, Key, Tz,
 +                              Url, Email, Tel, Label, Fn, Version, N, Photo,
 +                              Logo, Geo)
 +    end;
 +decode_vcard_temp_els(__TopXMLNS, __IgnoreEls,
 +                    [{xmlel, <<"TITLE">>, _attrs, _} = _el | _els], Mailer,
 +                    Adr, Class, Categories, Desc, Uid, Prodid, Jabberid,
 +                    Sound, Note, Role, Title, Nickname, Rev, Sort_string,
 +                    Org, Bday, Key, Tz, Url, Email, Tel, Label, Fn, Version,
 +                    N, Photo, Logo, Geo) ->
 +    case get_attr(<<"xmlns">>, _attrs) of
 +      <<"">> when __TopXMLNS == <<"vcard-temp">> ->
 +        decode_vcard_temp_els(__TopXMLNS, __IgnoreEls, _els,
 +                              Mailer, Adr, Class, Categories, Desc, Uid,
 +                              Prodid, Jabberid, Sound, Note, Role,
 +                              decode_vcard_TITLE(__TopXMLNS, __IgnoreEls,
 +                                                 _el),
 +                              Nickname, Rev, Sort_string, Org, Bday, Key, Tz,
 +                              Url, Email, Tel, Label, Fn, Version, N, Photo,
 +                              Logo, Geo);
 +      <<"vcard-temp">> ->
 +        decode_vcard_temp_els(__TopXMLNS, __IgnoreEls, _els,
 +                              Mailer, Adr, Class, Categories, Desc, Uid,
 +                              Prodid, Jabberid, Sound, Note, Role,
 +                              decode_vcard_TITLE(<<"vcard-temp">>,
 +                                                 __IgnoreEls, _el),
 +                              Nickname, Rev, Sort_string, Org, Bday, Key, Tz,
 +                              Url, Email, Tel, Label, Fn, Version, N, Photo,
 +                              Logo, Geo);
 +      _ ->
 +        decode_vcard_temp_els(__TopXMLNS, __IgnoreEls, _els,
 +                              Mailer, Adr, Class, Categories, Desc, Uid,
 +                              Prodid, Jabberid, Sound, Note, Role, Title,
 +                              Nickname, Rev, Sort_string, Org, Bday, Key, Tz,
 +                              Url, Email, Tel, Label, Fn, Version, N, Photo,
 +                              Logo, Geo)
 +    end;
 +decode_vcard_temp_els(__TopXMLNS, __IgnoreEls,
 +                    [{xmlel, <<"ROLE">>, _attrs, _} = _el | _els], Mailer,
 +                    Adr, Class, Categories, Desc, Uid, Prodid, Jabberid,
 +                    Sound, Note, Role, Title, Nickname, Rev, Sort_string,
 +                    Org, Bday, Key, Tz, Url, Email, Tel, Label, Fn, Version,
 +                    N, Photo, Logo, Geo) ->
 +    case get_attr(<<"xmlns">>, _attrs) of
 +      <<"">> when __TopXMLNS == <<"vcard-temp">> ->
 +        decode_vcard_temp_els(__TopXMLNS, __IgnoreEls, _els,
 +                              Mailer, Adr, Class, Categories, Desc, Uid,
 +                              Prodid, Jabberid, Sound, Note,
 +                              decode_vcard_ROLE(__TopXMLNS, __IgnoreEls, _el),
 +                              Title, Nickname, Rev, Sort_string, Org, Bday,
 +                              Key, Tz, Url, Email, Tel, Label, Fn, Version, N,
 +                              Photo, Logo, Geo);
 +      <<"vcard-temp">> ->
 +        decode_vcard_temp_els(__TopXMLNS, __IgnoreEls, _els,
 +                              Mailer, Adr, Class, Categories, Desc, Uid,
 +                              Prodid, Jabberid, Sound, Note,
 +                              decode_vcard_ROLE(<<"vcard-temp">>, __IgnoreEls,
 +                                                _el),
 +                              Title, Nickname, Rev, Sort_string, Org, Bday,
 +                              Key, Tz, Url, Email, Tel, Label, Fn, Version, N,
 +                              Photo, Logo, Geo);
 +      _ ->
 +        decode_vcard_temp_els(__TopXMLNS, __IgnoreEls, _els,
 +                              Mailer, Adr, Class, Categories, Desc, Uid,
 +                              Prodid, Jabberid, Sound, Note, Role, Title,
 +                              Nickname, Rev, Sort_string, Org, Bday, Key, Tz,
 +                              Url, Email, Tel, Label, Fn, Version, N, Photo,
 +                              Logo, Geo)
 +    end;
 +decode_vcard_temp_els(__TopXMLNS, __IgnoreEls,
 +                    [{xmlel, <<"NOTE">>, _attrs, _} = _el | _els], Mailer,
 +                    Adr, Class, Categories, Desc, Uid, Prodid, Jabberid,
 +                    Sound, Note, Role, Title, Nickname, Rev, Sort_string,
 +                    Org, Bday, Key, Tz, Url, Email, Tel, Label, Fn, Version,
 +                    N, Photo, Logo, Geo) ->
 +    case get_attr(<<"xmlns">>, _attrs) of
 +      <<"">> when __TopXMLNS == <<"vcard-temp">> ->
 +        decode_vcard_temp_els(__TopXMLNS, __IgnoreEls, _els,
 +                              Mailer, Adr, Class, Categories, Desc, Uid,
 +                              Prodid, Jabberid, Sound,
 +                              decode_vcard_NOTE(__TopXMLNS, __IgnoreEls, _el),
 +                              Role, Title, Nickname, Rev, Sort_string, Org,
 +                              Bday, Key, Tz, Url, Email, Tel, Label, Fn,
 +                              Version, N, Photo, Logo, Geo);
 +      <<"vcard-temp">> ->
 +        decode_vcard_temp_els(__TopXMLNS, __IgnoreEls, _els,
 +                              Mailer, Adr, Class, Categories, Desc, Uid,
 +                              Prodid, Jabberid, Sound,
 +                              decode_vcard_NOTE(<<"vcard-temp">>, __IgnoreEls,
 +                                                _el),
 +                              Role, Title, Nickname, Rev, Sort_string, Org,
 +                              Bday, Key, Tz, Url, Email, Tel, Label, Fn,
 +                              Version, N, Photo, Logo, Geo);
 +      _ ->
 +        decode_vcard_temp_els(__TopXMLNS, __IgnoreEls, _els,
 +                              Mailer, Adr, Class, Categories, Desc, Uid,
 +                              Prodid, Jabberid, Sound, Note, Role, Title,
 +                              Nickname, Rev, Sort_string, Org, Bday, Key, Tz,
 +                              Url, Email, Tel, Label, Fn, Version, N, Photo,
 +                              Logo, Geo)
 +    end;
 +decode_vcard_temp_els(__TopXMLNS, __IgnoreEls,
 +                    [{xmlel, <<"PRODID">>, _attrs, _} = _el | _els], Mailer,
 +                    Adr, Class, Categories, Desc, Uid, Prodid, Jabberid,
 +                    Sound, Note, Role, Title, Nickname, Rev, Sort_string,
 +                    Org, Bday, Key, Tz, Url, Email, Tel, Label, Fn, Version,
 +                    N, Photo, Logo, Geo) ->
 +    case get_attr(<<"xmlns">>, _attrs) of
 +      <<"">> when __TopXMLNS == <<"vcard-temp">> ->
 +        decode_vcard_temp_els(__TopXMLNS, __IgnoreEls, _els,
 +                              Mailer, Adr, Class, Categories, Desc, Uid,
 +                              decode_vcard_PRODID(__TopXMLNS, __IgnoreEls,
 +                                                  _el),
 +                              Jabberid, Sound, Note, Role, Title, Nickname,
 +                              Rev, Sort_string, Org, Bday, Key, Tz, Url,
 +                              Email, Tel, Label, Fn, Version, N, Photo, Logo,
 +                              Geo);
 +      <<"vcard-temp">> ->
 +        decode_vcard_temp_els(__TopXMLNS, __IgnoreEls, _els,
 +                              Mailer, Adr, Class, Categories, Desc, Uid,
 +                              decode_vcard_PRODID(<<"vcard-temp">>,
 +                                                  __IgnoreEls, _el),
 +                              Jabberid, Sound, Note, Role, Title, Nickname,
 +                              Rev, Sort_string, Org, Bday, Key, Tz, Url,
 +                              Email, Tel, Label, Fn, Version, N, Photo, Logo,
 +                              Geo);
 +      _ ->
 +        decode_vcard_temp_els(__TopXMLNS, __IgnoreEls, _els,
 +                              Mailer, Adr, Class, Categories, Desc, Uid,
 +                              Prodid, Jabberid, Sound, Note, Role, Title,
 +                              Nickname, Rev, Sort_string, Org, Bday, Key, Tz,
 +                              Url, Email, Tel, Label, Fn, Version, N, Photo,
 +                              Logo, Geo)
 +    end;
 +decode_vcard_temp_els(__TopXMLNS, __IgnoreEls,
 +                    [{xmlel, <<"REV">>, _attrs, _} = _el | _els], Mailer,
 +                    Adr, Class, Categories, Desc, Uid, Prodid, Jabberid,
 +                    Sound, Note, Role, Title, Nickname, Rev, Sort_string,
 +                    Org, Bday, Key, Tz, Url, Email, Tel, Label, Fn, Version,
 +                    N, Photo, Logo, Geo) ->
 +    case get_attr(<<"xmlns">>, _attrs) of
 +      <<"">> when __TopXMLNS == <<"vcard-temp">> ->
 +        decode_vcard_temp_els(__TopXMLNS, __IgnoreEls, _els,
 +                              Mailer, Adr, Class, Categories, Desc, Uid,
 +                              Prodid, Jabberid, Sound, Note, Role, Title,
 +                              Nickname,
 +                              decode_vcard_REV(__TopXMLNS, __IgnoreEls, _el),
 +                              Sort_string, Org, Bday, Key, Tz, Url, Email,
 +                              Tel, Label, Fn, Version, N, Photo, Logo, Geo);
 +      <<"vcard-temp">> ->
 +        decode_vcard_temp_els(__TopXMLNS, __IgnoreEls, _els,
 +                              Mailer, Adr, Class, Categories, Desc, Uid,
 +                              Prodid, Jabberid, Sound, Note, Role, Title,
 +                              Nickname,
 +                              decode_vcard_REV(<<"vcard-temp">>, __IgnoreEls,
 +                                               _el),
 +                              Sort_string, Org, Bday, Key, Tz, Url, Email,
 +                              Tel, Label, Fn, Version, N, Photo, Logo, Geo);
 +      _ ->
 +        decode_vcard_temp_els(__TopXMLNS, __IgnoreEls, _els,
 +                              Mailer, Adr, Class, Categories, Desc, Uid,
 +                              Prodid, Jabberid, Sound, Note, Role, Title,
 +                              Nickname, Rev, Sort_string, Org, Bday, Key, Tz,
 +                              Url, Email, Tel, Label, Fn, Version, N, Photo,
 +                              Logo, Geo)
 +    end;
 +decode_vcard_temp_els(__TopXMLNS, __IgnoreEls,
 +                    [{xmlel, <<"SORT-STRING">>, _attrs, _} = _el | _els],
 +                    Mailer, Adr, Class, Categories, Desc, Uid, Prodid,
 +                    Jabberid, Sound, Note, Role, Title, Nickname, Rev,
 +                    Sort_string, Org, Bday, Key, Tz, Url, Email, Tel, Label,
 +                    Fn, Version, N, Photo, Logo, Geo) ->
 +    case get_attr(<<"xmlns">>, _attrs) of
 +      <<"">> when __TopXMLNS == <<"vcard-temp">> ->
 +        decode_vcard_temp_els(__TopXMLNS, __IgnoreEls, _els,
 +                              Mailer, Adr, Class, Categories, Desc, Uid,
 +                              Prodid, Jabberid, Sound, Note, Role, Title,
 +                              Nickname, Rev,
 +                              decode_vcard_SORT_STRING(__TopXMLNS,
 +                                                       __IgnoreEls, _el),
 +                              Org, Bday, Key, Tz, Url, Email, Tel, Label, Fn,
 +                              Version, N, Photo, Logo, Geo);
 +      <<"vcard-temp">> ->
 +        decode_vcard_temp_els(__TopXMLNS, __IgnoreEls, _els,
 +                              Mailer, Adr, Class, Categories, Desc, Uid,
 +                              Prodid, Jabberid, Sound, Note, Role, Title,
 +                              Nickname, Rev,
 +                              decode_vcard_SORT_STRING(<<"vcard-temp">>,
 +                                                       __IgnoreEls, _el),
 +                              Org, Bday, Key, Tz, Url, Email, Tel, Label, Fn,
 +                              Version, N, Photo, Logo, Geo);
 +      _ ->
 +        decode_vcard_temp_els(__TopXMLNS, __IgnoreEls, _els,
 +                              Mailer, Adr, Class, Categories, Desc, Uid,
 +                              Prodid, Jabberid, Sound, Note, Role, Title,
 +                              Nickname, Rev, Sort_string, Org, Bday, Key, Tz,
 +                              Url, Email, Tel, Label, Fn, Version, N, Photo,
 +                              Logo, Geo)
 +    end;
 +decode_vcard_temp_els(__TopXMLNS, __IgnoreEls,
 +                    [{xmlel, <<"UID">>, _attrs, _} = _el | _els], Mailer,
 +                    Adr, Class, Categories, Desc, Uid, Prodid, Jabberid,
 +                    Sound, Note, Role, Title, Nickname, Rev, Sort_string,
 +                    Org, Bday, Key, Tz, Url, Email, Tel, Label, Fn, Version,
 +                    N, Photo, Logo, Geo) ->
 +    case get_attr(<<"xmlns">>, _attrs) of
 +      <<"">> when __TopXMLNS == <<"vcard-temp">> ->
 +        decode_vcard_temp_els(__TopXMLNS, __IgnoreEls, _els,
 +                              Mailer, Adr, Class, Categories, Desc,
 +                              decode_vcard_UID(__TopXMLNS, __IgnoreEls, _el),
 +                              Prodid, Jabberid, Sound, Note, Role, Title,
 +                              Nickname, Rev, Sort_string, Org, Bday, Key, Tz,
 +                              Url, Email, Tel, Label, Fn, Version, N, Photo,
 +                              Logo, Geo);
 +      <<"vcard-temp">> ->
 +        decode_vcard_temp_els(__TopXMLNS, __IgnoreEls, _els,
 +                              Mailer, Adr, Class, Categories, Desc,
 +                              decode_vcard_UID(<<"vcard-temp">>, __IgnoreEls,
 +                                               _el),
 +                              Prodid, Jabberid, Sound, Note, Role, Title,
 +                              Nickname, Rev, Sort_string, Org, Bday, Key, Tz,
 +                              Url, Email, Tel, Label, Fn, Version, N, Photo,
 +                              Logo, Geo);
 +      _ ->
 +        decode_vcard_temp_els(__TopXMLNS, __IgnoreEls, _els,
 +                              Mailer, Adr, Class, Categories, Desc, Uid,
 +                              Prodid, Jabberid, Sound, Note, Role, Title,
 +                              Nickname, Rev, Sort_string, Org, Bday, Key, Tz,
 +                              Url, Email, Tel, Label, Fn, Version, N, Photo,
 +                              Logo, Geo)
 +    end;
 +decode_vcard_temp_els(__TopXMLNS, __IgnoreEls,
 +                    [{xmlel, <<"URL">>, _attrs, _} = _el | _els], Mailer,
 +                    Adr, Class, Categories, Desc, Uid, Prodid, Jabberid,
 +                    Sound, Note, Role, Title, Nickname, Rev, Sort_string,
 +                    Org, Bday, Key, Tz, Url, Email, Tel, Label, Fn, Version,
 +                    N, Photo, Logo, Geo) ->
 +    case get_attr(<<"xmlns">>, _attrs) of
 +      <<"">> when __TopXMLNS == <<"vcard-temp">> ->
 +        decode_vcard_temp_els(__TopXMLNS, __IgnoreEls, _els,
 +                              Mailer, Adr, Class, Categories, Desc, Uid,
 +                              Prodid, Jabberid, Sound, Note, Role, Title,
 +                              Nickname, Rev, Sort_string, Org, Bday, Key, Tz,
 +                              decode_vcard_URL(__TopXMLNS, __IgnoreEls, _el),
 +                              Email, Tel, Label, Fn, Version, N, Photo, Logo,
 +                              Geo);
 +      <<"vcard-temp">> ->
 +        decode_vcard_temp_els(__TopXMLNS, __IgnoreEls, _els,
 +                              Mailer, Adr, Class, Categories, Desc, Uid,
 +                              Prodid, Jabberid, Sound, Note, Role, Title,
 +                              Nickname, Rev, Sort_string, Org, Bday, Key, Tz,
 +                              decode_vcard_URL(<<"vcard-temp">>, __IgnoreEls,
 +                                               _el),
 +                              Email, Tel, Label, Fn, Version, N, Photo, Logo,
 +                              Geo);
 +      _ ->
 +        decode_vcard_temp_els(__TopXMLNS, __IgnoreEls, _els,
 +                              Mailer, Adr, Class, Categories, Desc, Uid,
 +                              Prodid, Jabberid, Sound, Note, Role, Title,
 +                              Nickname, Rev, Sort_string, Org, Bday, Key, Tz,
 +                              Url, Email, Tel, Label, Fn, Version, N, Photo,
 +                              Logo, Geo)
 +    end;
 +decode_vcard_temp_els(__TopXMLNS, __IgnoreEls,
 +                    [{xmlel, <<"DESC">>, _attrs, _} = _el | _els], Mailer,
 +                    Adr, Class, Categories, Desc, Uid, Prodid, Jabberid,
 +                    Sound, Note, Role, Title, Nickname, Rev, Sort_string,
 +                    Org, Bday, Key, Tz, Url, Email, Tel, Label, Fn, Version,
 +                    N, Photo, Logo, Geo) ->
 +    case get_attr(<<"xmlns">>, _attrs) of
 +      <<"">> when __TopXMLNS == <<"vcard-temp">> ->
 +        decode_vcard_temp_els(__TopXMLNS, __IgnoreEls, _els,
 +                              Mailer, Adr, Class, Categories,
 +                              decode_vcard_DESC(__TopXMLNS, __IgnoreEls, _el),
 +                              Uid, Prodid, Jabberid, Sound, Note, Role, Title,
 +                              Nickname, Rev, Sort_string, Org, Bday, Key, Tz,
 +                              Url, Email, Tel, Label, Fn, Version, N, Photo,
 +                              Logo, Geo);
 +      <<"vcard-temp">> ->
 +        decode_vcard_temp_els(__TopXMLNS, __IgnoreEls, _els,
 +                              Mailer, Adr, Class, Categories,
 +                              decode_vcard_DESC(<<"vcard-temp">>, __IgnoreEls,
 +                                                _el),
 +                              Uid, Prodid, Jabberid, Sound, Note, Role, Title,
 +                              Nickname, Rev, Sort_string, Org, Bday, Key, Tz,
 +                              Url, Email, Tel, Label, Fn, Version, N, Photo,
 +                              Logo, Geo);
 +      _ ->
 +        decode_vcard_temp_els(__TopXMLNS, __IgnoreEls, _els,
 +                              Mailer, Adr, Class, Categories, Desc, Uid,
 +                              Prodid, Jabberid, Sound, Note, Role, Title,
 +                              Nickname, Rev, Sort_string, Org, Bday, Key, Tz,
 +                              Url, Email, Tel, Label, Fn, Version, N, Photo,
 +                              Logo, Geo)
 +    end;
 +decode_vcard_temp_els(__TopXMLNS, __IgnoreEls,
 +                    [{xmlel, <<"CATEGORIES">>, _attrs, _} = _el | _els],
 +                    Mailer, Adr, Class, Categories, Desc, Uid, Prodid,
 +                    Jabberid, Sound, Note, Role, Title, Nickname, Rev,
 +                    Sort_string, Org, Bday, Key, Tz, Url, Email, Tel, Label,
 +                    Fn, Version, N, Photo, Logo, Geo) ->
 +    case get_attr(<<"xmlns">>, _attrs) of
 +      <<"">> when __TopXMLNS == <<"vcard-temp">> ->
 +        decode_vcard_temp_els(__TopXMLNS, __IgnoreEls, _els,
 +                              Mailer, Adr, Class,
 +                              decode_vcard_CATEGORIES(__TopXMLNS, __IgnoreEls,
 +                                                      _el),
 +                              Desc, Uid, Prodid, Jabberid, Sound, Note, Role,
 +                              Title, Nickname, Rev, Sort_string, Org, Bday,
 +                              Key, Tz, Url, Email, Tel, Label, Fn, Version, N,
 +                              Photo, Logo, Geo);
 +      <<"vcard-temp">> ->
 +        decode_vcard_temp_els(__TopXMLNS, __IgnoreEls, _els,
 +                              Mailer, Adr, Class,
 +                              decode_vcard_CATEGORIES(<<"vcard-temp">>,
 +                                                      __IgnoreEls, _el),
 +                              Desc, Uid, Prodid, Jabberid, Sound, Note, Role,
 +                              Title, Nickname, Rev, Sort_string, Org, Bday,
 +                              Key, Tz, Url, Email, Tel, Label, Fn, Version, N,
 +                              Photo, Logo, Geo);
 +      _ ->
 +        decode_vcard_temp_els(__TopXMLNS, __IgnoreEls, _els,
 +                              Mailer, Adr, Class, Categories, Desc, Uid,
 +                              Prodid, Jabberid, Sound, Note, Role, Title,
 +                              Nickname, Rev, Sort_string, Org, Bday, Key, Tz,
 +                              Url, Email, Tel, Label, Fn, Version, N, Photo,
 +                              Logo, Geo)
 +    end;
 +decode_vcard_temp_els(__TopXMLNS, __IgnoreEls,
 +                    [{xmlel, <<"CLASS">>, _attrs, _} = _el | _els], Mailer,
 +                    Adr, Class, Categories, Desc, Uid, Prodid, Jabberid,
 +                    Sound, Note, Role, Title, Nickname, Rev, Sort_string,
 +                    Org, Bday, Key, Tz, Url, Email, Tel, Label, Fn, Version,
 +                    N, Photo, Logo, Geo) ->
 +    case get_attr(<<"xmlns">>, _attrs) of
 +      <<"">> when __TopXMLNS == <<"vcard-temp">> ->
 +        decode_vcard_temp_els(__TopXMLNS, __IgnoreEls, _els,
 +                              Mailer, Adr,
 +                              decode_vcard_CLASS(__TopXMLNS, __IgnoreEls,
 +                                                 _el),
 +                              Categories, Desc, Uid, Prodid, Jabberid, Sound,
 +                              Note, Role, Title, Nickname, Rev, Sort_string,
 +                              Org, Bday, Key, Tz, Url, Email, Tel, Label, Fn,
 +                              Version, N, Photo, Logo, Geo);
 +      <<"vcard-temp">> ->
 +        decode_vcard_temp_els(__TopXMLNS, __IgnoreEls, _els,
 +                              Mailer, Adr,
 +                              decode_vcard_CLASS(<<"vcard-temp">>,
 +                                                 __IgnoreEls, _el),
 +                              Categories, Desc, Uid, Prodid, Jabberid, Sound,
 +                              Note, Role, Title, Nickname, Rev, Sort_string,
 +                              Org, Bday, Key, Tz, Url, Email, Tel, Label, Fn,
 +                              Version, N, Photo, Logo, Geo);
 +      _ ->
 +        decode_vcard_temp_els(__TopXMLNS, __IgnoreEls, _els,
 +                              Mailer, Adr, Class, Categories, Desc, Uid,
 +                              Prodid, Jabberid, Sound, Note, Role, Title,
 +                              Nickname, Rev, Sort_string, Org, Bday, Key, Tz,
 +                              Url, Email, Tel, Label, Fn, Version, N, Photo,
 +                              Logo, Geo)
 +    end;
 +decode_vcard_temp_els(__TopXMLNS, __IgnoreEls,
 +                    [_ | _els], Mailer, Adr, Class, Categories, Desc, Uid,
 +                    Prodid, Jabberid, Sound, Note, Role, Title, Nickname,
 +                    Rev, Sort_string, Org, Bday, Key, Tz, Url, Email, Tel,
 +                    Label, Fn, Version, N, Photo, Logo, Geo) ->
 +    decode_vcard_temp_els(__TopXMLNS, __IgnoreEls, _els,
 +                        Mailer, Adr, Class, Categories, Desc, Uid, Prodid,
 +                        Jabberid, Sound, Note, Role, Title, Nickname, Rev,
 +                        Sort_string, Org, Bday, Key, Tz, Url, Email, Tel,
 +                        Label, Fn, Version, N, Photo, Logo, Geo).
 +
 +encode_vcard_temp({vcard_temp, Version, Fn, N, Nickname,
 +                 Photo, Bday, Adr, Label, Tel, Email, Jabberid, Mailer,
 +                 Tz, Geo, Title, Role, Logo, Org, Categories, Note,
 +                 Prodid, Rev, Sort_string, Sound, Uid, Url, Class, Key,
 +                 Desc},
 +                __TopXMLNS) ->
 +    __NewTopXMLNS = choose_top_xmlns(<<"vcard-temp">>, [],
 +                                   __TopXMLNS),
 +    _els = lists:reverse('encode_vcard_temp_$mailer'(Mailer,
 +                                                   __NewTopXMLNS,
 +                                                   'encode_vcard_temp_$adr'(Adr,
 +                                                                            __NewTopXMLNS,
 +                                                                            'encode_vcard_temp_$class'(Class,
 +                                                                                                       __NewTopXMLNS,
 +                                                                                                       'encode_vcard_temp_$categories'(Categories,
 +                                                                                                                                       __NewTopXMLNS,
 +                                                                                                                                       'encode_vcard_temp_$desc'(Desc,
 +                                                                                                                                                                 __NewTopXMLNS,
 +                                                                                                                                                                 'encode_vcard_temp_$uid'(Uid,
 +                                                                                                                                                                                          __NewTopXMLNS,
 +                                                                                                                                                                                          'encode_vcard_temp_$prodid'(Prodid,
 +                                                                                                                                                                                                                      __NewTopXMLNS,
 +                                                                                                                                                                                                                      'encode_vcard_temp_$jabberid'(Jabberid,
 +                                                                                                                                                                                                                                                    __NewTopXMLNS,
 +                                                                                                                                                                                                                                                    'encode_vcard_temp_$sound'(Sound,
 +                                                                                                                                                                                                                                                                               __NewTopXMLNS,
 +                                                                                                                                                                                                                                                                               'encode_vcard_temp_$note'(Note,
 +                                                                                                                                                                                                                                                                                                         __NewTopXMLNS,
 +                                                                                                                                                                                                                                                                                                         'encode_vcard_temp_$role'(Role,
 +                                                                                                                                                                                                                                                                                                                                   __NewTopXMLNS,
 +                                                                                                                                                                                                                                                                                                                                   'encode_vcard_temp_$title'(Title,
 +                                                                                                                                                                                                                                                                                                                                                              __NewTopXMLNS,
 +                                                                                                                                                                                                                                                                                                                                                              'encode_vcard_temp_$nickname'(Nickname,
 +                                                                                                                                                                                                                                                                                                                                                                                            __NewTopXMLNS,
 +                                                                                                                                                                                                                                                                                                                                                                                            'encode_vcard_temp_$rev'(Rev,
 +                                                                                                                                                                                                                                                                                                                                                                                                                     __NewTopXMLNS,
 +                                                                                                                                                                                                                                                                                                                                                                                                                     'encode_vcard_temp_$sort_string'(Sort_string,
 +                                                                                                                                                                                                                                                                                                                                                                                                                                                      __NewTopXMLNS,
 +                                                                                                                                                                                                                                                                                                                                                                                                                                                      'encode_vcard_temp_$org'(Org,
 +                                                                                                                                                                                                                                                                                                                                                                                                                                                                               __NewTopXMLNS,
 +                                                                                                                                                                                                                                                                                                                                                                                                                                                                               'encode_vcard_temp_$bday'(Bday,
 +                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                         __NewTopXMLNS,
 +                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                         'encode_vcard_temp_$key'(Key,
 +                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                  __NewTopXMLNS,
 +                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                  'encode_vcard_temp_$tz'(Tz,
 +                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                          __NewTopXMLNS,
 +                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                          'encode_vcard_temp_$url'(Url,
 +                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                   __NewTopXMLNS,
 +                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                   'encode_vcard_temp_$email'(Email,
 +                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                              __NewTopXMLNS,
 +                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                              'encode_vcard_temp_$tel'(Tel,
 +                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                       __NewTopXMLNS,
 +                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                       'encode_vcard_temp_$label'(Label,
 +                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                  __NewTopXMLNS,
 +                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                  'encode_vcard_temp_$fn'(Fn,
 +                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                          __NewTopXMLNS,
 +                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                          'encode_vcard_temp_$version'(Version,
 +                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                       __NewTopXMLNS,
 +                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                       'encode_vcard_temp_$n'(N,
 +                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                              __NewTopXMLNS,
 +                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                              'encode_vcard_temp_$photo'(Photo,
 +                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                         __NewTopXMLNS,
 +                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                         'encode_vcard_temp_$logo'(Logo,
 +                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                   __NewTopXMLNS,
 +                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                   'encode_vcard_temp_$geo'(Geo,
 +                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                            __NewTopXMLNS,
 +                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                            [])))))))))))))))))))))))))))))),
 +    _attrs = enc_xmlns_attrs(__NewTopXMLNS, __TopXMLNS),
 +    {xmlel, <<"vCard">>, _attrs, _els}.
 +
 +'encode_vcard_temp_$mailer'(undefined, __TopXMLNS,
 +                          _acc) ->
 +    _acc;
 +'encode_vcard_temp_$mailer'(Mailer, __TopXMLNS, _acc) ->
 +    [encode_vcard_MAILER(Mailer, __TopXMLNS) | _acc].
 +
 +'encode_vcard_temp_$adr'([], __TopXMLNS, _acc) -> _acc;
 +'encode_vcard_temp_$adr'([Adr | _els], __TopXMLNS,
 +                       _acc) ->
 +    'encode_vcard_temp_$adr'(_els, __TopXMLNS,
 +                           [encode_vcard_ADR(Adr, __TopXMLNS) | _acc]).
 +
 +'encode_vcard_temp_$class'(undefined, __TopXMLNS,
 +                         _acc) ->
 +    _acc;
 +'encode_vcard_temp_$class'(Class, __TopXMLNS, _acc) ->
 +    [encode_vcard_CLASS(Class, __TopXMLNS) | _acc].
 +
 +'encode_vcard_temp_$categories'([], __TopXMLNS, _acc) ->
 +    _acc;
 +'encode_vcard_temp_$categories'(Categories, __TopXMLNS,
 +                              _acc) ->
 +    [encode_vcard_CATEGORIES(Categories, __TopXMLNS)
 +     | _acc].
 +
 +'encode_vcard_temp_$desc'(undefined, __TopXMLNS,
 +                        _acc) ->
 +    _acc;
 +'encode_vcard_temp_$desc'(Desc, __TopXMLNS, _acc) ->
 +    [encode_vcard_DESC(Desc, __TopXMLNS) | _acc].
 +
 +'encode_vcard_temp_$uid'(undefined, __TopXMLNS, _acc) ->
 +    _acc;
 +'encode_vcard_temp_$uid'(Uid, __TopXMLNS, _acc) ->
 +    [encode_vcard_UID(Uid, __TopXMLNS) | _acc].
 +
 +'encode_vcard_temp_$prodid'(undefined, __TopXMLNS,
 +                          _acc) ->
 +    _acc;
 +'encode_vcard_temp_$prodid'(Prodid, __TopXMLNS, _acc) ->
 +    [encode_vcard_PRODID(Prodid, __TopXMLNS) | _acc].
 +
 +'encode_vcard_temp_$jabberid'(undefined, __TopXMLNS,
 +                            _acc) ->
 +    _acc;
 +'encode_vcard_temp_$jabberid'(Jabberid, __TopXMLNS,
 +                            _acc) ->
 +    [encode_vcard_JABBERID(Jabberid, __TopXMLNS) | _acc].
 +
 +'encode_vcard_temp_$sound'(undefined, __TopXMLNS,
 +                         _acc) ->
 +    _acc;
 +'encode_vcard_temp_$sound'(Sound, __TopXMLNS, _acc) ->
 +    [encode_vcard_SOUND(Sound, __TopXMLNS) | _acc].
 +
 +'encode_vcard_temp_$note'(undefined, __TopXMLNS,
 +                        _acc) ->
 +    _acc;
 +'encode_vcard_temp_$note'(Note, __TopXMLNS, _acc) ->
 +    [encode_vcard_NOTE(Note, __TopXMLNS) | _acc].
 +
 +'encode_vcard_temp_$role'(undefined, __TopXMLNS,
 +                        _acc) ->
 +    _acc;
 +'encode_vcard_temp_$role'(Role, __TopXMLNS, _acc) ->
 +    [encode_vcard_ROLE(Role, __TopXMLNS) | _acc].
 +
 +'encode_vcard_temp_$title'(undefined, __TopXMLNS,
 +                         _acc) ->
 +    _acc;
 +'encode_vcard_temp_$title'(Title, __TopXMLNS, _acc) ->
 +    [encode_vcard_TITLE(Title, __TopXMLNS) | _acc].
 +
 +'encode_vcard_temp_$nickname'(undefined, __TopXMLNS,
 +                            _acc) ->
 +    _acc;
 +'encode_vcard_temp_$nickname'(Nickname, __TopXMLNS,
 +                            _acc) ->
 +    [encode_vcard_NICKNAME(Nickname, __TopXMLNS) | _acc].
 +
 +'encode_vcard_temp_$rev'(undefined, __TopXMLNS, _acc) ->
 +    _acc;
 +'encode_vcard_temp_$rev'(Rev, __TopXMLNS, _acc) ->
 +    [encode_vcard_REV(Rev, __TopXMLNS) | _acc].
 +
 +'encode_vcard_temp_$sort_string'(undefined, __TopXMLNS,
 +                               _acc) ->
 +    _acc;
 +'encode_vcard_temp_$sort_string'(Sort_string,
 +                               __TopXMLNS, _acc) ->
 +    [encode_vcard_SORT_STRING(Sort_string, __TopXMLNS)
 +     | _acc].
 +
 +'encode_vcard_temp_$org'(undefined, __TopXMLNS, _acc) ->
 +    _acc;
 +'encode_vcard_temp_$org'(Org, __TopXMLNS, _acc) ->
 +    [encode_vcard_ORG(Org, __TopXMLNS) | _acc].
 +
 +'encode_vcard_temp_$bday'(undefined, __TopXMLNS,
 +                        _acc) ->
 +    _acc;
 +'encode_vcard_temp_$bday'(Bday, __TopXMLNS, _acc) ->
 +    [encode_vcard_BDAY(Bday, __TopXMLNS) | _acc].
 +
 +'encode_vcard_temp_$key'(undefined, __TopXMLNS, _acc) ->
 +    _acc;
 +'encode_vcard_temp_$key'(Key, __TopXMLNS, _acc) ->
 +    [encode_vcard_KEY(Key, __TopXMLNS) | _acc].
 +
 +'encode_vcard_temp_$tz'(undefined, __TopXMLNS, _acc) ->
 +    _acc;
 +'encode_vcard_temp_$tz'(Tz, __TopXMLNS, _acc) ->
 +    [encode_vcard_TZ(Tz, __TopXMLNS) | _acc].
 +
 +'encode_vcard_temp_$url'(undefined, __TopXMLNS, _acc) ->
 +    _acc;
 +'encode_vcard_temp_$url'(Url, __TopXMLNS, _acc) ->
 +    [encode_vcard_URL(Url, __TopXMLNS) | _acc].
 +
 +'encode_vcard_temp_$email'([], __TopXMLNS, _acc) ->
 +    _acc;
 +'encode_vcard_temp_$email'([Email | _els], __TopXMLNS,
 +                         _acc) ->
 +    'encode_vcard_temp_$email'(_els, __TopXMLNS,
 +                             [encode_vcard_EMAIL(Email, __TopXMLNS) | _acc]).
 +
 +'encode_vcard_temp_$tel'([], __TopXMLNS, _acc) -> _acc;
 +'encode_vcard_temp_$tel'([Tel | _els], __TopXMLNS,
 +                       _acc) ->
 +    'encode_vcard_temp_$tel'(_els, __TopXMLNS,
 +                           [encode_vcard_TEL(Tel, __TopXMLNS) | _acc]).
 +
 +'encode_vcard_temp_$label'([], __TopXMLNS, _acc) ->
 +    _acc;
 +'encode_vcard_temp_$label'([Label | _els], __TopXMLNS,
 +                         _acc) ->
 +    'encode_vcard_temp_$label'(_els, __TopXMLNS,
 +                             [encode_vcard_LABEL(Label, __TopXMLNS) | _acc]).
 +
 +'encode_vcard_temp_$fn'(undefined, __TopXMLNS, _acc) ->
 +    _acc;
 +'encode_vcard_temp_$fn'(Fn, __TopXMLNS, _acc) ->
 +    [encode_vcard_FN(Fn, __TopXMLNS) | _acc].
 +
 +'encode_vcard_temp_$version'(undefined, __TopXMLNS,
 +                           _acc) ->
 +    _acc;
 +'encode_vcard_temp_$version'(Version, __TopXMLNS,
 +                           _acc) ->
 +    [encode_vcard_VERSION(Version, __TopXMLNS) | _acc].
 +
 +'encode_vcard_temp_$n'(undefined, __TopXMLNS, _acc) ->
 +    _acc;
 +'encode_vcard_temp_$n'(N, __TopXMLNS, _acc) ->
 +    [encode_vcard_N(N, __TopXMLNS) | _acc].
 +
 +'encode_vcard_temp_$photo'(undefined, __TopXMLNS,
 +                         _acc) ->
 +    _acc;
 +'encode_vcard_temp_$photo'(Photo, __TopXMLNS, _acc) ->
 +    [encode_vcard_PHOTO(Photo, __TopXMLNS) | _acc].
 +
 +'encode_vcard_temp_$logo'(undefined, __TopXMLNS,
 +                        _acc) ->
 +    _acc;
 +'encode_vcard_temp_$logo'(Logo, __TopXMLNS, _acc) ->
 +    [encode_vcard_LOGO(Logo, __TopXMLNS) | _acc].
 +
 +'encode_vcard_temp_$geo'(undefined, __TopXMLNS, _acc) ->
 +    _acc;
 +'encode_vcard_temp_$geo'(Geo, __TopXMLNS, _acc) ->
 +    [encode_vcard_GEO(Geo, __TopXMLNS) | _acc].
 +
 +decode_vcard_CLASS(__TopXMLNS, __IgnoreEls,
 +                 {xmlel, <<"CLASS">>, _attrs, _els}) ->
 +    Class = decode_vcard_CLASS_els(__TopXMLNS, __IgnoreEls,
 +                                 _els, undefined),
 +    Class.
 +
 +decode_vcard_CLASS_els(__TopXMLNS, __IgnoreEls, [],
 +                     Class) ->
 +    Class;
 +decode_vcard_CLASS_els(__TopXMLNS, __IgnoreEls,
 +                     [{xmlel, <<"PUBLIC">>, _attrs, _} = _el | _els],
 +                     Class) ->
 +    case get_attr(<<"xmlns">>, _attrs) of
 +      <<"">> when __TopXMLNS == <<"vcard-temp">> ->
 +        decode_vcard_CLASS_els(__TopXMLNS, __IgnoreEls, _els,
 +                               decode_vcard_PUBLIC(__TopXMLNS, __IgnoreEls,
 +                                                   _el));
 +      <<"vcard-temp">> ->
 +        decode_vcard_CLASS_els(__TopXMLNS, __IgnoreEls, _els,
 +                               decode_vcard_PUBLIC(<<"vcard-temp">>,
 +                                                   __IgnoreEls, _el));
 +      _ ->
 +        decode_vcard_CLASS_els(__TopXMLNS, __IgnoreEls, _els,
 +                               Class)
 +    end;
 +decode_vcard_CLASS_els(__TopXMLNS, __IgnoreEls,
 +                     [{xmlel, <<"PRIVATE">>, _attrs, _} = _el | _els],
 +                     Class) ->
 +    case get_attr(<<"xmlns">>, _attrs) of
 +      <<"">> when __TopXMLNS == <<"vcard-temp">> ->
 +        decode_vcard_CLASS_els(__TopXMLNS, __IgnoreEls, _els,
 +                               decode_vcard_PRIVATE(__TopXMLNS, __IgnoreEls,
 +                                                    _el));
 +      <<"vcard-temp">> ->
 +        decode_vcard_CLASS_els(__TopXMLNS, __IgnoreEls, _els,
 +                               decode_vcard_PRIVATE(<<"vcard-temp">>,
 +                                                    __IgnoreEls, _el));
 +      _ ->
 +        decode_vcard_CLASS_els(__TopXMLNS, __IgnoreEls, _els,
 +                               Class)
 +    end;
 +decode_vcard_CLASS_els(__TopXMLNS, __IgnoreEls,
 +                     [{xmlel, <<"CONFIDENTIAL">>, _attrs, _} = _el | _els],
 +                     Class) ->
 +    case get_attr(<<"xmlns">>, _attrs) of
 +      <<"">> when __TopXMLNS == <<"vcard-temp">> ->
 +        decode_vcard_CLASS_els(__TopXMLNS, __IgnoreEls, _els,
 +                               decode_vcard_CONFIDENTIAL(__TopXMLNS,
 +                                                         __IgnoreEls, _el));
 +      <<"vcard-temp">> ->
 +        decode_vcard_CLASS_els(__TopXMLNS, __IgnoreEls, _els,
 +                               decode_vcard_CONFIDENTIAL(<<"vcard-temp">>,
 +                                                         __IgnoreEls, _el));
 +      _ ->
 +        decode_vcard_CLASS_els(__TopXMLNS, __IgnoreEls, _els,
 +                               Class)
 +    end;
 +decode_vcard_CLASS_els(__TopXMLNS, __IgnoreEls,
 +                     [_ | _els], Class) ->
 +    decode_vcard_CLASS_els(__TopXMLNS, __IgnoreEls, _els,
 +                         Class).
 +
 +encode_vcard_CLASS(Class, __TopXMLNS) ->
 +    __NewTopXMLNS = choose_top_xmlns(<<"vcard-temp">>, [],
 +                                   __TopXMLNS),
 +    _els = lists:reverse('encode_vcard_CLASS_$class'(Class,
 +                                                   __NewTopXMLNS, [])),
 +    _attrs = enc_xmlns_attrs(__NewTopXMLNS, __TopXMLNS),
 +    {xmlel, <<"CLASS">>, _attrs, _els}.
 +
 +'encode_vcard_CLASS_$class'(undefined, __TopXMLNS,
 +                          _acc) ->
 +    _acc;
 +'encode_vcard_CLASS_$class'(public = Class, __TopXMLNS,
 +                          _acc) ->
 +    [encode_vcard_PUBLIC(Class, __TopXMLNS) | _acc];
 +'encode_vcard_CLASS_$class'(private = Class, __TopXMLNS,
 +                          _acc) ->
 +    [encode_vcard_PRIVATE(Class, __TopXMLNS) | _acc];
 +'encode_vcard_CLASS_$class'(confidential = Class,
 +                          __TopXMLNS, _acc) ->
 +    [encode_vcard_CONFIDENTIAL(Class, __TopXMLNS) | _acc].
 +
 +decode_vcard_CATEGORIES(__TopXMLNS, __IgnoreEls,
 +                      {xmlel, <<"CATEGORIES">>, _attrs, _els}) ->
 +    Keywords = decode_vcard_CATEGORIES_els(__TopXMLNS,
 +                                         __IgnoreEls, _els, []),
 +    Keywords.
 +
 +decode_vcard_CATEGORIES_els(__TopXMLNS, __IgnoreEls, [],
 +                          Keywords) ->
 +    lists:reverse(Keywords);
 +decode_vcard_CATEGORIES_els(__TopXMLNS, __IgnoreEls,
 +                          [{xmlel, <<"KEYWORD">>, _attrs, _} = _el | _els],
 +                          Keywords) ->
 +    case get_attr(<<"xmlns">>, _attrs) of
 +      <<"">> when __TopXMLNS == <<"vcard-temp">> ->
 +        decode_vcard_CATEGORIES_els(__TopXMLNS, __IgnoreEls,
 +                                    _els,
 +                                    [decode_vcard_KEYWORD(__TopXMLNS,
 +                                                          __IgnoreEls, _el)
 +                                     | Keywords]);
 +      <<"vcard-temp">> ->
 +        decode_vcard_CATEGORIES_els(__TopXMLNS, __IgnoreEls,
 +                                    _els,
 +                                    [decode_vcard_KEYWORD(<<"vcard-temp">>,
 +                                                          __IgnoreEls, _el)
 +                                     | Keywords]);
 +      _ ->
 +        decode_vcard_CATEGORIES_els(__TopXMLNS, __IgnoreEls,
 +                                    _els, Keywords)
 +    end;
 +decode_vcard_CATEGORIES_els(__TopXMLNS, __IgnoreEls,
 +                          [_ | _els], Keywords) ->
 +    decode_vcard_CATEGORIES_els(__TopXMLNS, __IgnoreEls,
 +                              _els, Keywords).
 +
 +encode_vcard_CATEGORIES(Keywords, __TopXMLNS) ->
 +    __NewTopXMLNS = choose_top_xmlns(<<"vcard-temp">>, [],
 +                                   __TopXMLNS),
 +    _els =
 +      lists:reverse('encode_vcard_CATEGORIES_$keywords'(Keywords,
 +                                                        __NewTopXMLNS, [])),
 +    _attrs = enc_xmlns_attrs(__NewTopXMLNS, __TopXMLNS),
 +    {xmlel, <<"CATEGORIES">>, _attrs, _els}.
 +
 +'encode_vcard_CATEGORIES_$keywords'([], __TopXMLNS,
 +                                  _acc) ->
 +    _acc;
 +'encode_vcard_CATEGORIES_$keywords'([Keywords | _els],
 +                                  __TopXMLNS, _acc) ->
 +    'encode_vcard_CATEGORIES_$keywords'(_els, __TopXMLNS,
 +                                      [encode_vcard_KEYWORD(Keywords,
 +                                                            __TopXMLNS)
 +                                       | _acc]).
 +
 +decode_vcard_KEY(__TopXMLNS, __IgnoreEls,
 +               {xmlel, <<"KEY">>, _attrs, _els}) ->
 +    {Cred, Type} = decode_vcard_KEY_els(__TopXMLNS,
 +                                      __IgnoreEls, _els, undefined,
 +                                      undefined),
 +    {vcard_key, Type, Cred}.
 +
 +decode_vcard_KEY_els(__TopXMLNS, __IgnoreEls, [], Cred,
 +                   Type) ->
 +    {Cred, Type};
 +decode_vcard_KEY_els(__TopXMLNS, __IgnoreEls,
 +                   [{xmlel, <<"TYPE">>, _attrs, _} = _el | _els], Cred,
 +                   Type) ->
 +    case get_attr(<<"xmlns">>, _attrs) of
 +      <<"">> when __TopXMLNS == <<"vcard-temp">> ->
 +        decode_vcard_KEY_els(__TopXMLNS, __IgnoreEls, _els,
 +                             Cred,
 +                             decode_vcard_TYPE(__TopXMLNS, __IgnoreEls, _el));
 +      <<"vcard-temp">> ->
 +        decode_vcard_KEY_els(__TopXMLNS, __IgnoreEls, _els,
 +                             Cred,
 +                             decode_vcard_TYPE(<<"vcard-temp">>, __IgnoreEls,
 +                                               _el));
 +      _ ->
 +        decode_vcard_KEY_els(__TopXMLNS, __IgnoreEls, _els,
 +                             Cred, Type)
 +    end;
 +decode_vcard_KEY_els(__TopXMLNS, __IgnoreEls,
 +                   [{xmlel, <<"CRED">>, _attrs, _} = _el | _els], Cred,
 +                   Type) ->
 +    case get_attr(<<"xmlns">>, _attrs) of
 +      <<"">> when __TopXMLNS == <<"vcard-temp">> ->
 +        decode_vcard_KEY_els(__TopXMLNS, __IgnoreEls, _els,
 +                             decode_vcard_CRED(__TopXMLNS, __IgnoreEls, _el),
 +                             Type);
 +      <<"vcard-temp">> ->
 +        decode_vcard_KEY_els(__TopXMLNS, __IgnoreEls, _els,
 +                             decode_vcard_CRED(<<"vcard-temp">>, __IgnoreEls,
 +                                               _el),
 +                             Type);
 +      _ ->
 +        decode_vcard_KEY_els(__TopXMLNS, __IgnoreEls, _els,
 +                             Cred, Type)
 +    end;
 +decode_vcard_KEY_els(__TopXMLNS, __IgnoreEls,
 +                   [_ | _els], Cred, Type) ->
 +    decode_vcard_KEY_els(__TopXMLNS, __IgnoreEls, _els,
 +                       Cred, Type).
 +
 +encode_vcard_KEY({vcard_key, Type, Cred}, __TopXMLNS) ->
 +    __NewTopXMLNS = choose_top_xmlns(<<"vcard-temp">>, [],
 +                                   __TopXMLNS),
 +    _els = lists:reverse('encode_vcard_KEY_$cred'(Cred,
 +                                                __NewTopXMLNS,
 +                                                'encode_vcard_KEY_$type'(Type,
 +                                                                         __NewTopXMLNS,
 +                                                                         []))),
 +    _attrs = enc_xmlns_attrs(__NewTopXMLNS, __TopXMLNS),
 +    {xmlel, <<"KEY">>, _attrs, _els}.
 +
 +'encode_vcard_KEY_$cred'(undefined, __TopXMLNS, _acc) ->
 +    _acc;
 +'encode_vcard_KEY_$cred'(Cred, __TopXMLNS, _acc) ->
 +    [encode_vcard_CRED(Cred, __TopXMLNS) | _acc].
 +
 +'encode_vcard_KEY_$type'(undefined, __TopXMLNS, _acc) ->
 +    _acc;
 +'encode_vcard_KEY_$type'(Type, __TopXMLNS, _acc) ->
 +    [encode_vcard_TYPE(Type, __TopXMLNS) | _acc].
 +
 +decode_vcard_SOUND(__TopXMLNS, __IgnoreEls,
 +                 {xmlel, <<"SOUND">>, _attrs, _els}) ->
 +    {Phonetic, Extval, Binval} =
 +      decode_vcard_SOUND_els(__TopXMLNS, __IgnoreEls, _els,
 +                             undefined, undefined, undefined),
 +    {vcard_sound, Phonetic, Binval, Extval}.
 +
 +decode_vcard_SOUND_els(__TopXMLNS, __IgnoreEls, [],
 +                     Phonetic, Extval, Binval) ->
 +    {Phonetic, Extval, Binval};
 +decode_vcard_SOUND_els(__TopXMLNS, __IgnoreEls,
 +                     [{xmlel, <<"BINVAL">>, _attrs, _} = _el | _els],
 +                     Phonetic, Extval, Binval) ->
 +    case get_attr(<<"xmlns">>, _attrs) of
 +      <<"">> when __TopXMLNS == <<"vcard-temp">> ->
 +        decode_vcard_SOUND_els(__TopXMLNS, __IgnoreEls, _els,
 +                               Phonetic, Extval,
 +                               decode_vcard_BINVAL(__TopXMLNS, __IgnoreEls,
 +                                                   _el));
 +      <<"vcard-temp">> ->
 +        decode_vcard_SOUND_els(__TopXMLNS, __IgnoreEls, _els,
 +                               Phonetic, Extval,
 +                               decode_vcard_BINVAL(<<"vcard-temp">>,
 +                                                   __IgnoreEls, _el));
 +      _ ->
 +        decode_vcard_SOUND_els(__TopXMLNS, __IgnoreEls, _els,
 +                               Phonetic, Extval, Binval)
 +    end;
 +decode_vcard_SOUND_els(__TopXMLNS, __IgnoreEls,
 +                     [{xmlel, <<"EXTVAL">>, _attrs, _} = _el | _els],
 +                     Phonetic, Extval, Binval) ->
 +    case get_attr(<<"xmlns">>, _attrs) of
 +      <<"">> when __TopXMLNS == <<"vcard-temp">> ->
 +        decode_vcard_SOUND_els(__TopXMLNS, __IgnoreEls, _els,
 +                               Phonetic,
 +                               decode_vcard_EXTVAL(__TopXMLNS, __IgnoreEls,
 +                                                   _el),
 +                               Binval);
 +      <<"vcard-temp">> ->
 +        decode_vcard_SOUND_els(__TopXMLNS, __IgnoreEls, _els,
 +                               Phonetic,
 +                               decode_vcard_EXTVAL(<<"vcard-temp">>,
 +                                                   __IgnoreEls, _el),
 +                               Binval);
 +      _ ->
 +        decode_vcard_SOUND_els(__TopXMLNS, __IgnoreEls, _els,
 +                               Phonetic, Extval, Binval)
 +    end;
 +decode_vcard_SOUND_els(__TopXMLNS, __IgnoreEls,
 +                     [{xmlel, <<"PHONETIC">>, _attrs, _} = _el | _els],
 +                     Phonetic, Extval, Binval) ->
 +    case get_attr(<<"xmlns">>, _attrs) of
 +      <<"">> when __TopXMLNS == <<"vcard-temp">> ->
 +        decode_vcard_SOUND_els(__TopXMLNS, __IgnoreEls, _els,
 +                               decode_vcard_PHONETIC(__TopXMLNS, __IgnoreEls,
 +                                                     _el),
 +                               Extval, Binval);
 +      <<"vcard-temp">> ->
 +        decode_vcard_SOUND_els(__TopXMLNS, __IgnoreEls, _els,
 +                               decode_vcard_PHONETIC(<<"vcard-temp">>,
 +                                                     __IgnoreEls, _el),
 +                               Extval, Binval);
 +      _ ->
 +        decode_vcard_SOUND_els(__TopXMLNS, __IgnoreEls, _els,
 +                               Phonetic, Extval, Binval)
 +    end;
 +decode_vcard_SOUND_els(__TopXMLNS, __IgnoreEls,
 +                     [_ | _els], Phonetic, Extval, Binval) ->
 +    decode_vcard_SOUND_els(__TopXMLNS, __IgnoreEls, _els,
 +                         Phonetic, Extval, Binval).
 +
 +encode_vcard_SOUND({vcard_sound, Phonetic, Binval,
 +                  Extval},
 +                 __TopXMLNS) ->
 +    __NewTopXMLNS = choose_top_xmlns(<<"vcard-temp">>, [],
 +                                   __TopXMLNS),
 +    _els =
 +      lists:reverse('encode_vcard_SOUND_$phonetic'(Phonetic,
 +                                                   __NewTopXMLNS,
 +                                                   'encode_vcard_SOUND_$extval'(Extval,
 +                                                                                __NewTopXMLNS,
 +                                                                                'encode_vcard_SOUND_$binval'(Binval,
 +                                                                                                             __NewTopXMLNS,
 +                                                                                                             [])))),
 +    _attrs = enc_xmlns_attrs(__NewTopXMLNS, __TopXMLNS),
 +    {xmlel, <<"SOUND">>, _attrs, _els}.
 +
 +'encode_vcard_SOUND_$phonetic'(undefined, __TopXMLNS,
 +                             _acc) ->
 +    _acc;
 +'encode_vcard_SOUND_$phonetic'(Phonetic, __TopXMLNS,
 +                             _acc) ->
 +    [encode_vcard_PHONETIC(Phonetic, __TopXMLNS) | _acc].
 +
 +'encode_vcard_SOUND_$extval'(undefined, __TopXMLNS,
 +                           _acc) ->
 +    _acc;
 +'encode_vcard_SOUND_$extval'(Extval, __TopXMLNS,
 +                           _acc) ->
 +    [encode_vcard_EXTVAL(Extval, __TopXMLNS) | _acc].
 +
 +'encode_vcard_SOUND_$binval'(undefined, __TopXMLNS,
 +                           _acc) ->
 +    _acc;
 +'encode_vcard_SOUND_$binval'(Binval, __TopXMLNS,
 +                           _acc) ->
 +    [encode_vcard_BINVAL(Binval, __TopXMLNS) | _acc].
 +
 +decode_vcard_ORG(__TopXMLNS, __IgnoreEls,
 +               {xmlel, <<"ORG">>, _attrs, _els}) ->
 +    {Units, Name} = decode_vcard_ORG_els(__TopXMLNS,
 +                                       __IgnoreEls, _els, [], undefined),
 +    {vcard_org, Name, Units}.
 +
 +decode_vcard_ORG_els(__TopXMLNS, __IgnoreEls, [], Units,
 +                   Name) ->
 +    {lists:reverse(Units), Name};
 +decode_vcard_ORG_els(__TopXMLNS, __IgnoreEls,
 +                   [{xmlel, <<"ORGNAME">>, _attrs, _} = _el | _els], Units,
 +                   Name) ->
 +    case get_attr(<<"xmlns">>, _attrs) of
 +      <<"">> when __TopXMLNS == <<"vcard-temp">> ->
 +        decode_vcard_ORG_els(__TopXMLNS, __IgnoreEls, _els,
 +                             Units,
 +                             decode_vcard_ORGNAME(__TopXMLNS, __IgnoreEls,
 +                                                  _el));
 +      <<"vcard-temp">> ->
 +        decode_vcard_ORG_els(__TopXMLNS, __IgnoreEls, _els,
 +                             Units,
 +                             decode_vcard_ORGNAME(<<"vcard-temp">>,
 +                                                  __IgnoreEls, _el));
 +      _ ->
 +        decode_vcard_ORG_els(__TopXMLNS, __IgnoreEls, _els,
 +                             Units, Name)
 +    end;
 +decode_vcard_ORG_els(__TopXMLNS, __IgnoreEls,
 +                   [{xmlel, <<"ORGUNIT">>, _attrs, _} = _el | _els], Units,
 +                   Name) ->
 +    case get_attr(<<"xmlns">>, _attrs) of
 +      <<"">> when __TopXMLNS == <<"vcard-temp">> ->
 +        decode_vcard_ORG_els(__TopXMLNS, __IgnoreEls, _els,
 +                             [decode_vcard_ORGUNIT(__TopXMLNS, __IgnoreEls,
 +                                                   _el)
 +                              | Units],
 +                             Name);
 +      <<"vcard-temp">> ->
 +        decode_vcard_ORG_els(__TopXMLNS, __IgnoreEls, _els,
 +                             [decode_vcard_ORGUNIT(<<"vcard-temp">>,
 +                                                   __IgnoreEls, _el)
 +                              | Units],
 +                             Name);
 +      _ ->
 +        decode_vcard_ORG_els(__TopXMLNS, __IgnoreEls, _els,
 +                             Units, Name)
 +    end;
 +decode_vcard_ORG_els(__TopXMLNS, __IgnoreEls,
 +                   [_ | _els], Units, Name) ->
 +    decode_vcard_ORG_els(__TopXMLNS, __IgnoreEls, _els,
 +                       Units, Name).
 +
 +encode_vcard_ORG({vcard_org, Name, Units},
 +               __TopXMLNS) ->
 +    __NewTopXMLNS = choose_top_xmlns(<<"vcard-temp">>, [],
 +                                   __TopXMLNS),
 +    _els = lists:reverse('encode_vcard_ORG_$units'(Units,
 +                                                 __NewTopXMLNS,
 +                                                 'encode_vcard_ORG_$name'(Name,
 +                                                                          __NewTopXMLNS,
 +                                                                          []))),
 +    _attrs = enc_xmlns_attrs(__NewTopXMLNS, __TopXMLNS),
 +    {xmlel, <<"ORG">>, _attrs, _els}.
 +
 +'encode_vcard_ORG_$units'([], __TopXMLNS, _acc) -> _acc;
 +'encode_vcard_ORG_$units'([Units | _els], __TopXMLNS,
 +                        _acc) ->
 +    'encode_vcard_ORG_$units'(_els, __TopXMLNS,
 +                            [encode_vcard_ORGUNIT(Units, __TopXMLNS) | _acc]).
 +
 +'encode_vcard_ORG_$name'(undefined, __TopXMLNS, _acc) ->
 +    _acc;
 +'encode_vcard_ORG_$name'(Name, __TopXMLNS, _acc) ->
 +    [encode_vcard_ORGNAME(Name, __TopXMLNS) | _acc].
 +
 +decode_vcard_PHOTO(__TopXMLNS, __IgnoreEls,
 +                 {xmlel, <<"PHOTO">>, _attrs, _els}) ->
 +    {Type, Extval, Binval} =
 +      decode_vcard_PHOTO_els(__TopXMLNS, __IgnoreEls, _els,
 +                             undefined, undefined, undefined),
 +    {vcard_photo, Type, Binval, Extval}.
 +
 +decode_vcard_PHOTO_els(__TopXMLNS, __IgnoreEls, [],
 +                     Type, Extval, Binval) ->
 +    {Type, Extval, Binval};
 +decode_vcard_PHOTO_els(__TopXMLNS, __IgnoreEls,
 +                     [{xmlel, <<"TYPE">>, _attrs, _} = _el | _els], Type,
 +                     Extval, Binval) ->
 +    case get_attr(<<"xmlns">>, _attrs) of
 +      <<"">> when __TopXMLNS == <<"vcard-temp">> ->
 +        decode_vcard_PHOTO_els(__TopXMLNS, __IgnoreEls, _els,
 +                               decode_vcard_TYPE(__TopXMLNS, __IgnoreEls,
 +                                                 _el),
 +                               Extval, Binval);
 +      <<"vcard-temp">> ->
 +        decode_vcard_PHOTO_els(__TopXMLNS, __IgnoreEls, _els,
 +                               decode_vcard_TYPE(<<"vcard-temp">>,
 +                                                 __IgnoreEls, _el),
 +                               Extval, Binval);
 +      _ ->
 +        decode_vcard_PHOTO_els(__TopXMLNS, __IgnoreEls, _els,
 +                               Type, Extval, Binval)
 +    end;
 +decode_vcard_PHOTO_els(__TopXMLNS, __IgnoreEls,
 +                     [{xmlel, <<"BINVAL">>, _attrs, _} = _el | _els], Type,
 +                     Extval, Binval) ->
 +    case get_attr(<<"xmlns">>, _attrs) of
 +      <<"">> when __TopXMLNS == <<"vcard-temp">> ->
 +        decode_vcard_PHOTO_els(__TopXMLNS, __IgnoreEls, _els,
 +                               Type, Extval,
 +                               decode_vcard_BINVAL(__TopXMLNS, __IgnoreEls,
 +                                                   _el));
 +      <<"vcard-temp">> ->
 +        decode_vcard_PHOTO_els(__TopXMLNS, __IgnoreEls, _els,
 +                               Type, Extval,
 +                               decode_vcard_BINVAL(<<"vcard-temp">>,
 +                                                   __IgnoreEls, _el));
 +      _ ->
 +        decode_vcard_PHOTO_els(__TopXMLNS, __IgnoreEls, _els,
 +                               Type, Extval, Binval)
 +    end;
 +decode_vcard_PHOTO_els(__TopXMLNS, __IgnoreEls,
 +                     [{xmlel, <<"EXTVAL">>, _attrs, _} = _el | _els], Type,
 +                     Extval, Binval) ->
 +    case get_attr(<<"xmlns">>, _attrs) of
 +      <<"">> when __TopXMLNS == <<"vcard-temp">> ->
 +        decode_vcard_PHOTO_els(__TopXMLNS, __IgnoreEls, _els,
 +                               Type,
 +                               decode_vcard_EXTVAL(__TopXMLNS, __IgnoreEls,
 +                                                   _el),
 +                               Binval);
 +      <<"vcard-temp">> ->
 +        decode_vcard_PHOTO_els(__TopXMLNS, __IgnoreEls, _els,
 +                               Type,
 +                               decode_vcard_EXTVAL(<<"vcard-temp">>,
 +                                                   __IgnoreEls, _el),
 +                               Binval);
 +      _ ->
 +        decode_vcard_PHOTO_els(__TopXMLNS, __IgnoreEls, _els,
 +                               Type, Extval, Binval)
 +    end;
 +decode_vcard_PHOTO_els(__TopXMLNS, __IgnoreEls,
 +                     [_ | _els], Type, Extval, Binval) ->
 +    decode_vcard_PHOTO_els(__TopXMLNS, __IgnoreEls, _els,
 +                         Type, Extval, Binval).
 +
 +encode_vcard_PHOTO({vcard_photo, Type, Binval, Extval},
 +                 __TopXMLNS) ->
 +    __NewTopXMLNS = choose_top_xmlns(<<"vcard-temp">>, [],
 +                                   __TopXMLNS),
 +    _els = lists:reverse('encode_vcard_PHOTO_$type'(Type,
 +                                                  __NewTopXMLNS,
 +                                                  'encode_vcard_PHOTO_$extval'(Extval,
 +                                                                               __NewTopXMLNS,
 +                                                                               'encode_vcard_PHOTO_$binval'(Binval,
 +                                                                                                            __NewTopXMLNS,
 +                                                                                                            [])))),
 +    _attrs = enc_xmlns_attrs(__NewTopXMLNS, __TopXMLNS),
 +    {xmlel, <<"PHOTO">>, _attrs, _els}.
 +
 +'encode_vcard_PHOTO_$type'(undefined, __TopXMLNS,
 +                         _acc) ->
 +    _acc;
 +'encode_vcard_PHOTO_$type'(Type, __TopXMLNS, _acc) ->
 +    [encode_vcard_TYPE(Type, __TopXMLNS) | _acc].
 +
 +'encode_vcard_PHOTO_$extval'(undefined, __TopXMLNS,
 +                           _acc) ->
 +    _acc;
 +'encode_vcard_PHOTO_$extval'(Extval, __TopXMLNS,
 +                           _acc) ->
 +    [encode_vcard_EXTVAL(Extval, __TopXMLNS) | _acc].
 +
 +'encode_vcard_PHOTO_$binval'(undefined, __TopXMLNS,
 +                           _acc) ->
 +    _acc;
 +'encode_vcard_PHOTO_$binval'(Binval, __TopXMLNS,
 +                           _acc) ->
 +    [encode_vcard_BINVAL(Binval, __TopXMLNS) | _acc].
 +
 +decode_vcard_LOGO(__TopXMLNS, __IgnoreEls,
 +                {xmlel, <<"LOGO">>, _attrs, _els}) ->
 +    {Type, Extval, Binval} =
 +      decode_vcard_LOGO_els(__TopXMLNS, __IgnoreEls, _els,
 +                            undefined, undefined, undefined),
 +    {vcard_logo, Type, Binval, Extval}.
 +
 +decode_vcard_LOGO_els(__TopXMLNS, __IgnoreEls, [], Type,
 +                    Extval, Binval) ->
 +    {Type, Extval, Binval};
 +decode_vcard_LOGO_els(__TopXMLNS, __IgnoreEls,
 +                    [{xmlel, <<"TYPE">>, _attrs, _} = _el | _els], Type,
 +                    Extval, Binval) ->
 +    case get_attr(<<"xmlns">>, _attrs) of
 +      <<"">> when __TopXMLNS == <<"vcard-temp">> ->
 +        decode_vcard_LOGO_els(__TopXMLNS, __IgnoreEls, _els,
 +                              decode_vcard_TYPE(__TopXMLNS, __IgnoreEls, _el),
 +                              Extval, Binval);
 +      <<"vcard-temp">> ->
 +        decode_vcard_LOGO_els(__TopXMLNS, __IgnoreEls, _els,
 +                              decode_vcard_TYPE(<<"vcard-temp">>, __IgnoreEls,
 +                                                _el),
 +                              Extval, Binval);
 +      _ ->
 +        decode_vcard_LOGO_els(__TopXMLNS, __IgnoreEls, _els,
 +                              Type, Extval, Binval)
 +    end;
 +decode_vcard_LOGO_els(__TopXMLNS, __IgnoreEls,
 +                    [{xmlel, <<"BINVAL">>, _attrs, _} = _el | _els], Type,
 +                    Extval, Binval) ->
 +    case get_attr(<<"xmlns">>, _attrs) of
 +      <<"">> when __TopXMLNS == <<"vcard-temp">> ->
 +        decode_vcard_LOGO_els(__TopXMLNS, __IgnoreEls, _els,
 +                              Type, Extval,
 +                              decode_vcard_BINVAL(__TopXMLNS, __IgnoreEls,
 +                                                  _el));
 +      <<"vcard-temp">> ->
 +        decode_vcard_LOGO_els(__TopXMLNS, __IgnoreEls, _els,
 +                              Type, Extval,
 +                              decode_vcard_BINVAL(<<"vcard-temp">>,
 +                                                  __IgnoreEls, _el));
 +      _ ->
 +        decode_vcard_LOGO_els(__TopXMLNS, __IgnoreEls, _els,
 +                              Type, Extval, Binval)
 +    end;
 +decode_vcard_LOGO_els(__TopXMLNS, __IgnoreEls,
 +                    [{xmlel, <<"EXTVAL">>, _attrs, _} = _el | _els], Type,
 +                    Extval, Binval) ->
 +    case get_attr(<<"xmlns">>, _attrs) of
 +      <<"">> when __TopXMLNS == <<"vcard-temp">> ->
 +        decode_vcard_LOGO_els(__TopXMLNS, __IgnoreEls, _els,
 +                              Type,
 +                              decode_vcard_EXTVAL(__TopXMLNS, __IgnoreEls,
 +                                                  _el),
 +                              Binval);
 +      <<"vcard-temp">> ->
 +        decode_vcard_LOGO_els(__TopXMLNS, __IgnoreEls, _els,
 +                              Type,
 +                              decode_vcard_EXTVAL(<<"vcard-temp">>,
 +                                                  __IgnoreEls, _el),
 +                              Binval);
 +      _ ->
 +        decode_vcard_LOGO_els(__TopXMLNS, __IgnoreEls, _els,
 +                              Type, Extval, Binval)
 +    end;
 +decode_vcard_LOGO_els(__TopXMLNS, __IgnoreEls,
 +                    [_ | _els], Type, Extval, Binval) ->
 +    decode_vcard_LOGO_els(__TopXMLNS, __IgnoreEls, _els,
 +                        Type, Extval, Binval).
 +
 +encode_vcard_LOGO({vcard_logo, Type, Binval, Extval},
 +                __TopXMLNS) ->
 +    __NewTopXMLNS = choose_top_xmlns(<<"vcard-temp">>, [],
 +                                   __TopXMLNS),
 +    _els = lists:reverse('encode_vcard_LOGO_$type'(Type,
 +                                                 __NewTopXMLNS,
 +                                                 'encode_vcard_LOGO_$extval'(Extval,
 +                                                                             __NewTopXMLNS,
 +                                                                             'encode_vcard_LOGO_$binval'(Binval,
 +                                                                                                         __NewTopXMLNS,
 +                                                                                                         [])))),
 +    _attrs = enc_xmlns_attrs(__NewTopXMLNS, __TopXMLNS),
 +    {xmlel, <<"LOGO">>, _attrs, _els}.
 +
 +'encode_vcard_LOGO_$type'(undefined, __TopXMLNS,
 +                        _acc) ->
 +    _acc;
 +'encode_vcard_LOGO_$type'(Type, __TopXMLNS, _acc) ->
 +    [encode_vcard_TYPE(Type, __TopXMLNS) | _acc].
 +
 +'encode_vcard_LOGO_$extval'(undefined, __TopXMLNS,
 +                          _acc) ->
 +    _acc;
 +'encode_vcard_LOGO_$extval'(Extval, __TopXMLNS, _acc) ->
 +    [encode_vcard_EXTVAL(Extval, __TopXMLNS) | _acc].
 +
 +'encode_vcard_LOGO_$binval'(undefined, __TopXMLNS,
 +                          _acc) ->
 +    _acc;
 +'encode_vcard_LOGO_$binval'(Binval, __TopXMLNS, _acc) ->
 +    [encode_vcard_BINVAL(Binval, __TopXMLNS) | _acc].
 +
 +decode_vcard_BINVAL(__TopXMLNS, __IgnoreEls,
 +                  {xmlel, <<"BINVAL">>, _attrs, _els}) ->
 +    Cdata = decode_vcard_BINVAL_els(__TopXMLNS, __IgnoreEls,
 +                                  _els, <<>>),
 +    Cdata.
 +
 +decode_vcard_BINVAL_els(__TopXMLNS, __IgnoreEls, [],
 +                      Cdata) ->
 +    decode_vcard_BINVAL_cdata(__TopXMLNS, Cdata);
 +decode_vcard_BINVAL_els(__TopXMLNS, __IgnoreEls,
 +                      [{xmlcdata, _data} | _els], Cdata) ->
 +    decode_vcard_BINVAL_els(__TopXMLNS, __IgnoreEls, _els,
 +                          <<Cdata/binary, _data/binary>>);
 +decode_vcard_BINVAL_els(__TopXMLNS, __IgnoreEls,
 +                      [_ | _els], Cdata) ->
 +    decode_vcard_BINVAL_els(__TopXMLNS, __IgnoreEls, _els,
 +                          Cdata).
 +
 +encode_vcard_BINVAL(Cdata, __TopXMLNS) ->
 +    __NewTopXMLNS = choose_top_xmlns(<<"vcard-temp">>, [],
 +                                   __TopXMLNS),
 +    _els = encode_vcard_BINVAL_cdata(Cdata, []),
 +    _attrs = enc_xmlns_attrs(__NewTopXMLNS, __TopXMLNS),
 +    {xmlel, <<"BINVAL">>, _attrs, _els}.
 +
 +decode_vcard_BINVAL_cdata(__TopXMLNS, <<>>) -> <<>>;
 +decode_vcard_BINVAL_cdata(__TopXMLNS, _val) ->
 +    case catch base64:decode(_val) of
 +      {'EXIT', _} ->
 +        erlang:error({xmpp_codec,
 +                      {bad_cdata_value, <<>>, <<"BINVAL">>, __TopXMLNS}});
 +      _res -> _res
 +    end.
 +
 +encode_vcard_BINVAL_cdata(<<>>, _acc) -> _acc;
 +encode_vcard_BINVAL_cdata(_val, _acc) ->
 +    [{xmlcdata, base64:encode(_val)} | _acc].
 +
 +decode_vcard_GEO(__TopXMLNS, __IgnoreEls,
 +               {xmlel, <<"GEO">>, _attrs, _els}) ->
 +    {Lat, Lon} = decode_vcard_GEO_els(__TopXMLNS,
 +                                    __IgnoreEls, _els, undefined, undefined),
 +    {vcard_geo, Lat, Lon}.
 +
 +decode_vcard_GEO_els(__TopXMLNS, __IgnoreEls, [], Lat,
 +                   Lon) ->
 +    {Lat, Lon};
 +decode_vcard_GEO_els(__TopXMLNS, __IgnoreEls,
 +                   [{xmlel, <<"LAT">>, _attrs, _} = _el | _els], Lat,
 +                   Lon) ->
 +    case get_attr(<<"xmlns">>, _attrs) of
 +      <<"">> when __TopXMLNS == <<"vcard-temp">> ->
 +        decode_vcard_GEO_els(__TopXMLNS, __IgnoreEls, _els,
 +                             decode_vcard_LAT(__TopXMLNS, __IgnoreEls, _el),
 +                             Lon);
 +      <<"vcard-temp">> ->
 +        decode_vcard_GEO_els(__TopXMLNS, __IgnoreEls, _els,
 +                             decode_vcard_LAT(<<"vcard-temp">>, __IgnoreEls,
 +                                              _el),
 +                             Lon);
 +      _ ->
 +        decode_vcard_GEO_els(__TopXMLNS, __IgnoreEls, _els, Lat,
 +                             Lon)
 +    end;
 +decode_vcard_GEO_els(__TopXMLNS, __IgnoreEls,
 +                   [{xmlel, <<"LON">>, _attrs, _} = _el | _els], Lat,
 +                   Lon) ->
 +    case get_attr(<<"xmlns">>, _attrs) of
 +      <<"">> when __TopXMLNS == <<"vcard-temp">> ->
 +        decode_vcard_GEO_els(__TopXMLNS, __IgnoreEls, _els, Lat,
 +                             decode_vcard_LON(__TopXMLNS, __IgnoreEls, _el));
 +      <<"vcard-temp">> ->
 +        decode_vcard_GEO_els(__TopXMLNS, __IgnoreEls, _els, Lat,
 +                             decode_vcard_LON(<<"vcard-temp">>, __IgnoreEls,
 +                                              _el));
 +      _ ->
 +        decode_vcard_GEO_els(__TopXMLNS, __IgnoreEls, _els, Lat,
 +                             Lon)
 +    end;
 +decode_vcard_GEO_els(__TopXMLNS, __IgnoreEls,
 +                   [_ | _els], Lat, Lon) ->
 +    decode_vcard_GEO_els(__TopXMLNS, __IgnoreEls, _els, Lat,
 +                       Lon).
 +
 +encode_vcard_GEO({vcard_geo, Lat, Lon}, __TopXMLNS) ->
 +    __NewTopXMLNS = choose_top_xmlns(<<"vcard-temp">>, [],
 +                                   __TopXMLNS),
 +    _els = lists:reverse('encode_vcard_GEO_$lat'(Lat,
 +                                               __NewTopXMLNS,
 +                                               'encode_vcard_GEO_$lon'(Lon,
 +                                                                       __NewTopXMLNS,
 +                                                                       []))),
 +    _attrs = enc_xmlns_attrs(__NewTopXMLNS, __TopXMLNS),
 +    {xmlel, <<"GEO">>, _attrs, _els}.
 +
 +'encode_vcard_GEO_$lat'(undefined, __TopXMLNS, _acc) ->
 +    _acc;
 +'encode_vcard_GEO_$lat'(Lat, __TopXMLNS, _acc) ->
 +    [encode_vcard_LAT(Lat, __TopXMLNS) | _acc].
 +
 +'encode_vcard_GEO_$lon'(undefined, __TopXMLNS, _acc) ->
 +    _acc;
 +'encode_vcard_GEO_$lon'(Lon, __TopXMLNS, _acc) ->
 +    [encode_vcard_LON(Lon, __TopXMLNS) | _acc].
 +
 +decode_vcard_EMAIL(__TopXMLNS, __IgnoreEls,
 +                 {xmlel, <<"EMAIL">>, _attrs, _els}) ->
 +    {X400, Userid, Internet, Home, Pref, Work} =
 +      decode_vcard_EMAIL_els(__TopXMLNS, __IgnoreEls, _els,
 +                             false, undefined, false, false, false, false),
 +    {vcard_email, Home, Work, Internet, Pref, X400, Userid}.
 +
 +decode_vcard_EMAIL_els(__TopXMLNS, __IgnoreEls, [],
 +                     X400, Userid, Internet, Home, Pref, Work) ->
 +    {X400, Userid, Internet, Home, Pref, Work};
 +decode_vcard_EMAIL_els(__TopXMLNS, __IgnoreEls,
 +                     [{xmlel, <<"HOME">>, _attrs, _} = _el | _els], X400,
 +                     Userid, Internet, Home, Pref, Work) ->
 +    case get_attr(<<"xmlns">>, _attrs) of
 +      <<"">> when __TopXMLNS == <<"vcard-temp">> ->
 +        decode_vcard_EMAIL_els(__TopXMLNS, __IgnoreEls, _els,
 +                               X400, Userid, Internet,
 +                               decode_vcard_HOME(__TopXMLNS, __IgnoreEls,
 +                                                 _el),
 +                               Pref, Work);
 +      <<"vcard-temp">> ->
 +        decode_vcard_EMAIL_els(__TopXMLNS, __IgnoreEls, _els,
 +                               X400, Userid, Internet,
 +                               decode_vcard_HOME(<<"vcard-temp">>,
 +                                                 __IgnoreEls, _el),
 +                               Pref, Work);
 +      _ ->
 +        decode_vcard_EMAIL_els(__TopXMLNS, __IgnoreEls, _els,
 +                               X400, Userid, Internet, Home, Pref, Work)
 +    end;
 +decode_vcard_EMAIL_els(__TopXMLNS, __IgnoreEls,
 +                     [{xmlel, <<"WORK">>, _attrs, _} = _el | _els], X400,
 +                     Userid, Internet, Home, Pref, Work) ->
 +    case get_attr(<<"xmlns">>, _attrs) of
 +      <<"">> when __TopXMLNS == <<"vcard-temp">> ->
 +        decode_vcard_EMAIL_els(__TopXMLNS, __IgnoreEls, _els,
 +                               X400, Userid, Internet, Home, Pref,
 +                               decode_vcard_WORK(__TopXMLNS, __IgnoreEls,
 +                                                 _el));
 +      <<"vcard-temp">> ->
 +        decode_vcard_EMAIL_els(__TopXMLNS, __IgnoreEls, _els,
 +                               X400, Userid, Internet, Home, Pref,
 +                               decode_vcard_WORK(<<"vcard-temp">>,
 +                                                 __IgnoreEls, _el));
 +      _ ->
 +        decode_vcard_EMAIL_els(__TopXMLNS, __IgnoreEls, _els,
 +                               X400, Userid, Internet, Home, Pref, Work)
 +    end;
 +decode_vcard_EMAIL_els(__TopXMLNS, __IgnoreEls,
 +                     [{xmlel, <<"INTERNET">>, _attrs, _} = _el | _els], X400,
 +                     Userid, Internet, Home, Pref, Work) ->
 +    case get_attr(<<"xmlns">>, _attrs) of
 +      <<"">> when __TopXMLNS == <<"vcard-temp">> ->
 +        decode_vcard_EMAIL_els(__TopXMLNS, __IgnoreEls, _els,
 +                               X400, Userid,
 +                               decode_vcard_INTERNET(__TopXMLNS, __IgnoreEls,
 +                                                     _el),
 +                               Home, Pref, Work);
 +      <<"vcard-temp">> ->
 +        decode_vcard_EMAIL_els(__TopXMLNS, __IgnoreEls, _els,
 +                               X400, Userid,
 +                               decode_vcard_INTERNET(<<"vcard-temp">>,
 +                                                     __IgnoreEls, _el),
 +                               Home, Pref, Work);
 +      _ ->
 +        decode_vcard_EMAIL_els(__TopXMLNS, __IgnoreEls, _els,
 +                               X400, Userid, Internet, Home, Pref, Work)
 +    end;
 +decode_vcard_EMAIL_els(__TopXMLNS, __IgnoreEls,
 +                     [{xmlel, <<"PREF">>, _attrs, _} = _el | _els], X400,
 +                     Userid, Internet, Home, Pref, Work) ->
 +    case get_attr(<<"xmlns">>, _attrs) of
 +      <<"">> when __TopXMLNS == <<"vcard-temp">> ->
 +        decode_vcard_EMAIL_els(__TopXMLNS, __IgnoreEls, _els,
 +                               X400, Userid, Internet, Home,
 +                               decode_vcard_PREF(__TopXMLNS, __IgnoreEls,
 +                                                 _el),
 +                               Work);
 +      <<"vcard-temp">> ->
 +        decode_vcard_EMAIL_els(__TopXMLNS, __IgnoreEls, _els,
 +                               X400, Userid, Internet, Home,
 +                               decode_vcard_PREF(<<"vcard-temp">>,
 +                                                 __IgnoreEls, _el),
 +                               Work);
 +      _ ->
 +        decode_vcard_EMAIL_els(__TopXMLNS, __IgnoreEls, _els,
 +                               X400, Userid, Internet, Home, Pref, Work)
 +    end;
 +decode_vcard_EMAIL_els(__TopXMLNS, __IgnoreEls,
 +                     [{xmlel, <<"X400">>, _attrs, _} = _el | _els], X400,
 +                     Userid, Internet, Home, Pref, Work) ->
 +    case get_attr(<<"xmlns">>, _attrs) of
 +      <<"">> when __TopXMLNS == <<"vcard-temp">> ->
 +        decode_vcard_EMAIL_els(__TopXMLNS, __IgnoreEls, _els,
 +                               decode_vcard_X400(__TopXMLNS, __IgnoreEls,
 +                                                 _el),
 +                               Userid, Internet, Home, Pref, Work);
 +      <<"vcard-temp">> ->
 +        decode_vcard_EMAIL_els(__TopXMLNS, __IgnoreEls, _els,
 +                               decode_vcard_X400(<<"vcard-temp">>,
 +                                                 __IgnoreEls, _el),
 +                               Userid, Internet, Home, Pref, Work);
 +      _ ->
 +        decode_vcard_EMAIL_els(__TopXMLNS, __IgnoreEls, _els,
 +                               X400, Userid, Internet, Home, Pref, Work)
 +    end;
 +decode_vcard_EMAIL_els(__TopXMLNS, __IgnoreEls,
 +                     [{xmlel, <<"USERID">>, _attrs, _} = _el | _els], X400,
 +                     Userid, Internet, Home, Pref, Work) ->
 +    case get_attr(<<"xmlns">>, _attrs) of
 +      <<"">> when __TopXMLNS == <<"vcard-temp">> ->
 +        decode_vcard_EMAIL_els(__TopXMLNS, __IgnoreEls, _els,
 +                               X400,
 +                               decode_vcard_USERID(__TopXMLNS, __IgnoreEls,
 +                                                   _el),
 +                               Internet, Home, Pref, Work);
 +      <<"vcard-temp">> ->
 +        decode_vcard_EMAIL_els(__TopXMLNS, __IgnoreEls, _els,
 +                               X400,
 +                               decode_vcard_USERID(<<"vcard-temp">>,
 +                                                   __IgnoreEls, _el),
 +                               Internet, Home, Pref, Work);
 +      _ ->
 +        decode_vcard_EMAIL_els(__TopXMLNS, __IgnoreEls, _els,
 +                               X400, Userid, Internet, Home, Pref, Work)
 +    end;
 +decode_vcard_EMAIL_els(__TopXMLNS, __IgnoreEls,
 +                     [_ | _els], X400, Userid, Internet, Home, Pref, Work) ->
 +    decode_vcard_EMAIL_els(__TopXMLNS, __IgnoreEls, _els,
 +                         X400, Userid, Internet, Home, Pref, Work).
 +
 +encode_vcard_EMAIL({vcard_email, Home, Work, Internet,
 +                  Pref, X400, Userid},
 +                 __TopXMLNS) ->
 +    __NewTopXMLNS = choose_top_xmlns(<<"vcard-temp">>, [],
 +                                   __TopXMLNS),
 +    _els = lists:reverse('encode_vcard_EMAIL_$x400'(X400,
 +                                                  __NewTopXMLNS,
 +                                                  'encode_vcard_EMAIL_$userid'(Userid,
 +                                                                               __NewTopXMLNS,
 +                                                                               'encode_vcard_EMAIL_$internet'(Internet,
 +                                                                                                              __NewTopXMLNS,
 +                                                                                                              'encode_vcard_EMAIL_$home'(Home,
 +                                                                                                                                         __NewTopXMLNS,
 +                                                                                                                                         'encode_vcard_EMAIL_$pref'(Pref,
 +                                                                                                                                                                    __NewTopXMLNS,
 +                                                                                                                                                                    'encode_vcard_EMAIL_$work'(Work,
 +                                                                                                                                                                                               __NewTopXMLNS,
 +                                                                                                                                                                                               []))))))),
 +    _attrs = enc_xmlns_attrs(__NewTopXMLNS, __TopXMLNS),
 +    {xmlel, <<"EMAIL">>, _attrs, _els}.
 +
 +'encode_vcard_EMAIL_$x400'(false, __TopXMLNS, _acc) ->
 +    _acc;
 +'encode_vcard_EMAIL_$x400'(X400, __TopXMLNS, _acc) ->
 +    [encode_vcard_X400(X400, __TopXMLNS) | _acc].
 +
 +'encode_vcard_EMAIL_$userid'(undefined, __TopXMLNS,
 +                           _acc) ->
 +    _acc;
 +'encode_vcard_EMAIL_$userid'(Userid, __TopXMLNS,
 +                           _acc) ->
 +    [encode_vcard_USERID(Userid, __TopXMLNS) | _acc].
 +
 +'encode_vcard_EMAIL_$internet'(false, __TopXMLNS,
 +                             _acc) ->
 +    _acc;
 +'encode_vcard_EMAIL_$internet'(Internet, __TopXMLNS,
 +                             _acc) ->
 +    [encode_vcard_INTERNET(Internet, __TopXMLNS) | _acc].
 +
 +'encode_vcard_EMAIL_$home'(false, __TopXMLNS, _acc) ->
 +    _acc;
 +'encode_vcard_EMAIL_$home'(Home, __TopXMLNS, _acc) ->
 +    [encode_vcard_HOME(Home, __TopXMLNS) | _acc].
 +
 +'encode_vcard_EMAIL_$pref'(false, __TopXMLNS, _acc) ->
 +    _acc;
 +'encode_vcard_EMAIL_$pref'(Pref, __TopXMLNS, _acc) ->
 +    [encode_vcard_PREF(Pref, __TopXMLNS) | _acc].
 +
 +'encode_vcard_EMAIL_$work'(false, __TopXMLNS, _acc) ->
 +    _acc;
 +'encode_vcard_EMAIL_$work'(Work, __TopXMLNS, _acc) ->
 +    [encode_vcard_WORK(Work, __TopXMLNS) | _acc].
 +
 +decode_vcard_TEL(__TopXMLNS, __IgnoreEls,
 +               {xmlel, <<"TEL">>, _attrs, _els}) ->
 +    {Number, Pager, Pcs, Bbs, Voice, Home, Pref, Msg, Fax,
 +     Work, Cell, Modem, Isdn, Video} =
 +      decode_vcard_TEL_els(__TopXMLNS, __IgnoreEls, _els,
 +                           undefined, false, false, false, false, false,
 +                           false, false, false, false, false, false, false,
 +                           false),
 +    {vcard_tel, Home, Work, Voice, Fax, Pager, Msg, Cell,
 +     Video, Bbs, Modem, Isdn, Pcs, Pref, Number}.
 +
 +decode_vcard_TEL_els(__TopXMLNS, __IgnoreEls, [],
 +                   Number, Pager, Pcs, Bbs, Voice, Home, Pref, Msg, Fax,
 +                   Work, Cell, Modem, Isdn, Video) ->
 +    {Number, Pager, Pcs, Bbs, Voice, Home, Pref, Msg, Fax,
 +     Work, Cell, Modem, Isdn, Video};
 +decode_vcard_TEL_els(__TopXMLNS, __IgnoreEls,
 +                   [{xmlel, <<"HOME">>, _attrs, _} = _el | _els], Number,
 +                   Pager, Pcs, Bbs, Voice, Home, Pref, Msg, Fax, Work,
 +                   Cell, Modem, Isdn, Video) ->
 +    case get_attr(<<"xmlns">>, _attrs) of
 +      <<"">> when __TopXMLNS == <<"vcard-temp">> ->
 +        decode_vcard_TEL_els(__TopXMLNS, __IgnoreEls, _els,
 +                             Number, Pager, Pcs, Bbs, Voice,
 +                             decode_vcard_HOME(__TopXMLNS, __IgnoreEls, _el),
 +                             Pref, Msg, Fax, Work, Cell, Modem, Isdn, Video);
 +      <<"vcard-temp">> ->
 +        decode_vcard_TEL_els(__TopXMLNS, __IgnoreEls, _els,
 +                             Number, Pager, Pcs, Bbs, Voice,
 +                             decode_vcard_HOME(<<"vcard-temp">>, __IgnoreEls,
 +                                               _el),
 +                             Pref, Msg, Fax, Work, Cell, Modem, Isdn, Video);
 +      _ ->
 +        decode_vcard_TEL_els(__TopXMLNS, __IgnoreEls, _els,
 +                             Number, Pager, Pcs, Bbs, Voice, Home, Pref, Msg,
 +                             Fax, Work, Cell, Modem, Isdn, Video)
 +    end;
 +decode_vcard_TEL_els(__TopXMLNS, __IgnoreEls,
 +                   [{xmlel, <<"WORK">>, _attrs, _} = _el | _els], Number,
 +                   Pager, Pcs, Bbs, Voice, Home, Pref, Msg, Fax, Work,
 +                   Cell, Modem, Isdn, Video) ->
 +    case get_attr(<<"xmlns">>, _attrs) of
 +      <<"">> when __TopXMLNS == <<"vcard-temp">> ->
 +        decode_vcard_TEL_els(__TopXMLNS, __IgnoreEls, _els,
 +                             Number, Pager, Pcs, Bbs, Voice, Home, Pref, Msg,
 +                             Fax,
 +                             decode_vcard_WORK(__TopXMLNS, __IgnoreEls, _el),
 +                             Cell, Modem, Isdn, Video);
 +      <<"vcard-temp">> ->
 +        decode_vcard_TEL_els(__TopXMLNS, __IgnoreEls, _els,
 +                             Number, Pager, Pcs, Bbs, Voice, Home, Pref, Msg,
 +                             Fax,
 +                             decode_vcard_WORK(<<"vcard-temp">>, __IgnoreEls,
 +                                               _el),
 +                             Cell, Modem, Isdn, Video);
 +      _ ->
 +        decode_vcard_TEL_els(__TopXMLNS, __IgnoreEls, _els,
 +                             Number, Pager, Pcs, Bbs, Voice, Home, Pref, Msg,
 +                             Fax, Work, Cell, Modem, Isdn, Video)
 +    end;
 +decode_vcard_TEL_els(__TopXMLNS, __IgnoreEls,
 +                   [{xmlel, <<"VOICE">>, _attrs, _} = _el | _els], Number,
 +                   Pager, Pcs, Bbs, Voice, Home, Pref, Msg, Fax, Work,
 +                   Cell, Modem, Isdn, Video) ->
 +    case get_attr(<<"xmlns">>, _attrs) of
 +      <<"">> when __TopXMLNS == <<"vcard-temp">> ->
 +        decode_vcard_TEL_els(__TopXMLNS, __IgnoreEls, _els,
 +                             Number, Pager, Pcs, Bbs,
 +                             decode_vcard_VOICE(__TopXMLNS, __IgnoreEls, _el),
 +                             Home, Pref, Msg, Fax, Work, Cell, Modem, Isdn,
 +                             Video);
 +      <<"vcard-temp">> ->
 +        decode_vcard_TEL_els(__TopXMLNS, __IgnoreEls, _els,
 +                             Number, Pager, Pcs, Bbs,
 +                             decode_vcard_VOICE(<<"vcard-temp">>, __IgnoreEls,
 +                                                _el),
 +                             Home, Pref, Msg, Fax, Work, Cell, Modem, Isdn,
 +                             Video);
 +      _ ->
 +        decode_vcard_TEL_els(__TopXMLNS, __IgnoreEls, _els,
 +                             Number, Pager, Pcs, Bbs, Voice, Home, Pref, Msg,
 +                             Fax, Work, Cell, Modem, Isdn, Video)
 +    end;
 +decode_vcard_TEL_els(__TopXMLNS, __IgnoreEls,
 +                   [{xmlel, <<"FAX">>, _attrs, _} = _el | _els], Number,
 +                   Pager, Pcs, Bbs, Voice, Home, Pref, Msg, Fax, Work,
 +                   Cell, Modem, Isdn, Video) ->
 +    case get_attr(<<"xmlns">>, _attrs) of
 +      <<"">> when __TopXMLNS == <<"vcard-temp">> ->
 +        decode_vcard_TEL_els(__TopXMLNS, __IgnoreEls, _els,
 +                             Number, Pager, Pcs, Bbs, Voice, Home, Pref, Msg,
 +                             decode_vcard_FAX(__TopXMLNS, __IgnoreEls, _el),
 +                             Work, Cell, Modem, Isdn, Video);
 +      <<"vcard-temp">> ->
 +        decode_vcard_TEL_els(__TopXMLNS, __IgnoreEls, _els,
 +                             Number, Pager, Pcs, Bbs, Voice, Home, Pref, Msg,
 +                             decode_vcard_FAX(<<"vcard-temp">>, __IgnoreEls,
 +                                              _el),
 +                             Work, Cell, Modem, Isdn, Video);
 +      _ ->
 +        decode_vcard_TEL_els(__TopXMLNS, __IgnoreEls, _els,
 +                             Number, Pager, Pcs, Bbs, Voice, Home, Pref, Msg,
 +                             Fax, Work, Cell, Modem, Isdn, Video)
 +    end;
 +decode_vcard_TEL_els(__TopXMLNS, __IgnoreEls,
 +                   [{xmlel, <<"PAGER">>, _attrs, _} = _el | _els], Number,
 +                   Pager, Pcs, Bbs, Voice, Home, Pref, Msg, Fax, Work,
 +                   Cell, Modem, Isdn, Video) ->
 +    case get_attr(<<"xmlns">>, _attrs) of
 +      <<"">> when __TopXMLNS == <<"vcard-temp">> ->
 +        decode_vcard_TEL_els(__TopXMLNS, __IgnoreEls, _els,
 +                             Number,
 +                             decode_vcard_PAGER(__TopXMLNS, __IgnoreEls, _el),
 +                             Pcs, Bbs, Voice, Home, Pref, Msg, Fax, Work,
 +                             Cell, Modem, Isdn, Video);
 +      <<"vcard-temp">> ->
 +        decode_vcard_TEL_els(__TopXMLNS, __IgnoreEls, _els,
 +                             Number,
 +                             decode_vcard_PAGER(<<"vcard-temp">>, __IgnoreEls,
 +                                                _el),
 +                             Pcs, Bbs, Voice, Home, Pref, Msg, Fax, Work,
 +                             Cell, Modem, Isdn, Video);
 +      _ ->
 +        decode_vcard_TEL_els(__TopXMLNS, __IgnoreEls, _els,
 +                             Number, Pager, Pcs, Bbs, Voice, Home, Pref, Msg,
 +                             Fax, Work, Cell, Modem, Isdn, Video)
 +    end;
 +decode_vcard_TEL_els(__TopXMLNS, __IgnoreEls,
 +                   [{xmlel, <<"MSG">>, _attrs, _} = _el | _els], Number,
 +                   Pager, Pcs, Bbs, Voice, Home, Pref, Msg, Fax, Work,
 +                   Cell, Modem, Isdn, Video) ->
 +    case get_attr(<<"xmlns">>, _attrs) of
 +      <<"">> when __TopXMLNS == <<"vcard-temp">> ->
 +        decode_vcard_TEL_els(__TopXMLNS, __IgnoreEls, _els,
 +                             Number, Pager, Pcs, Bbs, Voice, Home, Pref,
 +                             decode_vcard_MSG(__TopXMLNS, __IgnoreEls, _el),
 +                             Fax, Work, Cell, Modem, Isdn, Video);
 +      <<"vcard-temp">> ->
 +        decode_vcard_TEL_els(__TopXMLNS, __IgnoreEls, _els,
 +                             Number, Pager, Pcs, Bbs, Voice, Home, Pref,
 +                             decode_vcard_MSG(<<"vcard-temp">>, __IgnoreEls,
 +                                              _el),
 +                             Fax, Work, Cell, Modem, Isdn, Video);
 +      _ ->
 +        decode_vcard_TEL_els(__TopXMLNS, __IgnoreEls, _els,
 +                             Number, Pager, Pcs, Bbs, Voice, Home, Pref, Msg,
 +                             Fax, Work, Cell, Modem, Isdn, Video)
 +    end;
 +decode_vcard_TEL_els(__TopXMLNS, __IgnoreEls,
 +                   [{xmlel, <<"CELL">>, _attrs, _} = _el | _els], Number,
 +                   Pager, Pcs, Bbs, Voice, Home, Pref, Msg, Fax, Work,
 +                   Cell, Modem, Isdn, Video) ->
 +    case get_attr(<<"xmlns">>, _attrs) of
 +      <<"">> when __TopXMLNS == <<"vcard-temp">> ->
 +        decode_vcard_TEL_els(__TopXMLNS, __IgnoreEls, _els,
 +                             Number, Pager, Pcs, Bbs, Voice, Home, Pref, Msg,
 +                             Fax, Work,
 +                             decode_vcard_CELL(__TopXMLNS, __IgnoreEls, _el),
 +                             Modem, Isdn, Video);
 +      <<"vcard-temp">> ->
 +        decode_vcard_TEL_els(__TopXMLNS, __IgnoreEls, _els,
 +                             Number, Pager, Pcs, Bbs, Voice, Home, Pref, Msg,
 +                             Fax, Work,
 +                             decode_vcard_CELL(<<"vcard-temp">>, __IgnoreEls,
 +                                               _el),
 +                             Modem, Isdn, Video);
 +      _ ->
 +        decode_vcard_TEL_els(__TopXMLNS, __IgnoreEls, _els,
 +                             Number, Pager, Pcs, Bbs, Voice, Home, Pref, Msg,
 +                             Fax, Work, Cell, Modem, Isdn, Video)
 +    end;
 +decode_vcard_TEL_els(__TopXMLNS, __IgnoreEls,
 +                   [{xmlel, <<"VIDEO">>, _attrs, _} = _el | _els], Number,
 +                   Pager, Pcs, Bbs, Voice, Home, Pref, Msg, Fax, Work,
 +                   Cell, Modem, Isdn, Video) ->
 +    case get_attr(<<"xmlns">>, _attrs) of
 +      <<"">> when __TopXMLNS == <<"vcard-temp">> ->
 +        decode_vcard_TEL_els(__TopXMLNS, __IgnoreEls, _els,
 +                             Number, Pager, Pcs, Bbs, Voice, Home, Pref, Msg,
 +                             Fax, Work, Cell, Modem, Isdn,
 +                             decode_vcard_VIDEO(__TopXMLNS, __IgnoreEls,
 +                                                _el));
 +      <<"vcard-temp">> ->
 +        decode_vcard_TEL_els(__TopXMLNS, __IgnoreEls, _els,
 +                             Number, Pager, Pcs, Bbs, Voice, Home, Pref, Msg,
 +                             Fax, Work, Cell, Modem, Isdn,
 +                             decode_vcard_VIDEO(<<"vcard-temp">>, __IgnoreEls,
 +                                                _el));
 +      _ ->
 +        decode_vcard_TEL_els(__TopXMLNS, __IgnoreEls, _els,
 +                             Number, Pager, Pcs, Bbs, Voice, Home, Pref, Msg,
 +                             Fax, Work, Cell, Modem, Isdn, Video)
 +    end;
 +decode_vcard_TEL_els(__TopXMLNS, __IgnoreEls,
 +                   [{xmlel, <<"BBS">>, _attrs, _} = _el | _els], Number,
 +                   Pager, Pcs, Bbs, Voice, Home, Pref, Msg, Fax, Work,
 +                   Cell, Modem, Isdn, Video) ->
 +    case get_attr(<<"xmlns">>, _attrs) of
 +      <<"">> when __TopXMLNS == <<"vcard-temp">> ->
 +        decode_vcard_TEL_els(__TopXMLNS, __IgnoreEls, _els,
 +                             Number, Pager, Pcs,
 +                             decode_vcard_BBS(__TopXMLNS, __IgnoreEls, _el),
 +                             Voice, Home, Pref, Msg, Fax, Work, Cell, Modem,
 +                             Isdn, Video);
 +      <<"vcard-temp">> ->
 +        decode_vcard_TEL_els(__TopXMLNS, __IgnoreEls, _els,
 +                             Number, Pager, Pcs,
 +                             decode_vcard_BBS(<<"vcard-temp">>, __IgnoreEls,
 +                                              _el),
 +                             Voice, Home, Pref, Msg, Fax, Work, Cell, Modem,
 +                             Isdn, Video);
 +      _ ->
 +        decode_vcard_TEL_els(__TopXMLNS, __IgnoreEls, _els,
 +                             Number, Pager, Pcs, Bbs, Voice, Home, Pref, Msg,
 +                             Fax, Work, Cell, Modem, Isdn, Video)
 +    end;
 +decode_vcard_TEL_els(__TopXMLNS, __IgnoreEls,
 +                   [{xmlel, <<"MODEM">>, _attrs, _} = _el | _els], Number,
 +                   Pager, Pcs, Bbs, Voice, Home, Pref, Msg, Fax, Work,
 +                   Cell, Modem, Isdn, Video) ->
 +    case get_attr(<<"xmlns">>, _attrs) of
 +      <<"">> when __TopXMLNS == <<"vcard-temp">> ->
 +        decode_vcard_TEL_els(__TopXMLNS, __IgnoreEls, _els,
 +                             Number, Pager, Pcs, Bbs, Voice, Home, Pref, Msg,
 +                             Fax, Work, Cell,
 +                             decode_vcard_MODEM(__TopXMLNS, __IgnoreEls, _el),
 +                             Isdn, Video);
 +      <<"vcard-temp">> ->
 +        decode_vcard_TEL_els(__TopXMLNS, __IgnoreEls, _els,
 +                             Number, Pager, Pcs, Bbs, Voice, Home, Pref, Msg,
 +                             Fax, Work, Cell,
 +                             decode_vcard_MODEM(<<"vcard-temp">>, __IgnoreEls,
 +                                                _el),
 +                             Isdn, Video);
 +      _ ->
 +        decode_vcard_TEL_els(__TopXMLNS, __IgnoreEls, _els,
 +                             Number, Pager, Pcs, Bbs, Voice, Home, Pref, Msg,
 +                             Fax, Work, Cell, Modem, Isdn, Video)
 +    end;
 +decode_vcard_TEL_els(__TopXMLNS, __IgnoreEls,
 +                   [{xmlel, <<"ISDN">>, _attrs, _} = _el | _els], Number,
 +                   Pager, Pcs, Bbs, Voice, Home, Pref, Msg, Fax, Work,
 +                   Cell, Modem, Isdn, Video) ->
 +    case get_attr(<<"xmlns">>, _attrs) of
 +      <<"">> when __TopXMLNS == <<"vcard-temp">> ->
 +        decode_vcard_TEL_els(__TopXMLNS, __IgnoreEls, _els,
 +                             Number, Pager, Pcs, Bbs, Voice, Home, Pref, Msg,
 +                             Fax, Work, Cell, Modem,
 +                             decode_vcard_ISDN(__TopXMLNS, __IgnoreEls, _el),
 +                             Video);
 +      <<"vcard-temp">> ->
 +        decode_vcard_TEL_els(__TopXMLNS, __IgnoreEls, _els,
 +                             Number, Pager, Pcs, Bbs, Voice, Home, Pref, Msg,
 +                             Fax, Work, Cell, Modem,
 +                             decode_vcard_ISDN(<<"vcard-temp">>, __IgnoreEls,
 +                                               _el),
 +                             Video);
 +      _ ->
 +        decode_vcard_TEL_els(__TopXMLNS, __IgnoreEls, _els,
 +                             Number, Pager, Pcs, Bbs, Voice, Home, Pref, Msg,
 +                             Fax, Work, Cell, Modem, Isdn, Video)
 +    end;
 +decode_vcard_TEL_els(__TopXMLNS, __IgnoreEls,
 +                   [{xmlel, <<"PCS">>, _attrs, _} = _el | _els], Number,
 +                   Pager, Pcs, Bbs, Voice, Home, Pref, Msg, Fax, Work,
 +                   Cell, Modem, Isdn, Video) ->
 +    case get_attr(<<"xmlns">>, _attrs) of
 +      <<"">> when __TopXMLNS == <<"vcard-temp">> ->
 +        decode_vcard_TEL_els(__TopXMLNS, __IgnoreEls, _els,
 +                             Number, Pager,
 +                             decode_vcard_PCS(__TopXMLNS, __IgnoreEls, _el),
 +                             Bbs, Voice, Home, Pref, Msg, Fax, Work, Cell,
 +                             Modem, Isdn, Video);
 +      <<"vcard-temp">> ->
 +        decode_vcard_TEL_els(__TopXMLNS, __IgnoreEls, _els,
 +                             Number, Pager,
 +                             decode_vcard_PCS(<<"vcard-temp">>, __IgnoreEls,
 +                                              _el),
 +                             Bbs, Voice, Home, Pref, Msg, Fax, Work, Cell,
 +                             Modem, Isdn, Video);
 +      _ ->
 +        decode_vcard_TEL_els(__TopXMLNS, __IgnoreEls, _els,
 +                             Number, Pager, Pcs, Bbs, Voice, Home, Pref, Msg,
 +                             Fax, Work, Cell, Modem, Isdn, Video)
 +    end;
 +decode_vcard_TEL_els(__TopXMLNS, __IgnoreEls,
 +                   [{xmlel, <<"PREF">>, _attrs, _} = _el | _els], Number,
 +                   Pager, Pcs, Bbs, Voice, Home, Pref, Msg, Fax, Work,
 +                   Cell, Modem, Isdn, Video) ->
 +    case get_attr(<<"xmlns">>, _attrs) of
 +      <<"">> when __TopXMLNS == <<"vcard-temp">> ->
 +        decode_vcard_TEL_els(__TopXMLNS, __IgnoreEls, _els,
 +                             Number, Pager, Pcs, Bbs, Voice, Home,
 +                             decode_vcard_PREF(__TopXMLNS, __IgnoreEls, _el),
 +                             Msg, Fax, Work, Cell, Modem, Isdn, Video);
 +      <<"vcard-temp">> ->
 +        decode_vcard_TEL_els(__TopXMLNS, __IgnoreEls, _els,
 +                             Number, Pager, Pcs, Bbs, Voice, Home,
 +                             decode_vcard_PREF(<<"vcard-temp">>, __IgnoreEls,
 +                                               _el),
 +                             Msg, Fax, Work, Cell, Modem, Isdn, Video);
 +      _ ->
 +        decode_vcard_TEL_els(__TopXMLNS, __IgnoreEls, _els,
 +                             Number, Pager, Pcs, Bbs, Voice, Home, Pref, Msg,
 +                             Fax, Work, Cell, Modem, Isdn, Video)
 +    end;
 +decode_vcard_TEL_els(__TopXMLNS, __IgnoreEls,
 +                   [{xmlel, <<"NUMBER">>, _attrs, _} = _el | _els], Number,
 +                   Pager, Pcs, Bbs, Voice, Home, Pref, Msg, Fax, Work,
 +                   Cell, Modem, Isdn, Video) ->
 +    case get_attr(<<"xmlns">>, _attrs) of
 +      <<"">> when __TopXMLNS == <<"vcard-temp">> ->
 +        decode_vcard_TEL_els(__TopXMLNS, __IgnoreEls, _els,
 +                             decode_vcard_NUMBER(__TopXMLNS, __IgnoreEls,
 +                                                 _el),
 +                             Pager, Pcs, Bbs, Voice, Home, Pref, Msg, Fax,
 +                             Work, Cell, Modem, Isdn, Video);
 +      <<"vcard-temp">> ->
 +        decode_vcard_TEL_els(__TopXMLNS, __IgnoreEls, _els,
 +                             decode_vcard_NUMBER(<<"vcard-temp">>,
 +                                                 __IgnoreEls, _el),
 +                             Pager, Pcs, Bbs, Voice, Home, Pref, Msg, Fax,
 +                             Work, Cell, Modem, Isdn, Video);
 +      _ ->
 +        decode_vcard_TEL_els(__TopXMLNS, __IgnoreEls, _els,
 +                             Number, Pager, Pcs, Bbs, Voice, Home, Pref, Msg,
 +                             Fax, Work, Cell, Modem, Isdn, Video)
 +    end;
 +decode_vcard_TEL_els(__TopXMLNS, __IgnoreEls,
 +                   [_ | _els], Number, Pager, Pcs, Bbs, Voice, Home, Pref,
 +                   Msg, Fax, Work, Cell, Modem, Isdn, Video) ->
 +    decode_vcard_TEL_els(__TopXMLNS, __IgnoreEls, _els,
 +                       Number, Pager, Pcs, Bbs, Voice, Home, Pref, Msg, Fax,
 +                       Work, Cell, Modem, Isdn, Video).
 +
 +encode_vcard_TEL({vcard_tel, Home, Work, Voice, Fax,
 +                Pager, Msg, Cell, Video, Bbs, Modem, Isdn, Pcs, Pref,
 +                Number},
 +               __TopXMLNS) ->
 +    __NewTopXMLNS = choose_top_xmlns(<<"vcard-temp">>, [],
 +                                   __TopXMLNS),
 +    _els = lists:reverse('encode_vcard_TEL_$number'(Number,
 +                                                  __NewTopXMLNS,
 +                                                  'encode_vcard_TEL_$pager'(Pager,
 +                                                                            __NewTopXMLNS,
 +                                                                            'encode_vcard_TEL_$pcs'(Pcs,
 +                                                                                                    __NewTopXMLNS,
 +                                                                                                    'encode_vcard_TEL_$bbs'(Bbs,
 +                                                                                                                            __NewTopXMLNS,
 +                                                                                                                            'encode_vcard_TEL_$voice'(Voice,
 +                                                                                                                                                      __NewTopXMLNS,
 +                                                                                                                                                      'encode_vcard_TEL_$home'(Home,
 +                                                                                                                                                                               __NewTopXMLNS,
 +                                                                                                                                                                               'encode_vcard_TEL_$pref'(Pref,
 +                                                                                                                                                                                                        __NewTopXMLNS,
 +                                                                                                                                                                                                        'encode_vcard_TEL_$msg'(Msg,
 +                                                                                                                                                                                                                                __NewTopXMLNS,
 +                                                                                                                                                                                                                                'encode_vcard_TEL_$fax'(Fax,
 +                                                                                                                                                                                                                                                        __NewTopXMLNS,
 +                                                                                                                                                                                                                                                        'encode_vcard_TEL_$work'(Work,
 +                                                                                                                                                                                                                                                                                 __NewTopXMLNS,
 +                                                                                                                                                                                                                                                                                 'encode_vcard_TEL_$cell'(Cell,
 +                                                                                                                                                                                                                                                                                                          __NewTopXMLNS,
 +                                                                                                                                                                                                                                                                                                          'encode_vcard_TEL_$modem'(Modem,
 +                                                                                                                                                                                                                                                                                                                                    __NewTopXMLNS,
 +                                                                                                                                                                                                                                                                                                                                    'encode_vcard_TEL_$isdn'(Isdn,
 +                                                                                                                                                                                                                                                                                                                                                             __NewTopXMLNS,
 +                                                                                                                                                                                                                                                                                                                                                             'encode_vcard_TEL_$video'(Video,
 +                                                                                                                                                                                                                                                                                                                                                                                       __NewTopXMLNS,
 +                                                                                                                                                                                                                                                                                                                                                                                       []))))))))))))))),
 +    _attrs = enc_xmlns_attrs(__NewTopXMLNS, __TopXMLNS),
 +    {xmlel, <<"TEL">>, _attrs, _els}.
 +
 +'encode_vcard_TEL_$number'(undefined, __TopXMLNS,
 +                         _acc) ->
 +    _acc;
 +'encode_vcard_TEL_$number'(Number, __TopXMLNS, _acc) ->
 +    [encode_vcard_NUMBER(Number, __TopXMLNS) | _acc].
 +
 +'encode_vcard_TEL_$pager'(false, __TopXMLNS, _acc) ->
 +    _acc;
 +'encode_vcard_TEL_$pager'(Pager, __TopXMLNS, _acc) ->
 +    [encode_vcard_PAGER(Pager, __TopXMLNS) | _acc].
 +
 +'encode_vcard_TEL_$pcs'(false, __TopXMLNS, _acc) ->
 +    _acc;
 +'encode_vcard_TEL_$pcs'(Pcs, __TopXMLNS, _acc) ->
 +    [encode_vcard_PCS(Pcs, __TopXMLNS) | _acc].
 +
 +'encode_vcard_TEL_$bbs'(false, __TopXMLNS, _acc) ->
 +    _acc;
 +'encode_vcard_TEL_$bbs'(Bbs, __TopXMLNS, _acc) ->
 +    [encode_vcard_BBS(Bbs, __TopXMLNS) | _acc].
 +
 +'encode_vcard_TEL_$voice'(false, __TopXMLNS, _acc) ->
 +    _acc;
 +'encode_vcard_TEL_$voice'(Voice, __TopXMLNS, _acc) ->
 +    [encode_vcard_VOICE(Voice, __TopXMLNS) | _acc].
 +
 +'encode_vcard_TEL_$home'(false, __TopXMLNS, _acc) ->
 +    _acc;
 +'encode_vcard_TEL_$home'(Home, __TopXMLNS, _acc) ->
 +    [encode_vcard_HOME(Home, __TopXMLNS) | _acc].
 +
 +'encode_vcard_TEL_$pref'(false, __TopXMLNS, _acc) ->
 +    _acc;
 +'encode_vcard_TEL_$pref'(Pref, __TopXMLNS, _acc) ->
 +    [encode_vcard_PREF(Pref, __TopXMLNS) | _acc].
 +
 +'encode_vcard_TEL_$msg'(false, __TopXMLNS, _acc) ->
 +    _acc;
 +'encode_vcard_TEL_$msg'(Msg, __TopXMLNS, _acc) ->
 +    [encode_vcard_MSG(Msg, __TopXMLNS) | _acc].
 +
 +'encode_vcard_TEL_$fax'(false, __TopXMLNS, _acc) ->
 +    _acc;
 +'encode_vcard_TEL_$fax'(Fax, __TopXMLNS, _acc) ->
 +    [encode_vcard_FAX(Fax, __TopXMLNS) | _acc].
 +
 +'encode_vcard_TEL_$work'(false, __TopXMLNS, _acc) ->
 +    _acc;
 +'encode_vcard_TEL_$work'(Work, __TopXMLNS, _acc) ->
 +    [encode_vcard_WORK(Work, __TopXMLNS) | _acc].
 +
 +'encode_vcard_TEL_$cell'(false, __TopXMLNS, _acc) ->
 +    _acc;
 +'encode_vcard_TEL_$cell'(Cell, __TopXMLNS, _acc) ->
 +    [encode_vcard_CELL(Cell, __TopXMLNS) | _acc].
 +
 +'encode_vcard_TEL_$modem'(false, __TopXMLNS, _acc) ->
 +    _acc;
 +'encode_vcard_TEL_$modem'(Modem, __TopXMLNS, _acc) ->
 +    [encode_vcard_MODEM(Modem, __TopXMLNS) | _acc].
 +
 +'encode_vcard_TEL_$isdn'(false, __TopXMLNS, _acc) ->
 +    _acc;
 +'encode_vcard_TEL_$isdn'(Isdn, __TopXMLNS, _acc) ->
 +    [encode_vcard_ISDN(Isdn, __TopXMLNS) | _acc].
 +
 +'encode_vcard_TEL_$video'(false, __TopXMLNS, _acc) ->
 +    _acc;
 +'encode_vcard_TEL_$video'(Video, __TopXMLNS, _acc) ->
 +    [encode_vcard_VIDEO(Video, __TopXMLNS) | _acc].
 +
 +decode_vcard_LABEL(__TopXMLNS, __IgnoreEls,
 +                 {xmlel, <<"LABEL">>, _attrs, _els}) ->
 +    {Line, Home, Pref, Work, Intl, Parcel, Postal, Dom} =
 +      decode_vcard_LABEL_els(__TopXMLNS, __IgnoreEls, _els,
 +                             [], false, false, false, false, false, false,
 +                             false),
 +    {vcard_label, Home, Work, Postal, Parcel, Dom, Intl,
 +     Pref, Line}.
 +
 +decode_vcard_LABEL_els(__TopXMLNS, __IgnoreEls, [],
 +                     Line, Home, Pref, Work, Intl, Parcel, Postal, Dom) ->
 +    {lists:reverse(Line), Home, Pref, Work, Intl, Parcel,
 +     Postal, Dom};
 +decode_vcard_LABEL_els(__TopXMLNS, __IgnoreEls,
 +                     [{xmlel, <<"HOME">>, _attrs, _} = _el | _els], Line,
 +                     Home, Pref, Work, Intl, Parcel, Postal, Dom) ->
 +    case get_attr(<<"xmlns">>, _attrs) of
 +      <<"">> when __TopXMLNS == <<"vcard-temp">> ->
 +        decode_vcard_LABEL_els(__TopXMLNS, __IgnoreEls, _els,
 +                               Line,
 +                               decode_vcard_HOME(__TopXMLNS, __IgnoreEls,
 +                                                 _el),
 +                               Pref, Work, Intl, Parcel, Postal, Dom);
 +      <<"vcard-temp">> ->
 +        decode_vcard_LABEL_els(__TopXMLNS, __IgnoreEls, _els,
 +                               Line,
 +                               decode_vcard_HOME(<<"vcard-temp">>,
 +                                                 __IgnoreEls, _el),
 +                               Pref, Work, Intl, Parcel, Postal, Dom);
 +      _ ->
 +        decode_vcard_LABEL_els(__TopXMLNS, __IgnoreEls, _els,
 +                               Line, Home, Pref, Work, Intl, Parcel, Postal,
 +                               Dom)
 +    end;
 +decode_vcard_LABEL_els(__TopXMLNS, __IgnoreEls,
 +                     [{xmlel, <<"WORK">>, _attrs, _} = _el | _els], Line,
 +                     Home, Pref, Work, Intl, Parcel, Postal, Dom) ->
 +    case get_attr(<<"xmlns">>, _attrs) of
 +      <<"">> when __TopXMLNS == <<"vcard-temp">> ->
 +        decode_vcard_LABEL_els(__TopXMLNS, __IgnoreEls, _els,
 +                               Line, Home, Pref,
 +                               decode_vcard_WORK(__TopXMLNS, __IgnoreEls,
 +                                                 _el),
 +                               Intl, Parcel, Postal, Dom);
 +      <<"vcard-temp">> ->
 +        decode_vcard_LABEL_els(__TopXMLNS, __IgnoreEls, _els,
 +                               Line, Home, Pref,
 +                               decode_vcard_WORK(<<"vcard-temp">>,
 +                                                 __IgnoreEls, _el),
 +                               Intl, Parcel, Postal, Dom);
 +      _ ->
 +        decode_vcard_LABEL_els(__TopXMLNS, __IgnoreEls, _els,
 +                               Line, Home, Pref, Work, Intl, Parcel, Postal,
 +                               Dom)
 +    end;
 +decode_vcard_LABEL_els(__TopXMLNS, __IgnoreEls,
 +                     [{xmlel, <<"POSTAL">>, _attrs, _} = _el | _els], Line,
 +                     Home, Pref, Work, Intl, Parcel, Postal, Dom) ->
 +    case get_attr(<<"xmlns">>, _attrs) of
 +      <<"">> when __TopXMLNS == <<"vcard-temp">> ->
 +        decode_vcard_LABEL_els(__TopXMLNS, __IgnoreEls, _els,
 +                               Line, Home, Pref, Work, Intl, Parcel,
 +                               decode_vcard_POSTAL(__TopXMLNS, __IgnoreEls,
 +                                                   _el),
 +                               Dom);
 +      <<"vcard-temp">> ->
 +        decode_vcard_LABEL_els(__TopXMLNS, __IgnoreEls, _els,
 +                               Line, Home, Pref, Work, Intl, Parcel,
 +                               decode_vcard_POSTAL(<<"vcard-temp">>,
 +                                                   __IgnoreEls, _el),
 +                               Dom);
 +      _ ->
 +        decode_vcard_LABEL_els(__TopXMLNS, __IgnoreEls, _els,
 +                               Line, Home, Pref, Work, Intl, Parcel, Postal,
 +                               Dom)
 +    end;
 +decode_vcard_LABEL_els(__TopXMLNS, __IgnoreEls,
 +                     [{xmlel, <<"PARCEL">>, _attrs, _} = _el | _els], Line,
 +                     Home, Pref, Work, Intl, Parcel, Postal, Dom) ->
 +    case get_attr(<<"xmlns">>, _attrs) of
 +      <<"">> when __TopXMLNS == <<"vcard-temp">> ->
 +        decode_vcard_LABEL_els(__TopXMLNS, __IgnoreEls, _els,
 +                               Line, Home, Pref, Work, Intl,
 +                               decode_vcard_PARCEL(__TopXMLNS, __IgnoreEls,
 +                                                   _el),
 +                               Postal, Dom);
 +      <<"vcard-temp">> ->
 +        decode_vcard_LABEL_els(__TopXMLNS, __IgnoreEls, _els,
 +                               Line, Home, Pref, Work, Intl,
 +                               decode_vcard_PARCEL(<<"vcard-temp">>,
 +                                                   __IgnoreEls, _el),
 +                               Postal, Dom);
 +      _ ->
 +        decode_vcard_LABEL_els(__TopXMLNS, __IgnoreEls, _els,
 +                               Line, Home, Pref, Work, Intl, Parcel, Postal,
 +                               Dom)
 +    end;
 +decode_vcard_LABEL_els(__TopXMLNS, __IgnoreEls,
 +                     [{xmlel, <<"DOM">>, _attrs, _} = _el | _els], Line,
 +                     Home, Pref, Work, Intl, Parcel, Postal, Dom) ->
 +    case get_attr(<<"xmlns">>, _attrs) of
 +      <<"">> when __TopXMLNS == <<"vcard-temp">> ->
 +        decode_vcard_LABEL_els(__TopXMLNS, __IgnoreEls, _els,
 +                               Line, Home, Pref, Work, Intl, Parcel, Postal,
 +                               decode_vcard_DOM(__TopXMLNS, __IgnoreEls,
 +                                                _el));
 +      <<"vcard-temp">> ->
 +        decode_vcard_LABEL_els(__TopXMLNS, __IgnoreEls, _els,
 +                               Line, Home, Pref, Work, Intl, Parcel, Postal,
 +                               decode_vcard_DOM(<<"vcard-temp">>, __IgnoreEls,
 +                                                _el));
 +      _ ->
 +        decode_vcard_LABEL_els(__TopXMLNS, __IgnoreEls, _els,
 +                               Line, Home, Pref, Work, Intl, Parcel, Postal,
 +                               Dom)
 +    end;
 +decode_vcard_LABEL_els(__TopXMLNS, __IgnoreEls,
 +                     [{xmlel, <<"INTL">>, _attrs, _} = _el | _els], Line,
 +                     Home, Pref, Work, Intl, Parcel, Postal, Dom) ->
 +    case get_attr(<<"xmlns">>, _attrs) of
 +      <<"">> when __TopXMLNS == <<"vcard-temp">> ->
 +        decode_vcard_LABEL_els(__TopXMLNS, __IgnoreEls, _els,
 +                               Line, Home, Pref, Work,
 +                               decode_vcard_INTL(__TopXMLNS, __IgnoreEls,
 +                                                 _el),
 +                               Parcel, Postal, Dom);
 +      <<"vcard-temp">> ->
 +        decode_vcard_LABEL_els(__TopXMLNS, __IgnoreEls, _els,
 +                               Line, Home, Pref, Work,
 +                               decode_vcard_INTL(<<"vcard-temp">>,
 +                                                 __IgnoreEls, _el),
 +                               Parcel, Postal, Dom);
 +      _ ->
 +        decode_vcard_LABEL_els(__TopXMLNS, __IgnoreEls, _els,
 +                               Line, Home, Pref, Work, Intl, Parcel, Postal,
 +                               Dom)
 +    end;
 +decode_vcard_LABEL_els(__TopXMLNS, __IgnoreEls,
 +                     [{xmlel, <<"PREF">>, _attrs, _} = _el | _els], Line,
 +                     Home, Pref, Work, Intl, Parcel, Postal, Dom) ->
 +    case get_attr(<<"xmlns">>, _attrs) of
 +      <<"">> when __TopXMLNS == <<"vcard-temp">> ->
 +        decode_vcard_LABEL_els(__TopXMLNS, __IgnoreEls, _els,
 +                               Line, Home,
 +                               decode_vcard_PREF(__TopXMLNS, __IgnoreEls,
 +                                                 _el),
 +                               Work, Intl, Parcel, Postal, Dom);
 +      <<"vcard-temp">> ->
 +        decode_vcard_LABEL_els(__TopXMLNS, __IgnoreEls, _els,
 +                               Line, Home,
 +                               decode_vcard_PREF(<<"vcard-temp">>,
 +                                                 __IgnoreEls, _el),
 +                               Work, Intl, Parcel, Postal, Dom);
 +      _ ->
 +        decode_vcard_LABEL_els(__TopXMLNS, __IgnoreEls, _els,
 +                               Line, Home, Pref, Work, Intl, Parcel, Postal,
 +                               Dom)
 +    end;
 +decode_vcard_LABEL_els(__TopXMLNS, __IgnoreEls,
 +                     [{xmlel, <<"LINE">>, _attrs, _} = _el | _els], Line,
 +                     Home, Pref, Work, Intl, Parcel, Postal, Dom) ->
 +    case get_attr(<<"xmlns">>, _attrs) of
 +      <<"">> when __TopXMLNS == <<"vcard-temp">> ->
 +        decode_vcard_LABEL_els(__TopXMLNS, __IgnoreEls, _els,
 +                               [decode_vcard_LINE(__TopXMLNS, __IgnoreEls,
 +                                                  _el)
 +                                | Line],
 +                               Home, Pref, Work, Intl, Parcel, Postal, Dom);
 +      <<"vcard-temp">> ->
 +        decode_vcard_LABEL_els(__TopXMLNS, __IgnoreEls, _els,
 +                               [decode_vcard_LINE(<<"vcard-temp">>,
 +                                                  __IgnoreEls, _el)
 +                                | Line],
 +                               Home, Pref, Work, Intl, Parcel, Postal, Dom);
 +      _ ->
 +        decode_vcard_LABEL_els(__TopXMLNS, __IgnoreEls, _els,
 +                               Line, Home, Pref, Work, Intl, Parcel, Postal,
 +                               Dom)
 +    end;
 +decode_vcard_LABEL_els(__TopXMLNS, __IgnoreEls,
 +                     [_ | _els], Line, Home, Pref, Work, Intl, Parcel,
 +                     Postal, Dom) ->
 +    decode_vcard_LABEL_els(__TopXMLNS, __IgnoreEls, _els,
 +                         Line, Home, Pref, Work, Intl, Parcel, Postal, Dom).
 +
 +encode_vcard_LABEL({vcard_label, Home, Work, Postal,
 +                  Parcel, Dom, Intl, Pref, Line},
 +                 __TopXMLNS) ->
 +    __NewTopXMLNS = choose_top_xmlns(<<"vcard-temp">>, [],
 +                                   __TopXMLNS),
 +    _els = lists:reverse('encode_vcard_LABEL_$line'(Line,
 +                                                  __NewTopXMLNS,
 +                                                  'encode_vcard_LABEL_$home'(Home,
 +                                                                             __NewTopXMLNS,
 +                                                                             'encode_vcard_LABEL_$pref'(Pref,
 +                                                                                                        __NewTopXMLNS,
 +                                                                                                        'encode_vcard_LABEL_$work'(Work,
 +                                                                                                                                   __NewTopXMLNS,
 +                                                                                                                                   'encode_vcard_LABEL_$intl'(Intl,
 +                                                                                                                                                              __NewTopXMLNS,
 +                                                                                                                                                              'encode_vcard_LABEL_$parcel'(Parcel,
 +                                                                                                                                                                                           __NewTopXMLNS,
 +                                                                                                                                                                                           'encode_vcard_LABEL_$postal'(Postal,
 +                                                                                                                                                                                                                        __NewTopXMLNS,
 +                                                                                                                                                                                                                        'encode_vcard_LABEL_$dom'(Dom,
 +                                                                                                                                                                                                                                                  __NewTopXMLNS,
 +                                                                                                                                                                                                                                                  []))))))))),
 +    _attrs = enc_xmlns_attrs(__NewTopXMLNS, __TopXMLNS),
 +    {xmlel, <<"LABEL">>, _attrs, _els}.
 +
 +'encode_vcard_LABEL_$line'([], __TopXMLNS, _acc) ->
 +    _acc;
 +'encode_vcard_LABEL_$line'([Line | _els], __TopXMLNS,
 +                         _acc) ->
 +    'encode_vcard_LABEL_$line'(_els, __TopXMLNS,
 +                             [encode_vcard_LINE(Line, __TopXMLNS) | _acc]).
 +
 +'encode_vcard_LABEL_$home'(false, __TopXMLNS, _acc) ->
 +    _acc;
 +'encode_vcard_LABEL_$home'(Home, __TopXMLNS, _acc) ->
 +    [encode_vcard_HOME(Home, __TopXMLNS) | _acc].
 +
 +'encode_vcard_LABEL_$pref'(false, __TopXMLNS, _acc) ->
 +    _acc;
 +'encode_vcard_LABEL_$pref'(Pref, __TopXMLNS, _acc) ->
 +    [encode_vcard_PREF(Pref, __TopXMLNS) | _acc].
 +
 +'encode_vcard_LABEL_$work'(false, __TopXMLNS, _acc) ->
 +    _acc;
 +'encode_vcard_LABEL_$work'(Work, __TopXMLNS, _acc) ->
 +    [encode_vcard_WORK(Work, __TopXMLNS) | _acc].
 +
 +'encode_vcard_LABEL_$intl'(false, __TopXMLNS, _acc) ->
 +    _acc;
 +'encode_vcard_LABEL_$intl'(Intl, __TopXMLNS, _acc) ->
 +    [encode_vcard_INTL(Intl, __TopXMLNS) | _acc].
 +
 +'encode_vcard_LABEL_$parcel'(false, __TopXMLNS, _acc) ->
 +    _acc;
 +'encode_vcard_LABEL_$parcel'(Parcel, __TopXMLNS,
 +                           _acc) ->
 +    [encode_vcard_PARCEL(Parcel, __TopXMLNS) | _acc].
 +
 +'encode_vcard_LABEL_$postal'(false, __TopXMLNS, _acc) ->
 +    _acc;
 +'encode_vcard_LABEL_$postal'(Postal, __TopXMLNS,
 +                           _acc) ->
 +    [encode_vcard_POSTAL(Postal, __TopXMLNS) | _acc].
 +
 +'encode_vcard_LABEL_$dom'(false, __TopXMLNS, _acc) ->
 +    _acc;
 +'encode_vcard_LABEL_$dom'(Dom, __TopXMLNS, _acc) ->
 +    [encode_vcard_DOM(Dom, __TopXMLNS) | _acc].
 +
 +decode_vcard_ADR(__TopXMLNS, __IgnoreEls,
 +               {xmlel, <<"ADR">>, _attrs, _els}) ->
 +    {Street, Extadd, Pcode, Home, Pref, Pobox, Ctry,
 +     Locality, Work, Intl, Parcel, Postal, Dom, Region} =
 +      decode_vcard_ADR_els(__TopXMLNS, __IgnoreEls, _els,
 +                           undefined, undefined, undefined, false, false,
 +                           undefined, undefined, undefined, false, false,
 +                           false, false, false, undefined),
 +    {vcard_adr, Home, Work, Postal, Parcel, Dom, Intl, Pref,
 +     Pobox, Extadd, Street, Locality, Region, Pcode, Ctry}.
 +
 +decode_vcard_ADR_els(__TopXMLNS, __IgnoreEls, [],
 +                   Street, Extadd, Pcode, Home, Pref, Pobox, Ctry,
 +                   Locality, Work, Intl, Parcel, Postal, Dom, Region) ->
 +    {Street, Extadd, Pcode, Home, Pref, Pobox, Ctry,
 +     Locality, Work, Intl, Parcel, Postal, Dom, Region};
 +decode_vcard_ADR_els(__TopXMLNS, __IgnoreEls,
 +                   [{xmlel, <<"HOME">>, _attrs, _} = _el | _els], Street,
 +                   Extadd, Pcode, Home, Pref, Pobox, Ctry, Locality, Work,
 +                   Intl, Parcel, Postal, Dom, Region) ->
 +    case get_attr(<<"xmlns">>, _attrs) of
 +      <<"">> when __TopXMLNS == <<"vcard-temp">> ->
 +        decode_vcard_ADR_els(__TopXMLNS, __IgnoreEls, _els,
 +                             Street, Extadd, Pcode,
 +                             decode_vcard_HOME(__TopXMLNS, __IgnoreEls, _el),
 +                             Pref, Pobox, Ctry, Locality, Work, Intl, Parcel,
 +                             Postal, Dom, Region);
 +      <<"vcard-temp">> ->
 +        decode_vcard_ADR_els(__TopXMLNS, __IgnoreEls, _els,
 +                             Street, Extadd, Pcode,
 +                             decode_vcard_HOME(<<"vcard-temp">>, __IgnoreEls,
 +                                               _el),
 +                             Pref, Pobox, Ctry, Locality, Work, Intl, Parcel,
 +                             Postal, Dom, Region);
 +      _ ->
 +        decode_vcard_ADR_els(__TopXMLNS, __IgnoreEls, _els,
 +                             Street, Extadd, Pcode, Home, Pref, Pobox, Ctry,
 +                             Locality, Work, Intl, Parcel, Postal, Dom,
 +                             Region)
 +    end;
 +decode_vcard_ADR_els(__TopXMLNS, __IgnoreEls,
 +                   [{xmlel, <<"WORK">>, _attrs, _} = _el | _els], Street,
 +                   Extadd, Pcode, Home, Pref, Pobox, Ctry, Locality, Work,
 +                   Intl, Parcel, Postal, Dom, Region) ->
 +    case get_attr(<<"xmlns">>, _attrs) of
 +      <<"">> when __TopXMLNS == <<"vcard-temp">> ->
 +        decode_vcard_ADR_els(__TopXMLNS, __IgnoreEls, _els,
 +                             Street, Extadd, Pcode, Home, Pref, Pobox, Ctry,
 +                             Locality,
 +                             decode_vcard_WORK(__TopXMLNS, __IgnoreEls, _el),
 +                             Intl, Parcel, Postal, Dom, Region);
 +      <<"vcard-temp">> ->
 +        decode_vcard_ADR_els(__TopXMLNS, __IgnoreEls, _els,
 +                             Street, Extadd, Pcode, Home, Pref, Pobox, Ctry,
 +                             Locality,
 +                             decode_vcard_WORK(<<"vcard-temp">>, __IgnoreEls,
 +                                               _el),
 +                             Intl, Parcel, Postal, Dom, Region);
 +      _ ->
 +        decode_vcard_ADR_els(__TopXMLNS, __IgnoreEls, _els,
 +                             Street, Extadd, Pcode, Home, Pref, Pobox, Ctry,
 +                             Locality, Work, Intl, Parcel, Postal, Dom,
 +                             Region)
 +    end;
 +decode_vcard_ADR_els(__TopXMLNS, __IgnoreEls,
 +                   [{xmlel, <<"POSTAL">>, _attrs, _} = _el | _els], Street,
 +                   Extadd, Pcode, Home, Pref, Pobox, Ctry, Locality, Work,
 +                   Intl, Parcel, Postal, Dom, Region) ->
 +    case get_attr(<<"xmlns">>, _attrs) of
 +      <<"">> when __TopXMLNS == <<"vcard-temp">> ->
 +        decode_vcard_ADR_els(__TopXMLNS, __IgnoreEls, _els,
 +                             Street, Extadd, Pcode, Home, Pref, Pobox, Ctry,
 +                             Locality, Work, Intl, Parcel,
 +                             decode_vcard_POSTAL(__TopXMLNS, __IgnoreEls,
 +                                                 _el),
 +                             Dom, Region);
 +      <<"vcard-temp">> ->
 +        decode_vcard_ADR_els(__TopXMLNS, __IgnoreEls, _els,
 +                             Street, Extadd, Pcode, Home, Pref, Pobox, Ctry,
 +                             Locality, Work, Intl, Parcel,
 +                             decode_vcard_POSTAL(<<"vcard-temp">>,
 +                                                 __IgnoreEls, _el),
 +                             Dom, Region);
 +      _ ->
 +        decode_vcard_ADR_els(__TopXMLNS, __IgnoreEls, _els,
 +                             Street, Extadd, Pcode, Home, Pref, Pobox, Ctry,
 +                             Locality, Work, Intl, Parcel, Postal, Dom,
 +                             Region)
 +    end;
 +decode_vcard_ADR_els(__TopXMLNS, __IgnoreEls,
 +                   [{xmlel, <<"PARCEL">>, _attrs, _} = _el | _els], Street,
 +                   Extadd, Pcode, Home, Pref, Pobox, Ctry, Locality, Work,
 +                   Intl, Parcel, Postal, Dom, Region) ->
 +    case get_attr(<<"xmlns">>, _attrs) of
 +      <<"">> when __TopXMLNS == <<"vcard-temp">> ->
 +        decode_vcard_ADR_els(__TopXMLNS, __IgnoreEls, _els,
 +                             Street, Extadd, Pcode, Home, Pref, Pobox, Ctry,
 +                             Locality, Work, Intl,
 +                             decode_vcard_PARCEL(__TopXMLNS, __IgnoreEls,
 +                                                 _el),
 +                             Postal, Dom, Region);
 +      <<"vcard-temp">> ->
 +        decode_vcard_ADR_els(__TopXMLNS, __IgnoreEls, _els,
 +                             Street, Extadd, Pcode, Home, Pref, Pobox, Ctry,
 +                             Locality, Work, Intl,
 +                             decode_vcard_PARCEL(<<"vcard-temp">>,
 +                                                 __IgnoreEls, _el),
 +                             Postal, Dom, Region);
 +      _ ->
 +        decode_vcard_ADR_els(__TopXMLNS, __IgnoreEls, _els,
 +                             Street, Extadd, Pcode, Home, Pref, Pobox, Ctry,
 +                             Locality, Work, Intl, Parcel, Postal, Dom,
 +                             Region)
 +    end;
 +decode_vcard_ADR_els(__TopXMLNS, __IgnoreEls,
 +                   [{xmlel, <<"DOM">>, _attrs, _} = _el | _els], Street,
 +                   Extadd, Pcode, Home, Pref, Pobox, Ctry, Locality, Work,
 +                   Intl, Parcel, Postal, Dom, Region) ->
 +    case get_attr(<<"xmlns">>, _attrs) of
 +      <<"">> when __TopXMLNS == <<"vcard-temp">> ->
 +        decode_vcard_ADR_els(__TopXMLNS, __IgnoreEls, _els,
 +                             Street, Extadd, Pcode, Home, Pref, Pobox, Ctry,
 +                             Locality, Work, Intl, Parcel, Postal,
 +                             decode_vcard_DOM(__TopXMLNS, __IgnoreEls, _el),
 +                             Region);
 +      <<"vcard-temp">> ->
 +        decode_vcard_ADR_els(__TopXMLNS, __IgnoreEls, _els,
 +                             Street, Extadd, Pcode, Home, Pref, Pobox, Ctry,
 +                             Locality, Work, Intl, Parcel, Postal,
 +                             decode_vcard_DOM(<<"vcard-temp">>, __IgnoreEls,
 +                                              _el),
 +                             Region);
 +      _ ->
 +        decode_vcard_ADR_els(__TopXMLNS, __IgnoreEls, _els,
 +                             Street, Extadd, Pcode, Home, Pref, Pobox, Ctry,
 +                             Locality, Work, Intl, Parcel, Postal, Dom,
 +                             Region)
 +    end;
 +decode_vcard_ADR_els(__TopXMLNS, __IgnoreEls,
 +                   [{xmlel, <<"INTL">>, _attrs, _} = _el | _els], Street,
 +                   Extadd, Pcode, Home, Pref, Pobox, Ctry, Locality, Work,
 +                   Intl, Parcel, Postal, Dom, Region) ->
 +    case get_attr(<<"xmlns">>, _attrs) of
 +      <<"">> when __TopXMLNS == <<"vcard-temp">> ->
 +        decode_vcard_ADR_els(__TopXMLNS, __IgnoreEls, _els,
 +                             Street, Extadd, Pcode, Home, Pref, Pobox, Ctry,
 +                             Locality, Work,
 +                             decode_vcard_INTL(__TopXMLNS, __IgnoreEls, _el),
 +                             Parcel, Postal, Dom, Region);
 +      <<"vcard-temp">> ->
 +        decode_vcard_ADR_els(__TopXMLNS, __IgnoreEls, _els,
 +                             Street, Extadd, Pcode, Home, Pref, Pobox, Ctry,
 +                             Locality, Work,
 +                             decode_vcard_INTL(<<"vcard-temp">>, __IgnoreEls,
 +                                               _el),
 +                             Parcel, Postal, Dom, Region);
 +      _ ->
 +        decode_vcard_ADR_els(__TopXMLNS, __IgnoreEls, _els,
 +                             Street, Extadd, Pcode, Home, Pref, Pobox, Ctry,
 +                             Locality, Work, Intl, Parcel, Postal, Dom,
 +                             Region)
 +    end;
 +decode_vcard_ADR_els(__TopXMLNS, __IgnoreEls,
 +                   [{xmlel, <<"PREF">>, _attrs, _} = _el | _els], Street,
 +                   Extadd, Pcode, Home, Pref, Pobox, Ctry, Locality, Work,
 +                   Intl, Parcel, Postal, Dom, Region) ->
 +    case get_attr(<<"xmlns">>, _attrs) of
 +      <<"">> when __TopXMLNS == <<"vcard-temp">> ->
 +        decode_vcard_ADR_els(__TopXMLNS, __IgnoreEls, _els,
 +                             Street, Extadd, Pcode, Home,
 +                             decode_vcard_PREF(__TopXMLNS, __IgnoreEls, _el),
 +                             Pobox, Ctry, Locality, Work, Intl, Parcel,
 +                             Postal, Dom, Region);
 +      <<"vcard-temp">> ->
 +        decode_vcard_ADR_els(__TopXMLNS, __IgnoreEls, _els,
 +                             Street, Extadd, Pcode, Home,
 +                             decode_vcard_PREF(<<"vcard-temp">>, __IgnoreEls,
 +                                               _el),
 +                             Pobox, Ctry, Locality, Work, Intl, Parcel,
 +                             Postal, Dom, Region);
 +      _ ->
 +        decode_vcard_ADR_els(__TopXMLNS, __IgnoreEls, _els,
 +                             Street, Extadd, Pcode, Home, Pref, Pobox, Ctry,
 +                             Locality, Work, Intl, Parcel, Postal, Dom,
 +                             Region)
 +    end;
 +decode_vcard_ADR_els(__TopXMLNS, __IgnoreEls,
 +                   [{xmlel, <<"POBOX">>, _attrs, _} = _el | _els], Street,
 +                   Extadd, Pcode, Home, Pref, Pobox, Ctry, Locality, Work,
 +                   Intl, Parcel, Postal, Dom, Region) ->
 +    case get_attr(<<"xmlns">>, _attrs) of
 +      <<"">> when __TopXMLNS == <<"vcard-temp">> ->
 +        decode_vcard_ADR_els(__TopXMLNS, __IgnoreEls, _els,
 +                             Street, Extadd, Pcode, Home, Pref,
 +                             decode_vcard_POBOX(__TopXMLNS, __IgnoreEls, _el),
 +                             Ctry, Locality, Work, Intl, Parcel, Postal, Dom,
 +                             Region);
 +      <<"vcard-temp">> ->
 +        decode_vcard_ADR_els(__TopXMLNS, __IgnoreEls, _els,
 +                             Street, Extadd, Pcode, Home, Pref,
 +                             decode_vcard_POBOX(<<"vcard-temp">>, __IgnoreEls,
 +                                                _el),
 +                             Ctry, Locality, Work, Intl, Parcel, Postal, Dom,
 +                             Region);
 +      _ ->
 +        decode_vcard_ADR_els(__TopXMLNS, __IgnoreEls, _els,
 +                             Street, Extadd, Pcode, Home, Pref, Pobox, Ctry,
 +                             Locality, Work, Intl, Parcel, Postal, Dom,
 +                             Region)
 +    end;
 +decode_vcard_ADR_els(__TopXMLNS, __IgnoreEls,
 +                   [{xmlel, <<"EXTADD">>, _attrs, _} = _el | _els], Street,
 +                   Extadd, Pcode, Home, Pref, Pobox, Ctry, Locality, Work,
 +                   Intl, Parcel, Postal, Dom, Region) ->
 +    case get_attr(<<"xmlns">>, _attrs) of
 +      <<"">> when __TopXMLNS == <<"vcard-temp">> ->
 +        decode_vcard_ADR_els(__TopXMLNS, __IgnoreEls, _els,
 +                             Street,
 +                             decode_vcard_EXTADD(__TopXMLNS, __IgnoreEls,
 +                                                 _el),
 +                             Pcode, Home, Pref, Pobox, Ctry, Locality, Work,
 +                             Intl, Parcel, Postal, Dom, Region);
 +      <<"vcard-temp">> ->
 +        decode_vcard_ADR_els(__TopXMLNS, __IgnoreEls, _els,
 +                             Street,
 +                             decode_vcard_EXTADD(<<"vcard-temp">>,
 +                                                 __IgnoreEls, _el),
 +                             Pcode, Home, Pref, Pobox, Ctry, Locality, Work,
 +                             Intl, Parcel, Postal, Dom, Region);
 +      _ ->
 +        decode_vcard_ADR_els(__TopXMLNS, __IgnoreEls, _els,
 +                             Street, Extadd, Pcode, Home, Pref, Pobox, Ctry,
 +                             Locality, Work, Intl, Parcel, Postal, Dom,
 +                             Region)
 +    end;
 +decode_vcard_ADR_els(__TopXMLNS, __IgnoreEls,
 +                   [{xmlel, <<"STREET">>, _attrs, _} = _el | _els], Street,
 +                   Extadd, Pcode, Home, Pref, Pobox, Ctry, Locality, Work,
 +                   Intl, Parcel, Postal, Dom, Region) ->
 +    case get_attr(<<"xmlns">>, _attrs) of
 +      <<"">> when __TopXMLNS == <<"vcard-temp">> ->
 +        decode_vcard_ADR_els(__TopXMLNS, __IgnoreEls, _els,
 +                             decode_vcard_STREET(__TopXMLNS, __IgnoreEls,
 +                                                 _el),
 +                             Extadd, Pcode, Home, Pref, Pobox, Ctry, Locality,
 +                             Work, Intl, Parcel, Postal, Dom, Region);
 +      <<"vcard-temp">> ->
 +        decode_vcard_ADR_els(__TopXMLNS, __IgnoreEls, _els,
 +                             decode_vcard_STREET(<<"vcard-temp">>,
 +                                                 __IgnoreEls, _el),
 +                             Extadd, Pcode, Home, Pref, Pobox, Ctry, Locality,
 +                             Work, Intl, Parcel, Postal, Dom, Region);
 +      _ ->
 +        decode_vcard_ADR_els(__TopXMLNS, __IgnoreEls, _els,
 +                             Street, Extadd, Pcode, Home, Pref, Pobox, Ctry,
 +                             Locality, Work, Intl, Parcel, Postal, Dom,
 +                             Region)
 +    end;
 +decode_vcard_ADR_els(__TopXMLNS, __IgnoreEls,
 +                   [{xmlel, <<"LOCALITY">>, _attrs, _} = _el | _els],
 +                   Street, Extadd, Pcode, Home, Pref, Pobox, Ctry,
 +                   Locality, Work, Intl, Parcel, Postal, Dom, Region) ->
 +    case get_attr(<<"xmlns">>, _attrs) of
 +      <<"">> when __TopXMLNS == <<"vcard-temp">> ->
 +        decode_vcard_ADR_els(__TopXMLNS, __IgnoreEls, _els,
 +                             Street, Extadd, Pcode, Home, Pref, Pobox, Ctry,
 +                             decode_vcard_LOCALITY(__TopXMLNS, __IgnoreEls,
 +                                                   _el),
 +                             Work, Intl, Parcel, Postal, Dom, Region);
 +      <<"vcard-temp">> ->
 +        decode_vcard_ADR_els(__TopXMLNS, __IgnoreEls, _els,
 +                             Street, Extadd, Pcode, Home, Pref, Pobox, Ctry,
 +                             decode_vcard_LOCALITY(<<"vcard-temp">>,
 +                                                   __IgnoreEls, _el),
 +                             Work, Intl, Parcel, Postal, Dom, Region);
 +      _ ->
 +        decode_vcard_ADR_els(__TopXMLNS, __IgnoreEls, _els,
 +                             Street, Extadd, Pcode, Home, Pref, Pobox, Ctry,
 +                             Locality, Work, Intl, Parcel, Postal, Dom,
 +                             Region)
 +    end;
 +decode_vcard_ADR_els(__TopXMLNS, __IgnoreEls,
 +                   [{xmlel, <<"REGION">>, _attrs, _} = _el | _els], Street,
 +                   Extadd, Pcode, Home, Pref, Pobox, Ctry, Locality, Work,
 +                   Intl, Parcel, Postal, Dom, Region) ->
 +    case get_attr(<<"xmlns">>, _attrs) of
 +      <<"">> when __TopXMLNS == <<"vcard-temp">> ->
 +        decode_vcard_ADR_els(__TopXMLNS, __IgnoreEls, _els,
 +                             Street, Extadd, Pcode, Home, Pref, Pobox, Ctry,
 +                             Locality, Work, Intl, Parcel, Postal, Dom,
 +                             decode_vcard_REGION(__TopXMLNS, __IgnoreEls,
 +                                                 _el));
 +      <<"vcard-temp">> ->
 +        decode_vcard_ADR_els(__TopXMLNS, __IgnoreEls, _els,
 +                             Street, Extadd, Pcode, Home, Pref, Pobox, Ctry,
 +                             Locality, Work, Intl, Parcel, Postal, Dom,
 +                             decode_vcard_REGION(<<"vcard-temp">>,
 +                                                 __IgnoreEls, _el));
 +      _ ->
 +        decode_vcard_ADR_els(__TopXMLNS, __IgnoreEls, _els,
 +                             Street, Extadd, Pcode, Home, Pref, Pobox, Ctry,
 +                             Locality, Work, Intl, Parcel, Postal, Dom,
 +                             Region)
 +    end;
 +decode_vcard_ADR_els(__TopXMLNS, __IgnoreEls,
 +                   [{xmlel, <<"PCODE">>, _attrs, _} = _el | _els], Street,
 +                   Extadd, Pcode, Home, Pref, Pobox, Ctry, Locality, Work,
 +                   Intl, Parcel, Postal, Dom, Region) ->
 +    case get_attr(<<"xmlns">>, _attrs) of
 +      <<"">> when __TopXMLNS == <<"vcard-temp">> ->
 +        decode_vcard_ADR_els(__TopXMLNS, __IgnoreEls, _els,
 +                             Street, Extadd,
 +                             decode_vcard_PCODE(__TopXMLNS, __IgnoreEls, _el),
 +                             Home, Pref, Pobox, Ctry, Locality, Work, Intl,
 +                             Parcel, Postal, Dom, Region);
 +      <<"vcard-temp">> ->
 +        decode_vcard_ADR_els(__TopXMLNS, __IgnoreEls, _els,
 +                             Street, Extadd,
 +                             decode_vcard_PCODE(<<"vcard-temp">>, __IgnoreEls,
 +                                                _el),
 +                             Home, Pref, Pobox, Ctry, Locality, Work, Intl,
 +                             Parcel, Postal, Dom, Region);
 +      _ ->
 +        decode_vcard_ADR_els(__TopXMLNS, __IgnoreEls, _els,
 +                             Street, Extadd, Pcode, Home, Pref, Pobox, Ctry,
 +                             Locality, Work, Intl, Parcel, Postal, Dom,
 +                             Region)
 +    end;
 +decode_vcard_ADR_els(__TopXMLNS, __IgnoreEls,
 +                   [{xmlel, <<"CTRY">>, _attrs, _} = _el | _els], Street,
 +                   Extadd, Pcode, Home, Pref, Pobox, Ctry, Locality, Work,
 +                   Intl, Parcel, Postal, Dom, Region) ->
 +    case get_attr(<<"xmlns">>, _attrs) of
 +      <<"">> when __TopXMLNS == <<"vcard-temp">> ->
 +        decode_vcard_ADR_els(__TopXMLNS, __IgnoreEls, _els,
 +                             Street, Extadd, Pcode, Home, Pref, Pobox,
 +                             decode_vcard_CTRY(__TopXMLNS, __IgnoreEls, _el),
 +                             Locality, Work, Intl, Parcel, Postal, Dom,
 +                             Region);
 +      <<"vcard-temp">> ->
 +        decode_vcard_ADR_els(__TopXMLNS, __IgnoreEls, _els,
 +                             Street, Extadd, Pcode, Home, Pref, Pobox,
 +                             decode_vcard_CTRY(<<"vcard-temp">>, __IgnoreEls,
 +                                               _el),
 +                             Locality, Work, Intl, Parcel, Postal, Dom,
 +                             Region);
 +      _ ->
 +        decode_vcard_ADR_els(__TopXMLNS, __IgnoreEls, _els,
 +                             Street, Extadd, Pcode, Home, Pref, Pobox, Ctry,
 +                             Locality, Work, Intl, Parcel, Postal, Dom,
 +                             Region)
 +    end;
 +decode_vcard_ADR_els(__TopXMLNS, __IgnoreEls,
 +                   [_ | _els], Street, Extadd, Pcode, Home, Pref, Pobox,
 +                   Ctry, Locality, Work, Intl, Parcel, Postal, Dom,
 +                   Region) ->
 +    decode_vcard_ADR_els(__TopXMLNS, __IgnoreEls, _els,
 +                       Street, Extadd, Pcode, Home, Pref, Pobox, Ctry,
 +                       Locality, Work, Intl, Parcel, Postal, Dom, Region).
 +
 +encode_vcard_ADR({vcard_adr, Home, Work, Postal, Parcel,
 +                Dom, Intl, Pref, Pobox, Extadd, Street, Locality,
 +                Region, Pcode, Ctry},
 +               __TopXMLNS) ->
 +    __NewTopXMLNS = choose_top_xmlns(<<"vcard-temp">>, [],
 +                                   __TopXMLNS),
 +    _els = lists:reverse('encode_vcard_ADR_$street'(Street,
 +                                                  __NewTopXMLNS,
 +                                                  'encode_vcard_ADR_$extadd'(Extadd,
 +                                                                             __NewTopXMLNS,
 +                                                                             'encode_vcard_ADR_$pcode'(Pcode,
 +                                                                                                       __NewTopXMLNS,
 +                                                                                                       'encode_vcard_ADR_$home'(Home,
 +                                                                                                                                __NewTopXMLNS,
 +                                                                                                                                'encode_vcard_ADR_$pref'(Pref,
 +                                                                                                                                                         __NewTopXMLNS,
 +                                                                                                                                                         'encode_vcard_ADR_$pobox'(Pobox,
 +                                                                                                                                                                                   __NewTopXMLNS,
 +                                                                                                                                                                                   'encode_vcard_ADR_$ctry'(Ctry,
 +                                                                                                                                                                                                            __NewTopXMLNS,
 +                                                                                                                                                                                                            'encode_vcard_ADR_$locality'(Locality,
 +                                                                                                                                                                                                                                         __NewTopXMLNS,
 +                                                                                                                                                                                                                                         'encode_vcard_ADR_$work'(Work,
 +                                                                                                                                                                                                                                                                  __NewTopXMLNS,
 +                                                                                                                                                                                                                                                                  'encode_vcard_ADR_$intl'(Intl,
 +                                                                                                                                                                                                                                                                                           __NewTopXMLNS,
 +                                                                                                                                                                                                                                                                                           'encode_vcard_ADR_$parcel'(Parcel,
 +                                                                                                                                                                                                                                                                                                                      __NewTopXMLNS,
 +                                                                                                                                                                                                                                                                                                                      'encode_vcard_ADR_$postal'(Postal,
 +                                                                                                                                                                                                                                                                                                                                                 __NewTopXMLNS,
 +                                                                                                                                                                                                                                                                                                                                                 'encode_vcard_ADR_$dom'(Dom,
 +                                                                                                                                                                                                                                                                                                                                                                         __NewTopXMLNS,
 +                                                                                                                                                                                                                                                                                                                                                                         'encode_vcard_ADR_$region'(Region,
 +                                                                                                                                                                                                                                                                                                                                                                                                    __NewTopXMLNS,
 +                                                                                                                                                                                                                                                                                                                                                                                                    []))))))))))))))),
 +    _attrs = enc_xmlns_attrs(__NewTopXMLNS, __TopXMLNS),
 +    {xmlel, <<"ADR">>, _attrs, _els}.
 +
 +'encode_vcard_ADR_$street'(undefined, __TopXMLNS,
 +                         _acc) ->
 +    _acc;
 +'encode_vcard_ADR_$street'(Street, __TopXMLNS, _acc) ->
 +    [encode_vcard_STREET(Street, __TopXMLNS) | _acc].
 +
 +'encode_vcard_ADR_$extadd'(undefined, __TopXMLNS,
 +                         _acc) ->
 +    _acc;
 +'encode_vcard_ADR_$extadd'(Extadd, __TopXMLNS, _acc) ->
 +    [encode_vcard_EXTADD(Extadd, __TopXMLNS) | _acc].
 +
 +'encode_vcard_ADR_$pcode'(undefined, __TopXMLNS,
 +                        _acc) ->
 +    _acc;
 +'encode_vcard_ADR_$pcode'(Pcode, __TopXMLNS, _acc) ->
 +    [encode_vcard_PCODE(Pcode, __TopXMLNS) | _acc].
 +
 +'encode_vcard_ADR_$home'(false, __TopXMLNS, _acc) ->
 +    _acc;
 +'encode_vcard_ADR_$home'(Home, __TopXMLNS, _acc) ->
 +    [encode_vcard_HOME(Home, __TopXMLNS) | _acc].
 +
 +'encode_vcard_ADR_$pref'(false, __TopXMLNS, _acc) ->
 +    _acc;
 +'encode_vcard_ADR_$pref'(Pref, __TopXMLNS, _acc) ->
 +    [encode_vcard_PREF(Pref, __TopXMLNS) | _acc].
 +
 +'encode_vcard_ADR_$pobox'(undefined, __TopXMLNS,
 +                        _acc) ->
 +    _acc;
 +'encode_vcard_ADR_$pobox'(Pobox, __TopXMLNS, _acc) ->
 +    [encode_vcard_POBOX(Pobox, __TopXMLNS) | _acc].
 +
 +'encode_vcard_ADR_$ctry'(undefined, __TopXMLNS, _acc) ->
 +    _acc;
 +'encode_vcard_ADR_$ctry'(Ctry, __TopXMLNS, _acc) ->
 +    [encode_vcard_CTRY(Ctry, __TopXMLNS) | _acc].
 +
 +'encode_vcard_ADR_$locality'(undefined, __TopXMLNS,
 +                           _acc) ->
 +    _acc;
 +'encode_vcard_ADR_$locality'(Locality, __TopXMLNS,
 +                           _acc) ->
 +    [encode_vcard_LOCALITY(Locality, __TopXMLNS) | _acc].
 +
 +'encode_vcard_ADR_$work'(false, __TopXMLNS, _acc) ->
 +    _acc;
 +'encode_vcard_ADR_$work'(Work, __TopXMLNS, _acc) ->
 +    [encode_vcard_WORK(Work, __TopXMLNS) | _acc].
 +
 +'encode_vcard_ADR_$intl'(false, __TopXMLNS, _acc) ->
 +    _acc;
 +'encode_vcard_ADR_$intl'(Intl, __TopXMLNS, _acc) ->
 +    [encode_vcard_INTL(Intl, __TopXMLNS) | _acc].
 +
 +'encode_vcard_ADR_$parcel'(false, __TopXMLNS, _acc) ->
 +    _acc;
 +'encode_vcard_ADR_$parcel'(Parcel, __TopXMLNS, _acc) ->
 +    [encode_vcard_PARCEL(Parcel, __TopXMLNS) | _acc].
 +
 +'encode_vcard_ADR_$postal'(false, __TopXMLNS, _acc) ->
 +    _acc;
 +'encode_vcard_ADR_$postal'(Postal, __TopXMLNS, _acc) ->
 +    [encode_vcard_POSTAL(Postal, __TopXMLNS) | _acc].
 +
 +'encode_vcard_ADR_$dom'(false, __TopXMLNS, _acc) ->
 +    _acc;
 +'encode_vcard_ADR_$dom'(Dom, __TopXMLNS, _acc) ->
 +    [encode_vcard_DOM(Dom, __TopXMLNS) | _acc].
 +
 +'encode_vcard_ADR_$region'(undefined, __TopXMLNS,
 +                         _acc) ->
 +    _acc;
 +'encode_vcard_ADR_$region'(Region, __TopXMLNS, _acc) ->
 +    [encode_vcard_REGION(Region, __TopXMLNS) | _acc].
 +
 +decode_vcard_N(__TopXMLNS, __IgnoreEls,
 +             {xmlel, <<"N">>, _attrs, _els}) ->
 +    {Middle, Suffix, Prefix, Family, Given} =
 +      decode_vcard_N_els(__TopXMLNS, __IgnoreEls, _els,
 +                         undefined, undefined, undefined, undefined,
 +                         undefined),
 +    {vcard_name, Family, Given, Middle, Prefix, Suffix}.
 +
 +decode_vcard_N_els(__TopXMLNS, __IgnoreEls, [], Middle,
 +                 Suffix, Prefix, Family, Given) ->
 +    {Middle, Suffix, Prefix, Family, Given};
 +decode_vcard_N_els(__TopXMLNS, __IgnoreEls,
 +                 [{xmlel, <<"FAMILY">>, _attrs, _} = _el | _els], Middle,
 +                 Suffix, Prefix, Family, Given) ->
 +    case get_attr(<<"xmlns">>, _attrs) of
 +      <<"">> when __TopXMLNS == <<"vcard-temp">> ->
 +        decode_vcard_N_els(__TopXMLNS, __IgnoreEls, _els,
 +                           Middle, Suffix, Prefix,
 +                           decode_vcard_FAMILY(__TopXMLNS, __IgnoreEls, _el),
 +                           Given);
 +      <<"vcard-temp">> ->
 +        decode_vcard_N_els(__TopXMLNS, __IgnoreEls, _els,
 +                           Middle, Suffix, Prefix,
 +                           decode_vcard_FAMILY(<<"vcard-temp">>, __IgnoreEls,
 +                                               _el),
 +                           Given);
 +      _ ->
 +        decode_vcard_N_els(__TopXMLNS, __IgnoreEls, _els,
 +                           Middle, Suffix, Prefix, Family, Given)
 +    end;
 +decode_vcard_N_els(__TopXMLNS, __IgnoreEls,
 +                 [{xmlel, <<"GIVEN">>, _attrs, _} = _el | _els], Middle,
 +                 Suffix, Prefix, Family, Given) ->
 +    case get_attr(<<"xmlns">>, _attrs) of
 +      <<"">> when __TopXMLNS == <<"vcard-temp">> ->
 +        decode_vcard_N_els(__TopXMLNS, __IgnoreEls, _els,
 +                           Middle, Suffix, Prefix, Family,
 +                           decode_vcard_GIVEN(__TopXMLNS, __IgnoreEls, _el));
 +      <<"vcard-temp">> ->
 +        decode_vcard_N_els(__TopXMLNS, __IgnoreEls, _els,
 +                           Middle, Suffix, Prefix, Family,
 +                           decode_vcard_GIVEN(<<"vcard-temp">>, __IgnoreEls,
 +                                              _el));
 +      _ ->
 +        decode_vcard_N_els(__TopXMLNS, __IgnoreEls, _els,
 +                           Middle, Suffix, Prefix, Family, Given)
 +    end;
 +decode_vcard_N_els(__TopXMLNS, __IgnoreEls,
 +                 [{xmlel, <<"MIDDLE">>, _attrs, _} = _el | _els], Middle,
 +                 Suffix, Prefix, Family, Given) ->
 +    case get_attr(<<"xmlns">>, _attrs) of
 +      <<"">> when __TopXMLNS == <<"vcard-temp">> ->
 +        decode_vcard_N_els(__TopXMLNS, __IgnoreEls, _els,
 +                           decode_vcard_MIDDLE(__TopXMLNS, __IgnoreEls, _el),
 +                           Suffix, Prefix, Family, Given);
 +      <<"vcard-temp">> ->
 +        decode_vcard_N_els(__TopXMLNS, __IgnoreEls, _els,
 +                           decode_vcard_MIDDLE(<<"vcard-temp">>, __IgnoreEls,
 +                                               _el),
 +                           Suffix, Prefix, Family, Given);
 +      _ ->
 +        decode_vcard_N_els(__TopXMLNS, __IgnoreEls, _els,
 +                           Middle, Suffix, Prefix, Family, Given)
 +    end;
 +decode_vcard_N_els(__TopXMLNS, __IgnoreEls,
 +                 [{xmlel, <<"PREFIX">>, _attrs, _} = _el | _els], Middle,
 +                 Suffix, Prefix, Family, Given) ->
 +    case get_attr(<<"xmlns">>, _attrs) of
 +      <<"">> when __TopXMLNS == <<"vcard-temp">> ->
 +        decode_vcard_N_els(__TopXMLNS, __IgnoreEls, _els,
 +                           Middle, Suffix,
 +                           decode_vcard_PREFIX(__TopXMLNS, __IgnoreEls, _el),
 +                           Family, Given);
 +      <<"vcard-temp">> ->
 +        decode_vcard_N_els(__TopXMLNS, __IgnoreEls, _els,
 +                           Middle, Suffix,
 +                           decode_vcard_PREFIX(<<"vcard-temp">>, __IgnoreEls,
 +                                               _el),
 +                           Family, Given);
 +      _ ->
 +        decode_vcard_N_els(__TopXMLNS, __IgnoreEls, _els,
 +                           Middle, Suffix, Prefix, Family, Given)
 +    end;
 +decode_vcard_N_els(__TopXMLNS, __IgnoreEls,
 +                 [{xmlel, <<"SUFFIX">>, _attrs, _} = _el | _els], Middle,
 +                 Suffix, Prefix, Family, Given) ->
 +    case get_attr(<<"xmlns">>, _attrs) of
 +      <<"">> when __TopXMLNS == <<"vcard-temp">> ->
 +        decode_vcard_N_els(__TopXMLNS, __IgnoreEls, _els,
 +                           Middle,
 +                           decode_vcard_SUFFIX(__TopXMLNS, __IgnoreEls, _el),
 +                           Prefix, Family, Given);
 +      <<"vcard-temp">> ->
 +        decode_vcard_N_els(__TopXMLNS, __IgnoreEls, _els,
 +                           Middle,
 +                           decode_vcard_SUFFIX(<<"vcard-temp">>, __IgnoreEls,
 +                                               _el),
 +                           Prefix, Family, Given);
 +      _ ->
 +        decode_vcard_N_els(__TopXMLNS, __IgnoreEls, _els,
 +                           Middle, Suffix, Prefix, Family, Given)
 +    end;
 +decode_vcard_N_els(__TopXMLNS, __IgnoreEls, [_ | _els],
 +                 Middle, Suffix, Prefix, Family, Given) ->
 +    decode_vcard_N_els(__TopXMLNS, __IgnoreEls, _els,
 +                     Middle, Suffix, Prefix, Family, Given).
 +
 +encode_vcard_N({vcard_name, Family, Given, Middle,
 +              Prefix, Suffix},
 +             __TopXMLNS) ->
 +    __NewTopXMLNS = choose_top_xmlns(<<"vcard-temp">>, [],
 +                                   __TopXMLNS),
 +    _els = lists:reverse('encode_vcard_N_$middle'(Middle,
 +                                                __NewTopXMLNS,
 +                                                'encode_vcard_N_$suffix'(Suffix,
 +                                                                         __NewTopXMLNS,
 +                                                                         'encode_vcard_N_$prefix'(Prefix,
 +                                                                                                  __NewTopXMLNS,
 +                                                                                                  'encode_vcard_N_$family'(Family,
 +                                                                                                                           __NewTopXMLNS,
 +                                                                                                                           'encode_vcard_N_$given'(Given,
 +                                                                                                                                                   __NewTopXMLNS,
 +                                                                                                                                                   [])))))),
 +    _attrs = enc_xmlns_attrs(__NewTopXMLNS, __TopXMLNS),
 +    {xmlel, <<"N">>, _attrs, _els}.
 +
 +'encode_vcard_N_$middle'(undefined, __TopXMLNS, _acc) ->
 +    _acc;
 +'encode_vcard_N_$middle'(Middle, __TopXMLNS, _acc) ->
 +    [encode_vcard_MIDDLE(Middle, __TopXMLNS) | _acc].
 +
 +'encode_vcard_N_$suffix'(undefined, __TopXMLNS, _acc) ->
 +    _acc;
 +'encode_vcard_N_$suffix'(Suffix, __TopXMLNS, _acc) ->
 +    [encode_vcard_SUFFIX(Suffix, __TopXMLNS) | _acc].
 +
 +'encode_vcard_N_$prefix'(undefined, __TopXMLNS, _acc) ->
 +    _acc;
 +'encode_vcard_N_$prefix'(Prefix, __TopXMLNS, _acc) ->
 +    [encode_vcard_PREFIX(Prefix, __TopXMLNS) | _acc].
 +
 +'encode_vcard_N_$family'(undefined, __TopXMLNS, _acc) ->
 +    _acc;
 +'encode_vcard_N_$family'(Family, __TopXMLNS, _acc) ->
 +    [encode_vcard_FAMILY(Family, __TopXMLNS) | _acc].
 +
 +'encode_vcard_N_$given'(undefined, __TopXMLNS, _acc) ->
 +    _acc;
 +'encode_vcard_N_$given'(Given, __TopXMLNS, _acc) ->
 +    [encode_vcard_GIVEN(Given, __TopXMLNS) | _acc].
 +
 +decode_vcard_CONFIDENTIAL(__TopXMLNS, __IgnoreEls,
 +                        {xmlel, <<"CONFIDENTIAL">>, _attrs, _els}) ->
 +    confidential.
 +
 +encode_vcard_CONFIDENTIAL(confidential, __TopXMLNS) ->
 +    __NewTopXMLNS = choose_top_xmlns(<<"vcard-temp">>, [],
 +                                   __TopXMLNS),
 +    _els = [],
 +    _attrs = enc_xmlns_attrs(__NewTopXMLNS, __TopXMLNS),
 +    {xmlel, <<"CONFIDENTIAL">>, _attrs, _els}.
 +
 +decode_vcard_PRIVATE(__TopXMLNS, __IgnoreEls,
 +                   {xmlel, <<"PRIVATE">>, _attrs, _els}) ->
 +    private.
 +
 +encode_vcard_PRIVATE(private, __TopXMLNS) ->
 +    __NewTopXMLNS = choose_top_xmlns(<<"vcard-temp">>, [],
 +                                   __TopXMLNS),
 +    _els = [],
 +    _attrs = enc_xmlns_attrs(__NewTopXMLNS, __TopXMLNS),
 +    {xmlel, <<"PRIVATE">>, _attrs, _els}.
 +
 +decode_vcard_PUBLIC(__TopXMLNS, __IgnoreEls,
 +                  {xmlel, <<"PUBLIC">>, _attrs, _els}) ->
 +    public.
 +
 +encode_vcard_PUBLIC(public, __TopXMLNS) ->
 +    __NewTopXMLNS = choose_top_xmlns(<<"vcard-temp">>, [],
 +                                   __TopXMLNS),
 +    _els = [],
 +    _attrs = enc_xmlns_attrs(__NewTopXMLNS, __TopXMLNS),
 +    {xmlel, <<"PUBLIC">>, _attrs, _els}.
 +
 +decode_vcard_EXTVAL(__TopXMLNS, __IgnoreEls,
 +                  {xmlel, <<"EXTVAL">>, _attrs, _els}) ->
 +    Cdata = decode_vcard_EXTVAL_els(__TopXMLNS, __IgnoreEls,
 +                                  _els, <<>>),
 +    Cdata.
 +
 +decode_vcard_EXTVAL_els(__TopXMLNS, __IgnoreEls, [],
 +                      Cdata) ->
 +    decode_vcard_EXTVAL_cdata(__TopXMLNS, Cdata);
 +decode_vcard_EXTVAL_els(__TopXMLNS, __IgnoreEls,
 +                      [{xmlcdata, _data} | _els], Cdata) ->
 +    decode_vcard_EXTVAL_els(__TopXMLNS, __IgnoreEls, _els,
 +                          <<Cdata/binary, _data/binary>>);
 +decode_vcard_EXTVAL_els(__TopXMLNS, __IgnoreEls,
 +                      [_ | _els], Cdata) ->
 +    decode_vcard_EXTVAL_els(__TopXMLNS, __IgnoreEls, _els,
 +                          Cdata).
 +
 +encode_vcard_EXTVAL(Cdata, __TopXMLNS) ->
 +    __NewTopXMLNS = choose_top_xmlns(<<"vcard-temp">>, [],
 +                                   __TopXMLNS),
 +    _els = encode_vcard_EXTVAL_cdata(Cdata, []),
 +    _attrs = enc_xmlns_attrs(__NewTopXMLNS, __TopXMLNS),
 +    {xmlel, <<"EXTVAL">>, _attrs, _els}.
 +
 +decode_vcard_EXTVAL_cdata(__TopXMLNS, <<>>) -> <<>>;
 +decode_vcard_EXTVAL_cdata(__TopXMLNS, _val) -> _val.
 +
 +encode_vcard_EXTVAL_cdata(<<>>, _acc) -> _acc;
 +encode_vcard_EXTVAL_cdata(_val, _acc) ->
 +    [{xmlcdata, _val} | _acc].
 +
 +decode_vcard_TYPE(__TopXMLNS, __IgnoreEls,
 +                {xmlel, <<"TYPE">>, _attrs, _els}) ->
 +    Cdata = decode_vcard_TYPE_els(__TopXMLNS, __IgnoreEls,
 +                                _els, <<>>),
 +    Cdata.
 +
 +decode_vcard_TYPE_els(__TopXMLNS, __IgnoreEls, [],
 +                    Cdata) ->
 +    decode_vcard_TYPE_cdata(__TopXMLNS, Cdata);
 +decode_vcard_TYPE_els(__TopXMLNS, __IgnoreEls,
 +                    [{xmlcdata, _data} | _els], Cdata) ->
 +    decode_vcard_TYPE_els(__TopXMLNS, __IgnoreEls, _els,
 +                        <<Cdata/binary, _data/binary>>);
 +decode_vcard_TYPE_els(__TopXMLNS, __IgnoreEls,
 +                    [_ | _els], Cdata) ->
 +    decode_vcard_TYPE_els(__TopXMLNS, __IgnoreEls, _els,
 +                        Cdata).
 +
 +encode_vcard_TYPE(Cdata, __TopXMLNS) ->
 +    __NewTopXMLNS = choose_top_xmlns(<<"vcard-temp">>, [],
 +                                   __TopXMLNS),
 +    _els = encode_vcard_TYPE_cdata(Cdata, []),
 +    _attrs = enc_xmlns_attrs(__NewTopXMLNS, __TopXMLNS),
 +    {xmlel, <<"TYPE">>, _attrs, _els}.
 +
 +decode_vcard_TYPE_cdata(__TopXMLNS, <<>>) -> <<>>;
 +decode_vcard_TYPE_cdata(__TopXMLNS, _val) -> _val.
 +
 +encode_vcard_TYPE_cdata(<<>>, _acc) -> _acc;
 +encode_vcard_TYPE_cdata(_val, _acc) ->
 +    [{xmlcdata, _val} | _acc].
 +
 +decode_vcard_DESC(__TopXMLNS, __IgnoreEls,
 +                {xmlel, <<"DESC">>, _attrs, _els}) ->
 +    Cdata = decode_vcard_DESC_els(__TopXMLNS, __IgnoreEls,
 +                                _els, <<>>),
 +    Cdata.
 +
 +decode_vcard_DESC_els(__TopXMLNS, __IgnoreEls, [],
 +                    Cdata) ->
 +    decode_vcard_DESC_cdata(__TopXMLNS, Cdata);
 +decode_vcard_DESC_els(__TopXMLNS, __IgnoreEls,
 +                    [{xmlcdata, _data} | _els], Cdata) ->
 +    decode_vcard_DESC_els(__TopXMLNS, __IgnoreEls, _els,
 +                        <<Cdata/binary, _data/binary>>);
 +decode_vcard_DESC_els(__TopXMLNS, __IgnoreEls,
 +                    [_ | _els], Cdata) ->
 +    decode_vcard_DESC_els(__TopXMLNS, __IgnoreEls, _els,
 +                        Cdata).
 +
 +encode_vcard_DESC(Cdata, __TopXMLNS) ->
 +    __NewTopXMLNS = choose_top_xmlns(<<"vcard-temp">>, [],
 +                                   __TopXMLNS),
 +    _els = encode_vcard_DESC_cdata(Cdata, []),
 +    _attrs = enc_xmlns_attrs(__NewTopXMLNS, __TopXMLNS),
 +    {xmlel, <<"DESC">>, _attrs, _els}.
 +
 +decode_vcard_DESC_cdata(__TopXMLNS, <<>>) -> <<>>;
 +decode_vcard_DESC_cdata(__TopXMLNS, _val) -> _val.
 +
 +encode_vcard_DESC_cdata(<<>>, _acc) -> _acc;
 +encode_vcard_DESC_cdata(_val, _acc) ->
 +    [{xmlcdata, _val} | _acc].
 +
 +decode_vcard_URL(__TopXMLNS, __IgnoreEls,
 +               {xmlel, <<"URL">>, _attrs, _els}) ->
 +    Cdata = decode_vcard_URL_els(__TopXMLNS, __IgnoreEls,
 +                               _els, <<>>),
 +    Cdata.
 +
 +decode_vcard_URL_els(__TopXMLNS, __IgnoreEls, [],
 +                   Cdata) ->
 +    decode_vcard_URL_cdata(__TopXMLNS, Cdata);
 +decode_vcard_URL_els(__TopXMLNS, __IgnoreEls,
 +                   [{xmlcdata, _data} | _els], Cdata) ->
 +    decode_vcard_URL_els(__TopXMLNS, __IgnoreEls, _els,
 +                       <<Cdata/binary, _data/binary>>);
 +decode_vcard_URL_els(__TopXMLNS, __IgnoreEls,
 +                   [_ | _els], Cdata) ->
 +    decode_vcard_URL_els(__TopXMLNS, __IgnoreEls, _els,
 +                       Cdata).
 +
 +encode_vcard_URL(Cdata, __TopXMLNS) ->
 +    __NewTopXMLNS = choose_top_xmlns(<<"vcard-temp">>, [],
 +                                   __TopXMLNS),
 +    _els = encode_vcard_URL_cdata(Cdata, []),
 +    _attrs = enc_xmlns_attrs(__NewTopXMLNS, __TopXMLNS),
 +    {xmlel, <<"URL">>, _attrs, _els}.
 +
 +decode_vcard_URL_cdata(__TopXMLNS, <<>>) -> <<>>;
 +decode_vcard_URL_cdata(__TopXMLNS, _val) -> _val.
 +
 +encode_vcard_URL_cdata(<<>>, _acc) -> _acc;
 +encode_vcard_URL_cdata(_val, _acc) ->
 +    [{xmlcdata, _val} | _acc].
 +
 +decode_vcard_UID(__TopXMLNS, __IgnoreEls,
 +               {xmlel, <<"UID">>, _attrs, _els}) ->
 +    Cdata = decode_vcard_UID_els(__TopXMLNS, __IgnoreEls,
 +                               _els, <<>>),
 +    Cdata.
 +
 +decode_vcard_UID_els(__TopXMLNS, __IgnoreEls, [],
 +                   Cdata) ->
 +    decode_vcard_UID_cdata(__TopXMLNS, Cdata);
 +decode_vcard_UID_els(__TopXMLNS, __IgnoreEls,
 +                   [{xmlcdata, _data} | _els], Cdata) ->
 +    decode_vcard_UID_els(__TopXMLNS, __IgnoreEls, _els,
 +                       <<Cdata/binary, _data/binary>>);
 +decode_vcard_UID_els(__TopXMLNS, __IgnoreEls,
 +                   [_ | _els], Cdata) ->
 +    decode_vcard_UID_els(__TopXMLNS, __IgnoreEls, _els,
 +                       Cdata).
 +
 +encode_vcard_UID(Cdata, __TopXMLNS) ->
 +    __NewTopXMLNS = choose_top_xmlns(<<"vcard-temp">>, [],
 +                                   __TopXMLNS),
 +    _els = encode_vcard_UID_cdata(Cdata, []),
 +    _attrs = enc_xmlns_attrs(__NewTopXMLNS, __TopXMLNS),
 +    {xmlel, <<"UID">>, _attrs, _els}.
 +
 +decode_vcard_UID_cdata(__TopXMLNS, <<>>) -> <<>>;
 +decode_vcard_UID_cdata(__TopXMLNS, _val) -> _val.
 +
 +encode_vcard_UID_cdata(<<>>, _acc) -> _acc;
 +encode_vcard_UID_cdata(_val, _acc) ->
 +    [{xmlcdata, _val} | _acc].
 +
 +decode_vcard_SORT_STRING(__TopXMLNS, __IgnoreEls,
 +                       {xmlel, <<"SORT-STRING">>, _attrs, _els}) ->
 +    Cdata = decode_vcard_SORT_STRING_els(__TopXMLNS,
 +                                       __IgnoreEls, _els, <<>>),
 +    Cdata.
 +
 +decode_vcard_SORT_STRING_els(__TopXMLNS, __IgnoreEls,
 +                           [], Cdata) ->
 +    decode_vcard_SORT_STRING_cdata(__TopXMLNS, Cdata);
 +decode_vcard_SORT_STRING_els(__TopXMLNS, __IgnoreEls,
 +                           [{xmlcdata, _data} | _els], Cdata) ->
 +    decode_vcard_SORT_STRING_els(__TopXMLNS, __IgnoreEls,
 +                               _els, <<Cdata/binary, _data/binary>>);
 +decode_vcard_SORT_STRING_els(__TopXMLNS, __IgnoreEls,
 +                           [_ | _els], Cdata) ->
 +    decode_vcard_SORT_STRING_els(__TopXMLNS, __IgnoreEls,
 +                               _els, Cdata).
 +
 +encode_vcard_SORT_STRING(Cdata, __TopXMLNS) ->
 +    __NewTopXMLNS = choose_top_xmlns(<<"vcard-temp">>, [],
 +                                   __TopXMLNS),
 +    _els = encode_vcard_SORT_STRING_cdata(Cdata, []),
 +    _attrs = enc_xmlns_attrs(__NewTopXMLNS, __TopXMLNS),
 +    {xmlel, <<"SORT-STRING">>, _attrs, _els}.
 +
 +decode_vcard_SORT_STRING_cdata(__TopXMLNS, <<>>) ->
 +    <<>>;
 +decode_vcard_SORT_STRING_cdata(__TopXMLNS, _val) ->
 +    _val.
 +
 +encode_vcard_SORT_STRING_cdata(<<>>, _acc) -> _acc;
 +encode_vcard_SORT_STRING_cdata(_val, _acc) ->
 +    [{xmlcdata, _val} | _acc].
 +
 +decode_vcard_REV(__TopXMLNS, __IgnoreEls,
 +               {xmlel, <<"REV">>, _attrs, _els}) ->
 +    Cdata = decode_vcard_REV_els(__TopXMLNS, __IgnoreEls,
 +                               _els, <<>>),
 +    Cdata.
 +
 +decode_vcard_REV_els(__TopXMLNS, __IgnoreEls, [],
 +                   Cdata) ->
 +    decode_vcard_REV_cdata(__TopXMLNS, Cdata);
 +decode_vcard_REV_els(__TopXMLNS, __IgnoreEls,
 +                   [{xmlcdata, _data} | _els], Cdata) ->
 +    decode_vcard_REV_els(__TopXMLNS, __IgnoreEls, _els,
 +                       <<Cdata/binary, _data/binary>>);
 +decode_vcard_REV_els(__TopXMLNS, __IgnoreEls,
 +                   [_ | _els], Cdata) ->
 +    decode_vcard_REV_els(__TopXMLNS, __IgnoreEls, _els,
 +                       Cdata).
 +
 +encode_vcard_REV(Cdata, __TopXMLNS) ->
 +    __NewTopXMLNS = choose_top_xmlns(<<"vcard-temp">>, [],
 +                                   __TopXMLNS),
 +    _els = encode_vcard_REV_cdata(Cdata, []),
 +    _attrs = enc_xmlns_attrs(__NewTopXMLNS, __TopXMLNS),
 +    {xmlel, <<"REV">>, _attrs, _els}.
 +
 +decode_vcard_REV_cdata(__TopXMLNS, <<>>) -> <<>>;
 +decode_vcard_REV_cdata(__TopXMLNS, _val) -> _val.
 +
 +encode_vcard_REV_cdata(<<>>, _acc) -> _acc;
 +encode_vcard_REV_cdata(_val, _acc) ->
 +    [{xmlcdata, _val} | _acc].
 +
 +decode_vcard_PRODID(__TopXMLNS, __IgnoreEls,
 +                  {xmlel, <<"PRODID">>, _attrs, _els}) ->
 +    Cdata = decode_vcard_PRODID_els(__TopXMLNS, __IgnoreEls,
 +                                  _els, <<>>),
 +    Cdata.
 +
 +decode_vcard_PRODID_els(__TopXMLNS, __IgnoreEls, [],
 +                      Cdata) ->
 +    decode_vcard_PRODID_cdata(__TopXMLNS, Cdata);
 +decode_vcard_PRODID_els(__TopXMLNS, __IgnoreEls,
 +                      [{xmlcdata, _data} | _els], Cdata) ->
 +    decode_vcard_PRODID_els(__TopXMLNS, __IgnoreEls, _els,
 +                          <<Cdata/binary, _data/binary>>);
 +decode_vcard_PRODID_els(__TopXMLNS, __IgnoreEls,
 +                      [_ | _els], Cdata) ->
 +    decode_vcard_PRODID_els(__TopXMLNS, __IgnoreEls, _els,
 +                          Cdata).
 +
 +encode_vcard_PRODID(Cdata, __TopXMLNS) ->
 +    __NewTopXMLNS = choose_top_xmlns(<<"vcard-temp">>, [],
 +                                   __TopXMLNS),
 +    _els = encode_vcard_PRODID_cdata(Cdata, []),
 +    _attrs = enc_xmlns_attrs(__NewTopXMLNS, __TopXMLNS),
 +    {xmlel, <<"PRODID">>, _attrs, _els}.
 +
 +decode_vcard_PRODID_cdata(__TopXMLNS, <<>>) -> <<>>;
 +decode_vcard_PRODID_cdata(__TopXMLNS, _val) -> _val.
 +
 +encode_vcard_PRODID_cdata(<<>>, _acc) -> _acc;
 +encode_vcard_PRODID_cdata(_val, _acc) ->
 +    [{xmlcdata, _val} | _acc].
 +
 +decode_vcard_NOTE(__TopXMLNS, __IgnoreEls,
 +                {xmlel, <<"NOTE">>, _attrs, _els}) ->
 +    Cdata = decode_vcard_NOTE_els(__TopXMLNS, __IgnoreEls,
 +                                _els, <<>>),
 +    Cdata.
 +
 +decode_vcard_NOTE_els(__TopXMLNS, __IgnoreEls, [],
 +                    Cdata) ->
 +    decode_vcard_NOTE_cdata(__TopXMLNS, Cdata);
 +decode_vcard_NOTE_els(__TopXMLNS, __IgnoreEls,
 +                    [{xmlcdata, _data} | _els], Cdata) ->
 +    decode_vcard_NOTE_els(__TopXMLNS, __IgnoreEls, _els,
 +                        <<Cdata/binary, _data/binary>>);
 +decode_vcard_NOTE_els(__TopXMLNS, __IgnoreEls,
 +                    [_ | _els], Cdata) ->
 +    decode_vcard_NOTE_els(__TopXMLNS, __IgnoreEls, _els,
 +                        Cdata).
 +
 +encode_vcard_NOTE(Cdata, __TopXMLNS) ->
 +    __NewTopXMLNS = choose_top_xmlns(<<"vcard-temp">>, [],
 +                                   __TopXMLNS),
 +    _els = encode_vcard_NOTE_cdata(Cdata, []),
 +    _attrs = enc_xmlns_attrs(__NewTopXMLNS, __TopXMLNS),
 +    {xmlel, <<"NOTE">>, _attrs, _els}.
 +
 +decode_vcard_NOTE_cdata(__TopXMLNS, <<>>) -> <<>>;
 +decode_vcard_NOTE_cdata(__TopXMLNS, _val) -> _val.
 +
 +encode_vcard_NOTE_cdata(<<>>, _acc) -> _acc;
 +encode_vcard_NOTE_cdata(_val, _acc) ->
 +    [{xmlcdata, _val} | _acc].
 +
 +decode_vcard_KEYWORD(__TopXMLNS, __IgnoreEls,
 +                   {xmlel, <<"KEYWORD">>, _attrs, _els}) ->
 +    Cdata = decode_vcard_KEYWORD_els(__TopXMLNS,
 +                                   __IgnoreEls, _els, <<>>),
 +    Cdata.
 +
 +decode_vcard_KEYWORD_els(__TopXMLNS, __IgnoreEls, [],
 +                       Cdata) ->
 +    decode_vcard_KEYWORD_cdata(__TopXMLNS, Cdata);
 +decode_vcard_KEYWORD_els(__TopXMLNS, __IgnoreEls,
 +                       [{xmlcdata, _data} | _els], Cdata) ->
 +    decode_vcard_KEYWORD_els(__TopXMLNS, __IgnoreEls, _els,
 +                           <<Cdata/binary, _data/binary>>);
 +decode_vcard_KEYWORD_els(__TopXMLNS, __IgnoreEls,
 +                       [_ | _els], Cdata) ->
 +    decode_vcard_KEYWORD_els(__TopXMLNS, __IgnoreEls, _els,
 +                           Cdata).
 +
 +encode_vcard_KEYWORD(Cdata, __TopXMLNS) ->
 +    __NewTopXMLNS = choose_top_xmlns(<<"vcard-temp">>, [],
 +                                   __TopXMLNS),
 +    _els = encode_vcard_KEYWORD_cdata(Cdata, []),
 +    _attrs = enc_xmlns_attrs(__NewTopXMLNS, __TopXMLNS),
 +    {xmlel, <<"KEYWORD">>, _attrs, _els}.
 +
 +decode_vcard_KEYWORD_cdata(__TopXMLNS, <<>>) -> <<>>;
 +decode_vcard_KEYWORD_cdata(__TopXMLNS, _val) -> _val.
 +
 +encode_vcard_KEYWORD_cdata(<<>>, _acc) -> _acc;
 +encode_vcard_KEYWORD_cdata(_val, _acc) ->
 +    [{xmlcdata, _val} | _acc].
 +
 +decode_vcard_ROLE(__TopXMLNS, __IgnoreEls,
 +                {xmlel, <<"ROLE">>, _attrs, _els}) ->
 +    Cdata = decode_vcard_ROLE_els(__TopXMLNS, __IgnoreEls,
 +                                _els, <<>>),
 +    Cdata.
 +
 +decode_vcard_ROLE_els(__TopXMLNS, __IgnoreEls, [],
 +                    Cdata) ->
 +    decode_vcard_ROLE_cdata(__TopXMLNS, Cdata);
 +decode_vcard_ROLE_els(__TopXMLNS, __IgnoreEls,
 +                    [{xmlcdata, _data} | _els], Cdata) ->
 +    decode_vcard_ROLE_els(__TopXMLNS, __IgnoreEls, _els,
 +                        <<Cdata/binary, _data/binary>>);
 +decode_vcard_ROLE_els(__TopXMLNS, __IgnoreEls,
 +                    [_ | _els], Cdata) ->
 +    decode_vcard_ROLE_els(__TopXMLNS, __IgnoreEls, _els,
 +                        Cdata).
 +
 +encode_vcard_ROLE(Cdata, __TopXMLNS) ->
 +    __NewTopXMLNS = choose_top_xmlns(<<"vcard-temp">>, [],
 +                                   __TopXMLNS),
 +    _els = encode_vcard_ROLE_cdata(Cdata, []),
 +    _attrs = enc_xmlns_attrs(__NewTopXMLNS, __TopXMLNS),
 +    {xmlel, <<"ROLE">>, _attrs, _els}.
 +
 +decode_vcard_ROLE_cdata(__TopXMLNS, <<>>) -> <<>>;
 +decode_vcard_ROLE_cdata(__TopXMLNS, _val) -> _val.
 +
 +encode_vcard_ROLE_cdata(<<>>, _acc) -> _acc;
 +encode_vcard_ROLE_cdata(_val, _acc) ->
 +    [{xmlcdata, _val} | _acc].
 +
 +decode_vcard_TITLE(__TopXMLNS, __IgnoreEls,
 +                 {xmlel, <<"TITLE">>, _attrs, _els}) ->
 +    Cdata = decode_vcard_TITLE_els(__TopXMLNS, __IgnoreEls,
 +                                 _els, <<>>),
 +    Cdata.
 +
 +decode_vcard_TITLE_els(__TopXMLNS, __IgnoreEls, [],
 +                     Cdata) ->
 +    decode_vcard_TITLE_cdata(__TopXMLNS, Cdata);
 +decode_vcard_TITLE_els(__TopXMLNS, __IgnoreEls,
 +                     [{xmlcdata, _data} | _els], Cdata) ->
 +    decode_vcard_TITLE_els(__TopXMLNS, __IgnoreEls, _els,
 +                         <<Cdata/binary, _data/binary>>);
 +decode_vcard_TITLE_els(__TopXMLNS, __IgnoreEls,
 +                     [_ | _els], Cdata) ->
 +    decode_vcard_TITLE_els(__TopXMLNS, __IgnoreEls, _els,
 +                         Cdata).
 +
 +encode_vcard_TITLE(Cdata, __TopXMLNS) ->
 +    __NewTopXMLNS = choose_top_xmlns(<<"vcard-temp">>, [],
 +                                   __TopXMLNS),
 +    _els = encode_vcard_TITLE_cdata(Cdata, []),
 +    _attrs = enc_xmlns_attrs(__NewTopXMLNS, __TopXMLNS),
 +    {xmlel, <<"TITLE">>, _attrs, _els}.
 +
 +decode_vcard_TITLE_cdata(__TopXMLNS, <<>>) -> <<>>;
 +decode_vcard_TITLE_cdata(__TopXMLNS, _val) -> _val.
 +
 +encode_vcard_TITLE_cdata(<<>>, _acc) -> _acc;
 +encode_vcard_TITLE_cdata(_val, _acc) ->
 +    [{xmlcdata, _val} | _acc].
 +
 +decode_vcard_TZ(__TopXMLNS, __IgnoreEls,
 +              {xmlel, <<"TZ">>, _attrs, _els}) ->
 +    Cdata = decode_vcard_TZ_els(__TopXMLNS, __IgnoreEls,
 +                              _els, <<>>),
 +    Cdata.
 +
 +decode_vcard_TZ_els(__TopXMLNS, __IgnoreEls, [],
 +                  Cdata) ->
 +    decode_vcard_TZ_cdata(__TopXMLNS, Cdata);
 +decode_vcard_TZ_els(__TopXMLNS, __IgnoreEls,
 +                  [{xmlcdata, _data} | _els], Cdata) ->
 +    decode_vcard_TZ_els(__TopXMLNS, __IgnoreEls, _els,
 +                      <<Cdata/binary, _data/binary>>);
 +decode_vcard_TZ_els(__TopXMLNS, __IgnoreEls, [_ | _els],
 +                  Cdata) ->
 +    decode_vcard_TZ_els(__TopXMLNS, __IgnoreEls, _els,
 +                      Cdata).
 +
 +encode_vcard_TZ(Cdata, __TopXMLNS) ->
 +    __NewTopXMLNS = choose_top_xmlns(<<"vcard-temp">>, [],
 +                                   __TopXMLNS),
 +    _els = encode_vcard_TZ_cdata(Cdata, []),
 +    _attrs = enc_xmlns_attrs(__NewTopXMLNS, __TopXMLNS),
 +    {xmlel, <<"TZ">>, _attrs, _els}.
 +
 +decode_vcard_TZ_cdata(__TopXMLNS, <<>>) -> <<>>;
 +decode_vcard_TZ_cdata(__TopXMLNS, _val) -> _val.
 +
 +encode_vcard_TZ_cdata(<<>>, _acc) -> _acc;
 +encode_vcard_TZ_cdata(_val, _acc) ->
 +    [{xmlcdata, _val} | _acc].
 +
 +decode_vcard_MAILER(__TopXMLNS, __IgnoreEls,
 +                  {xmlel, <<"MAILER">>, _attrs, _els}) ->
 +    Cdata = decode_vcard_MAILER_els(__TopXMLNS, __IgnoreEls,
 +                                  _els, <<>>),
 +    Cdata.
 +
 +decode_vcard_MAILER_els(__TopXMLNS, __IgnoreEls, [],
 +                      Cdata) ->
 +    decode_vcard_MAILER_cdata(__TopXMLNS, Cdata);
 +decode_vcard_MAILER_els(__TopXMLNS, __IgnoreEls,
 +                      [{xmlcdata, _data} | _els], Cdata) ->
 +    decode_vcard_MAILER_els(__TopXMLNS, __IgnoreEls, _els,
 +                          <<Cdata/binary, _data/binary>>);
 +decode_vcard_MAILER_els(__TopXMLNS, __IgnoreEls,
 +                      [_ | _els], Cdata) ->
 +    decode_vcard_MAILER_els(__TopXMLNS, __IgnoreEls, _els,
 +                          Cdata).
 +
 +encode_vcard_MAILER(Cdata, __TopXMLNS) ->
 +    __NewTopXMLNS = choose_top_xmlns(<<"vcard-temp">>, [],
 +                                   __TopXMLNS),
 +    _els = encode_vcard_MAILER_cdata(Cdata, []),
 +    _attrs = enc_xmlns_attrs(__NewTopXMLNS, __TopXMLNS),
 +    {xmlel, <<"MAILER">>, _attrs, _els}.
 +
 +decode_vcard_MAILER_cdata(__TopXMLNS, <<>>) -> <<>>;
 +decode_vcard_MAILER_cdata(__TopXMLNS, _val) -> _val.
 +
 +encode_vcard_MAILER_cdata(<<>>, _acc) -> _acc;
 +encode_vcard_MAILER_cdata(_val, _acc) ->
 +    [{xmlcdata, _val} | _acc].
 +
 +decode_vcard_JABBERID(__TopXMLNS, __IgnoreEls,
 +                    {xmlel, <<"JABBERID">>, _attrs, _els}) ->
 +    Cdata = decode_vcard_JABBERID_els(__TopXMLNS,
 +                                    __IgnoreEls, _els, <<>>),
 +    Cdata.
 +
 +decode_vcard_JABBERID_els(__TopXMLNS, __IgnoreEls, [],
 +                        Cdata) ->
 +    decode_vcard_JABBERID_cdata(__TopXMLNS, Cdata);
 +decode_vcard_JABBERID_els(__TopXMLNS, __IgnoreEls,
 +                        [{xmlcdata, _data} | _els], Cdata) ->
 +    decode_vcard_JABBERID_els(__TopXMLNS, __IgnoreEls, _els,
 +                            <<Cdata/binary, _data/binary>>);
 +decode_vcard_JABBERID_els(__TopXMLNS, __IgnoreEls,
 +                        [_ | _els], Cdata) ->
 +    decode_vcard_JABBERID_els(__TopXMLNS, __IgnoreEls, _els,
 +                            Cdata).
 +
 +encode_vcard_JABBERID(Cdata, __TopXMLNS) ->
 +    __NewTopXMLNS = choose_top_xmlns(<<"vcard-temp">>, [],
 +                                   __TopXMLNS),
 +    _els = encode_vcard_JABBERID_cdata(Cdata, []),
 +    _attrs = enc_xmlns_attrs(__NewTopXMLNS, __TopXMLNS),
 +    {xmlel, <<"JABBERID">>, _attrs, _els}.
 +
 +decode_vcard_JABBERID_cdata(__TopXMLNS, <<>>) -> <<>>;
 +decode_vcard_JABBERID_cdata(__TopXMLNS, _val) -> _val.
 +
 +encode_vcard_JABBERID_cdata(<<>>, _acc) -> _acc;
 +encode_vcard_JABBERID_cdata(_val, _acc) ->
 +    [{xmlcdata, _val} | _acc].
 +
 +decode_vcard_BDAY(__TopXMLNS, __IgnoreEls,
 +                {xmlel, <<"BDAY">>, _attrs, _els}) ->
 +    Cdata = decode_vcard_BDAY_els(__TopXMLNS, __IgnoreEls,
 +                                _els, <<>>),
 +    Cdata.
 +
 +decode_vcard_BDAY_els(__TopXMLNS, __IgnoreEls, [],
 +                    Cdata) ->
 +    decode_vcard_BDAY_cdata(__TopXMLNS, Cdata);
 +decode_vcard_BDAY_els(__TopXMLNS, __IgnoreEls,
 +                    [{xmlcdata, _data} | _els], Cdata) ->
 +    decode_vcard_BDAY_els(__TopXMLNS, __IgnoreEls, _els,
 +                        <<Cdata/binary, _data/binary>>);
 +decode_vcard_BDAY_els(__TopXMLNS, __IgnoreEls,
 +                    [_ | _els], Cdata) ->
 +    decode_vcard_BDAY_els(__TopXMLNS, __IgnoreEls, _els,
 +                        Cdata).
 +
 +encode_vcard_BDAY(Cdata, __TopXMLNS) ->
 +    __NewTopXMLNS = choose_top_xmlns(<<"vcard-temp">>, [],
 +                                   __TopXMLNS),
 +    _els = encode_vcard_BDAY_cdata(Cdata, []),
 +    _attrs = enc_xmlns_attrs(__NewTopXMLNS, __TopXMLNS),
 +    {xmlel, <<"BDAY">>, _attrs, _els}.
 +
 +decode_vcard_BDAY_cdata(__TopXMLNS, <<>>) -> <<>>;
 +decode_vcard_BDAY_cdata(__TopXMLNS, _val) -> _val.
 +
 +encode_vcard_BDAY_cdata(<<>>, _acc) -> _acc;
 +encode_vcard_BDAY_cdata(_val, _acc) ->
 +    [{xmlcdata, _val} | _acc].
 +
 +decode_vcard_NICKNAME(__TopXMLNS, __IgnoreEls,
 +                    {xmlel, <<"NICKNAME">>, _attrs, _els}) ->
 +    Cdata = decode_vcard_NICKNAME_els(__TopXMLNS,
 +                                    __IgnoreEls, _els, <<>>),
 +    Cdata.
 +
 +decode_vcard_NICKNAME_els(__TopXMLNS, __IgnoreEls, [],
 +                        Cdata) ->
 +    decode_vcard_NICKNAME_cdata(__TopXMLNS, Cdata);
 +decode_vcard_NICKNAME_els(__TopXMLNS, __IgnoreEls,
 +                        [{xmlcdata, _data} | _els], Cdata) ->
 +    decode_vcard_NICKNAME_els(__TopXMLNS, __IgnoreEls, _els,
 +                            <<Cdata/binary, _data/binary>>);
 +decode_vcard_NICKNAME_els(__TopXMLNS, __IgnoreEls,
 +                        [_ | _els], Cdata) ->
 +    decode_vcard_NICKNAME_els(__TopXMLNS, __IgnoreEls, _els,
 +                            Cdata).
 +
 +encode_vcard_NICKNAME(Cdata, __TopXMLNS) ->
 +    __NewTopXMLNS = choose_top_xmlns(<<"vcard-temp">>, [],
 +                                   __TopXMLNS),
 +    _els = encode_vcard_NICKNAME_cdata(Cdata, []),
 +    _attrs = enc_xmlns_attrs(__NewTopXMLNS, __TopXMLNS),
 +    {xmlel, <<"NICKNAME">>, _attrs, _els}.
 +
 +decode_vcard_NICKNAME_cdata(__TopXMLNS, <<>>) -> <<>>;
 +decode_vcard_NICKNAME_cdata(__TopXMLNS, _val) -> _val.
 +
 +encode_vcard_NICKNAME_cdata(<<>>, _acc) -> _acc;
 +encode_vcard_NICKNAME_cdata(_val, _acc) ->
 +    [{xmlcdata, _val} | _acc].
 +
 +decode_vcard_FN(__TopXMLNS, __IgnoreEls,
 +              {xmlel, <<"FN">>, _attrs, _els}) ->
 +    Cdata = decode_vcard_FN_els(__TopXMLNS, __IgnoreEls,
 +                              _els, <<>>),
 +    Cdata.
 +
 +decode_vcard_FN_els(__TopXMLNS, __IgnoreEls, [],
 +                  Cdata) ->
 +    decode_vcard_FN_cdata(__TopXMLNS, Cdata);
 +decode_vcard_FN_els(__TopXMLNS, __IgnoreEls,
 +                  [{xmlcdata, _data} | _els], Cdata) ->
 +    decode_vcard_FN_els(__TopXMLNS, __IgnoreEls, _els,
 +                      <<Cdata/binary, _data/binary>>);
 +decode_vcard_FN_els(__TopXMLNS, __IgnoreEls, [_ | _els],
 +                  Cdata) ->
 +    decode_vcard_FN_els(__TopXMLNS, __IgnoreEls, _els,
 +                      Cdata).
 +
 +encode_vcard_FN(Cdata, __TopXMLNS) ->
 +    __NewTopXMLNS = choose_top_xmlns(<<"vcard-temp">>, [],
 +                                   __TopXMLNS),
 +    _els = encode_vcard_FN_cdata(Cdata, []),
 +    _attrs = enc_xmlns_attrs(__NewTopXMLNS, __TopXMLNS),
 +    {xmlel, <<"FN">>, _attrs, _els}.
 +
 +decode_vcard_FN_cdata(__TopXMLNS, <<>>) -> <<>>;
 +decode_vcard_FN_cdata(__TopXMLNS, _val) -> _val.
 +
 +encode_vcard_FN_cdata(<<>>, _acc) -> _acc;
 +encode_vcard_FN_cdata(_val, _acc) ->
 +    [{xmlcdata, _val} | _acc].
 +
 +decode_vcard_VERSION(__TopXMLNS, __IgnoreEls,
 +                   {xmlel, <<"VERSION">>, _attrs, _els}) ->
 +    Cdata = decode_vcard_VERSION_els(__TopXMLNS,
 +                                   __IgnoreEls, _els, <<>>),
 +    Cdata.
 +
 +decode_vcard_VERSION_els(__TopXMLNS, __IgnoreEls, [],
 +                       Cdata) ->
 +    decode_vcard_VERSION_cdata(__TopXMLNS, Cdata);
 +decode_vcard_VERSION_els(__TopXMLNS, __IgnoreEls,
 +                       [{xmlcdata, _data} | _els], Cdata) ->
 +    decode_vcard_VERSION_els(__TopXMLNS, __IgnoreEls, _els,
 +                           <<Cdata/binary, _data/binary>>);
 +decode_vcard_VERSION_els(__TopXMLNS, __IgnoreEls,
 +                       [_ | _els], Cdata) ->
 +    decode_vcard_VERSION_els(__TopXMLNS, __IgnoreEls, _els,
 +                           Cdata).
 +
 +encode_vcard_VERSION(Cdata, __TopXMLNS) ->
 +    __NewTopXMLNS = choose_top_xmlns(<<"vcard-temp">>, [],
 +                                   __TopXMLNS),
 +    _els = encode_vcard_VERSION_cdata(Cdata, []),
 +    _attrs = enc_xmlns_attrs(__NewTopXMLNS, __TopXMLNS),
 +    {xmlel, <<"VERSION">>, _attrs, _els}.
 +
 +decode_vcard_VERSION_cdata(__TopXMLNS, <<>>) -> <<>>;
 +decode_vcard_VERSION_cdata(__TopXMLNS, _val) -> _val.
 +
 +encode_vcard_VERSION_cdata(<<>>, _acc) -> _acc;
 +encode_vcard_VERSION_cdata(_val, _acc) ->
 +    [{xmlcdata, _val} | _acc].
 +
 +decode_vcard_CRED(__TopXMLNS, __IgnoreEls,
 +                {xmlel, <<"CRED">>, _attrs, _els}) ->
 +    Cdata = decode_vcard_CRED_els(__TopXMLNS, __IgnoreEls,
 +                                _els, <<>>),
 +    Cdata.
 +
 +decode_vcard_CRED_els(__TopXMLNS, __IgnoreEls, [],
 +                    Cdata) ->
 +    decode_vcard_CRED_cdata(__TopXMLNS, Cdata);
 +decode_vcard_CRED_els(__TopXMLNS, __IgnoreEls,
 +                    [{xmlcdata, _data} | _els], Cdata) ->
 +    decode_vcard_CRED_els(__TopXMLNS, __IgnoreEls, _els,
 +                        <<Cdata/binary, _data/binary>>);
 +decode_vcard_CRED_els(__TopXMLNS, __IgnoreEls,
 +                    [_ | _els], Cdata) ->
 +    decode_vcard_CRED_els(__TopXMLNS, __IgnoreEls, _els,
 +                        Cdata).
 +
 +encode_vcard_CRED(Cdata, __TopXMLNS) ->
 +    __NewTopXMLNS = choose_top_xmlns(<<"vcard-temp">>, [],
 +                                   __TopXMLNS),
 +    _els = encode_vcard_CRED_cdata(Cdata, []),
 +    _attrs = enc_xmlns_attrs(__NewTopXMLNS, __TopXMLNS),
 +    {xmlel, <<"CRED">>, _attrs, _els}.
 +
 +decode_vcard_CRED_cdata(__TopXMLNS, <<>>) -> <<>>;
 +decode_vcard_CRED_cdata(__TopXMLNS, _val) -> _val.
 +
 +encode_vcard_CRED_cdata(<<>>, _acc) -> _acc;
 +encode_vcard_CRED_cdata(_val, _acc) ->
 +    [{xmlcdata, _val} | _acc].
 +
 +decode_vcard_PHONETIC(__TopXMLNS, __IgnoreEls,
 +                    {xmlel, <<"PHONETIC">>, _attrs, _els}) ->
 +    Cdata = decode_vcard_PHONETIC_els(__TopXMLNS,
 +                                    __IgnoreEls, _els, <<>>),
 +    Cdata.
 +
 +decode_vcard_PHONETIC_els(__TopXMLNS, __IgnoreEls, [],
 +                        Cdata) ->
 +    decode_vcard_PHONETIC_cdata(__TopXMLNS, Cdata);
 +decode_vcard_PHONETIC_els(__TopXMLNS, __IgnoreEls,
 +                        [{xmlcdata, _data} | _els], Cdata) ->
 +    decode_vcard_PHONETIC_els(__TopXMLNS, __IgnoreEls, _els,
 +                            <<Cdata/binary, _data/binary>>);
 +decode_vcard_PHONETIC_els(__TopXMLNS, __IgnoreEls,
 +                        [_ | _els], Cdata) ->
 +    decode_vcard_PHONETIC_els(__TopXMLNS, __IgnoreEls, _els,
 +                            Cdata).
 +
 +encode_vcard_PHONETIC(Cdata, __TopXMLNS) ->
 +    __NewTopXMLNS = choose_top_xmlns(<<"vcard-temp">>, [],
 +                                   __TopXMLNS),
 +    _els = encode_vcard_PHONETIC_cdata(Cdata, []),
 +    _attrs = enc_xmlns_attrs(__NewTopXMLNS, __TopXMLNS),
 +    {xmlel, <<"PHONETIC">>, _attrs, _els}.
 +
 +decode_vcard_PHONETIC_cdata(__TopXMLNS, <<>>) -> <<>>;
 +decode_vcard_PHONETIC_cdata(__TopXMLNS, _val) -> _val.
 +
 +encode_vcard_PHONETIC_cdata(<<>>, _acc) -> _acc;
 +encode_vcard_PHONETIC_cdata(_val, _acc) ->
 +    [{xmlcdata, _val} | _acc].
 +
 +decode_vcard_ORGUNIT(__TopXMLNS, __IgnoreEls,
 +                   {xmlel, <<"ORGUNIT">>, _attrs, _els}) ->
 +    Cdata = decode_vcard_ORGUNIT_els(__TopXMLNS,
 +                                   __IgnoreEls, _els, <<>>),
 +    Cdata.
 +
 +decode_vcard_ORGUNIT_els(__TopXMLNS, __IgnoreEls, [],
 +                       Cdata) ->
 +    decode_vcard_ORGUNIT_cdata(__TopXMLNS, Cdata);
 +decode_vcard_ORGUNIT_els(__TopXMLNS, __IgnoreEls,
 +                       [{xmlcdata, _data} | _els], Cdata) ->
 +    decode_vcard_ORGUNIT_els(__TopXMLNS, __IgnoreEls, _els,
 +                           <<Cdata/binary, _data/binary>>);
 +decode_vcard_ORGUNIT_els(__TopXMLNS, __IgnoreEls,
 +                       [_ | _els], Cdata) ->
 +    decode_vcard_ORGUNIT_els(__TopXMLNS, __IgnoreEls, _els,
 +                           Cdata).
 +
 +encode_vcard_ORGUNIT(Cdata, __TopXMLNS) ->
 +    __NewTopXMLNS = choose_top_xmlns(<<"vcard-temp">>, [],
 +                                   __TopXMLNS),
 +    _els = encode_vcard_ORGUNIT_cdata(Cdata, []),
 +    _attrs = enc_xmlns_attrs(__NewTopXMLNS, __TopXMLNS),
 +    {xmlel, <<"ORGUNIT">>, _attrs, _els}.
 +
 +decode_vcard_ORGUNIT_cdata(__TopXMLNS, <<>>) -> <<>>;
 +decode_vcard_ORGUNIT_cdata(__TopXMLNS, _val) -> _val.
 +
 +encode_vcard_ORGUNIT_cdata(<<>>, _acc) -> _acc;
 +encode_vcard_ORGUNIT_cdata(_val, _acc) ->
 +    [{xmlcdata, _val} | _acc].
 +
 +decode_vcard_ORGNAME(__TopXMLNS, __IgnoreEls,
 +                   {xmlel, <<"ORGNAME">>, _attrs, _els}) ->
 +    Cdata = decode_vcard_ORGNAME_els(__TopXMLNS,
 +                                   __IgnoreEls, _els, <<>>),
 +    Cdata.
 +
 +decode_vcard_ORGNAME_els(__TopXMLNS, __IgnoreEls, [],
 +                       Cdata) ->
 +    decode_vcard_ORGNAME_cdata(__TopXMLNS, Cdata);
 +decode_vcard_ORGNAME_els(__TopXMLNS, __IgnoreEls,
 +                       [{xmlcdata, _data} | _els], Cdata) ->
 +    decode_vcard_ORGNAME_els(__TopXMLNS, __IgnoreEls, _els,
 +                           <<Cdata/binary, _data/binary>>);
 +decode_vcard_ORGNAME_els(__TopXMLNS, __IgnoreEls,
 +                       [_ | _els], Cdata) ->
 +    decode_vcard_ORGNAME_els(__TopXMLNS, __IgnoreEls, _els,
 +                           Cdata).
 +
 +encode_vcard_ORGNAME(Cdata, __TopXMLNS) ->
 +    __NewTopXMLNS = choose_top_xmlns(<<"vcard-temp">>, [],
 +                                   __TopXMLNS),
 +    _els = encode_vcard_ORGNAME_cdata(Cdata, []),
 +    _attrs = enc_xmlns_attrs(__NewTopXMLNS, __TopXMLNS),
 +    {xmlel, <<"ORGNAME">>, _attrs, _els}.
 +
 +decode_vcard_ORGNAME_cdata(__TopXMLNS, <<>>) -> <<>>;
 +decode_vcard_ORGNAME_cdata(__TopXMLNS, _val) -> _val.
 +
 +encode_vcard_ORGNAME_cdata(<<>>, _acc) -> _acc;
 +encode_vcard_ORGNAME_cdata(_val, _acc) ->
 +    [{xmlcdata, _val} | _acc].
 +
 +decode_vcard_LON(__TopXMLNS, __IgnoreEls,
 +               {xmlel, <<"LON">>, _attrs, _els}) ->
 +    Cdata = decode_vcard_LON_els(__TopXMLNS, __IgnoreEls,
 +                               _els, <<>>),
 +    Cdata.
 +
 +decode_vcard_LON_els(__TopXMLNS, __IgnoreEls, [],
 +                   Cdata) ->
 +    decode_vcard_LON_cdata(__TopXMLNS, Cdata);
 +decode_vcard_LON_els(__TopXMLNS, __IgnoreEls,
 +                   [{xmlcdata, _data} | _els], Cdata) ->
 +    decode_vcard_LON_els(__TopXMLNS, __IgnoreEls, _els,
 +                       <<Cdata/binary, _data/binary>>);
 +decode_vcard_LON_els(__TopXMLNS, __IgnoreEls,
 +                   [_ | _els], Cdata) ->
 +    decode_vcard_LON_els(__TopXMLNS, __IgnoreEls, _els,
 +                       Cdata).
 +
 +encode_vcard_LON(Cdata, __TopXMLNS) ->
 +    __NewTopXMLNS = choose_top_xmlns(<<"vcard-temp">>, [],
 +                                   __TopXMLNS),
 +    _els = encode_vcard_LON_cdata(Cdata, []),
 +    _attrs = enc_xmlns_attrs(__NewTopXMLNS, __TopXMLNS),
 +    {xmlel, <<"LON">>, _attrs, _els}.
 +
 +decode_vcard_LON_cdata(__TopXMLNS, <<>>) -> <<>>;
 +decode_vcard_LON_cdata(__TopXMLNS, _val) -> _val.
 +
 +encode_vcard_LON_cdata(<<>>, _acc) -> _acc;
 +encode_vcard_LON_cdata(_val, _acc) ->
 +    [{xmlcdata, _val} | _acc].
 +
 +decode_vcard_LAT(__TopXMLNS, __IgnoreEls,
 +               {xmlel, <<"LAT">>, _attrs, _els}) ->
 +    Cdata = decode_vcard_LAT_els(__TopXMLNS, __IgnoreEls,
 +                               _els, <<>>),
 +    Cdata.
 +
 +decode_vcard_LAT_els(__TopXMLNS, __IgnoreEls, [],
 +                   Cdata) ->
 +    decode_vcard_LAT_cdata(__TopXMLNS, Cdata);
 +decode_vcard_LAT_els(__TopXMLNS, __IgnoreEls,
 +                   [{xmlcdata, _data} | _els], Cdata) ->
 +    decode_vcard_LAT_els(__TopXMLNS, __IgnoreEls, _els,
 +                       <<Cdata/binary, _data/binary>>);
 +decode_vcard_LAT_els(__TopXMLNS, __IgnoreEls,
 +                   [_ | _els], Cdata) ->
 +    decode_vcard_LAT_els(__TopXMLNS, __IgnoreEls, _els,
 +                       Cdata).
 +
 +encode_vcard_LAT(Cdata, __TopXMLNS) ->
 +    __NewTopXMLNS = choose_top_xmlns(<<"vcard-temp">>, [],
 +                                   __TopXMLNS),
 +    _els = encode_vcard_LAT_cdata(Cdata, []),
 +    _attrs = enc_xmlns_attrs(__NewTopXMLNS, __TopXMLNS),
 +    {xmlel, <<"LAT">>, _attrs, _els}.
 +
 +decode_vcard_LAT_cdata(__TopXMLNS, <<>>) -> <<>>;
 +decode_vcard_LAT_cdata(__TopXMLNS, _val) -> _val.
 +
 +encode_vcard_LAT_cdata(<<>>, _acc) -> _acc;
 +encode_vcard_LAT_cdata(_val, _acc) ->
 +    [{xmlcdata, _val} | _acc].
 +
 +decode_vcard_USERID(__TopXMLNS, __IgnoreEls,
 +                  {xmlel, <<"USERID">>, _attrs, _els}) ->
 +    Cdata = decode_vcard_USERID_els(__TopXMLNS, __IgnoreEls,
 +                                  _els, <<>>),
 +    Cdata.
 +
 +decode_vcard_USERID_els(__TopXMLNS, __IgnoreEls, [],
 +                      Cdata) ->
 +    decode_vcard_USERID_cdata(__TopXMLNS, Cdata);
 +decode_vcard_USERID_els(__TopXMLNS, __IgnoreEls,
 +                      [{xmlcdata, _data} | _els], Cdata) ->
 +    decode_vcard_USERID_els(__TopXMLNS, __IgnoreEls, _els,
 +                          <<Cdata/binary, _data/binary>>);
 +decode_vcard_USERID_els(__TopXMLNS, __IgnoreEls,
 +                      [_ | _els], Cdata) ->
 +    decode_vcard_USERID_els(__TopXMLNS, __IgnoreEls, _els,
 +                          Cdata).
 +
 +encode_vcard_USERID(Cdata, __TopXMLNS) ->
 +    __NewTopXMLNS = choose_top_xmlns(<<"vcard-temp">>, [],
 +                                   __TopXMLNS),
 +    _els = encode_vcard_USERID_cdata(Cdata, []),
 +    _attrs = enc_xmlns_attrs(__NewTopXMLNS, __TopXMLNS),
 +    {xmlel, <<"USERID">>, _attrs, _els}.
 +
 +decode_vcard_USERID_cdata(__TopXMLNS, <<>>) -> <<>>;
 +decode_vcard_USERID_cdata(__TopXMLNS, _val) -> _val.
 +
 +encode_vcard_USERID_cdata(<<>>, _acc) -> _acc;
 +encode_vcard_USERID_cdata(_val, _acc) ->
 +    [{xmlcdata, _val} | _acc].
 +
 +decode_vcard_NUMBER(__TopXMLNS, __IgnoreEls,
 +                  {xmlel, <<"NUMBER">>, _attrs, _els}) ->
 +    Cdata = decode_vcard_NUMBER_els(__TopXMLNS, __IgnoreEls,
 +                                  _els, <<>>),
 +    Cdata.
 +
 +decode_vcard_NUMBER_els(__TopXMLNS, __IgnoreEls, [],
 +                      Cdata) ->
 +    decode_vcard_NUMBER_cdata(__TopXMLNS, Cdata);
 +decode_vcard_NUMBER_els(__TopXMLNS, __IgnoreEls,
 +                      [{xmlcdata, _data} | _els], Cdata) ->
 +    decode_vcard_NUMBER_els(__TopXMLNS, __IgnoreEls, _els,
 +                          <<Cdata/binary, _data/binary>>);
 +decode_vcard_NUMBER_els(__TopXMLNS, __IgnoreEls,
 +                      [_ | _els], Cdata) ->
 +    decode_vcard_NUMBER_els(__TopXMLNS, __IgnoreEls, _els,
 +                          Cdata).
 +
 +encode_vcard_NUMBER(Cdata, __TopXMLNS) ->
 +    __NewTopXMLNS = choose_top_xmlns(<<"vcard-temp">>, [],
 +                                   __TopXMLNS),
 +    _els = encode_vcard_NUMBER_cdata(Cdata, []),
 +    _attrs = enc_xmlns_attrs(__NewTopXMLNS, __TopXMLNS),
 +    {xmlel, <<"NUMBER">>, _attrs, _els}.
 +
 +decode_vcard_NUMBER_cdata(__TopXMLNS, <<>>) -> <<>>;
 +decode_vcard_NUMBER_cdata(__TopXMLNS, _val) -> _val.
 +
 +encode_vcard_NUMBER_cdata(<<>>, _acc) -> _acc;
 +encode_vcard_NUMBER_cdata(_val, _acc) ->
 +    [{xmlcdata, _val} | _acc].
 +
 +decode_vcard_LINE(__TopXMLNS, __IgnoreEls,
 +                {xmlel, <<"LINE">>, _attrs, _els}) ->
 +    Cdata = decode_vcard_LINE_els(__TopXMLNS, __IgnoreEls,
 +                                _els, <<>>),
 +    Cdata.
 +
 +decode_vcard_LINE_els(__TopXMLNS, __IgnoreEls, [],
 +                    Cdata) ->
 +    decode_vcard_LINE_cdata(__TopXMLNS, Cdata);
 +decode_vcard_LINE_els(__TopXMLNS, __IgnoreEls,
 +                    [{xmlcdata, _data} | _els], Cdata) ->
 +    decode_vcard_LINE_els(__TopXMLNS, __IgnoreEls, _els,
 +                        <<Cdata/binary, _data/binary>>);
 +decode_vcard_LINE_els(__TopXMLNS, __IgnoreEls,
 +                    [_ | _els], Cdata) ->
 +    decode_vcard_LINE_els(__TopXMLNS, __IgnoreEls, _els,
 +                        Cdata).
 +
 +encode_vcard_LINE(Cdata, __TopXMLNS) ->
 +    __NewTopXMLNS = choose_top_xmlns(<<"vcard-temp">>, [],
 +                                   __TopXMLNS),
 +    _els = encode_vcard_LINE_cdata(Cdata, []),
 +    _attrs = enc_xmlns_attrs(__NewTopXMLNS, __TopXMLNS),
 +    {xmlel, <<"LINE">>, _attrs, _els}.
 +
 +decode_vcard_LINE_cdata(__TopXMLNS, <<>>) -> <<>>;
 +decode_vcard_LINE_cdata(__TopXMLNS, _val) -> _val.
 +
 +encode_vcard_LINE_cdata(<<>>, _acc) -> _acc;
 +encode_vcard_LINE_cdata(_val, _acc) ->
 +    [{xmlcdata, _val} | _acc].
 +
 +decode_vcard_CTRY(__TopXMLNS, __IgnoreEls,
 +                {xmlel, <<"CTRY">>, _attrs, _els}) ->
 +    Cdata = decode_vcard_CTRY_els(__TopXMLNS, __IgnoreEls,
 +                                _els, <<>>),
 +    Cdata.
 +
 +decode_vcard_CTRY_els(__TopXMLNS, __IgnoreEls, [],
 +                    Cdata) ->
 +    decode_vcard_CTRY_cdata(__TopXMLNS, Cdata);
 +decode_vcard_CTRY_els(__TopXMLNS, __IgnoreEls,
 +                    [{xmlcdata, _data} | _els], Cdata) ->
 +    decode_vcard_CTRY_els(__TopXMLNS, __IgnoreEls, _els,
 +                        <<Cdata/binary, _data/binary>>);
 +decode_vcard_CTRY_els(__TopXMLNS, __IgnoreEls,
 +                    [_ | _els], Cdata) ->
 +    decode_vcard_CTRY_els(__TopXMLNS, __IgnoreEls, _els,
 +                        Cdata).
 +
 +encode_vcard_CTRY(Cdata, __TopXMLNS) ->
 +    __NewTopXMLNS = choose_top_xmlns(<<"vcard-temp">>, [],
 +                                   __TopXMLNS),
 +    _els = encode_vcard_CTRY_cdata(Cdata, []),
 +    _attrs = enc_xmlns_attrs(__NewTopXMLNS, __TopXMLNS),
 +    {xmlel, <<"CTRY">>, _attrs, _els}.
 +
 +decode_vcard_CTRY_cdata(__TopXMLNS, <<>>) -> <<>>;
 +decode_vcard_CTRY_cdata(__TopXMLNS, _val) -> _val.
 +
 +encode_vcard_CTRY_cdata(<<>>, _acc) -> _acc;
 +encode_vcard_CTRY_cdata(_val, _acc) ->
 +    [{xmlcdata, _val} | _acc].
 +
 +decode_vcard_PCODE(__TopXMLNS, __IgnoreEls,
 +                 {xmlel, <<"PCODE">>, _attrs, _els}) ->
 +    Cdata = decode_vcard_PCODE_els(__TopXMLNS, __IgnoreEls,
 +                                 _els, <<>>),
 +    Cdata.
 +
 +decode_vcard_PCODE_els(__TopXMLNS, __IgnoreEls, [],
 +                     Cdata) ->
 +    decode_vcard_PCODE_cdata(__TopXMLNS, Cdata);
 +decode_vcard_PCODE_els(__TopXMLNS, __IgnoreEls,
 +                     [{xmlcdata, _data} | _els], Cdata) ->
 +    decode_vcard_PCODE_els(__TopXMLNS, __IgnoreEls, _els,
 +                         <<Cdata/binary, _data/binary>>);
 +decode_vcard_PCODE_els(__TopXMLNS, __IgnoreEls,
 +                     [_ | _els], Cdata) ->
 +    decode_vcard_PCODE_els(__TopXMLNS, __IgnoreEls, _els,
 +                         Cdata).
 +
 +encode_vcard_PCODE(Cdata, __TopXMLNS) ->
 +    __NewTopXMLNS = choose_top_xmlns(<<"vcard-temp">>, [],
 +                                   __TopXMLNS),
 +    _els = encode_vcard_PCODE_cdata(Cdata, []),
 +    _attrs = enc_xmlns_attrs(__NewTopXMLNS, __TopXMLNS),
 +    {xmlel, <<"PCODE">>, _attrs, _els}.
 +
 +decode_vcard_PCODE_cdata(__TopXMLNS, <<>>) -> <<>>;
 +decode_vcard_PCODE_cdata(__TopXMLNS, _val) -> _val.
 +
 +encode_vcard_PCODE_cdata(<<>>, _acc) -> _acc;
 +encode_vcard_PCODE_cdata(_val, _acc) ->
 +    [{xmlcdata, _val} | _acc].
 +
 +decode_vcard_REGION(__TopXMLNS, __IgnoreEls,
 +                  {xmlel, <<"REGION">>, _attrs, _els}) ->
 +    Cdata = decode_vcard_REGION_els(__TopXMLNS, __IgnoreEls,
 +                                  _els, <<>>),
 +    Cdata.
 +
 +decode_vcard_REGION_els(__TopXMLNS, __IgnoreEls, [],
 +                      Cdata) ->
 +    decode_vcard_REGION_cdata(__TopXMLNS, Cdata);
 +decode_vcard_REGION_els(__TopXMLNS, __IgnoreEls,
 +                      [{xmlcdata, _data} | _els], Cdata) ->
 +    decode_vcard_REGION_els(__TopXMLNS, __IgnoreEls, _els,
 +                          <<Cdata/binary, _data/binary>>);
 +decode_vcard_REGION_els(__TopXMLNS, __IgnoreEls,
 +                      [_ | _els], Cdata) ->
 +    decode_vcard_REGION_els(__TopXMLNS, __IgnoreEls, _els,
 +                          Cdata).
 +
 +encode_vcard_REGION(Cdata, __TopXMLNS) ->
 +    __NewTopXMLNS = choose_top_xmlns(<<"vcard-temp">>, [],
 +                                   __TopXMLNS),
 +    _els = encode_vcard_REGION_cdata(Cdata, []),
 +    _attrs = enc_xmlns_attrs(__NewTopXMLNS, __TopXMLNS),
 +    {xmlel, <<"REGION">>, _attrs, _els}.
 +
 +decode_vcard_REGION_cdata(__TopXMLNS, <<>>) -> <<>>;
 +decode_vcard_REGION_cdata(__TopXMLNS, _val) -> _val.
 +
 +encode_vcard_REGION_cdata(<<>>, _acc) -> _acc;
 +encode_vcard_REGION_cdata(_val, _acc) ->
 +    [{xmlcdata, _val} | _acc].
 +
 +decode_vcard_LOCALITY(__TopXMLNS, __IgnoreEls,
 +                    {xmlel, <<"LOCALITY">>, _attrs, _els}) ->
 +    Cdata = decode_vcard_LOCALITY_els(__TopXMLNS,
 +                                    __IgnoreEls, _els, <<>>),
 +    Cdata.
 +
 +decode_vcard_LOCALITY_els(__TopXMLNS, __IgnoreEls, [],
 +                        Cdata) ->
 +    decode_vcard_LOCALITY_cdata(__TopXMLNS, Cdata);
 +decode_vcard_LOCALITY_els(__TopXMLNS, __IgnoreEls,
 +                        [{xmlcdata, _data} | _els], Cdata) ->
 +    decode_vcard_LOCALITY_els(__TopXMLNS, __IgnoreEls, _els,
 +                            <<Cdata/binary, _data/binary>>);
 +decode_vcard_LOCALITY_els(__TopXMLNS, __IgnoreEls,
 +                        [_ | _els], Cdata) ->
 +    decode_vcard_LOCALITY_els(__TopXMLNS, __IgnoreEls, _els,
 +                            Cdata).
 +
 +encode_vcard_LOCALITY(Cdata, __TopXMLNS) ->
 +    __NewTopXMLNS = choose_top_xmlns(<<"vcard-temp">>, [],
 +                                   __TopXMLNS),
 +    _els = encode_vcard_LOCALITY_cdata(Cdata, []),
 +    _attrs = enc_xmlns_attrs(__NewTopXMLNS, __TopXMLNS),
 +    {xmlel, <<"LOCALITY">>, _attrs, _els}.
 +
 +decode_vcard_LOCALITY_cdata(__TopXMLNS, <<>>) -> <<>>;
 +decode_vcard_LOCALITY_cdata(__TopXMLNS, _val) -> _val.
 +
 +encode_vcard_LOCALITY_cdata(<<>>, _acc) -> _acc;
 +encode_vcard_LOCALITY_cdata(_val, _acc) ->
 +    [{xmlcdata, _val} | _acc].
 +
 +decode_vcard_STREET(__TopXMLNS, __IgnoreEls,
 +                  {xmlel, <<"STREET">>, _attrs, _els}) ->
 +    Cdata = decode_vcard_STREET_els(__TopXMLNS, __IgnoreEls,
 +                                  _els, <<>>),
 +    Cdata.
 +
 +decode_vcard_STREET_els(__TopXMLNS, __IgnoreEls, [],
 +                      Cdata) ->
 +    decode_vcard_STREET_cdata(__TopXMLNS, Cdata);
 +decode_vcard_STREET_els(__TopXMLNS, __IgnoreEls,
 +                      [{xmlcdata, _data} | _els], Cdata) ->
 +    decode_vcard_STREET_els(__TopXMLNS, __IgnoreEls, _els,
 +                          <<Cdata/binary, _data/binary>>);
 +decode_vcard_STREET_els(__TopXMLNS, __IgnoreEls,
 +                      [_ | _els], Cdata) ->
 +    decode_vcard_STREET_els(__TopXMLNS, __IgnoreEls, _els,
 +                          Cdata).
 +
 +encode_vcard_STREET(Cdata, __TopXMLNS) ->
 +    __NewTopXMLNS = choose_top_xmlns(<<"vcard-temp">>, [],
 +                                   __TopXMLNS),
 +    _els = encode_vcard_STREET_cdata(Cdata, []),
 +    _attrs = enc_xmlns_attrs(__NewTopXMLNS, __TopXMLNS),
 +    {xmlel, <<"STREET">>, _attrs, _els}.
 +
 +decode_vcard_STREET_cdata(__TopXMLNS, <<>>) -> <<>>;
 +decode_vcard_STREET_cdata(__TopXMLNS, _val) -> _val.
 +
 +encode_vcard_STREET_cdata(<<>>, _acc) -> _acc;
 +encode_vcard_STREET_cdata(_val, _acc) ->
 +    [{xmlcdata, _val} | _acc].
 +
 +decode_vcard_EXTADD(__TopXMLNS, __IgnoreEls,
 +                  {xmlel, <<"EXTADD">>, _attrs, _els}) ->
 +    Cdata = decode_vcard_EXTADD_els(__TopXMLNS, __IgnoreEls,
 +                                  _els, <<>>),
 +    Cdata.
 +
 +decode_vcard_EXTADD_els(__TopXMLNS, __IgnoreEls, [],
 +                      Cdata) ->
 +    decode_vcard_EXTADD_cdata(__TopXMLNS, Cdata);
 +decode_vcard_EXTADD_els(__TopXMLNS, __IgnoreEls,
 +                      [{xmlcdata, _data} | _els], Cdata) ->
 +    decode_vcard_EXTADD_els(__TopXMLNS, __IgnoreEls, _els,
 +                          <<Cdata/binary, _data/binary>>);
 +decode_vcard_EXTADD_els(__TopXMLNS, __IgnoreEls,
 +                      [_ | _els], Cdata) ->
 +    decode_vcard_EXTADD_els(__TopXMLNS, __IgnoreEls, _els,
 +                          Cdata).
 +
 +encode_vcard_EXTADD(Cdata, __TopXMLNS) ->
 +    __NewTopXMLNS = choose_top_xmlns(<<"vcard-temp">>, [],
 +                                   __TopXMLNS),
 +    _els = encode_vcard_EXTADD_cdata(Cdata, []),
 +    _attrs = enc_xmlns_attrs(__NewTopXMLNS, __TopXMLNS),
 +    {xmlel, <<"EXTADD">>, _attrs, _els}.
 +
 +decode_vcard_EXTADD_cdata(__TopXMLNS, <<>>) -> <<>>;
 +decode_vcard_EXTADD_cdata(__TopXMLNS, _val) -> _val.
 +
 +encode_vcard_EXTADD_cdata(<<>>, _acc) -> _acc;
 +encode_vcard_EXTADD_cdata(_val, _acc) ->
 +    [{xmlcdata, _val} | _acc].
 +
 +decode_vcard_POBOX(__TopXMLNS, __IgnoreEls,
 +                 {xmlel, <<"POBOX">>, _attrs, _els}) ->
 +    Cdata = decode_vcard_POBOX_els(__TopXMLNS, __IgnoreEls,
 +                                 _els, <<>>),
 +    Cdata.
 +
 +decode_vcard_POBOX_els(__TopXMLNS, __IgnoreEls, [],
 +                     Cdata) ->
 +    decode_vcard_POBOX_cdata(__TopXMLNS, Cdata);
 +decode_vcard_POBOX_els(__TopXMLNS, __IgnoreEls,
 +                     [{xmlcdata, _data} | _els], Cdata) ->
 +    decode_vcard_POBOX_els(__TopXMLNS, __IgnoreEls, _els,
 +                         <<Cdata/binary, _data/binary>>);
 +decode_vcard_POBOX_els(__TopXMLNS, __IgnoreEls,
 +                     [_ | _els], Cdata) ->
 +    decode_vcard_POBOX_els(__TopXMLNS, __IgnoreEls, _els,
 +                         Cdata).
 +
 +encode_vcard_POBOX(Cdata, __TopXMLNS) ->
 +    __NewTopXMLNS = choose_top_xmlns(<<"vcard-temp">>, [],
 +                                   __TopXMLNS),
 +    _els = encode_vcard_POBOX_cdata(Cdata, []),
 +    _attrs = enc_xmlns_attrs(__NewTopXMLNS, __TopXMLNS),
 +    {xmlel, <<"POBOX">>, _attrs, _els}.
 +
 +decode_vcard_POBOX_cdata(__TopXMLNS, <<>>) -> <<>>;
 +decode_vcard_POBOX_cdata(__TopXMLNS, _val) -> _val.
 +
 +encode_vcard_POBOX_cdata(<<>>, _acc) -> _acc;
 +encode_vcard_POBOX_cdata(_val, _acc) ->
 +    [{xmlcdata, _val} | _acc].
 +
 +decode_vcard_SUFFIX(__TopXMLNS, __IgnoreEls,
 +                  {xmlel, <<"SUFFIX">>, _attrs, _els}) ->
 +    Cdata = decode_vcard_SUFFIX_els(__TopXMLNS, __IgnoreEls,
 +                                  _els, <<>>),
 +    Cdata.
 +
 +decode_vcard_SUFFIX_els(__TopXMLNS, __IgnoreEls, [],
 +                      Cdata) ->
 +    decode_vcard_SUFFIX_cdata(__TopXMLNS, Cdata);
 +decode_vcard_SUFFIX_els(__TopXMLNS, __IgnoreEls,
 +                      [{xmlcdata, _data} | _els], Cdata) ->
 +    decode_vcard_SUFFIX_els(__TopXMLNS, __IgnoreEls, _els,
 +                          <<Cdata/binary, _data/binary>>);
 +decode_vcard_SUFFIX_els(__TopXMLNS, __IgnoreEls,
 +                      [_ | _els], Cdata) ->
 +    decode_vcard_SUFFIX_els(__TopXMLNS, __IgnoreEls, _els,
 +                          Cdata).
 +
 +encode_vcard_SUFFIX(Cdata, __TopXMLNS) ->
 +    __NewTopXMLNS = choose_top_xmlns(<<"vcard-temp">>, [],
 +                                   __TopXMLNS),
 +    _els = encode_vcard_SUFFIX_cdata(Cdata, []),
 +    _attrs = enc_xmlns_attrs(__NewTopXMLNS, __TopXMLNS),
 +    {xmlel, <<"SUFFIX">>, _attrs, _els}.
 +
 +decode_vcard_SUFFIX_cdata(__TopXMLNS, <<>>) -> <<>>;
 +decode_vcard_SUFFIX_cdata(__TopXMLNS, _val) -> _val.
 +
 +encode_vcard_SUFFIX_cdata(<<>>, _acc) -> _acc;
 +encode_vcard_SUFFIX_cdata(_val, _acc) ->
 +    [{xmlcdata, _val} | _acc].
 +
 +decode_vcard_PREFIX(__TopXMLNS, __IgnoreEls,
 +                  {xmlel, <<"PREFIX">>, _attrs, _els}) ->
 +    Cdata = decode_vcard_PREFIX_els(__TopXMLNS, __IgnoreEls,
 +                                  _els, <<>>),
 +    Cdata.
 +
 +decode_vcard_PREFIX_els(__TopXMLNS, __IgnoreEls, [],
 +                      Cdata) ->
 +    decode_vcard_PREFIX_cdata(__TopXMLNS, Cdata);
 +decode_vcard_PREFIX_els(__TopXMLNS, __IgnoreEls,
 +                      [{xmlcdata, _data} | _els], Cdata) ->
 +    decode_vcard_PREFIX_els(__TopXMLNS, __IgnoreEls, _els,
 +                          <<Cdata/binary, _data/binary>>);
 +decode_vcard_PREFIX_els(__TopXMLNS, __IgnoreEls,
 +                      [_ | _els], Cdata) ->
 +    decode_vcard_PREFIX_els(__TopXMLNS, __IgnoreEls, _els,
 +                          Cdata).
 +
 +encode_vcard_PREFIX(Cdata, __TopXMLNS) ->
 +    __NewTopXMLNS = choose_top_xmlns(<<"vcard-temp">>, [],
 +                                   __TopXMLNS),
 +    _els = encode_vcard_PREFIX_cdata(Cdata, []),
 +    _attrs = enc_xmlns_attrs(__NewTopXMLNS, __TopXMLNS),
 +    {xmlel, <<"PREFIX">>, _attrs, _els}.
 +
 +decode_vcard_PREFIX_cdata(__TopXMLNS, <<>>) -> <<>>;
 +decode_vcard_PREFIX_cdata(__TopXMLNS, _val) -> _val.
 +
 +encode_vcard_PREFIX_cdata(<<>>, _acc) -> _acc;
 +encode_vcard_PREFIX_cdata(_val, _acc) ->
 +    [{xmlcdata, _val} | _acc].
 +
 +decode_vcard_MIDDLE(__TopXMLNS, __IgnoreEls,
 +                  {xmlel, <<"MIDDLE">>, _attrs, _els}) ->
 +    Cdata = decode_vcard_MIDDLE_els(__TopXMLNS, __IgnoreEls,
 +                                  _els, <<>>),
 +    Cdata.
 +
 +decode_vcard_MIDDLE_els(__TopXMLNS, __IgnoreEls, [],
 +                      Cdata) ->
 +    decode_vcard_MIDDLE_cdata(__TopXMLNS, Cdata);
 +decode_vcard_MIDDLE_els(__TopXMLNS, __IgnoreEls,
 +                      [{xmlcdata, _data} | _els], Cdata) ->
 +    decode_vcard_MIDDLE_els(__TopXMLNS, __IgnoreEls, _els,
 +                          <<Cdata/binary, _data/binary>>);
 +decode_vcard_MIDDLE_els(__TopXMLNS, __IgnoreEls,
 +                      [_ | _els], Cdata) ->
 +    decode_vcard_MIDDLE_els(__TopXMLNS, __IgnoreEls, _els,
 +                          Cdata).
 +
 +encode_vcard_MIDDLE(Cdata, __TopXMLNS) ->
 +    __NewTopXMLNS = choose_top_xmlns(<<"vcard-temp">>, [],
 +                                   __TopXMLNS),
 +    _els = encode_vcard_MIDDLE_cdata(Cdata, []),
 +    _attrs = enc_xmlns_attrs(__NewTopXMLNS, __TopXMLNS),
 +    {xmlel, <<"MIDDLE">>, _attrs, _els}.
 +
 +decode_vcard_MIDDLE_cdata(__TopXMLNS, <<>>) -> <<>>;
 +decode_vcard_MIDDLE_cdata(__TopXMLNS, _val) -> _val.
 +
 +encode_vcard_MIDDLE_cdata(<<>>, _acc) -> _acc;
 +encode_vcard_MIDDLE_cdata(_val, _acc) ->
 +    [{xmlcdata, _val} | _acc].
 +
 +decode_vcard_GIVEN(__TopXMLNS, __IgnoreEls,
 +                 {xmlel, <<"GIVEN">>, _attrs, _els}) ->
 +    Cdata = decode_vcard_GIVEN_els(__TopXMLNS, __IgnoreEls,
 +                                 _els, <<>>),
 +    Cdata.
 +
 +decode_vcard_GIVEN_els(__TopXMLNS, __IgnoreEls, [],
 +                     Cdata) ->
 +    decode_vcard_GIVEN_cdata(__TopXMLNS, Cdata);
 +decode_vcard_GIVEN_els(__TopXMLNS, __IgnoreEls,
 +                     [{xmlcdata, _data} | _els], Cdata) ->
 +    decode_vcard_GIVEN_els(__TopXMLNS, __IgnoreEls, _els,
 +                         <<Cdata/binary, _data/binary>>);
 +decode_vcard_GIVEN_els(__TopXMLNS, __IgnoreEls,
 +                     [_ | _els], Cdata) ->
 +    decode_vcard_GIVEN_els(__TopXMLNS, __IgnoreEls, _els,
 +                         Cdata).
 +
 +encode_vcard_GIVEN(Cdata, __TopXMLNS) ->
 +    __NewTopXMLNS = choose_top_xmlns(<<"vcard-temp">>, [],
 +                                   __TopXMLNS),
 +    _els = encode_vcard_GIVEN_cdata(Cdata, []),
 +    _attrs = enc_xmlns_attrs(__NewTopXMLNS, __TopXMLNS),
 +    {xmlel, <<"GIVEN">>, _attrs, _els}.
 +
 +decode_vcard_GIVEN_cdata(__TopXMLNS, <<>>) -> <<>>;
 +decode_vcard_GIVEN_cdata(__TopXMLNS, _val) -> _val.
 +
 +encode_vcard_GIVEN_cdata(<<>>, _acc) -> _acc;
 +encode_vcard_GIVEN_cdata(_val, _acc) ->
 +    [{xmlcdata, _val} | _acc].
 +
 +decode_vcard_FAMILY(__TopXMLNS, __IgnoreEls,
 +                  {xmlel, <<"FAMILY">>, _attrs, _els}) ->
 +    Cdata = decode_vcard_FAMILY_els(__TopXMLNS, __IgnoreEls,
 +                                  _els, <<>>),
 +    Cdata.
 +
 +decode_vcard_FAMILY_els(__TopXMLNS, __IgnoreEls, [],
 +                      Cdata) ->
 +    decode_vcard_FAMILY_cdata(__TopXMLNS, Cdata);
 +decode_vcard_FAMILY_els(__TopXMLNS, __IgnoreEls,
 +                      [{xmlcdata, _data} | _els], Cdata) ->
 +    decode_vcard_FAMILY_els(__TopXMLNS, __IgnoreEls, _els,
 +                          <<Cdata/binary, _data/binary>>);
 +decode_vcard_FAMILY_els(__TopXMLNS, __IgnoreEls,
 +                      [_ | _els], Cdata) ->
 +    decode_vcard_FAMILY_els(__TopXMLNS, __IgnoreEls, _els,
 +                          Cdata).
 +
 +encode_vcard_FAMILY(Cdata, __TopXMLNS) ->
 +    __NewTopXMLNS = choose_top_xmlns(<<"vcard-temp">>, [],
 +                                   __TopXMLNS),
 +    _els = encode_vcard_FAMILY_cdata(Cdata, []),
 +    _attrs = enc_xmlns_attrs(__NewTopXMLNS, __TopXMLNS),
 +    {xmlel, <<"FAMILY">>, _attrs, _els}.
 +
 +decode_vcard_FAMILY_cdata(__TopXMLNS, <<>>) -> <<>>;
 +decode_vcard_FAMILY_cdata(__TopXMLNS, _val) -> _val.
 +
 +encode_vcard_FAMILY_cdata(<<>>, _acc) -> _acc;
 +encode_vcard_FAMILY_cdata(_val, _acc) ->
 +    [{xmlcdata, _val} | _acc].
 +
 +decode_vcard_X400(__TopXMLNS, __IgnoreEls,
 +                {xmlel, <<"X400">>, _attrs, _els}) ->
 +    true.
 +
 +encode_vcard_X400(true, __TopXMLNS) ->
 +    __NewTopXMLNS = choose_top_xmlns(<<"vcard-temp">>, [],
 +                                   __TopXMLNS),
 +    _els = [],
 +    _attrs = enc_xmlns_attrs(__NewTopXMLNS, __TopXMLNS),
 +    {xmlel, <<"X400">>, _attrs, _els}.
 +
 +decode_vcard_INTERNET(__TopXMLNS, __IgnoreEls,
 +                    {xmlel, <<"INTERNET">>, _attrs, _els}) ->
 +    true.
 +
 +encode_vcard_INTERNET(true, __TopXMLNS) ->
 +    __NewTopXMLNS = choose_top_xmlns(<<"vcard-temp">>, [],
 +                                   __TopXMLNS),
 +    _els = [],
 +    _attrs = enc_xmlns_attrs(__NewTopXMLNS, __TopXMLNS),
 +    {xmlel, <<"INTERNET">>, _attrs, _els}.
 +
 +decode_vcard_PREF(__TopXMLNS, __IgnoreEls,
 +                {xmlel, <<"PREF">>, _attrs, _els}) ->
 +    true.
 +
 +encode_vcard_PREF(true, __TopXMLNS) ->
 +    __NewTopXMLNS = choose_top_xmlns(<<"vcard-temp">>, [],
 +                                   __TopXMLNS),
 +    _els = [],
 +    _attrs = enc_xmlns_attrs(__NewTopXMLNS, __TopXMLNS),
 +    {xmlel, <<"PREF">>, _attrs, _els}.
 +
 +decode_vcard_INTL(__TopXMLNS, __IgnoreEls,
 +                {xmlel, <<"INTL">>, _attrs, _els}) ->
 +    true.
 +
 +encode_vcard_INTL(true, __TopXMLNS) ->
 +    __NewTopXMLNS = choose_top_xmlns(<<"vcard-temp">>, [],
 +                                   __TopXMLNS),
 +    _els = [],
 +    _attrs = enc_xmlns_attrs(__NewTopXMLNS, __TopXMLNS),
 +    {xmlel, <<"INTL">>, _attrs, _els}.
 +
 +decode_vcard_DOM(__TopXMLNS, __IgnoreEls,
 +               {xmlel, <<"DOM">>, _attrs, _els}) ->
 +    true.
 +
 +encode_vcard_DOM(true, __TopXMLNS) ->
 +    __NewTopXMLNS = choose_top_xmlns(<<"vcard-temp">>, [],
 +                                   __TopXMLNS),
 +    _els = [],
 +    _attrs = enc_xmlns_attrs(__NewTopXMLNS, __TopXMLNS),
 +    {xmlel, <<"DOM">>, _attrs, _els}.
 +
 +decode_vcard_PARCEL(__TopXMLNS, __IgnoreEls,
 +                  {xmlel, <<"PARCEL">>, _attrs, _els}) ->
 +    true.
 +
 +encode_vcard_PARCEL(true, __TopXMLNS) ->
 +    __NewTopXMLNS = choose_top_xmlns(<<"vcard-temp">>, [],
 +                                   __TopXMLNS),
 +    _els = [],
 +    _attrs = enc_xmlns_attrs(__NewTopXMLNS, __TopXMLNS),
 +    {xmlel, <<"PARCEL">>, _attrs, _els}.
 +
 +decode_vcard_POSTAL(__TopXMLNS, __IgnoreEls,
 +                  {xmlel, <<"POSTAL">>, _attrs, _els}) ->
 +    true.
 +
 +encode_vcard_POSTAL(true, __TopXMLNS) ->
 +    __NewTopXMLNS = choose_top_xmlns(<<"vcard-temp">>, [],
 +                                   __TopXMLNS),
 +    _els = [],
 +    _attrs = enc_xmlns_attrs(__NewTopXMLNS, __TopXMLNS),
 +    {xmlel, <<"POSTAL">>, _attrs, _els}.
 +
 +decode_vcard_PCS(__TopXMLNS, __IgnoreEls,
 +               {xmlel, <<"PCS">>, _attrs, _els}) ->
 +    true.
 +
 +encode_vcard_PCS(true, __TopXMLNS) ->
 +    __NewTopXMLNS = choose_top_xmlns(<<"vcard-temp">>, [],
 +                                   __TopXMLNS),
 +    _els = [],
 +    _attrs = enc_xmlns_attrs(__NewTopXMLNS, __TopXMLNS),
 +    {xmlel, <<"PCS">>, _attrs, _els}.
 +
 +decode_vcard_ISDN(__TopXMLNS, __IgnoreEls,
 +                {xmlel, <<"ISDN">>, _attrs, _els}) ->
 +    true.
 +
 +encode_vcard_ISDN(true, __TopXMLNS) ->
 +    __NewTopXMLNS = choose_top_xmlns(<<"vcard-temp">>, [],
 +                                   __TopXMLNS),
 +    _els = [],
 +    _attrs = enc_xmlns_attrs(__NewTopXMLNS, __TopXMLNS),
 +    {xmlel, <<"ISDN">>, _attrs, _els}.
 +
 +decode_vcard_MODEM(__TopXMLNS, __IgnoreEls,
 +                 {xmlel, <<"MODEM">>, _attrs, _els}) ->
 +    true.
 +
 +encode_vcard_MODEM(true, __TopXMLNS) ->
 +    __NewTopXMLNS = choose_top_xmlns(<<"vcard-temp">>, [],
 +                                   __TopXMLNS),
 +    _els = [],
 +    _attrs = enc_xmlns_attrs(__NewTopXMLNS, __TopXMLNS),
 +    {xmlel, <<"MODEM">>, _attrs, _els}.
 +
 +decode_vcard_BBS(__TopXMLNS, __IgnoreEls,
 +               {xmlel, <<"BBS">>, _attrs, _els}) ->
 +    true.
 +
 +encode_vcard_BBS(true, __TopXMLNS) ->
 +    __NewTopXMLNS = choose_top_xmlns(<<"vcard-temp">>, [],
 +                                   __TopXMLNS),
 +    _els = [],
 +    _attrs = enc_xmlns_attrs(__NewTopXMLNS, __TopXMLNS),
 +    {xmlel, <<"BBS">>, _attrs, _els}.
 +
 +decode_vcard_VIDEO(__TopXMLNS, __IgnoreEls,
 +                 {xmlel, <<"VIDEO">>, _attrs, _els}) ->
 +    true.
 +
 +encode_vcard_VIDEO(true, __TopXMLNS) ->
 +    __NewTopXMLNS = choose_top_xmlns(<<"vcard-temp">>, [],
 +                                   __TopXMLNS),
 +    _els = [],
 +    _attrs = enc_xmlns_attrs(__NewTopXMLNS, __TopXMLNS),
 +    {xmlel, <<"VIDEO">>, _attrs, _els}.
 +
 +decode_vcard_CELL(__TopXMLNS, __IgnoreEls,
 +                {xmlel, <<"CELL">>, _attrs, _els}) ->
 +    true.
 +
 +encode_vcard_CELL(true, __TopXMLNS) ->
 +    __NewTopXMLNS = choose_top_xmlns(<<"vcard-temp">>, [],
 +                                   __TopXMLNS),
 +    _els = [],
 +    _attrs = enc_xmlns_attrs(__NewTopXMLNS, __TopXMLNS),
 +    {xmlel, <<"CELL">>, _attrs, _els}.
 +
 +decode_vcard_MSG(__TopXMLNS, __IgnoreEls,
 +               {xmlel, <<"MSG">>, _attrs, _els}) ->
 +    true.
 +
 +encode_vcard_MSG(true, __TopXMLNS) ->
 +    __NewTopXMLNS = choose_top_xmlns(<<"vcard-temp">>, [],
 +                                   __TopXMLNS),
 +    _els = [],
 +    _attrs = enc_xmlns_attrs(__NewTopXMLNS, __TopXMLNS),
 +    {xmlel, <<"MSG">>, _attrs, _els}.
 +
 +decode_vcard_PAGER(__TopXMLNS, __IgnoreEls,
 +                 {xmlel, <<"PAGER">>, _attrs, _els}) ->
 +    true.
 +
 +encode_vcard_PAGER(true, __TopXMLNS) ->
 +    __NewTopXMLNS = choose_top_xmlns(<<"vcard-temp">>, [],
 +                                   __TopXMLNS),
 +    _els = [],
 +    _attrs = enc_xmlns_attrs(__NewTopXMLNS, __TopXMLNS),
 +    {xmlel, <<"PAGER">>, _attrs, _els}.
 +
 +decode_vcard_FAX(__TopXMLNS, __IgnoreEls,
 +               {xmlel, <<"FAX">>, _attrs, _els}) ->
 +    true.
 +
 +encode_vcard_FAX(true, __TopXMLNS) ->
 +    __NewTopXMLNS = choose_top_xmlns(<<"vcard-temp">>, [],
 +                                   __TopXMLNS),
 +    _els = [],
 +    _attrs = enc_xmlns_attrs(__NewTopXMLNS, __TopXMLNS),
 +    {xmlel, <<"FAX">>, _attrs, _els}.
 +
 +decode_vcard_VOICE(__TopXMLNS, __IgnoreEls,
 +                 {xmlel, <<"VOICE">>, _attrs, _els}) ->
 +    true.
 +
 +encode_vcard_VOICE(true, __TopXMLNS) ->
 +    __NewTopXMLNS = choose_top_xmlns(<<"vcard-temp">>, [],
 +                                   __TopXMLNS),
 +    _els = [],
 +    _attrs = enc_xmlns_attrs(__NewTopXMLNS, __TopXMLNS),
 +    {xmlel, <<"VOICE">>, _attrs, _els}.
 +
 +decode_vcard_WORK(__TopXMLNS, __IgnoreEls,
 +                {xmlel, <<"WORK">>, _attrs, _els}) ->
 +    true.
 +
 +encode_vcard_WORK(true, __TopXMLNS) ->
 +    __NewTopXMLNS = choose_top_xmlns(<<"vcard-temp">>, [],
 +                                   __TopXMLNS),
 +    _els = [],
 +    _attrs = enc_xmlns_attrs(__NewTopXMLNS, __TopXMLNS),
 +    {xmlel, <<"WORK">>, _attrs, _els}.
 +
 +decode_vcard_HOME(__TopXMLNS, __IgnoreEls,
 +                {xmlel, <<"HOME">>, _attrs, _els}) ->
 +    true.
 +
 +encode_vcard_HOME(true, __TopXMLNS) ->
 +    __NewTopXMLNS = choose_top_xmlns(<<"vcard-temp">>, [],
 +                                   __TopXMLNS),
 +    _els = [],
 +    _attrs = enc_xmlns_attrs(__NewTopXMLNS, __TopXMLNS),
 +    {xmlel, <<"HOME">>, _attrs, _els}.
 +
 +decode_stream_error(__TopXMLNS, __IgnoreEls,
 +                  {xmlel, <<"stream:error">>, _attrs, _els}) ->
 +    {Text, Reason} = decode_stream_error_els(__TopXMLNS,
 +                                           __IgnoreEls, _els, undefined,
 +                                           undefined),
 +    {stream_error, Reason, Text}.
 +
 +decode_stream_error_els(__TopXMLNS, __IgnoreEls, [],
 +                      Text, Reason) ->
 +    {Text, Reason};
 +decode_stream_error_els(__TopXMLNS, __IgnoreEls,
 +                      [{xmlel, <<"text">>, _attrs, _} = _el | _els], Text,
 +                      Reason) ->
 +    case get_attr(<<"xmlns">>, _attrs) of
 +      <<"urn:ietf:params:xml:ns:xmpp-streams">> ->
 +        decode_stream_error_els(__TopXMLNS, __IgnoreEls, _els,
 +                                decode_stream_error_text(<<"urn:ietf:params:xml:ns:xmpp-streams">>,
 +                                                         __IgnoreEls, _el),
 +                                Reason);
 +      _ ->
 +        decode_stream_error_els(__TopXMLNS, __IgnoreEls, _els,
 +                                Text, Reason)
 +    end;
 +decode_stream_error_els(__TopXMLNS, __IgnoreEls,
 +                      [{xmlel, <<"bad-format">>, _attrs, _} = _el | _els],
 +                      Text, Reason) ->
 +    case get_attr(<<"xmlns">>, _attrs) of
 +      <<"urn:ietf:params:xml:ns:xmpp-streams">> ->
 +        decode_stream_error_els(__TopXMLNS, __IgnoreEls, _els,
 +                                Text,
 +                                decode_stream_error_bad_format(<<"urn:ietf:params:xml:ns:xmpp-streams">>,
 +                                                               __IgnoreEls,
 +                                                               _el));
 +      _ ->
 +        decode_stream_error_els(__TopXMLNS, __IgnoreEls, _els,
 +                                Text, Reason)
 +    end;
 +decode_stream_error_els(__TopXMLNS, __IgnoreEls,
 +                      [{xmlel, <<"bad-namespace-prefix">>, _attrs, _} = _el
 +                       | _els],
 +                      Text, Reason) ->
 +    case get_attr(<<"xmlns">>, _attrs) of
 +      <<"urn:ietf:params:xml:ns:xmpp-streams">> ->
 +        decode_stream_error_els(__TopXMLNS, __IgnoreEls, _els,
 +                                Text,
 +                                decode_stream_error_bad_namespace_prefix(<<"urn:ietf:params:xml:ns:xmpp-streams">>,
 +                                                                         __IgnoreEls,
 +                                                                         _el));
 +      _ ->
 +        decode_stream_error_els(__TopXMLNS, __IgnoreEls, _els,
 +                                Text, Reason)
 +    end;
 +decode_stream_error_els(__TopXMLNS, __IgnoreEls,
 +                      [{xmlel, <<"conflict">>, _attrs, _} = _el | _els], Text,
 +                      Reason) ->
 +    case get_attr(<<"xmlns">>, _attrs) of
 +      <<"urn:ietf:params:xml:ns:xmpp-streams">> ->
 +        decode_stream_error_els(__TopXMLNS, __IgnoreEls, _els,
 +                                Text,
 +                                decode_stream_error_conflict(<<"urn:ietf:params:xml:ns:xmpp-streams">>,
 +                                                             __IgnoreEls,
 +                                                             _el));
 +      _ ->
 +        decode_stream_error_els(__TopXMLNS, __IgnoreEls, _els,
 +                                Text, Reason)
 +    end;
 +decode_stream_error_els(__TopXMLNS, __IgnoreEls,
 +                      [{xmlel, <<"connection-timeout">>, _attrs, _} = _el
 +                       | _els],
 +                      Text, Reason) ->
 +    case get_attr(<<"xmlns">>, _attrs) of
 +      <<"urn:ietf:params:xml:ns:xmpp-streams">> ->
 +        decode_stream_error_els(__TopXMLNS, __IgnoreEls, _els,
 +                                Text,
 +                                decode_stream_error_connection_timeout(<<"urn:ietf:params:xml:ns:xmpp-streams">>,
 +                                                                       __IgnoreEls,
 +                                                                       _el));
 +      _ ->
 +        decode_stream_error_els(__TopXMLNS, __IgnoreEls, _els,
 +                                Text, Reason)
 +    end;
 +decode_stream_error_els(__TopXMLNS, __IgnoreEls,
 +                      [{xmlel, <<"host-gone">>, _attrs, _} = _el | _els],
 +                      Text, Reason) ->
 +    case get_attr(<<"xmlns">>, _attrs) of
 +      <<"urn:ietf:params:xml:ns:xmpp-streams">> ->
 +        decode_stream_error_els(__TopXMLNS, __IgnoreEls, _els,
 +                                Text,
 +                                decode_stream_error_host_gone(<<"urn:ietf:params:xml:ns:xmpp-streams">>,
 +                                                              __IgnoreEls,
 +                                                              _el));
 +      _ ->
 +        decode_stream_error_els(__TopXMLNS, __IgnoreEls, _els,
 +                                Text, Reason)
 +    end;
 +decode_stream_error_els(__TopXMLNS, __IgnoreEls,
 +                      [{xmlel, <<"host-unknown">>, _attrs, _} = _el | _els],
 +                      Text, Reason) ->
 +    case get_attr(<<"xmlns">>, _attrs) of
 +      <<"urn:ietf:params:xml:ns:xmpp-streams">> ->
 +        decode_stream_error_els(__TopXMLNS, __IgnoreEls, _els,
 +                                Text,
 +                                decode_stream_error_host_unknown(<<"urn:ietf:params:xml:ns:xmpp-streams">>,
 +                                                                 __IgnoreEls,
 +                                                                 _el));
 +      _ ->
 +        decode_stream_error_els(__TopXMLNS, __IgnoreEls, _els,
 +                                Text, Reason)
 +    end;
 +decode_stream_error_els(__TopXMLNS, __IgnoreEls,
 +                      [{xmlel, <<"improper-addressing">>, _attrs, _} = _el
 +                       | _els],
 +                      Text, Reason) ->
 +    case get_attr(<<"xmlns">>, _attrs) of
 +      <<"urn:ietf:params:xml:ns:xmpp-streams">> ->
 +        decode_stream_error_els(__TopXMLNS, __IgnoreEls, _els,
 +                                Text,
 +                                decode_stream_error_improper_addressing(<<"urn:ietf:params:xml:ns:xmpp-streams">>,
 +                                                                        __IgnoreEls,
 +                                                                        _el));
 +      _ ->
 +        decode_stream_error_els(__TopXMLNS, __IgnoreEls, _els,
 +                                Text, Reason)
 +    end;
 +decode_stream_error_els(__TopXMLNS, __IgnoreEls,
 +                      [{xmlel, <<"internal-server-error">>, _attrs, _} = _el
 +                       | _els],
 +                      Text, Reason) ->
 +    case get_attr(<<"xmlns">>, _attrs) of
 +      <<"urn:ietf:params:xml:ns:xmpp-streams">> ->
 +        decode_stream_error_els(__TopXMLNS, __IgnoreEls, _els,
 +                                Text,
 +                                decode_stream_error_internal_server_error(<<"urn:ietf:params:xml:ns:xmpp-streams">>,
 +                                                                          __IgnoreEls,
 +                                                                          _el));
 +      _ ->
 +        decode_stream_error_els(__TopXMLNS, __IgnoreEls, _els,
 +                                Text, Reason)
 +    end;
 +decode_stream_error_els(__TopXMLNS, __IgnoreEls,
 +                      [{xmlel, <<"invalid-from">>, _attrs, _} = _el | _els],
 +                      Text, Reason) ->
 +    case get_attr(<<"xmlns">>, _attrs) of
 +      <<"urn:ietf:params:xml:ns:xmpp-streams">> ->
 +        decode_stream_error_els(__TopXMLNS, __IgnoreEls, _els,
 +                                Text,
 +                                decode_stream_error_invalid_from(<<"urn:ietf:params:xml:ns:xmpp-streams">>,
 +                                                                 __IgnoreEls,
 +                                                                 _el));
 +      _ ->
 +        decode_stream_error_els(__TopXMLNS, __IgnoreEls, _els,
 +                                Text, Reason)
 +    end;
 +decode_stream_error_els(__TopXMLNS, __IgnoreEls,
 +                      [{xmlel, <<"invalid-id">>, _attrs, _} = _el | _els],
 +                      Text, Reason) ->
 +    case get_attr(<<"xmlns">>, _attrs) of
 +      <<"urn:ietf:params:xml:ns:xmpp-streams">> ->
 +        decode_stream_error_els(__TopXMLNS, __IgnoreEls, _els,
 +                                Text,
 +                                decode_stream_error_invalid_id(<<"urn:ietf:params:xml:ns:xmpp-streams">>,
 +                                                               __IgnoreEls,
 +                                                               _el));
 +      _ ->
 +        decode_stream_error_els(__TopXMLNS, __IgnoreEls, _els,
 +                                Text, Reason)
 +    end;
 +decode_stream_error_els(__TopXMLNS, __IgnoreEls,
 +                      [{xmlel, <<"invalid-namespace">>, _attrs, _} = _el
 +                       | _els],
 +                      Text, Reason) ->
 +    case get_attr(<<"xmlns">>, _attrs) of
 +      <<"urn:ietf:params:xml:ns:xmpp-streams">> ->
 +        decode_stream_error_els(__TopXMLNS, __IgnoreEls, _els,
 +                                Text,
 +                                decode_stream_error_invalid_namespace(<<"urn:ietf:params:xml:ns:xmpp-streams">>,
 +                                                                      __IgnoreEls,
 +                                                                      _el));
 +      _ ->
 +        decode_stream_error_els(__TopXMLNS, __IgnoreEls, _els,
 +                                Text, Reason)
 +    end;
 +decode_stream_error_els(__TopXMLNS, __IgnoreEls,
 +                      [{xmlel, <<"invalid-xml">>, _attrs, _} = _el | _els],
 +                      Text, Reason) ->
 +    case get_attr(<<"xmlns">>, _attrs) of
 +      <<"urn:ietf:params:xml:ns:xmpp-streams">> ->
 +        decode_stream_error_els(__TopXMLNS, __IgnoreEls, _els,
 +                                Text,
 +                                decode_stream_error_invalid_xml(<<"urn:ietf:params:xml:ns:xmpp-streams">>,
 +                                                                __IgnoreEls,
 +                                                                _el));
 +      _ ->
 +        decode_stream_error_els(__TopXMLNS, __IgnoreEls, _els,
 +                                Text, Reason)
 +    end;
 +decode_stream_error_els(__TopXMLNS, __IgnoreEls,
 +                      [{xmlel, <<"not-authorized">>, _attrs, _} = _el | _els],
 +                      Text, Reason) ->
 +    case get_attr(<<"xmlns">>, _attrs) of
 +      <<"urn:ietf:params:xml:ns:xmpp-streams">> ->
 +        decode_stream_error_els(__TopXMLNS, __IgnoreEls, _els,
 +                                Text,
 +                                decode_stream_error_not_authorized(<<"urn:ietf:params:xml:ns:xmpp-streams">>,
 +                                                                   __IgnoreEls,
 +                                                                   _el));
 +      _ ->
 +        decode_stream_error_els(__TopXMLNS, __IgnoreEls, _els,
 +                                Text, Reason)
 +    end;
 +decode_stream_error_els(__TopXMLNS, __IgnoreEls,
 +                      [{xmlel, <<"not-well-formed">>, _attrs, _} = _el
 +                       | _els],
 +                      Text, Reason) ->
 +    case get_attr(<<"xmlns">>, _attrs) of
 +      <<"urn:ietf:params:xml:ns:xmpp-streams">> ->
 +        decode_stream_error_els(__TopXMLNS, __IgnoreEls, _els,
 +                                Text,
 +                                decode_stream_error_not_well_formed(<<"urn:ietf:params:xml:ns:xmpp-streams">>,
 +                                                                    __IgnoreEls,
 +                                                                    _el));
 +      _ ->
 +        decode_stream_error_els(__TopXMLNS, __IgnoreEls, _els,
 +                                Text, Reason)
 +    end;
 +decode_stream_error_els(__TopXMLNS, __IgnoreEls,
 +                      [{xmlel, <<"policy-violation">>, _attrs, _} = _el
 +                       | _els],
 +                      Text, Reason) ->
 +    case get_attr(<<"xmlns">>, _attrs) of
 +      <<"urn:ietf:params:xml:ns:xmpp-streams">> ->
 +        decode_stream_error_els(__TopXMLNS, __IgnoreEls, _els,
 +                                Text,
 +                                decode_stream_error_policy_violation(<<"urn:ietf:params:xml:ns:xmpp-streams">>,
 +                                                                     __IgnoreEls,
 +                                                                     _el));
 +      _ ->
 +        decode_stream_error_els(__TopXMLNS, __IgnoreEls, _els,
 +                                Text, Reason)
 +    end;
 +decode_stream_error_els(__TopXMLNS, __IgnoreEls,
 +                      [{xmlel, <<"remote-connection-failed">>, _attrs, _} =
 +                           _el
 +                       | _els],
 +                      Text, Reason) ->
 +    case get_attr(<<"xmlns">>, _attrs) of
 +      <<"urn:ietf:params:xml:ns:xmpp-streams">> ->
 +        decode_stream_error_els(__TopXMLNS, __IgnoreEls, _els,
 +                                Text,
 +                                decode_stream_error_remote_connection_failed(<<"urn:ietf:params:xml:ns:xmpp-streams">>,
 +                                                                             __IgnoreEls,
 +                                                                             _el));
 +      _ ->
 +        decode_stream_error_els(__TopXMLNS, __IgnoreEls, _els,
 +                                Text, Reason)
 +    end;
 +decode_stream_error_els(__TopXMLNS, __IgnoreEls,
 +                      [{xmlel, <<"reset">>, _attrs, _} = _el | _els], Text,
 +                      Reason) ->
 +    case get_attr(<<"xmlns">>, _attrs) of
 +      <<"urn:ietf:params:xml:ns:xmpp-streams">> ->
 +        decode_stream_error_els(__TopXMLNS, __IgnoreEls, _els,
 +                                Text,
 +                                decode_stream_error_reset(<<"urn:ietf:params:xml:ns:xmpp-streams">>,
 +                                                          __IgnoreEls, _el));
 +      _ ->
 +        decode_stream_error_els(__TopXMLNS, __IgnoreEls, _els,
 +                                Text, Reason)
 +    end;
 +decode_stream_error_els(__TopXMLNS, __IgnoreEls,
 +                      [{xmlel, <<"resource-constraint">>, _attrs, _} = _el
 +                       | _els],
 +                      Text, Reason) ->
 +    case get_attr(<<"xmlns">>, _attrs) of
 +      <<"urn:ietf:params:xml:ns:xmpp-streams">> ->
 +        decode_stream_error_els(__TopXMLNS, __IgnoreEls, _els,
 +                                Text,
 +                                decode_stream_error_resource_constraint(<<"urn:ietf:params:xml:ns:xmpp-streams">>,
 +                                                                        __IgnoreEls,
 +                                                                        _el));
 +      _ ->
 +        decode_stream_error_els(__TopXMLNS, __IgnoreEls, _els,
 +                                Text, Reason)
 +    end;
 +decode_stream_error_els(__TopXMLNS, __IgnoreEls,
 +                      [{xmlel, <<"restricted-xml">>, _attrs, _} = _el | _els],
 +                      Text, Reason) ->
 +    case get_attr(<<"xmlns">>, _attrs) of
 +      <<"urn:ietf:params:xml:ns:xmpp-streams">> ->
 +        decode_stream_error_els(__TopXMLNS, __IgnoreEls, _els,
 +                                Text,
 +                                decode_stream_error_restricted_xml(<<"urn:ietf:params:xml:ns:xmpp-streams">>,
 +                                                                   __IgnoreEls,
 +                                                                   _el));
 +      _ ->
 +        decode_stream_error_els(__TopXMLNS, __IgnoreEls, _els,
 +                                Text, Reason)
 +    end;
 +decode_stream_error_els(__TopXMLNS, __IgnoreEls,
 +                      [{xmlel, <<"see-other-host">>, _attrs, _} = _el | _els],
 +                      Text, Reason) ->
 +    case get_attr(<<"xmlns">>, _attrs) of
 +      <<"urn:ietf:params:xml:ns:xmpp-streams">> ->
 +        decode_stream_error_els(__TopXMLNS, __IgnoreEls, _els,
 +                                Text,
 +                                decode_stream_error_see_other_host(<<"urn:ietf:params:xml:ns:xmpp-streams">>,
 +                                                                   __IgnoreEls,
 +                                                                   _el));
 +      _ ->
 +        decode_stream_error_els(__TopXMLNS, __IgnoreEls, _els,
 +                                Text, Reason)
 +    end;
 +decode_stream_error_els(__TopXMLNS, __IgnoreEls,
 +                      [{xmlel, <<"system-shutdown">>, _attrs, _} = _el
 +                       | _els],
 +                      Text, Reason) ->
 +    case get_attr(<<"xmlns">>, _attrs) of
 +      <<"urn:ietf:params:xml:ns:xmpp-streams">> ->
 +        decode_stream_error_els(__TopXMLNS, __IgnoreEls, _els,
 +                                Text,
 +                                decode_stream_error_system_shutdown(<<"urn:ietf:params:xml:ns:xmpp-streams">>,
 +                                                                    __IgnoreEls,
 +                                                                    _el));
 +      _ ->
 +        decode_stream_error_els(__TopXMLNS, __IgnoreEls, _els,
 +                                Text, Reason)
 +    end;
 +decode_stream_error_els(__TopXMLNS, __IgnoreEls,
 +                      [{xmlel, <<"undefined-condition">>, _attrs, _} = _el
 +                       | _els],
 +                      Text, Reason) ->
 +    case get_attr(<<"xmlns">>, _attrs) of
 +      <<"urn:ietf:params:xml:ns:xmpp-streams">> ->
 +        decode_stream_error_els(__TopXMLNS, __IgnoreEls, _els,
 +                                Text,
 +                                decode_stream_error_undefined_condition(<<"urn:ietf:params:xml:ns:xmpp-streams">>,
 +                                                                        __IgnoreEls,
 +                                                                        _el));
 +      _ ->
 +        decode_stream_error_els(__TopXMLNS, __IgnoreEls, _els,
 +                                Text, Reason)
 +    end;
 +decode_stream_error_els(__TopXMLNS, __IgnoreEls,
 +                      [{xmlel, <<"unsupported-encoding">>, _attrs, _} = _el
 +                       | _els],
 +                      Text, Reason) ->
 +    case get_attr(<<"xmlns">>, _attrs) of
 +      <<"urn:ietf:params:xml:ns:xmpp-streams">> ->
 +        decode_stream_error_els(__TopXMLNS, __IgnoreEls, _els,
 +                                Text,
 +                                decode_stream_error_unsupported_encoding(<<"urn:ietf:params:xml:ns:xmpp-streams">>,
 +                                                                         __IgnoreEls,
 +                                                                         _el));
 +      _ ->
 +        decode_stream_error_els(__TopXMLNS, __IgnoreEls, _els,
 +                                Text, Reason)
 +    end;
 +decode_stream_error_els(__TopXMLNS, __IgnoreEls,
 +                      [{xmlel, <<"unsupported-stanza-type">>, _attrs, _} = _el
 +                       | _els],
 +                      Text, Reason) ->
 +    case get_attr(<<"xmlns">>, _attrs) of
 +      <<"urn:ietf:params:xml:ns:xmpp-streams">> ->
 +        decode_stream_error_els(__TopXMLNS, __IgnoreEls, _els,
 +                                Text,
 +                                decode_stream_error_unsupported_stanza_type(<<"urn:ietf:params:xml:ns:xmpp-streams">>,
 +                                                                            __IgnoreEls,
 +                                                                            _el));
 +      _ ->
 +        decode_stream_error_els(__TopXMLNS, __IgnoreEls, _els,
 +                                Text, Reason)
 +    end;
 +decode_stream_error_els(__TopXMLNS, __IgnoreEls,
 +                      [{xmlel, <<"unsupported-version">>, _attrs, _} = _el
 +                       | _els],
 +                      Text, Reason) ->
 +    case get_attr(<<"xmlns">>, _attrs) of
 +      <<"urn:ietf:params:xml:ns:xmpp-streams">> ->
 +        decode_stream_error_els(__TopXMLNS, __IgnoreEls, _els,
 +                                Text,
 +                                decode_stream_error_unsupported_version(<<"urn:ietf:params:xml:ns:xmpp-streams">>,
 +                                                                        __IgnoreEls,
 +                                                                        _el));
 +      _ ->
 +        decode_stream_error_els(__TopXMLNS, __IgnoreEls, _els,
 +                                Text, Reason)
 +    end;
 +decode_stream_error_els(__TopXMLNS, __IgnoreEls,
 +                      [_ | _els], Text, Reason) ->
 +    decode_stream_error_els(__TopXMLNS, __IgnoreEls, _els,
 +                          Text, Reason).
 +
 +encode_stream_error({stream_error, Reason, Text},
 +                  __TopXMLNS) ->
 +    __NewTopXMLNS = choose_top_xmlns(<<>>,
 +                                   [<<"jabber:client">>, <<"jabber:server">>,
 +                                    <<"jabber:component:accept">>],
 +                                   __TopXMLNS),
 +    _els = lists:reverse('encode_stream_error_$text'(Text,
 +                                                   __NewTopXMLNS,
 +                                                   'encode_stream_error_$reason'(Reason,
 +                                                                                 __NewTopXMLNS,
 +                                                                                 []))),
 +    _attrs = enc_xmlns_attrs(__NewTopXMLNS, __TopXMLNS),
 +    {xmlel, <<"stream:error">>, _attrs, _els}.
 +
 +'encode_stream_error_$text'(undefined, __TopXMLNS,
 +                          _acc) ->
 +    _acc;
 +'encode_stream_error_$text'(Text, __TopXMLNS, _acc) ->
 +    [encode_stream_error_text(Text, __TopXMLNS) | _acc].
 +
 +'encode_stream_error_$reason'(undefined, __TopXMLNS,
 +                            _acc) ->
 +    _acc;
 +'encode_stream_error_$reason'('bad-format' = Reason,
 +                            __TopXMLNS, _acc) ->
 +    [encode_stream_error_bad_format(Reason, __TopXMLNS)
 +     | _acc];
 +'encode_stream_error_$reason'('bad-namespace-prefix' =
 +                                Reason,
 +                            __TopXMLNS, _acc) ->
 +    [encode_stream_error_bad_namespace_prefix(Reason,
 +                                            __TopXMLNS)
 +     | _acc];
 +'encode_stream_error_$reason'(conflict = Reason,
 +                            __TopXMLNS, _acc) ->
 +    [encode_stream_error_conflict(Reason, __TopXMLNS)
 +     | _acc];
 +'encode_stream_error_$reason'('connection-timeout' =
 +                                Reason,
 +                            __TopXMLNS, _acc) ->
 +    [encode_stream_error_connection_timeout(Reason,
 +                                          __TopXMLNS)
 +     | _acc];
 +'encode_stream_error_$reason'('host-gone' = Reason,
 +                            __TopXMLNS, _acc) ->
 +    [encode_stream_error_host_gone(Reason, __TopXMLNS)
 +     | _acc];
 +'encode_stream_error_$reason'('host-unknown' = Reason,
 +                            __TopXMLNS, _acc) ->
 +    [encode_stream_error_host_unknown(Reason, __TopXMLNS)
 +     | _acc];
 +'encode_stream_error_$reason'('improper-addressing' =
 +                                Reason,
 +                            __TopXMLNS, _acc) ->
 +    [encode_stream_error_improper_addressing(Reason,
 +                                           __TopXMLNS)
 +     | _acc];
 +'encode_stream_error_$reason'('internal-server-error' =
 +                                Reason,
 +                            __TopXMLNS, _acc) ->
 +    [encode_stream_error_internal_server_error(Reason,
 +                                             __TopXMLNS)
 +     | _acc];
 +'encode_stream_error_$reason'('invalid-from' = Reason,
 +                            __TopXMLNS, _acc) ->
 +    [encode_stream_error_invalid_from(Reason, __TopXMLNS)
 +     | _acc];
 +'encode_stream_error_$reason'('invalid-id' = Reason,
 +                            __TopXMLNS, _acc) ->
 +    [encode_stream_error_invalid_id(Reason, __TopXMLNS)
 +     | _acc];
 +'encode_stream_error_$reason'('invalid-namespace' =
 +                                Reason,
 +                            __TopXMLNS, _acc) ->
 +    [encode_stream_error_invalid_namespace(Reason,
 +                                         __TopXMLNS)
 +     | _acc];
 +'encode_stream_error_$reason'('invalid-xml' = Reason,
 +                            __TopXMLNS, _acc) ->
 +    [encode_stream_error_invalid_xml(Reason, __TopXMLNS)
 +     | _acc];
 +'encode_stream_error_$reason'('not-authorized' = Reason,
 +                            __TopXMLNS, _acc) ->
 +    [encode_stream_error_not_authorized(Reason, __TopXMLNS)
 +     | _acc];
 +'encode_stream_error_$reason'('not-well-formed' =
 +                                Reason,
 +                            __TopXMLNS, _acc) ->
 +    [encode_stream_error_not_well_formed(Reason, __TopXMLNS)
 +     | _acc];
 +'encode_stream_error_$reason'('policy-violation' =
 +                                Reason,
 +                            __TopXMLNS, _acc) ->
 +    [encode_stream_error_policy_violation(Reason,
 +                                        __TopXMLNS)
 +     | _acc];
 +'encode_stream_error_$reason'('remote-connection-failed' =
 +                                Reason,
 +                            __TopXMLNS, _acc) ->
 +    [encode_stream_error_remote_connection_failed(Reason,
 +                                                __TopXMLNS)
 +     | _acc];
 +'encode_stream_error_$reason'(reset = Reason,
 +                            __TopXMLNS, _acc) ->
 +    [encode_stream_error_reset(Reason, __TopXMLNS) | _acc];
 +'encode_stream_error_$reason'('resource-constraint' =
 +                                Reason,
 +                            __TopXMLNS, _acc) ->
 +    [encode_stream_error_resource_constraint(Reason,
 +                                           __TopXMLNS)
 +     | _acc];
 +'encode_stream_error_$reason'('restricted-xml' = Reason,
 +                            __TopXMLNS, _acc) ->
 +    [encode_stream_error_restricted_xml(Reason, __TopXMLNS)
 +     | _acc];
 +'encode_stream_error_$reason'({'see-other-host', _} =
 +                                Reason,
 +                            __TopXMLNS, _acc) ->
 +    [encode_stream_error_see_other_host(Reason, __TopXMLNS)
 +     | _acc];
 +'encode_stream_error_$reason'('system-shutdown' =
 +                                Reason,
 +                            __TopXMLNS, _acc) ->
 +    [encode_stream_error_system_shutdown(Reason, __TopXMLNS)
 +     | _acc];
 +'encode_stream_error_$reason'('undefined-condition' =
 +                                Reason,
 +                            __TopXMLNS, _acc) ->
 +    [encode_stream_error_undefined_condition(Reason,
 +                                           __TopXMLNS)
 +     | _acc];
 +'encode_stream_error_$reason'('unsupported-encoding' =
 +                                Reason,
 +                            __TopXMLNS, _acc) ->
 +    [encode_stream_error_unsupported_encoding(Reason,
 +                                            __TopXMLNS)
 +     | _acc];
 +'encode_stream_error_$reason'('unsupported-stanza-type' =
 +                                Reason,
 +                            __TopXMLNS, _acc) ->
 +    [encode_stream_error_unsupported_stanza_type(Reason,
 +                                               __TopXMLNS)
 +     | _acc];
 +'encode_stream_error_$reason'('unsupported-version' =
 +                                Reason,
 +                            __TopXMLNS, _acc) ->
 +    [encode_stream_error_unsupported_version(Reason,
 +                                           __TopXMLNS)
 +     | _acc].
 +
 +decode_stream_error_unsupported_version(__TopXMLNS,
 +                                      __IgnoreEls,
 +                                      {xmlel, <<"unsupported-version">>,
 +                                       _attrs, _els}) ->
 +    'unsupported-version'.
 +
 +encode_stream_error_unsupported_version('unsupported-version',
 +                                      __TopXMLNS) ->
 +    __NewTopXMLNS =
 +      choose_top_xmlns(<<"urn:ietf:params:xml:ns:xmpp-streams">>,
 +                       [], __TopXMLNS),
 +    _els = [],
 +    _attrs = enc_xmlns_attrs(__NewTopXMLNS, __TopXMLNS),
 +    {xmlel, <<"unsupported-version">>, _attrs, _els}.
 +
 +decode_stream_error_unsupported_stanza_type(__TopXMLNS,
 +                                          __IgnoreEls,
 +                                          {xmlel,
 +                                           <<"unsupported-stanza-type">>,
 +                                           _attrs, _els}) ->
 +    'unsupported-stanza-type'.
 +
 +encode_stream_error_unsupported_stanza_type('unsupported-stanza-type',
 +                                          __TopXMLNS) ->
 +    __NewTopXMLNS =
 +      choose_top_xmlns(<<"urn:ietf:params:xml:ns:xmpp-streams">>,
 +                       [], __TopXMLNS),
 +    _els = [],
 +    _attrs = enc_xmlns_attrs(__NewTopXMLNS, __TopXMLNS),
 +    {xmlel, <<"unsupported-stanza-type">>, _attrs, _els}.
 +
 +decode_stream_error_unsupported_encoding(__TopXMLNS,
 +                                       __IgnoreEls,
 +                                       {xmlel, <<"unsupported-encoding">>,
 +                                        _attrs, _els}) ->
 +    'unsupported-encoding'.
 +
 +encode_stream_error_unsupported_encoding('unsupported-encoding',
 +                                       __TopXMLNS) ->
 +    __NewTopXMLNS =
 +      choose_top_xmlns(<<"urn:ietf:params:xml:ns:xmpp-streams">>,
 +                       [], __TopXMLNS),
 +    _els = [],
 +    _attrs = enc_xmlns_attrs(__NewTopXMLNS, __TopXMLNS),
 +    {xmlel, <<"unsupported-encoding">>, _attrs, _els}.
 +
 +decode_stream_error_undefined_condition(__TopXMLNS,
 +                                      __IgnoreEls,
 +                                      {xmlel, <<"undefined-condition">>,
 +                                       _attrs, _els}) ->
 +    'undefined-condition'.
 +
 +encode_stream_error_undefined_condition('undefined-condition',
 +                                      __TopXMLNS) ->
 +    __NewTopXMLNS =
 +      choose_top_xmlns(<<"urn:ietf:params:xml:ns:xmpp-streams">>,
 +                       [], __TopXMLNS),
 +    _els = [],
 +    _attrs = enc_xmlns_attrs(__NewTopXMLNS, __TopXMLNS),
 +    {xmlel, <<"undefined-condition">>, _attrs, _els}.
 +
 +decode_stream_error_system_shutdown(__TopXMLNS,
 +                                  __IgnoreEls,
 +                                  {xmlel, <<"system-shutdown">>, _attrs,
 +                                   _els}) ->
 +    'system-shutdown'.
 +
 +encode_stream_error_system_shutdown('system-shutdown',
 +                                  __TopXMLNS) ->
 +    __NewTopXMLNS =
 +      choose_top_xmlns(<<"urn:ietf:params:xml:ns:xmpp-streams">>,
 +                       [], __TopXMLNS),
 +    _els = [],
 +    _attrs = enc_xmlns_attrs(__NewTopXMLNS, __TopXMLNS),
 +    {xmlel, <<"system-shutdown">>, _attrs, _els}.
 +
 +decode_stream_error_see_other_host(__TopXMLNS,
 +                                 __IgnoreEls,
 +                                 {xmlel, <<"see-other-host">>, _attrs,
 +                                  _els}) ->
 +    Host =
 +      decode_stream_error_see_other_host_els(__TopXMLNS,
 +                                             __IgnoreEls, _els, <<>>),
 +    {'see-other-host', Host}.
 +
 +decode_stream_error_see_other_host_els(__TopXMLNS,
 +                                     __IgnoreEls, [], Host) ->
 +    decode_stream_error_see_other_host_cdata(__TopXMLNS,
 +                                           Host);
 +decode_stream_error_see_other_host_els(__TopXMLNS,
 +                                     __IgnoreEls, [{xmlcdata, _data} | _els],
 +                                     Host) ->
 +    decode_stream_error_see_other_host_els(__TopXMLNS,
 +                                         __IgnoreEls, _els,
 +                                         <<Host/binary, _data/binary>>);
 +decode_stream_error_see_other_host_els(__TopXMLNS,
 +                                     __IgnoreEls, [_ | _els], Host) ->
 +    decode_stream_error_see_other_host_els(__TopXMLNS,
 +                                         __IgnoreEls, _els, Host).
 +
 +encode_stream_error_see_other_host({'see-other-host',
 +                                  Host},
 +                                 __TopXMLNS) ->
 +    __NewTopXMLNS =
 +      choose_top_xmlns(<<"urn:ietf:params:xml:ns:xmpp-streams">>,
 +                       [], __TopXMLNS),
 +    _els = encode_stream_error_see_other_host_cdata(Host,
 +                                                  []),
 +    _attrs = enc_xmlns_attrs(__NewTopXMLNS, __TopXMLNS),
 +    {xmlel, <<"see-other-host">>, _attrs, _els}.
 +
 +decode_stream_error_see_other_host_cdata(__TopXMLNS,
 +                                       <<>>) ->
 +    erlang:error({xmpp_codec,
 +                {missing_cdata, <<>>, <<"see-other-host">>,
 +                 __TopXMLNS}});
 +decode_stream_error_see_other_host_cdata(__TopXMLNS,
 +                                       _val) ->
 +    case catch dec_host_port(_val) of
 +      {'EXIT', _} ->
 +        erlang:error({xmpp_codec,
 +                      {bad_cdata_value, <<>>, <<"see-other-host">>,
 +                       __TopXMLNS}});
 +      _res -> _res
 +    end.
 +
 +encode_stream_error_see_other_host_cdata(_val, _acc) ->
 +    [{xmlcdata, enc_host_port(_val)} | _acc].
 +
 +decode_stream_error_restricted_xml(__TopXMLNS,
 +                                 __IgnoreEls,
 +                                 {xmlel, <<"restricted-xml">>, _attrs,
 +                                  _els}) ->
 +    'restricted-xml'.
 +
 +encode_stream_error_restricted_xml('restricted-xml',
 +                                 __TopXMLNS) ->
 +    __NewTopXMLNS =
 +      choose_top_xmlns(<<"urn:ietf:params:xml:ns:xmpp-streams">>,
 +                       [], __TopXMLNS),
 +    _els = [],
 +    _attrs = enc_xmlns_attrs(__NewTopXMLNS, __TopXMLNS),
 +    {xmlel, <<"restricted-xml">>, _attrs, _els}.
 +
 +decode_stream_error_resource_constraint(__TopXMLNS,
 +                                      __IgnoreEls,
 +                                      {xmlel, <<"resource-constraint">>,
 +                                       _attrs, _els}) ->
 +    'resource-constraint'.
 +
 +encode_stream_error_resource_constraint('resource-constraint',
 +                                      __TopXMLNS) ->
 +    __NewTopXMLNS =
 +      choose_top_xmlns(<<"urn:ietf:params:xml:ns:xmpp-streams">>,
 +                       [], __TopXMLNS),
 +    _els = [],
 +    _attrs = enc_xmlns_attrs(__NewTopXMLNS, __TopXMLNS),
 +    {xmlel, <<"resource-constraint">>, _attrs, _els}.
 +
 +decode_stream_error_reset(__TopXMLNS, __IgnoreEls,
 +                        {xmlel, <<"reset">>, _attrs, _els}) ->
 +    reset.
 +
 +encode_stream_error_reset(reset, __TopXMLNS) ->
 +    __NewTopXMLNS =
 +      choose_top_xmlns(<<"urn:ietf:params:xml:ns:xmpp-streams">>,
 +                       [], __TopXMLNS),
 +    _els = [],
 +    _attrs = enc_xmlns_attrs(__NewTopXMLNS, __TopXMLNS),
 +    {xmlel, <<"reset">>, _attrs, _els}.
 +
 +decode_stream_error_remote_connection_failed(__TopXMLNS,
 +                                           __IgnoreEls,
 +                                           {xmlel,
 +                                            <<"remote-connection-failed">>,
 +                                            _attrs, _els}) ->
 +    'remote-connection-failed'.
 +
 +encode_stream_error_remote_connection_failed('remote-connection-failed',
 +                                           __TopXMLNS) ->
 +    __NewTopXMLNS =
 +      choose_top_xmlns(<<"urn:ietf:params:xml:ns:xmpp-streams">>,
 +                       [], __TopXMLNS),
 +    _els = [],
 +    _attrs = enc_xmlns_attrs(__NewTopXMLNS, __TopXMLNS),
 +    {xmlel, <<"remote-connection-failed">>, _attrs, _els}.
 +
 +decode_stream_error_policy_violation(__TopXMLNS,
 +                                   __IgnoreEls,
 +                                   {xmlel, <<"policy-violation">>, _attrs,
 +                                    _els}) ->
 +    'policy-violation'.
 +
 +encode_stream_error_policy_violation('policy-violation',
 +                                   __TopXMLNS) ->
 +    __NewTopXMLNS =
 +      choose_top_xmlns(<<"urn:ietf:params:xml:ns:xmpp-streams">>,
 +                       [], __TopXMLNS),
 +    _els = [],
 +    _attrs = enc_xmlns_attrs(__NewTopXMLNS, __TopXMLNS),
 +    {xmlel, <<"policy-violation">>, _attrs, _els}.
 +
 +decode_stream_error_not_well_formed(__TopXMLNS,
 +                                  __IgnoreEls,
 +                                  {xmlel, <<"not-well-formed">>, _attrs,
 +                                   _els}) ->
 +    'not-well-formed'.
 +
 +encode_stream_error_not_well_formed('not-well-formed',
 +                                  __TopXMLNS) ->
 +    __NewTopXMLNS =
 +      choose_top_xmlns(<<"urn:ietf:params:xml:ns:xmpp-streams">>,
 +                       [], __TopXMLNS),
 +    _els = [],
 +    _attrs = enc_xmlns_attrs(__NewTopXMLNS, __TopXMLNS),
 +    {xmlel, <<"not-well-formed">>, _attrs, _els}.
 +
 +decode_stream_error_not_authorized(__TopXMLNS,
 +                                 __IgnoreEls,
 +                                 {xmlel, <<"not-authorized">>, _attrs,
 +                                  _els}) ->
 +    'not-authorized'.
 +
 +encode_stream_error_not_authorized('not-authorized',
 +                                 __TopXMLNS) ->
 +    __NewTopXMLNS =
 +      choose_top_xmlns(<<"urn:ietf:params:xml:ns:xmpp-streams">>,
 +                       [], __TopXMLNS),
 +    _els = [],
 +    _attrs = enc_xmlns_attrs(__NewTopXMLNS, __TopXMLNS),
 +    {xmlel, <<"not-authorized">>, _attrs, _els}.
 +
 +decode_stream_error_invalid_xml(__TopXMLNS, __IgnoreEls,
 +                              {xmlel, <<"invalid-xml">>, _attrs, _els}) ->
 +    'invalid-xml'.
 +
 +encode_stream_error_invalid_xml('invalid-xml',
 +                              __TopXMLNS) ->
 +    __NewTopXMLNS =
 +      choose_top_xmlns(<<"urn:ietf:params:xml:ns:xmpp-streams">>,
 +                       [], __TopXMLNS),
 +    _els = [],
 +    _attrs = enc_xmlns_attrs(__NewTopXMLNS, __TopXMLNS),
 +    {xmlel, <<"invalid-xml">>, _attrs, _els}.
 +
 +decode_stream_error_invalid_namespace(__TopXMLNS,
 +                                    __IgnoreEls,
 +                                    {xmlel, <<"invalid-namespace">>, _attrs,
 +                                     _els}) ->
 +    'invalid-namespace'.
 +
 +encode_stream_error_invalid_namespace('invalid-namespace',
 +                                    __TopXMLNS) ->
 +    __NewTopXMLNS =
 +      choose_top_xmlns(<<"urn:ietf:params:xml:ns:xmpp-streams">>,
 +                       [], __TopXMLNS),
 +    _els = [],
 +    _attrs = enc_xmlns_attrs(__NewTopXMLNS, __TopXMLNS),
 +    {xmlel, <<"invalid-namespace">>, _attrs, _els}.
 +
 +decode_stream_error_invalid_id(__TopXMLNS, __IgnoreEls,
 +                             {xmlel, <<"invalid-id">>, _attrs, _els}) ->
 +    'invalid-id'.
 +
 +encode_stream_error_invalid_id('invalid-id',
 +                             __TopXMLNS) ->
 +    __NewTopXMLNS =
 +      choose_top_xmlns(<<"urn:ietf:params:xml:ns:xmpp-streams">>,
 +                       [], __TopXMLNS),
 +    _els = [],
 +    _attrs = enc_xmlns_attrs(__NewTopXMLNS, __TopXMLNS),
 +    {xmlel, <<"invalid-id">>, _attrs, _els}.
 +
 +decode_stream_error_invalid_from(__TopXMLNS,
 +                               __IgnoreEls,
 +                               {xmlel, <<"invalid-from">>, _attrs, _els}) ->
 +    'invalid-from'.
 +
 +encode_stream_error_invalid_from('invalid-from',
 +                               __TopXMLNS) ->
 +    __NewTopXMLNS =
 +      choose_top_xmlns(<<"urn:ietf:params:xml:ns:xmpp-streams">>,
 +                       [], __TopXMLNS),
 +    _els = [],
 +    _attrs = enc_xmlns_attrs(__NewTopXMLNS, __TopXMLNS),
 +    {xmlel, <<"invalid-from">>, _attrs, _els}.
 +
 +decode_stream_error_internal_server_error(__TopXMLNS,
 +                                        __IgnoreEls,
 +                                        {xmlel, <<"internal-server-error">>,
 +                                         _attrs, _els}) ->
 +    'internal-server-error'.
 +
 +encode_stream_error_internal_server_error('internal-server-error',
 +                                        __TopXMLNS) ->
 +    __NewTopXMLNS =
 +      choose_top_xmlns(<<"urn:ietf:params:xml:ns:xmpp-streams">>,
 +                       [], __TopXMLNS),
 +    _els = [],
 +    _attrs = enc_xmlns_attrs(__NewTopXMLNS, __TopXMLNS),
 +    {xmlel, <<"internal-server-error">>, _attrs, _els}.
 +
 +decode_stream_error_improper_addressing(__TopXMLNS,
 +                                      __IgnoreEls,
 +                                      {xmlel, <<"improper-addressing">>,
 +                                       _attrs, _els}) ->
 +    'improper-addressing'.
 +
 +encode_stream_error_improper_addressing('improper-addressing',
 +                                      __TopXMLNS) ->
 +    __NewTopXMLNS =
 +      choose_top_xmlns(<<"urn:ietf:params:xml:ns:xmpp-streams">>,
 +                       [], __TopXMLNS),
 +    _els = [],
 +    _attrs = enc_xmlns_attrs(__NewTopXMLNS, __TopXMLNS),
 +    {xmlel, <<"improper-addressing">>, _attrs, _els}.
 +
 +decode_stream_error_host_unknown(__TopXMLNS,
 +                               __IgnoreEls,
 +                               {xmlel, <<"host-unknown">>, _attrs, _els}) ->
 +    'host-unknown'.
 +
 +encode_stream_error_host_unknown('host-unknown',
 +                               __TopXMLNS) ->
 +    __NewTopXMLNS =
 +      choose_top_xmlns(<<"urn:ietf:params:xml:ns:xmpp-streams">>,
 +                       [], __TopXMLNS),
 +    _els = [],
 +    _attrs = enc_xmlns_attrs(__NewTopXMLNS, __TopXMLNS),
 +    {xmlel, <<"host-unknown">>, _attrs, _els}.
 +
 +decode_stream_error_host_gone(__TopXMLNS, __IgnoreEls,
 +                            {xmlel, <<"host-gone">>, _attrs, _els}) ->
 +    'host-gone'.
 +
 +encode_stream_error_host_gone('host-gone',
 +                            __TopXMLNS) ->
 +    __NewTopXMLNS =
 +      choose_top_xmlns(<<"urn:ietf:params:xml:ns:xmpp-streams">>,
 +                       [], __TopXMLNS),
 +    _els = [],
 +    _attrs = enc_xmlns_attrs(__NewTopXMLNS, __TopXMLNS),
 +    {xmlel, <<"host-gone">>, _attrs, _els}.
 +
 +decode_stream_error_connection_timeout(__TopXMLNS,
 +                                     __IgnoreEls,
 +                                     {xmlel, <<"connection-timeout">>, _attrs,
 +                                      _els}) ->
 +    'connection-timeout'.
 +
 +encode_stream_error_connection_timeout('connection-timeout',
 +                                     __TopXMLNS) ->
 +    __NewTopXMLNS =
 +      choose_top_xmlns(<<"urn:ietf:params:xml:ns:xmpp-streams">>,
 +                       [], __TopXMLNS),
 +    _els = [],
 +    _attrs = enc_xmlns_attrs(__NewTopXMLNS, __TopXMLNS),
 +    {xmlel, <<"connection-timeout">>, _attrs, _els}.
 +
 +decode_stream_error_conflict(__TopXMLNS, __IgnoreEls,
 +                           {xmlel, <<"conflict">>, _attrs, _els}) ->
 +    conflict.
 +
 +encode_stream_error_conflict(conflict, __TopXMLNS) ->
 +    __NewTopXMLNS =
 +      choose_top_xmlns(<<"urn:ietf:params:xml:ns:xmpp-streams">>,
 +                       [], __TopXMLNS),
 +    _els = [],
 +    _attrs = enc_xmlns_attrs(__NewTopXMLNS, __TopXMLNS),
 +    {xmlel, <<"conflict">>, _attrs, _els}.
 +
 +decode_stream_error_bad_namespace_prefix(__TopXMLNS,
 +                                       __IgnoreEls,
 +                                       {xmlel, <<"bad-namespace-prefix">>,
 +                                        _attrs, _els}) ->
 +    'bad-namespace-prefix'.
 +
 +encode_stream_error_bad_namespace_prefix('bad-namespace-prefix',
 +                                       __TopXMLNS) ->
 +    __NewTopXMLNS =
 +      choose_top_xmlns(<<"urn:ietf:params:xml:ns:xmpp-streams">>,
 +                       [], __TopXMLNS),
 +    _els = [],
 +    _attrs = enc_xmlns_attrs(__NewTopXMLNS, __TopXMLNS),
 +    {xmlel, <<"bad-namespace-prefix">>, _attrs, _els}.
 +
 +decode_stream_error_bad_format(__TopXMLNS, __IgnoreEls,
 +                             {xmlel, <<"bad-format">>, _attrs, _els}) ->
 +    'bad-format'.
 +
 +encode_stream_error_bad_format('bad-format',
 +                             __TopXMLNS) ->
 +    __NewTopXMLNS =
 +      choose_top_xmlns(<<"urn:ietf:params:xml:ns:xmpp-streams">>,
 +                       [], __TopXMLNS),
 +    _els = [],
 +    _attrs = enc_xmlns_attrs(__NewTopXMLNS, __TopXMLNS),
 +    {xmlel, <<"bad-format">>, _attrs, _els}.
 +
 +decode_stream_error_text(__TopXMLNS, __IgnoreEls,
 +                       {xmlel, <<"text">>, _attrs, _els}) ->
 +    Data = decode_stream_error_text_els(__TopXMLNS,
 +                                      __IgnoreEls, _els, <<>>),
 +    Lang = decode_stream_error_text_attrs(__TopXMLNS,
 +                                        _attrs, undefined),
 +    {text, Lang, Data}.
 +
 +decode_stream_error_text_els(__TopXMLNS, __IgnoreEls,
 +                           [], Data) ->
 +    decode_stream_error_text_cdata(__TopXMLNS, Data);
 +decode_stream_error_text_els(__TopXMLNS, __IgnoreEls,
 +                           [{xmlcdata, _data} | _els], Data) ->
 +    decode_stream_error_text_els(__TopXMLNS, __IgnoreEls,
 +                               _els, <<Data/binary, _data/binary>>);
 +decode_stream_error_text_els(__TopXMLNS, __IgnoreEls,
 +                           [_ | _els], Data) ->
 +    decode_stream_error_text_els(__TopXMLNS, __IgnoreEls,
 +                               _els, Data).
 +
 +decode_stream_error_text_attrs(__TopXMLNS,
 +                             [{<<"xml:lang">>, _val} | _attrs], _Lang) ->
 +    decode_stream_error_text_attrs(__TopXMLNS, _attrs,
 +                                 _val);
 +decode_stream_error_text_attrs(__TopXMLNS, [_ | _attrs],
 +                             Lang) ->
 +    decode_stream_error_text_attrs(__TopXMLNS, _attrs,
 +                                 Lang);
 +decode_stream_error_text_attrs(__TopXMLNS, [], Lang) ->
 +    'decode_stream_error_text_attr_xml:lang'(__TopXMLNS,
 +                                           Lang).
 +
 +encode_stream_error_text({text, Lang, Data},
 +                       __TopXMLNS) ->
 +    __NewTopXMLNS =
 +      choose_top_xmlns(<<"urn:ietf:params:xml:ns:xmpp-streams">>,
 +                       [], __TopXMLNS),
 +    _els = encode_stream_error_text_cdata(Data, []),
 +    _attrs = 'encode_stream_error_text_attr_xml:lang'(Lang,
 +                                                    enc_xmlns_attrs(__NewTopXMLNS,
 +                                                                    __TopXMLNS)),
 +    {xmlel, <<"text">>, _attrs, _els}.
 +
 +'decode_stream_error_text_attr_xml:lang'(__TopXMLNS,
 +                                       undefined) ->
 +    <<>>;
 +'decode_stream_error_text_attr_xml:lang'(__TopXMLNS,
 +                                       _val) ->
 +    _val.
 +
 +'encode_stream_error_text_attr_xml:lang'(<<>>, _acc) ->
 +    _acc;
 +'encode_stream_error_text_attr_xml:lang'(_val, _acc) ->
 +    [{<<"xml:lang">>, _val} | _acc].
 +
 +decode_stream_error_text_cdata(__TopXMLNS, <<>>) ->
 +    <<>>;
 +decode_stream_error_text_cdata(__TopXMLNS, _val) ->
 +    _val.
 +
 +encode_stream_error_text_cdata(<<>>, _acc) -> _acc;
 +encode_stream_error_text_cdata(_val, _acc) ->
 +    [{xmlcdata, _val} | _acc].
 +
 +decode_time(__TopXMLNS, __IgnoreEls,
 +          {xmlel, <<"time">>, _attrs, _els}) ->
 +    {Utc, Tzo} = decode_time_els(__TopXMLNS, __IgnoreEls,
 +                               _els, undefined, undefined),
 +    {time, Tzo, Utc}.
 +
 +decode_time_els(__TopXMLNS, __IgnoreEls, [], Utc,
 +              Tzo) ->
 +    {Utc, Tzo};
 +decode_time_els(__TopXMLNS, __IgnoreEls,
 +              [{xmlel, <<"tzo">>, _attrs, _} = _el | _els], Utc,
 +              Tzo) ->
 +    case get_attr(<<"xmlns">>, _attrs) of
 +      <<"">> when __TopXMLNS == <<"urn:xmpp:time">> ->
 +        decode_time_els(__TopXMLNS, __IgnoreEls, _els, Utc,
 +                        decode_time_tzo(__TopXMLNS, __IgnoreEls, _el));
 +      <<"urn:xmpp:time">> ->
 +        decode_time_els(__TopXMLNS, __IgnoreEls, _els, Utc,
 +                        decode_time_tzo(<<"urn:xmpp:time">>, __IgnoreEls,
 +                                        _el));
 +      _ ->
 +        decode_time_els(__TopXMLNS, __IgnoreEls, _els, Utc, Tzo)
 +    end;
 +decode_time_els(__TopXMLNS, __IgnoreEls,
 +              [{xmlel, <<"utc">>, _attrs, _} = _el | _els], Utc,
 +              Tzo) ->
 +    case get_attr(<<"xmlns">>, _attrs) of
 +      <<"">> when __TopXMLNS == <<"urn:xmpp:time">> ->
 +        decode_time_els(__TopXMLNS, __IgnoreEls, _els,
 +                        decode_time_utc(__TopXMLNS, __IgnoreEls, _el), Tzo);
 +      <<"urn:xmpp:time">> ->
 +        decode_time_els(__TopXMLNS, __IgnoreEls, _els,
 +                        decode_time_utc(<<"urn:xmpp:time">>, __IgnoreEls,
 +                                        _el),
 +                        Tzo);
 +      _ ->
 +        decode_time_els(__TopXMLNS, __IgnoreEls, _els, Utc, Tzo)
 +    end;
 +decode_time_els(__TopXMLNS, __IgnoreEls, [_ | _els],
 +              Utc, Tzo) ->
 +    decode_time_els(__TopXMLNS, __IgnoreEls, _els, Utc,
 +                  Tzo).
 +
 +encode_time({time, Tzo, Utc}, __TopXMLNS) ->
 +    __NewTopXMLNS = choose_top_xmlns(<<"urn:xmpp:time">>,
 +                                   [], __TopXMLNS),
 +    _els = lists:reverse('encode_time_$utc'(Utc,
 +                                          __NewTopXMLNS,
 +                                          'encode_time_$tzo'(Tzo,
 +                                                             __NewTopXMLNS,
 +                                                             []))),
 +    _attrs = enc_xmlns_attrs(__NewTopXMLNS, __TopXMLNS),
 +    {xmlel, <<"time">>, _attrs, _els}.
 +
 +'encode_time_$utc'(undefined, __TopXMLNS, _acc) -> _acc;
 +'encode_time_$utc'(Utc, __TopXMLNS, _acc) ->
 +    [encode_time_utc(Utc, __TopXMLNS) | _acc].
 +
 +'encode_time_$tzo'(undefined, __TopXMLNS, _acc) -> _acc;
 +'encode_time_$tzo'(Tzo, __TopXMLNS, _acc) ->
 +    [encode_time_tzo(Tzo, __TopXMLNS) | _acc].
 +
 +decode_time_tzo(__TopXMLNS, __IgnoreEls,
 +              {xmlel, <<"tzo">>, _attrs, _els}) ->
 +    Cdata = decode_time_tzo_els(__TopXMLNS, __IgnoreEls,
 +                              _els, <<>>),
 +    Cdata.
 +
 +decode_time_tzo_els(__TopXMLNS, __IgnoreEls, [],
 +                  Cdata) ->
 +    decode_time_tzo_cdata(__TopXMLNS, Cdata);
 +decode_time_tzo_els(__TopXMLNS, __IgnoreEls,
 +                  [{xmlcdata, _data} | _els], Cdata) ->
 +    decode_time_tzo_els(__TopXMLNS, __IgnoreEls, _els,
 +                      <<Cdata/binary, _data/binary>>);
 +decode_time_tzo_els(__TopXMLNS, __IgnoreEls, [_ | _els],
 +                  Cdata) ->
 +    decode_time_tzo_els(__TopXMLNS, __IgnoreEls, _els,
 +                      Cdata).
 +
 +encode_time_tzo(Cdata, __TopXMLNS) ->
 +    __NewTopXMLNS = choose_top_xmlns(<<"urn:xmpp:time">>,
 +                                   [], __TopXMLNS),
 +    _els = encode_time_tzo_cdata(Cdata, []),
 +    _attrs = enc_xmlns_attrs(__NewTopXMLNS, __TopXMLNS),
 +    {xmlel, <<"tzo">>, _attrs, _els}.
 +
 +decode_time_tzo_cdata(__TopXMLNS, <<>>) -> undefined;
 +decode_time_tzo_cdata(__TopXMLNS, _val) ->
 +    case catch dec_tzo(_val) of
 +      {'EXIT', _} ->
 +        erlang:error({xmpp_codec,
 +                      {bad_cdata_value, <<>>, <<"tzo">>, __TopXMLNS}});
 +      _res -> _res
 +    end.
 +
 +encode_time_tzo_cdata(undefined, _acc) -> _acc;
 +encode_time_tzo_cdata(_val, _acc) ->
 +    [{xmlcdata, enc_tzo(_val)} | _acc].
 +
 +decode_time_utc(__TopXMLNS, __IgnoreEls,
 +              {xmlel, <<"utc">>, _attrs, _els}) ->
 +    Cdata = decode_time_utc_els(__TopXMLNS, __IgnoreEls,
 +                              _els, <<>>),
 +    Cdata.
 +
 +decode_time_utc_els(__TopXMLNS, __IgnoreEls, [],
 +                  Cdata) ->
 +    decode_time_utc_cdata(__TopXMLNS, Cdata);
 +decode_time_utc_els(__TopXMLNS, __IgnoreEls,
 +                  [{xmlcdata, _data} | _els], Cdata) ->
 +    decode_time_utc_els(__TopXMLNS, __IgnoreEls, _els,
 +                      <<Cdata/binary, _data/binary>>);
 +decode_time_utc_els(__TopXMLNS, __IgnoreEls, [_ | _els],
 +                  Cdata) ->
 +    decode_time_utc_els(__TopXMLNS, __IgnoreEls, _els,
 +                      Cdata).
 +
 +encode_time_utc(Cdata, __TopXMLNS) ->
 +    __NewTopXMLNS = choose_top_xmlns(<<"urn:xmpp:time">>,
 +                                   [], __TopXMLNS),
 +    _els = encode_time_utc_cdata(Cdata, []),
 +    _attrs = enc_xmlns_attrs(__NewTopXMLNS, __TopXMLNS),
 +    {xmlel, <<"utc">>, _attrs, _els}.
 +
 +decode_time_utc_cdata(__TopXMLNS, <<>>) -> undefined;
 +decode_time_utc_cdata(__TopXMLNS, _val) ->
 +    case catch dec_utc(_val) of
 +      {'EXIT', _} ->
 +        erlang:error({xmpp_codec,
 +                      {bad_cdata_value, <<>>, <<"utc">>, __TopXMLNS}});
 +      _res -> _res
 +    end.
 +
 +encode_time_utc_cdata(undefined, _acc) -> _acc;
 +encode_time_utc_cdata(_val, _acc) ->
 +    [{xmlcdata, enc_utc(_val)} | _acc].
 +
 +decode_ping(__TopXMLNS, __IgnoreEls,
 +          {xmlel, <<"ping">>, _attrs, _els}) ->
 +    {ping}.
 +
 +encode_ping({ping}, __TopXMLNS) ->
 +    __NewTopXMLNS = choose_top_xmlns(<<"urn:xmpp:ping">>,
 +                                   [], __TopXMLNS),
 +    _els = [],
 +    _attrs = enc_xmlns_attrs(__NewTopXMLNS, __TopXMLNS),
 +    {xmlel, <<"ping">>, _attrs, _els}.
 +
 +decode_session(__TopXMLNS, __IgnoreEls,
 +             {xmlel, <<"session">>, _attrs, _els}) ->
 +    Optional = decode_session_els(__TopXMLNS, __IgnoreEls,
 +                                _els, false),
 +    {xmpp_session, Optional}.
 +
 +decode_session_els(__TopXMLNS, __IgnoreEls, [],
 +                 Optional) ->
 +    Optional;
 +decode_session_els(__TopXMLNS, __IgnoreEls,
 +                 [{xmlel, <<"optional">>, _attrs, _} = _el | _els],
 +                 Optional) ->
 +    case get_attr(<<"xmlns">>, _attrs) of
 +      <<"">>
 +        when __TopXMLNS ==
 +               <<"urn:ietf:params:xml:ns:xmpp-session">> ->
 +        decode_session_els(__TopXMLNS, __IgnoreEls, _els,
 +                           decode_session_optional(__TopXMLNS, __IgnoreEls,
 +                                                   _el));
 +      <<"urn:ietf:params:xml:ns:xmpp-session">> ->
 +        decode_session_els(__TopXMLNS, __IgnoreEls, _els,
 +                           decode_session_optional(<<"urn:ietf:params:xml:ns:xmpp-session">>,
 +                                                   __IgnoreEls, _el));
 +      _ ->
 +        decode_session_els(__TopXMLNS, __IgnoreEls, _els,
 +                           Optional)
 +    end;
 +decode_session_els(__TopXMLNS, __IgnoreEls, [_ | _els],
 +                 Optional) ->
 +    decode_session_els(__TopXMLNS, __IgnoreEls, _els,
 +                     Optional).
 +
 +encode_session({xmpp_session, Optional}, __TopXMLNS) ->
 +    __NewTopXMLNS =
 +      choose_top_xmlns(<<"urn:ietf:params:xml:ns:xmpp-session">>,
 +                       [], __TopXMLNS),
 +    _els =
 +      lists:reverse('encode_session_$optional'(Optional,
 +                                               __NewTopXMLNS, [])),
 +    _attrs = enc_xmlns_attrs(__NewTopXMLNS, __TopXMLNS),
 +    {xmlel, <<"session">>, _attrs, _els}.
 +
 +'encode_session_$optional'(false, __TopXMLNS, _acc) ->
 +    _acc;
 +'encode_session_$optional'(Optional, __TopXMLNS,
 +                         _acc) ->
 +    [encode_session_optional(Optional, __TopXMLNS) | _acc].
 +
 +decode_session_optional(__TopXMLNS, __IgnoreEls,
 +                      {xmlel, <<"optional">>, _attrs, _els}) ->
 +    true.
 +
 +encode_session_optional(true, __TopXMLNS) ->
 +    __NewTopXMLNS =
 +      choose_top_xmlns(<<"urn:ietf:params:xml:ns:xmpp-session">>,
 +                       [], __TopXMLNS),
 +    _els = [],
 +    _attrs = enc_xmlns_attrs(__NewTopXMLNS, __TopXMLNS),
 +    {xmlel, <<"optional">>, _attrs, _els}.
 +
 +decode_register(__TopXMLNS, __IgnoreEls,
 +              {xmlel, <<"query">>, _attrs, _els}) ->
 +    {Zip, Xdata, Misc, Address, Instructions, Text, Last,
 +     First, Password, Registered, Date, Phone, State, Name,
 +     Username, Remove, Key, City, Nick, Url, Email, __Els} =
 +      decode_register_els(__TopXMLNS, __IgnoreEls, _els,
 +                          undefined, undefined, undefined, undefined,
 +                          undefined, undefined, undefined, undefined,
 +                          undefined, false, undefined, undefined, undefined,
 +                          undefined, undefined, false, undefined, undefined,
 +                          undefined, undefined, undefined, []),
 +    {register, Registered, Remove, Instructions, Username,
 +     Nick, Password, Name, First, Last, Email, Address, City,
 +     State, Zip, Phone, Url, Date, Misc, Text, Key, Xdata,
 +     __Els}.
 +
 +decode_register_els(__TopXMLNS, __IgnoreEls, [], Zip,
 +                  Xdata, Misc, Address, Instructions, Text, Last, First,
 +                  Password, Registered, Date, Phone, State, Name,
 +                  Username, Remove, Key, City, Nick, Url, Email, __Els) ->
 +    {Zip, Xdata, Misc, Address, Instructions, Text, Last,
 +     First, Password, Registered, Date, Phone, State, Name,
 +     Username, Remove, Key, City, Nick, Url, Email,
 +     lists:reverse(__Els)};
 +decode_register_els(__TopXMLNS, __IgnoreEls,
 +                  [{xmlel, <<"x">>, _attrs, _} = _el | _els], Zip, Xdata,
 +                  Misc, Address, Instructions, Text, Last, First,
 +                  Password, Registered, Date, Phone, State, Name,
 +                  Username, Remove, Key, City, Nick, Url, Email, __Els) ->
 +    case get_attr(<<"xmlns">>, _attrs) of
 +      <<"jabber:x:data">> ->
 +        decode_register_els(__TopXMLNS, __IgnoreEls, _els, Zip,
 +                            decode_xdata(<<"jabber:x:data">>, __IgnoreEls,
 +                                         _el),
 +                            Misc, Address, Instructions, Text, Last, First,
 +                            Password, Registered, Date, Phone, State, Name,
 +                            Username, Remove, Key, City, Nick, Url, Email,
 +                            __Els);
 +      _ ->
 +        decode_register_els(__TopXMLNS, __IgnoreEls, _els, Zip,
 +                            Xdata, Misc, Address, Instructions, Text, Last,
 +                            First, Password, Registered, Date, Phone, State,
 +                            Name, Username, Remove, Key, City, Nick, Url,
 +                            Email, __Els)
 +    end;
 +decode_register_els(__TopXMLNS, __IgnoreEls,
 +                  [{xmlel, <<"registered">>, _attrs, _} = _el | _els],
 +                  Zip, Xdata, Misc, Address, Instructions, Text, Last,
 +                  First, Password, Registered, Date, Phone, State, Name,
 +                  Username, Remove, Key, City, Nick, Url, Email, __Els) ->
 +    case get_attr(<<"xmlns">>, _attrs) of
 +      <<"">> when __TopXMLNS == <<"jabber:iq:register">> ->
 +        decode_register_els(__TopXMLNS, __IgnoreEls, _els, Zip,
 +                            Xdata, Misc, Address, Instructions, Text, Last,
 +                            First, Password,
 +                            decode_register_registered(__TopXMLNS,
 +                                                       __IgnoreEls, _el),
 +                            Date, Phone, State, Name, Username, Remove, Key,
 +                            City, Nick, Url, Email, __Els);
 +      <<"jabber:iq:register">> ->
 +        decode_register_els(__TopXMLNS, __IgnoreEls, _els, Zip,
 +                            Xdata, Misc, Address, Instructions, Text, Last,
 +                            First, Password,
 +                            decode_register_registered(<<"jabber:iq:register">>,
 +                                                       __IgnoreEls, _el),
 +                            Date, Phone, State, Name, Username, Remove, Key,
 +                            City, Nick, Url, Email, __Els);
 +      _ ->
 +        decode_register_els(__TopXMLNS, __IgnoreEls, _els, Zip,
 +                            Xdata, Misc, Address, Instructions, Text, Last,
 +                            First, Password, Registered, Date, Phone, State,
 +                            Name, Username, Remove, Key, City, Nick, Url,
 +                            Email, __Els)
 +    end;
 +decode_register_els(__TopXMLNS, __IgnoreEls,
 +                  [{xmlel, <<"remove">>, _attrs, _} = _el | _els], Zip,
 +                  Xdata, Misc, Address, Instructions, Text, Last, First,
 +                  Password, Registered, Date, Phone, State, Name,
 +                  Username, Remove, Key, City, Nick, Url, Email, __Els) ->
 +    case get_attr(<<"xmlns">>, _attrs) of
 +      <<"">> when __TopXMLNS == <<"jabber:iq:register">> ->
 +        decode_register_els(__TopXMLNS, __IgnoreEls, _els, Zip,
 +                            Xdata, Misc, Address, Instructions, Text, Last,
 +                            First, Password, Registered, Date, Phone, State,
 +                            Name, Username,
 +                            decode_register_remove(__TopXMLNS, __IgnoreEls,
 +                                                   _el),
 +                            Key, City, Nick, Url, Email, __Els);
 +      <<"jabber:iq:register">> ->
 +        decode_register_els(__TopXMLNS, __IgnoreEls, _els, Zip,
 +                            Xdata, Misc, Address, Instructions, Text, Last,
 +                            First, Password, Registered, Date, Phone, State,
 +                            Name, Username,
 +                            decode_register_remove(<<"jabber:iq:register">>,
 +                                                   __IgnoreEls, _el),
 +                            Key, City, Nick, Url, Email, __Els);
 +      _ ->
 +        decode_register_els(__TopXMLNS, __IgnoreEls, _els, Zip,
 +                            Xdata, Misc, Address, Instructions, Text, Last,
 +                            First, Password, Registered, Date, Phone, State,
 +                            Name, Username, Remove, Key, City, Nick, Url,
 +                            Email, __Els)
 +    end;
 +decode_register_els(__TopXMLNS, __IgnoreEls,
 +                  [{xmlel, <<"instructions">>, _attrs, _} = _el | _els],
 +                  Zip, Xdata, Misc, Address, Instructions, Text, Last,
 +                  First, Password, Registered, Date, Phone, State, Name,
 +                  Username, Remove, Key, City, Nick, Url, Email, __Els) ->
 +    case get_attr(<<"xmlns">>, _attrs) of
 +      <<"">> when __TopXMLNS == <<"jabber:iq:register">> ->
 +        decode_register_els(__TopXMLNS, __IgnoreEls, _els, Zip,
 +                            Xdata, Misc, Address,
 +                            decode_register_instructions(__TopXMLNS,
 +                                                         __IgnoreEls, _el),
 +                            Text, Last, First, Password, Registered, Date,
 +                            Phone, State, Name, Username, Remove, Key, City,
 +                            Nick, Url, Email, __Els);
 +      <<"jabber:iq:register">> ->
 +        decode_register_els(__TopXMLNS, __IgnoreEls, _els, Zip,
 +                            Xdata, Misc, Address,
 +                            decode_register_instructions(<<"jabber:iq:register">>,
 +                                                         __IgnoreEls, _el),
 +                            Text, Last, First, Password, Registered, Date,
 +                            Phone, State, Name, Username, Remove, Key, City,
 +                            Nick, Url, Email, __Els);
 +      _ ->
 +        decode_register_els(__TopXMLNS, __IgnoreEls, _els, Zip,
 +                            Xdata, Misc, Address, Instructions, Text, Last,
 +                            First, Password, Registered, Date, Phone, State,
 +                            Name, Username, Remove, Key, City, Nick, Url,
 +                            Email, __Els)
 +    end;
 +decode_register_els(__TopXMLNS, __IgnoreEls,
 +                  [{xmlel, <<"username">>, _attrs, _} = _el | _els], Zip,
 +                  Xdata, Misc, Address, Instructions, Text, Last, First,
 +                  Password, Registered, Date, Phone, State, Name,
 +                  Username, Remove, Key, City, Nick, Url, Email, __Els) ->
 +    case get_attr(<<"xmlns">>, _attrs) of
 +      <<"">> when __TopXMLNS == <<"jabber:iq:register">> ->
 +        decode_register_els(__TopXMLNS, __IgnoreEls, _els, Zip,
 +                            Xdata, Misc, Address, Instructions, Text, Last,
 +                            First, Password, Registered, Date, Phone, State,
 +                            Name,
 +                            decode_register_username(__TopXMLNS, __IgnoreEls,
 +                                                     _el),
 +                            Remove, Key, City, Nick, Url, Email, __Els);
 +      <<"jabber:iq:register">> ->
 +        decode_register_els(__TopXMLNS, __IgnoreEls, _els, Zip,
 +                            Xdata, Misc, Address, Instructions, Text, Last,
 +                            First, Password, Registered, Date, Phone, State,
 +                            Name,
 +                            decode_register_username(<<"jabber:iq:register">>,
 +                                                     __IgnoreEls, _el),
 +                            Remove, Key, City, Nick, Url, Email, __Els);
 +      _ ->
 +        decode_register_els(__TopXMLNS, __IgnoreEls, _els, Zip,
 +                            Xdata, Misc, Address, Instructions, Text, Last,
 +                            First, Password, Registered, Date, Phone, State,
 +                            Name, Username, Remove, Key, City, Nick, Url,
 +                            Email, __Els)
 +    end;
 +decode_register_els(__TopXMLNS, __IgnoreEls,
 +                  [{xmlel, <<"nick">>, _attrs, _} = _el | _els], Zip,
 +                  Xdata, Misc, Address, Instructions, Text, Last, First,
 +                  Password, Registered, Date, Phone, State, Name,
 +                  Username, Remove, Key, City, Nick, Url, Email, __Els) ->
 +    case get_attr(<<"xmlns">>, _attrs) of
 +      <<"">> when __TopXMLNS == <<"jabber:iq:register">> ->
 +        decode_register_els(__TopXMLNS, __IgnoreEls, _els, Zip,
 +                            Xdata, Misc, Address, Instructions, Text, Last,
 +                            First, Password, Registered, Date, Phone, State,
 +                            Name, Username, Remove, Key, City,
 +                            decode_register_nick(__TopXMLNS, __IgnoreEls,
 +                                                 _el),
 +                            Url, Email, __Els);
 +      <<"jabber:iq:register">> ->
 +        decode_register_els(__TopXMLNS, __IgnoreEls, _els, Zip,
 +                            Xdata, Misc, Address, Instructions, Text, Last,
 +                            First, Password, Registered, Date, Phone, State,
 +                            Name, Username, Remove, Key, City,
 +                            decode_register_nick(<<"jabber:iq:register">>,
 +                                                 __IgnoreEls, _el),
 +                            Url, Email, __Els);
 +      _ ->
 +        decode_register_els(__TopXMLNS, __IgnoreEls, _els, Zip,
 +                            Xdata, Misc, Address, Instructions, Text, Last,
 +                            First, Password, Registered, Date, Phone, State,
 +                            Name, Username, Remove, Key, City, Nick, Url,
 +                            Email, __Els)
 +    end;
 +decode_register_els(__TopXMLNS, __IgnoreEls,
 +                  [{xmlel, <<"password">>, _attrs, _} = _el | _els], Zip,
 +                  Xdata, Misc, Address, Instructions, Text, Last, First,
 +                  Password, Registered, Date, Phone, State, Name,
 +                  Username, Remove, Key, City, Nick, Url, Email, __Els) ->
 +    case get_attr(<<"xmlns">>, _attrs) of
 +      <<"">> when __TopXMLNS == <<"jabber:iq:register">> ->
 +        decode_register_els(__TopXMLNS, __IgnoreEls, _els, Zip,
 +                            Xdata, Misc, Address, Instructions, Text, Last,
 +                            First,
 +                            decode_register_password(__TopXMLNS, __IgnoreEls,
 +                                                     _el),
 +                            Registered, Date, Phone, State, Name, Username,
 +                            Remove, Key, City, Nick, Url, Email, __Els);
 +      <<"jabber:iq:register">> ->
 +        decode_register_els(__TopXMLNS, __IgnoreEls, _els, Zip,
 +                            Xdata, Misc, Address, Instructions, Text, Last,
 +                            First,
 +                            decode_register_password(<<"jabber:iq:register">>,
 +                                                     __IgnoreEls, _el),
 +                            Registered, Date, Phone, State, Name, Username,
 +                            Remove, Key, City, Nick, Url, Email, __Els);
 +      _ ->
 +        decode_register_els(__TopXMLNS, __IgnoreEls, _els, Zip,
 +                            Xdata, Misc, Address, Instructions, Text, Last,
 +                            First, Password, Registered, Date, Phone, State,
 +                            Name, Username, Remove, Key, City, Nick, Url,
 +                            Email, __Els)
 +    end;
 +decode_register_els(__TopXMLNS, __IgnoreEls,
 +                  [{xmlel, <<"name">>, _attrs, _} = _el | _els], Zip,
 +                  Xdata, Misc, Address, Instructions, Text, Last, First,
 +                  Password, Registered, Date, Phone, State, Name,
 +                  Username, Remove, Key, City, Nick, Url, Email, __Els) ->
 +    case get_attr(<<"xmlns">>, _attrs) of
 +      <<"">> when __TopXMLNS == <<"jabber:iq:register">> ->
 +        decode_register_els(__TopXMLNS, __IgnoreEls, _els, Zip,
 +                            Xdata, Misc, Address, Instructions, Text, Last,
 +                            First, Password, Registered, Date, Phone, State,
 +                            decode_register_name(__TopXMLNS, __IgnoreEls,
 +                                                 _el),
 +                            Username, Remove, Key, City, Nick, Url, Email,
 +                            __Els);
 +      <<"jabber:iq:register">> ->
 +        decode_register_els(__TopXMLNS, __IgnoreEls, _els, Zip,
 +                            Xdata, Misc, Address, Instructions, Text, Last,
 +                            First, Password, Registered, Date, Phone, State,
 +                            decode_register_name(<<"jabber:iq:register">>,
 +                                                 __IgnoreEls, _el),
 +                            Username, Remove, Key, City, Nick, Url, Email,
 +                            __Els);
 +      _ ->
 +        decode_register_els(__TopXMLNS, __IgnoreEls, _els, Zip,
 +                            Xdata, Misc, Address, Instructions, Text, Last,
 +                            First, Password, Registered, Date, Phone, State,
 +                            Name, Username, Remove, Key, City, Nick, Url,
 +                            Email, __Els)
 +    end;
 +decode_register_els(__TopXMLNS, __IgnoreEls,
 +                  [{xmlel, <<"first">>, _attrs, _} = _el | _els], Zip,
 +                  Xdata, Misc, Address, Instructions, Text, Last, First,
 +                  Password, Registered, Date, Phone, State, Name,
 +                  Username, Remove, Key, City, Nick, Url, Email, __Els) ->
 +    case get_attr(<<"xmlns">>, _attrs) of
 +      <<"">> when __TopXMLNS == <<"jabber:iq:register">> ->
 +        decode_register_els(__TopXMLNS, __IgnoreEls, _els, Zip,
 +                            Xdata, Misc, Address, Instructions, Text, Last,
 +                            decode_register_first(__TopXMLNS, __IgnoreEls,
 +                                                  _el),
 +                            Password, Registered, Date, Phone, State, Name,
 +                            Username, Remove, Key, City, Nick, Url, Email,
 +                            __Els);
 +      <<"jabber:iq:register">> ->
 +        decode_register_els(__TopXMLNS, __IgnoreEls, _els, Zip,
 +                            Xdata, Misc, Address, Instructions, Text, Last,
 +                            decode_register_first(<<"jabber:iq:register">>,
 +                                                  __IgnoreEls, _el),
 +                            Password, Registered, Date, Phone, State, Name,
 +                            Username, Remove, Key, City, Nick, Url, Email,
 +                            __Els);
 +      _ ->
 +        decode_register_els(__TopXMLNS, __IgnoreEls, _els, Zip,
 +                            Xdata, Misc, Address, Instructions, Text, Last,
 +                            First, Password, Registered, Date, Phone, State,
 +                            Name, Username, Remove, Key, City, Nick, Url,
 +                            Email, __Els)
 +    end;
 +decode_register_els(__TopXMLNS, __IgnoreEls,
 +                  [{xmlel, <<"last">>, _attrs, _} = _el | _els], Zip,
 +                  Xdata, Misc, Address, Instructions, Text, Last, First,
 +                  Password, Registered, Date, Phone, State, Name,
 +                  Username, Remove, Key, City, Nick, Url, Email, __Els) ->
 +    case get_attr(<<"xmlns">>, _attrs) of
 +      <<"">> when __TopXMLNS == <<"jabber:iq:register">> ->
 +        decode_register_els(__TopXMLNS, __IgnoreEls, _els, Zip,
 +                            Xdata, Misc, Address, Instructions, Text,
 +                            decode_register_last(__TopXMLNS, __IgnoreEls,
 +                                                 _el),
 +                            First, Password, Registered, Date, Phone, State,
 +                            Name, Username, Remove, Key, City, Nick, Url,
 +                            Email, __Els);
 +      <<"jabber:iq:register">> ->
 +        decode_register_els(__TopXMLNS, __IgnoreEls, _els, Zip,
 +                            Xdata, Misc, Address, Instructions, Text,
 +                            decode_register_last(<<"jabber:iq:register">>,
 +                                                 __IgnoreEls, _el),
 +                            First, Password, Registered, Date, Phone, State,
 +                            Name, Username, Remove, Key, City, Nick, Url,
 +                            Email, __Els);
 +      _ ->
 +        decode_register_els(__TopXMLNS, __IgnoreEls, _els, Zip,
 +                            Xdata, Misc, Address, Instructions, Text, Last,
 +                            First, Password, Registered, Date, Phone, State,
 +                            Name, Username, Remove, Key, City, Nick, Url,
 +                            Email, __Els)
 +    end;
 +decode_register_els(__TopXMLNS, __IgnoreEls,
 +                  [{xmlel, <<"email">>, _attrs, _} = _el | _els], Zip,
 +                  Xdata, Misc, Address, Instructions, Text, Last, First,
 +                  Password, Registered, Date, Phone, State, Name,
 +                  Username, Remove, Key, City, Nick, Url, Email, __Els) ->
 +    case get_attr(<<"xmlns">>, _attrs) of
 +      <<"">> when __TopXMLNS == <<"jabber:iq:register">> ->
 +        decode_register_els(__TopXMLNS, __IgnoreEls, _els, Zip,
 +                            Xdata, Misc, Address, Instructions, Text, Last,
 +                            First, Password, Registered, Date, Phone, State,
 +                            Name, Username, Remove, Key, City, Nick, Url,
 +                            decode_register_email(__TopXMLNS, __IgnoreEls,
 +                                                  _el),
 +                            __Els);
 +      <<"jabber:iq:register">> ->
 +        decode_register_els(__TopXMLNS, __IgnoreEls, _els, Zip,
 +                            Xdata, Misc, Address, Instructions, Text, Last,
 +                            First, Password, Registered, Date, Phone, State,
 +                            Name, Username, Remove, Key, City, Nick, Url,
 +                            decode_register_email(<<"jabber:iq:register">>,
 +                                                  __IgnoreEls, _el),
 +                            __Els);
 +      _ ->
 +        decode_register_els(__TopXMLNS, __IgnoreEls, _els, Zip,
 +                            Xdata, Misc, Address, Instructions, Text, Last,
 +                            First, Password, Registered, Date, Phone, State,
 +                            Name, Username, Remove, Key, City, Nick, Url,
 +                            Email, __Els)
 +    end;
 +decode_register_els(__TopXMLNS, __IgnoreEls,
 +                  [{xmlel, <<"address">>, _attrs, _} = _el | _els], Zip,
 +                  Xdata, Misc, Address, Instructions, Text, Last, First,
 +                  Password, Registered, Date, Phone, State, Name,
 +                  Username, Remove, Key, City, Nick, Url, Email, __Els) ->
 +    case get_attr(<<"xmlns">>, _attrs) of
 +      <<"">> when __TopXMLNS == <<"jabber:iq:register">> ->
 +        decode_register_els(__TopXMLNS, __IgnoreEls, _els, Zip,
 +                            Xdata, Misc,
 +                            decode_register_address(__TopXMLNS, __IgnoreEls,
 +                                                    _el),
 +                            Instructions, Text, Last, First, Password,
 +                            Registered, Date, Phone, State, Name, Username,
 +                            Remove, Key, City, Nick, Url, Email, __Els);
 +      <<"jabber:iq:register">> ->
 +        decode_register_els(__TopXMLNS, __IgnoreEls, _els, Zip,
 +                            Xdata, Misc,
 +                            decode_register_address(<<"jabber:iq:register">>,
 +                                                    __IgnoreEls, _el),
 +                            Instructions, Text, Last, First, Password,
 +                            Registered, Date, Phone, State, Name, Username,
 +                            Remove, Key, City, Nick, Url, Email, __Els);
 +      _ ->
 +        decode_register_els(__TopXMLNS, __IgnoreEls, _els, Zip,
 +                            Xdata, Misc, Address, Instructions, Text, Last,
 +                            First, Password, Registered, Date, Phone, State,
 +                            Name, Username, Remove, Key, City, Nick, Url,
 +                            Email, __Els)
 +    end;
 +decode_register_els(__TopXMLNS, __IgnoreEls,
 +                  [{xmlel, <<"city">>, _attrs, _} = _el | _els], Zip,
 +                  Xdata, Misc, Address, Instructions, Text, Last, First,
 +                  Password, Registered, Date, Phone, State, Name,
 +                  Username, Remove, Key, City, Nick, Url, Email, __Els) ->
 +    case get_attr(<<"xmlns">>, _attrs) of
 +      <<"">> when __TopXMLNS == <<"jabber:iq:register">> ->
 +        decode_register_els(__TopXMLNS, __IgnoreEls, _els, Zip,
 +                            Xdata, Misc, Address, Instructions, Text, Last,
 +                            First, Password, Registered, Date, Phone, State,
 +                            Name, Username, Remove, Key,
 +                            decode_register_city(__TopXMLNS, __IgnoreEls,
 +                                                 _el),
 +                            Nick, Url, Email, __Els);
 +      <<"jabber:iq:register">> ->
 +        decode_register_els(__TopXMLNS, __IgnoreEls, _els, Zip,
 +                            Xdata, Misc, Address, Instructions, Text, Last,
 +                            First, Password, Registered, Date, Phone, State,
 +                            Name, Username, Remove, Key,
 +                            decode_register_city(<<"jabber:iq:register">>,
 +                                                 __IgnoreEls, _el),
 +                            Nick, Url, Email, __Els);
 +      _ ->
 +        decode_register_els(__TopXMLNS, __IgnoreEls, _els, Zip,
 +                            Xdata, Misc, Address, Instructions, Text, Last,
 +                            First, Password, Registered, Date, Phone, State,
 +                            Name, Username, Remove, Key, City, Nick, Url,
 +                            Email, __Els)
 +    end;
 +decode_register_els(__TopXMLNS, __IgnoreEls,
 +                  [{xmlel, <<"state">>, _attrs, _} = _el | _els], Zip,
 +                  Xdata, Misc, Address, Instructions, Text, Last, First,
 +                  Password, Registered, Date, Phone, State, Name,
 +                  Username, Remove, Key, City, Nick, Url, Email, __Els) ->
 +    case get_attr(<<"xmlns">>, _attrs) of
 +      <<"">> when __TopXMLNS == <<"jabber:iq:register">> ->
 +        decode_register_els(__TopXMLNS, __IgnoreEls, _els, Zip,
 +                            Xdata, Misc, Address, Instructions, Text, Last,
 +                            First, Password, Registered, Date, Phone,
 +                            decode_register_state(__TopXMLNS, __IgnoreEls,
 +                                                  _el),
 +                            Name, Username, Remove, Key, City, Nick, Url,
 +                            Email, __Els);
 +      <<"jabber:iq:register">> ->
 +        decode_register_els(__TopXMLNS, __IgnoreEls, _els, Zip,
 +                            Xdata, Misc, Address, Instructions, Text, Last,
 +                            First, Password, Registered, Date, Phone,
 +                            decode_register_state(<<"jabber:iq:register">>,
 +                                                  __IgnoreEls, _el),
 +                            Name, Username, Remove, Key, City, Nick, Url,
 +                            Email, __Els);
 +      _ ->
 +        decode_register_els(__TopXMLNS, __IgnoreEls, _els, Zip,
 +                            Xdata, Misc, Address, Instructions, Text, Last,
 +                            First, Password, Registered, Date, Phone, State,
 +                            Name, Username, Remove, Key, City, Nick, Url,
 +                            Email, __Els)
 +    end;
 +decode_register_els(__TopXMLNS, __IgnoreEls,
 +                  [{xmlel, <<"zip">>, _attrs, _} = _el | _els], Zip,
 +                  Xdata, Misc, Address, Instructions, Text, Last, First,
 +                  Password, Registered, Date, Phone, State, Name,
 +                  Username, Remove, Key, City, Nick, Url, Email, __Els) ->
 +    case get_attr(<<"xmlns">>, _attrs) of
 +      <<"">> when __TopXMLNS == <<"jabber:iq:register">> ->
 +        decode_register_els(__TopXMLNS, __IgnoreEls, _els,
 +                            decode_register_zip(__TopXMLNS, __IgnoreEls, _el),
 +                            Xdata, Misc, Address, Instructions, Text, Last,
 +                            First, Password, Registered, Date, Phone, State,
 +                            Name, Username, Remove, Key, City, Nick, Url,
 +                            Email, __Els);
 +      <<"jabber:iq:register">> ->
 +        decode_register_els(__TopXMLNS, __IgnoreEls, _els,
 +                            decode_register_zip(<<"jabber:iq:register">>,
 +                                                __IgnoreEls, _el),
 +                            Xdata, Misc, Address, Instructions, Text, Last,
 +                            First, Password, Registered, Date, Phone, State,
 +                            Name, Username, Remove, Key, City, Nick, Url,
 +                            Email, __Els);
 +      _ ->
 +        decode_register_els(__TopXMLNS, __IgnoreEls, _els, Zip,
 +                            Xdata, Misc, Address, Instructions, Text, Last,
 +                            First, Password, Registered, Date, Phone, State,
 +                            Name, Username, Remove, Key, City, Nick, Url,
 +                            Email, __Els)
 +    end;
 +decode_register_els(__TopXMLNS, __IgnoreEls,
 +                  [{xmlel, <<"phone">>, _attrs, _} = _el | _els], Zip,
 +                  Xdata, Misc, Address, Instructions, Text, Last, First,
 +                  Password, Registered, Date, Phone, State, Name,
 +                  Username, Remove, Key, City, Nick, Url, Email, __Els) ->
 +    case get_attr(<<"xmlns">>, _attrs) of
 +      <<"">> when __TopXMLNS == <<"jabber:iq:register">> ->
 +        decode_register_els(__TopXMLNS, __IgnoreEls, _els, Zip,
 +                            Xdata, Misc, Address, Instructions, Text, Last,
 +                            First, Password, Registered, Date,
 +                            decode_register_phone(__TopXMLNS, __IgnoreEls,
 +                                                  _el),
 +                            State, Name, Username, Remove, Key, City, Nick,
 +                            Url, Email, __Els);
 +      <<"jabber:iq:register">> ->
 +        decode_register_els(__TopXMLNS, __IgnoreEls, _els, Zip,
 +                            Xdata, Misc, Address, Instructions, Text, Last,
 +                            First, Password, Registered, Date,
 +                            decode_register_phone(<<"jabber:iq:register">>,
 +                                                  __IgnoreEls, _el),
 +                            State, Name, Username, Remove, Key, City, Nick,
 +                            Url, Email, __Els);
 +      _ ->
 +        decode_register_els(__TopXMLNS, __IgnoreEls, _els, Zip,
 +                            Xdata, Misc, Address, Instructions, Text, Last,
 +                            First, Password, Registered, Date, Phone, State,
 +                            Name, Username, Remove, Key, City, Nick, Url,
 +                            Email, __Els)
 +    end;
 +decode_register_els(__TopXMLNS, __IgnoreEls,
 +                  [{xmlel, <<"url">>, _attrs, _} = _el | _els], Zip,
 +                  Xdata, Misc, Address, Instructions, Text, Last, First,
 +                  Password, Registered, Date, Phone, State, Name,
 +                  Username, Remove, Key, City, Nick, Url, Email, __Els) ->
 +    case get_attr(<<"xmlns">>, _attrs) of
 +      <<"">> when __TopXMLNS == <<"jabber:iq:register">> ->
 +        decode_register_els(__TopXMLNS, __IgnoreEls, _els, Zip,
 +                            Xdata, Misc, Address, Instructions, Text, Last,
 +                            First, Password, Registered, Date, Phone, State,
 +                            Name, Username, Remove, Key, City, Nick,
 +                            decode_register_url(__TopXMLNS, __IgnoreEls, _el),
 +                            Email, __Els);
 +      <<"jabber:iq:register">> ->
 +        decode_register_els(__TopXMLNS, __IgnoreEls, _els, Zip,
 +                            Xdata, Misc, Address, Instructions, Text, Last,
 +                            First, Password, Registered, Date, Phone, State,
 +                            Name, Username, Remove, Key, City, Nick,
 +                            decode_register_url(<<"jabber:iq:register">>,
 +                                                __IgnoreEls, _el),
 +                            Email, __Els);
 +      _ ->
 +        decode_register_els(__TopXMLNS, __IgnoreEls, _els, Zip,
 +                            Xdata, Misc, Address, Instructions, Text, Last,
 +                            First, Password, Registered, Date, Phone, State,
 +                            Name, Username, Remove, Key, City, Nick, Url,
 +                            Email, __Els)
 +    end;
 +decode_register_els(__TopXMLNS, __IgnoreEls,
 +                  [{xmlel, <<"date">>, _attrs, _} = _el | _els], Zip,
 +                  Xdata, Misc, Address, Instructions, Text, Last, First,
 +                  Password, Registered, Date, Phone, State, Name,
 +                  Username, Remove, Key, City, Nick, Url, Email, __Els) ->
 +    case get_attr(<<"xmlns">>, _attrs) of
 +      <<"">> when __TopXMLNS == <<"jabber:iq:register">> ->
 +        decode_register_els(__TopXMLNS, __IgnoreEls, _els, Zip,
 +                            Xdata, Misc, Address, Instructions, Text, Last,
 +                            First, Password, Registered,
 +                            decode_register_date(__TopXMLNS, __IgnoreEls,
 +                                                 _el),
 +                            Phone, State, Name, Username, Remove, Key, City,
 +                            Nick, Url, Email, __Els);
 +      <<"jabber:iq:register">> ->
 +        decode_register_els(__TopXMLNS, __IgnoreEls, _els, Zip,
 +                            Xdata, Misc, Address, Instructions, Text, Last,
 +                            First, Password, Registered,
 +                            decode_register_date(<<"jabber:iq:register">>,
 +                                                 __IgnoreEls, _el),
 +                            Phone, State, Name, Username, Remove, Key, City,
 +                            Nick, Url, Email, __Els);
 +      _ ->
 +        decode_register_els(__TopXMLNS, __IgnoreEls, _els, Zip,
 +                            Xdata, Misc, Address, Instructions, Text, Last,
 +                            First, Password, Registered, Date, Phone, State,
 +                            Name, Username, Remove, Key, City, Nick, Url,
 +                            Email, __Els)
 +    end;
 +decode_register_els(__TopXMLNS, __IgnoreEls,
 +                  [{xmlel, <<"misc">>, _attrs, _} = _el | _els], Zip,
 +                  Xdata, Misc, Address, Instructions, Text, Last, First,
 +                  Password, Registered, Date, Phone, State, Name,
 +                  Username, Remove, Key, City, Nick, Url, Email, __Els) ->
 +    case get_attr(<<"xmlns">>, _attrs) of
 +      <<"">> when __TopXMLNS == <<"jabber:iq:register">> ->
 +        decode_register_els(__TopXMLNS, __IgnoreEls, _els, Zip,
 +                            Xdata,
 +                            decode_register_misc(__TopXMLNS, __IgnoreEls,
 +                                                 _el),
 +                            Address, Instructions, Text, Last, First,
 +                            Password, Registered, Date, Phone, State, Name,
 +                            Username, Remove, Key, City, Nick, Url, Email,
 +                            __Els);
 +      <<"jabber:iq:register">> ->
 +        decode_register_els(__TopXMLNS, __IgnoreEls, _els, Zip,
 +                            Xdata,
 +                            decode_register_misc(<<"jabber:iq:register">>,
 +                                                 __IgnoreEls, _el),
 +                            Address, Instructions, Text, Last, First,
 +                            Password, Registered, Date, Phone, State, Name,
 +                            Username, Remove, Key, City, Nick, Url, Email,
 +                            __Els);
 +      _ ->
 +        decode_register_els(__TopXMLNS, __IgnoreEls, _els, Zip,
 +                            Xdata, Misc, Address, Instructions, Text, Last,
 +                            First, Password, Registered, Date, Phone, State,
 +                            Name, Username, Remove, Key, City, Nick, Url,
 +                            Email, __Els)
 +    end;
 +decode_register_els(__TopXMLNS, __IgnoreEls,
 +                  [{xmlel, <<"text">>, _attrs, _} = _el | _els], Zip,
 +                  Xdata, Misc, Address, Instructions, Text, Last, First,
 +                  Password, Registered, Date, Phone, State, Name,
 +                  Username, Remove, Key, City, Nick, Url, Email, __Els) ->
 +    case get_attr(<<"xmlns">>, _attrs) of
 +      <<"">> when __TopXMLNS == <<"jabber:iq:register">> ->
 +        decode_register_els(__TopXMLNS, __IgnoreEls, _els, Zip,
 +                            Xdata, Misc, Address, Instructions,
 +                            decode_register_text(__TopXMLNS, __IgnoreEls,
 +                                                 _el),
 +                            Last, First, Password, Registered, Date, Phone,
 +                            State, Name, Username, Remove, Key, City, Nick,
 +                            Url, Email, __Els);
 +      <<"jabber:iq:register">> ->
 +        decode_register_els(__TopXMLNS, __IgnoreEls, _els, Zip,
 +                            Xdata, Misc, Address, Instructions,
 +                            decode_register_text(<<"jabber:iq:register">>,
 +                                                 __IgnoreEls, _el),
 +                            Last, First, Password, Registered, Date, Phone,
 +                            State, Name, Username, Remove, Key, City, Nick,
 +                            Url, Email, __Els);
 +      _ ->
 +        decode_register_els(__TopXMLNS, __IgnoreEls, _els, Zip,
 +                            Xdata, Misc, Address, Instructions, Text, Last,
 +                            First, Password, Registered, Date, Phone, State,
 +                            Name, Username, Remove, Key, City, Nick, Url,
 +                            Email, __Els)
 +    end;
 +decode_register_els(__TopXMLNS, __IgnoreEls,
 +                  [{xmlel, <<"key">>, _attrs, _} = _el | _els], Zip,
 +                  Xdata, Misc, Address, Instructions, Text, Last, First,
 +                  Password, Registered, Date, Phone, State, Name,
 +                  Username, Remove, Key, City, Nick, Url, Email, __Els) ->
 +    case get_attr(<<"xmlns">>, _attrs) of
 +      <<"">> when __TopXMLNS == <<"jabber:iq:register">> ->
 +        decode_register_els(__TopXMLNS, __IgnoreEls, _els, Zip,
 +                            Xdata, Misc, Address, Instructions, Text, Last,
 +                            First, Password, Registered, Date, Phone, State,
 +                            Name, Username, Remove,
 +                            decode_register_key(__TopXMLNS, __IgnoreEls, _el),
 +                            City, Nick, Url, Email, __Els);
 +      <<"jabber:iq:register">> ->
 +        decode_register_els(__TopXMLNS, __IgnoreEls, _els, Zip,
 +                            Xdata, Misc, Address, Instructions, Text, Last,
 +                            First, Password, Registered, Date, Phone, State,
 +                            Name, Username, Remove,
 +                            decode_register_key(<<"jabber:iq:register">>,
 +                                                __IgnoreEls, _el),
 +                            City, Nick, Url, Email, __Els);
 +      _ ->
 +        decode_register_els(__TopXMLNS, __IgnoreEls, _els, Zip,
 +                            Xdata, Misc, Address, Instructions, Text, Last,
 +                            First, Password, Registered, Date, Phone, State,
 +                            Name, Username, Remove, Key, City, Nick, Url,
 +                            Email, __Els)
 +    end;
 +decode_register_els(__TopXMLNS, __IgnoreEls,
 +                  [{xmlel, _, _, _} = _el | _els], Zip, Xdata, Misc,
 +                  Address, Instructions, Text, Last, First, Password,
 +                  Registered, Date, Phone, State, Name, Username, Remove,
 +                  Key, City, Nick, Url, Email, __Els) ->
 +    if __IgnoreEls ->
 +         decode_register_els(__TopXMLNS, __IgnoreEls, _els, Zip,
 +                             Xdata, Misc, Address, Instructions, Text, Last,
 +                             First, Password, Registered, Date, Phone, State,
 +                             Name, Username, Remove, Key, City, Nick, Url,
 +                             Email, [_el | __Els]);
 +       true ->
 +         case is_known_tag(_el, __TopXMLNS) of
 +           true ->
 +               decode_register_els(__TopXMLNS, __IgnoreEls, _els, Zip,
 +                                   Xdata, Misc, Address, Instructions, Text,
 +                                   Last, First, Password, Registered, Date,
 +                                   Phone, State, Name, Username, Remove, Key,
 +                                   City, Nick, Url, Email,
 +                                   [decode(_el, __TopXMLNS, []) | __Els]);
 +           false ->
 +               decode_register_els(__TopXMLNS, __IgnoreEls, _els, Zip,
 +                                   Xdata, Misc, Address, Instructions, Text,
 +                                   Last, First, Password, Registered, Date,
 +                                   Phone, State, Name, Username, Remove, Key,
 +                                   City, Nick, Url, Email, __Els)
 +         end
 +    end;
 +decode_register_els(__TopXMLNS, __IgnoreEls, [_ | _els],
 +                  Zip, Xdata, Misc, Address, Instructions, Text, Last,
 +                  First, Password, Registered, Date, Phone, State, Name,
 +                  Username, Remove, Key, City, Nick, Url, Email, __Els) ->
 +    decode_register_els(__TopXMLNS, __IgnoreEls, _els, Zip,
 +                      Xdata, Misc, Address, Instructions, Text, Last, First,
 +                      Password, Registered, Date, Phone, State, Name,
 +                      Username, Remove, Key, City, Nick, Url, Email, __Els).
 +
 +encode_register({register, Registered, Remove,
 +               Instructions, Username, Nick, Password, Name, First,
 +               Last, Email, Address, City, State, Zip, Phone, Url,
 +               Date, Misc, Text, Key, Xdata, __Els},
 +              __TopXMLNS) ->
 +    __NewTopXMLNS =
 +      choose_top_xmlns(<<"jabber:iq:register">>, [],
 +                       __TopXMLNS),
 +    _els = [encode(_el, __NewTopXMLNS) || _el <- __Els] ++
 +           lists:reverse('encode_register_$zip'(Zip, __NewTopXMLNS,
 +                                                'encode_register_$xdata'(Xdata,
 +                                                                         __NewTopXMLNS,
 +                                                                         'encode_register_$misc'(Misc,
 +                                                                                                 __NewTopXMLNS,
 +                                                                                                 'encode_register_$address'(Address,
 +                                                                                                                            __NewTopXMLNS,
 +                                                                                                                            'encode_register_$instructions'(Instructions,
 +                                                                                                                                                            __NewTopXMLNS,
 +                                                                                                                                                            'encode_register_$text'(Text,
 +                                                                                                                                                                                    __NewTopXMLNS,
 +                                                                                                                                                                                    'encode_register_$last'(Last,
 +                                                                                                                                                                                                            __NewTopXMLNS,
 +                                                                                                                                                                                                            'encode_register_$first'(First,
 +                                                                                                                                                                                                                                     __NewTopXMLNS,
 +                                                                                                                                                                                                                                     'encode_register_$password'(Password,
 +                                                                                                                                                                                                                                                                 __NewTopXMLNS,
 +                                                                                                                                                                                                                                                                 'encode_register_$registered'(Registered,
 +                                                                                                                                                                                                                                                                                               __NewTopXMLNS,
 +                                                                                                                                                                                                                                                                                               'encode_register_$date'(Date,
 +                                                                                                                                                                                                                                                                                                                       __NewTopXMLNS,
 +                                                                                                                                                                                                                                                                                                                       'encode_register_$phone'(Phone,
 +                                                                                                                                                                                                                                                                                                                                                __NewTopXMLNS,
 +                                                                                                                                                                                                                                                                                                                                                'encode_register_$state'(State,
 +                                                                                                                                                                                                                                                                                                                                                                         __NewTopXMLNS,
 +                                                                                                                                                                                                                                                                                                                                                                         'encode_register_$name'(Name,
 +                                                                                                                                                                                                                                                                                                                                                                                                 __NewTopXMLNS,
 +                                                                                                                                                                                                                                                                                                                                                                                                 'encode_register_$username'(Username,
 +                                                                                                                                                                                                                                                                                                                                                                                                                             __NewTopXMLNS,
 +                                                                                                                                                                                                                                                                                                                                                                                                                             'encode_register_$remove'(Remove,
 +                                                                                                                                                                                                                                                                                                                                                                                                                                                       __NewTopXMLNS,
 +                                                                                                                                                                                                                                                                                                                                                                                                                                                       'encode_register_$key'(Key,
 +                                                                                                                                                                                                                                                                                                                                                                                                                                                                              __NewTopXMLNS,
 +                                                                                                                                                                                                                                                                                                                                                                                                                                                                              'encode_register_$city'(City,
 +                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                      __NewTopXMLNS,
 +                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                      'encode_register_$nick'(Nick,
 +                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                              __NewTopXMLNS,
 +                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                              'encode_register_$url'(Url,
 +                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                     __NewTopXMLNS,
 +                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                     'encode_register_$email'(Email,
 +                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                              __NewTopXMLNS,
 +                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                              [])))))))))))))))))))))),
 +    _attrs = enc_xmlns_attrs(__NewTopXMLNS, __TopXMLNS),
 +    {xmlel, <<"query">>, _attrs, _els}.
 +
 +'encode_register_$zip'(undefined, __TopXMLNS, _acc) ->
 +    _acc;
 +'encode_register_$zip'(Zip, __TopXMLNS, _acc) ->
 +    [encode_register_zip(Zip, __TopXMLNS) | _acc].
 +
 +'encode_register_$xdata'(undefined, __TopXMLNS, _acc) ->
 +    _acc;
 +'encode_register_$xdata'(Xdata, __TopXMLNS, _acc) ->
 +    [encode_xdata(Xdata, __TopXMLNS) | _acc].
 +
 +'encode_register_$misc'(undefined, __TopXMLNS, _acc) ->
 +    _acc;
 +'encode_register_$misc'(Misc, __TopXMLNS, _acc) ->
 +    [encode_register_misc(Misc, __TopXMLNS) | _acc].
 +
 +'encode_register_$address'(undefined, __TopXMLNS,
 +                         _acc) ->
 +    _acc;
 +'encode_register_$address'(Address, __TopXMLNS, _acc) ->
 +    [encode_register_address(Address, __TopXMLNS) | _acc].
 +
 +'encode_register_$instructions'(undefined, __TopXMLNS,
 +                              _acc) ->
 +    _acc;
 +'encode_register_$instructions'(Instructions,
 +                              __TopXMLNS, _acc) ->
 +    [encode_register_instructions(Instructions, __TopXMLNS)
 +     | _acc].
 +
 +'encode_register_$text'(undefined, __TopXMLNS, _acc) ->
 +    _acc;
 +'encode_register_$text'(Text, __TopXMLNS, _acc) ->
 +    [encode_register_text(Text, __TopXMLNS) | _acc].
 +
 +'encode_register_$last'(undefined, __TopXMLNS, _acc) ->
 +    _acc;
 +'encode_register_$last'(Last, __TopXMLNS, _acc) ->
 +    [encode_register_last(Last, __TopXMLNS) | _acc].
 +
 +'encode_register_$first'(undefined, __TopXMLNS, _acc) ->
 +    _acc;
 +'encode_register_$first'(First, __TopXMLNS, _acc) ->
 +    [encode_register_first(First, __TopXMLNS) | _acc].
 +
 +'encode_register_$password'(undefined, __TopXMLNS,
 +                          _acc) ->
 +    _acc;
 +'encode_register_$password'(Password, __TopXMLNS,
 +                          _acc) ->
 +    [encode_register_password(Password, __TopXMLNS) | _acc].
 +
 +'encode_register_$registered'(false, __TopXMLNS,
 +                            _acc) ->
 +    _acc;
 +'encode_register_$registered'(Registered, __TopXMLNS,
 +                            _acc) ->
 +    [encode_register_registered(Registered, __TopXMLNS)
 +     | _acc].
 +
 +'encode_register_$date'(undefined, __TopXMLNS, _acc) ->
 +    _acc;
 +'encode_register_$date'(Date, __TopXMLNS, _acc) ->
 +    [encode_register_date(Date, __TopXMLNS) | _acc].
 +
 +'encode_register_$phone'(undefined, __TopXMLNS, _acc) ->
 +    _acc;
 +'encode_register_$phone'(Phone, __TopXMLNS, _acc) ->
 +    [encode_register_phone(Phone, __TopXMLNS) | _acc].
 +
 +'encode_register_$state'(undefined, __TopXMLNS, _acc) ->
 +    _acc;
 +'encode_register_$state'(State, __TopXMLNS, _acc) ->
 +    [encode_register_state(State, __TopXMLNS) | _acc].
 +
 +'encode_register_$name'(undefined, __TopXMLNS, _acc) ->
 +    _acc;
 +'encode_register_$name'(Name, __TopXMLNS, _acc) ->
 +    [encode_register_name(Name, __TopXMLNS) | _acc].
 +
 +'encode_register_$username'(undefined, __TopXMLNS,
 +                          _acc) ->
 +    _acc;
 +'encode_register_$username'(Username, __TopXMLNS,
 +                          _acc) ->
 +    [encode_register_username(Username, __TopXMLNS) | _acc].
 +
 +'encode_register_$remove'(false, __TopXMLNS, _acc) ->
 +    _acc;
 +'encode_register_$remove'(Remove, __TopXMLNS, _acc) ->
 +    [encode_register_remove(Remove, __TopXMLNS) | _acc].
 +
 +'encode_register_$key'(undefined, __TopXMLNS, _acc) ->
 +    _acc;
 +'encode_register_$key'(Key, __TopXMLNS, _acc) ->
 +    [encode_register_key(Key, __TopXMLNS) | _acc].
 +
 +'encode_register_$city'(undefined, __TopXMLNS, _acc) ->
 +    _acc;
 +'encode_register_$city'(City, __TopXMLNS, _acc) ->
 +    [encode_register_city(City, __TopXMLNS) | _acc].
 +
 +'encode_register_$nick'(undefined, __TopXMLNS, _acc) ->
 +    _acc;
 +'encode_register_$nick'(Nick, __TopXMLNS, _acc) ->
 +    [encode_register_nick(Nick, __TopXMLNS) | _acc].
 +
 +'encode_register_$url'(undefined, __TopXMLNS, _acc) ->
 +    _acc;
 +'encode_register_$url'(Url, __TopXMLNS, _acc) ->
 +    [encode_register_url(Url, __TopXMLNS) | _acc].
 +
 +'encode_register_$email'(undefined, __TopXMLNS, _acc) ->
 +    _acc;
 +'encode_register_$email'(Email, __TopXMLNS, _acc) ->
 +    [encode_register_email(Email, __TopXMLNS) | _acc].
 +
 +decode_register_key(__TopXMLNS, __IgnoreEls,
 +                  {xmlel, <<"key">>, _attrs, _els}) ->
 +    Cdata = decode_register_key_els(__TopXMLNS, __IgnoreEls,
 +                                  _els, <<>>),
 +    Cdata.
 +
 +decode_register_key_els(__TopXMLNS, __IgnoreEls, [],
 +                      Cdata) ->
 +    decode_register_key_cdata(__TopXMLNS, Cdata);
 +decode_register_key_els(__TopXMLNS, __IgnoreEls,
 +                      [{xmlcdata, _data} | _els], Cdata) ->
 +    decode_register_key_els(__TopXMLNS, __IgnoreEls, _els,
 +                          <<Cdata/binary, _data/binary>>);
 +decode_register_key_els(__TopXMLNS, __IgnoreEls,
 +                      [_ | _els], Cdata) ->
 +    decode_register_key_els(__TopXMLNS, __IgnoreEls, _els,
 +                          Cdata).
 +
 +encode_register_key(Cdata, __TopXMLNS) ->
 +    __NewTopXMLNS =
 +      choose_top_xmlns(<<"jabber:iq:register">>, [],
 +                       __TopXMLNS),
 +    _els = encode_register_key_cdata(Cdata, []),
 +    _attrs = enc_xmlns_attrs(__NewTopXMLNS, __TopXMLNS),
 +    {xmlel, <<"key">>, _attrs, _els}.
 +
 +decode_register_key_cdata(__TopXMLNS, <<>>) -> <<>>;
 +decode_register_key_cdata(__TopXMLNS, _val) -> _val.
 +
 +encode_register_key_cdata(<<>>, _acc) -> _acc;
 +encode_register_key_cdata(_val, _acc) ->
 +    [{xmlcdata, _val} | _acc].
 +
 +decode_register_text(__TopXMLNS, __IgnoreEls,
 +                   {xmlel, <<"text">>, _attrs, _els}) ->
 +    Cdata = decode_register_text_els(__TopXMLNS,
 +                                   __IgnoreEls, _els, <<>>),
 +    Cdata.
 +
 +decode_register_text_els(__TopXMLNS, __IgnoreEls, [],
 +                       Cdata) ->
 +    decode_register_text_cdata(__TopXMLNS, Cdata);
 +decode_register_text_els(__TopXMLNS, __IgnoreEls,
 +                       [{xmlcdata, _data} | _els], Cdata) ->
 +    decode_register_text_els(__TopXMLNS, __IgnoreEls, _els,
 +                           <<Cdata/binary, _data/binary>>);
 +decode_register_text_els(__TopXMLNS, __IgnoreEls,
 +                       [_ | _els], Cdata) ->
 +    decode_register_text_els(__TopXMLNS, __IgnoreEls, _els,
 +                           Cdata).
 +
 +encode_register_text(Cdata, __TopXMLNS) ->
 +    __NewTopXMLNS =
 +      choose_top_xmlns(<<"jabber:iq:register">>, [],
 +                       __TopXMLNS),
 +    _els = encode_register_text_cdata(Cdata, []),
 +    _attrs = enc_xmlns_attrs(__NewTopXMLNS, __TopXMLNS),
 +    {xmlel, <<"text">>, _attrs, _els}.
 +
 +decode_register_text_cdata(__TopXMLNS, <<>>) -> <<>>;
 +decode_register_text_cdata(__TopXMLNS, _val) -> _val.
 +
 +encode_register_text_cdata(<<>>, _acc) -> _acc;
 +encode_register_text_cdata(_val, _acc) ->
 +    [{xmlcdata, _val} | _acc].
 +
 +decode_register_misc(__TopXMLNS, __IgnoreEls,
 +                   {xmlel, <<"misc">>, _attrs, _els}) ->
 +    Cdata = decode_register_misc_els(__TopXMLNS,
 +                                   __IgnoreEls, _els, <<>>),
 +    Cdata.
 +
 +decode_register_misc_els(__TopXMLNS, __IgnoreEls, [],
 +                       Cdata) ->
 +    decode_register_misc_cdata(__TopXMLNS, Cdata);
 +decode_register_misc_els(__TopXMLNS, __IgnoreEls,
 +                       [{xmlcdata, _data} | _els], Cdata) ->
 +    decode_register_misc_els(__TopXMLNS, __IgnoreEls, _els,
 +                           <<Cdata/binary, _data/binary>>);
 +decode_register_misc_els(__TopXMLNS, __IgnoreEls,
 +                       [_ | _els], Cdata) ->
 +    decode_register_misc_els(__TopXMLNS, __IgnoreEls, _els,
 +                           Cdata).
 +
 +encode_register_misc(Cdata, __TopXMLNS) ->
 +    __NewTopXMLNS =
 +      choose_top_xmlns(<<"jabber:iq:register">>, [],
 +                       __TopXMLNS),
 +    _els = encode_register_misc_cdata(Cdata, []),
 +    _attrs = enc_xmlns_attrs(__NewTopXMLNS, __TopXMLNS),
 +    {xmlel, <<"misc">>, _attrs, _els}.
 +
 +decode_register_misc_cdata(__TopXMLNS, <<>>) -> <<>>;
 +decode_register_misc_cdata(__TopXMLNS, _val) -> _val.
 +
 +encode_register_misc_cdata(<<>>, _acc) -> _acc;
 +encode_register_misc_cdata(_val, _acc) ->
 +    [{xmlcdata, _val} | _acc].
 +
 +decode_register_date(__TopXMLNS, __IgnoreEls,
 +                   {xmlel, <<"date">>, _attrs, _els}) ->
 +    Cdata = decode_register_date_els(__TopXMLNS,
 +                                   __IgnoreEls, _els, <<>>),
 +    Cdata.
 +
 +decode_register_date_els(__TopXMLNS, __IgnoreEls, [],
 +                       Cdata) ->
 +    decode_register_date_cdata(__TopXMLNS, Cdata);
 +decode_register_date_els(__TopXMLNS, __IgnoreEls,
 +                       [{xmlcdata, _data} | _els], Cdata) ->
 +    decode_register_date_els(__TopXMLNS, __IgnoreEls, _els,
 +                           <<Cdata/binary, _data/binary>>);
 +decode_register_date_els(__TopXMLNS, __IgnoreEls,
 +                       [_ | _els], Cdata) ->
 +    decode_register_date_els(__TopXMLNS, __IgnoreEls, _els,
 +                           Cdata).
 +
 +encode_register_date(Cdata, __TopXMLNS) ->
 +    __NewTopXMLNS =
 +      choose_top_xmlns(<<"jabber:iq:register">>, [],
 +                       __TopXMLNS),
 +    _els = encode_register_date_cdata(Cdata, []),
 +    _attrs = enc_xmlns_attrs(__NewTopXMLNS, __TopXMLNS),
 +    {xmlel, <<"date">>, _attrs, _els}.
 +
 +decode_register_date_cdata(__TopXMLNS, <<>>) -> <<>>;
 +decode_register_date_cdata(__TopXMLNS, _val) -> _val.
 +
 +encode_register_date_cdata(<<>>, _acc) -> _acc;
 +encode_register_date_cdata(_val, _acc) ->
 +    [{xmlcdata, _val} | _acc].
 +
 +decode_register_url(__TopXMLNS, __IgnoreEls,
 +                  {xmlel, <<"url">>, _attrs, _els}) ->
 +    Cdata = decode_register_url_els(__TopXMLNS, __IgnoreEls,
 +                                  _els, <<>>),
 +    Cdata.
 +
 +decode_register_url_els(__TopXMLNS, __IgnoreEls, [],
 +                      Cdata) ->
 +    decode_register_url_cdata(__TopXMLNS, Cdata);
 +decode_register_url_els(__TopXMLNS, __IgnoreEls,
 +                      [{xmlcdata, _data} | _els], Cdata) ->
 +    decode_register_url_els(__TopXMLNS, __IgnoreEls, _els,
 +                          <<Cdata/binary, _data/binary>>);
 +decode_register_url_els(__TopXMLNS, __IgnoreEls,
 +                      [_ | _els], Cdata) ->
 +    decode_register_url_els(__TopXMLNS, __IgnoreEls, _els,
 +                          Cdata).
 +
 +encode_register_url(Cdata, __TopXMLNS) ->
 +    __NewTopXMLNS =
 +      choose_top_xmlns(<<"jabber:iq:register">>, [],
 +                       __TopXMLNS),
 +    _els = encode_register_url_cdata(Cdata, []),
 +    _attrs = enc_xmlns_attrs(__NewTopXMLNS, __TopXMLNS),
 +    {xmlel, <<"url">>, _attrs, _els}.
 +
 +decode_register_url_cdata(__TopXMLNS, <<>>) -> <<>>;
 +decode_register_url_cdata(__TopXMLNS, _val) -> _val.
 +
 +encode_register_url_cdata(<<>>, _acc) -> _acc;
 +encode_register_url_cdata(_val, _acc) ->
 +    [{xmlcdata, _val} | _acc].
 +
 +decode_register_phone(__TopXMLNS, __IgnoreEls,
 +                    {xmlel, <<"phone">>, _attrs, _els}) ->
 +    Cdata = decode_register_phone_els(__TopXMLNS,
 +                                    __IgnoreEls, _els, <<>>),
 +    Cdata.
 +
 +decode_register_phone_els(__TopXMLNS, __IgnoreEls, [],
 +                        Cdata) ->
 +    decode_register_phone_cdata(__TopXMLNS, Cdata);
 +decode_register_phone_els(__TopXMLNS, __IgnoreEls,
 +                        [{xmlcdata, _data} | _els], Cdata) ->
 +    decode_register_phone_els(__TopXMLNS, __IgnoreEls, _els,
 +                            <<Cdata/binary, _data/binary>>);
 +decode_register_phone_els(__TopXMLNS, __IgnoreEls,
 +                        [_ | _els], Cdata) ->
 +    decode_register_phone_els(__TopXMLNS, __IgnoreEls, _els,
 +                            Cdata).
 +
 +encode_register_phone(Cdata, __TopXMLNS) ->
 +    __NewTopXMLNS =
 +      choose_top_xmlns(<<"jabber:iq:register">>, [],
 +                       __TopXMLNS),
 +    _els = encode_register_phone_cdata(Cdata, []),
 +    _attrs = enc_xmlns_attrs(__NewTopXMLNS, __TopXMLNS),
 +    {xmlel, <<"phone">>, _attrs, _els}.
 +
 +decode_register_phone_cdata(__TopXMLNS, <<>>) -> <<>>;
 +decode_register_phone_cdata(__TopXMLNS, _val) -> _val.
 +
 +encode_register_phone_cdata(<<>>, _acc) -> _acc;
 +encode_register_phone_cdata(_val, _acc) ->
 +    [{xmlcdata, _val} | _acc].
 +
 +decode_register_zip(__TopXMLNS, __IgnoreEls,
 +                  {xmlel, <<"zip">>, _attrs, _els}) ->
 +    Cdata = decode_register_zip_els(__TopXMLNS, __IgnoreEls,
 +                                  _els, <<>>),
 +    Cdata.
 +
 +decode_register_zip_els(__TopXMLNS, __IgnoreEls, [],
 +                      Cdata) ->
 +    decode_register_zip_cdata(__TopXMLNS, Cdata);
 +decode_register_zip_els(__TopXMLNS, __IgnoreEls,
 +                      [{xmlcdata, _data} | _els], Cdata) ->
 +    decode_register_zip_els(__TopXMLNS, __IgnoreEls, _els,
 +                          <<Cdata/binary, _data/binary>>);
 +decode_register_zip_els(__TopXMLNS, __IgnoreEls,
 +                      [_ | _els], Cdata) ->
 +    decode_register_zip_els(__TopXMLNS, __IgnoreEls, _els,
 +                          Cdata).
 +
 +encode_register_zip(Cdata, __TopXMLNS) ->
 +    __NewTopXMLNS =
 +      choose_top_xmlns(<<"jabber:iq:register">>, [],
 +                       __TopXMLNS),
 +    _els = encode_register_zip_cdata(Cdata, []),
 +    _attrs = enc_xmlns_attrs(__NewTopXMLNS, __TopXMLNS),
 +    {xmlel, <<"zip">>, _attrs, _els}.
 +
 +decode_register_zip_cdata(__TopXMLNS, <<>>) -> <<>>;
 +decode_register_zip_cdata(__TopXMLNS, _val) -> _val.
 +
 +encode_register_zip_cdata(<<>>, _acc) -> _acc;
 +encode_register_zip_cdata(_val, _acc) ->
 +    [{xmlcdata, _val} | _acc].
 +
 +decode_register_state(__TopXMLNS, __IgnoreEls,
 +                    {xmlel, <<"state">>, _attrs, _els}) ->
 +    Cdata = decode_register_state_els(__TopXMLNS,
 +                                    __IgnoreEls, _els, <<>>),
 +    Cdata.
 +
 +decode_register_state_els(__TopXMLNS, __IgnoreEls, [],
 +                        Cdata) ->
 +    decode_register_state_cdata(__TopXMLNS, Cdata);
 +decode_register_state_els(__TopXMLNS, __IgnoreEls,
 +                        [{xmlcdata, _data} | _els], Cdata) ->
 +    decode_register_state_els(__TopXMLNS, __IgnoreEls, _els,
 +                            <<Cdata/binary, _data/binary>>);
 +decode_register_state_els(__TopXMLNS, __IgnoreEls,
 +                        [_ | _els], Cdata) ->
 +    decode_register_state_els(__TopXMLNS, __IgnoreEls, _els,
 +                            Cdata).
 +
 +encode_register_state(Cdata, __TopXMLNS) ->
 +    __NewTopXMLNS =
 +      choose_top_xmlns(<<"jabber:iq:register">>, [],
 +                       __TopXMLNS),
 +    _els = encode_register_state_cdata(Cdata, []),
 +    _attrs = enc_xmlns_attrs(__NewTopXMLNS, __TopXMLNS),
 +    {xmlel, <<"state">>, _attrs, _els}.
 +
 +decode_register_state_cdata(__TopXMLNS, <<>>) -> <<>>;
 +decode_register_state_cdata(__TopXMLNS, _val) -> _val.
 +
 +encode_register_state_cdata(<<>>, _acc) -> _acc;
 +encode_register_state_cdata(_val, _acc) ->
 +    [{xmlcdata, _val} | _acc].
 +
 +decode_register_city(__TopXMLNS, __IgnoreEls,
 +                   {xmlel, <<"city">>, _attrs, _els}) ->
 +    Cdata = decode_register_city_els(__TopXMLNS,
 +                                   __IgnoreEls, _els, <<>>),
 +    Cdata.
 +
 +decode_register_city_els(__TopXMLNS, __IgnoreEls, [],
 +                       Cdata) ->
 +    decode_register_city_cdata(__TopXMLNS, Cdata);
 +decode_register_city_els(__TopXMLNS, __IgnoreEls,
 +                       [{xmlcdata, _data} | _els], Cdata) ->
 +    decode_register_city_els(__TopXMLNS, __IgnoreEls, _els,
 +                           <<Cdata/binary, _data/binary>>);
 +decode_register_city_els(__TopXMLNS, __IgnoreEls,
 +                       [_ | _els], Cdata) ->
 +    decode_register_city_els(__TopXMLNS, __IgnoreEls, _els,
 +                           Cdata).
 +
 +encode_register_city(Cdata, __TopXMLNS) ->
 +    __NewTopXMLNS =
 +      choose_top_xmlns(<<"jabber:iq:register">>, [],
 +                       __TopXMLNS),
 +    _els = encode_register_city_cdata(Cdata, []),
 +    _attrs = enc_xmlns_attrs(__NewTopXMLNS, __TopXMLNS),
 +    {xmlel, <<"city">>, _attrs, _els}.
 +
 +decode_register_city_cdata(__TopXMLNS, <<>>) -> <<>>;
 +decode_register_city_cdata(__TopXMLNS, _val) -> _val.
 +
 +encode_register_city_cdata(<<>>, _acc) -> _acc;
 +encode_register_city_cdata(_val, _acc) ->
 +    [{xmlcdata, _val} | _acc].
 +
 +decode_register_address(__TopXMLNS, __IgnoreEls,
 +                      {xmlel, <<"address">>, _attrs, _els}) ->
 +    Cdata = decode_register_address_els(__TopXMLNS,
 +                                      __IgnoreEls, _els, <<>>),
 +    Cdata.
 +
 +decode_register_address_els(__TopXMLNS, __IgnoreEls, [],
 +                          Cdata) ->
 +    decode_register_address_cdata(__TopXMLNS, Cdata);
 +decode_register_address_els(__TopXMLNS, __IgnoreEls,
 +                          [{xmlcdata, _data} | _els], Cdata) ->
 +    decode_register_address_els(__TopXMLNS, __IgnoreEls,
 +                              _els, <<Cdata/binary, _data/binary>>);
 +decode_register_address_els(__TopXMLNS, __IgnoreEls,
 +                          [_ | _els], Cdata) ->
 +    decode_register_address_els(__TopXMLNS, __IgnoreEls,
 +                              _els, Cdata).
 +
 +encode_register_address(Cdata, __TopXMLNS) ->
 +    __NewTopXMLNS =
 +      choose_top_xmlns(<<"jabber:iq:register">>, [],
 +                       __TopXMLNS),
 +    _els = encode_register_address_cdata(Cdata, []),
 +    _attrs = enc_xmlns_attrs(__NewTopXMLNS, __TopXMLNS),
 +    {xmlel, <<"address">>, _attrs, _els}.
 +
 +decode_register_address_cdata(__TopXMLNS, <<>>) -> <<>>;
 +decode_register_address_cdata(__TopXMLNS, _val) -> _val.
 +
 +encode_register_address_cdata(<<>>, _acc) -> _acc;
 +encode_register_address_cdata(_val, _acc) ->
 +    [{xmlcdata, _val} | _acc].
 +
 +decode_register_email(__TopXMLNS, __IgnoreEls,
 +                    {xmlel, <<"email">>, _attrs, _els}) ->
 +    Cdata = decode_register_email_els(__TopXMLNS,
 +                                    __IgnoreEls, _els, <<>>),
 +    Cdata.
 +
 +decode_register_email_els(__TopXMLNS, __IgnoreEls, [],
 +                        Cdata) ->
 +    decode_register_email_cdata(__TopXMLNS, Cdata);
 +decode_register_email_els(__TopXMLNS, __IgnoreEls,
 +                        [{xmlcdata, _data} | _els], Cdata) ->
 +    decode_register_email_els(__TopXMLNS, __IgnoreEls, _els,
 +                            <<Cdata/binary, _data/binary>>);
 +decode_register_email_els(__TopXMLNS, __IgnoreEls,
 +                        [_ | _els], Cdata) ->
 +    decode_register_email_els(__TopXMLNS, __IgnoreEls, _els,
 +                            Cdata).
 +
 +encode_register_email(Cdata, __TopXMLNS) ->
 +    __NewTopXMLNS =
 +      choose_top_xmlns(<<"jabber:iq:register">>, [],
 +                       __TopXMLNS),
 +    _els = encode_register_email_cdata(Cdata, []),
 +    _attrs = enc_xmlns_attrs(__NewTopXMLNS, __TopXMLNS),
 +    {xmlel, <<"email">>, _attrs, _els}.
 +
 +decode_register_email_cdata(__TopXMLNS, <<>>) -> <<>>;
 +decode_register_email_cdata(__TopXMLNS, _val) -> _val.
 +
 +encode_register_email_cdata(<<>>, _acc) -> _acc;
 +encode_register_email_cdata(_val, _acc) ->
 +    [{xmlcdata, _val} | _acc].
 +
 +decode_register_last(__TopXMLNS, __IgnoreEls,
 +                   {xmlel, <<"last">>, _attrs, _els}) ->
 +    Cdata = decode_register_last_els(__TopXMLNS,
 +                                   __IgnoreEls, _els, <<>>),
 +    Cdata.
 +
 +decode_register_last_els(__TopXMLNS, __IgnoreEls, [],
 +                       Cdata) ->
 +    decode_register_last_cdata(__TopXMLNS, Cdata);
 +decode_register_last_els(__TopXMLNS, __IgnoreEls,
 +                       [{xmlcdata, _data} | _els], Cdata) ->
 +    decode_register_last_els(__TopXMLNS, __IgnoreEls, _els,
 +                           <<Cdata/binary, _data/binary>>);
 +decode_register_last_els(__TopXMLNS, __IgnoreEls,
 +                       [_ | _els], Cdata) ->
 +    decode_register_last_els(__TopXMLNS, __IgnoreEls, _els,
 +                           Cdata).
 +
 +encode_register_last(Cdata, __TopXMLNS) ->
 +    __NewTopXMLNS =
 +      choose_top_xmlns(<<"jabber:iq:register">>, [],
 +                       __TopXMLNS),
 +    _els = encode_register_last_cdata(Cdata, []),
 +    _attrs = enc_xmlns_attrs(__NewTopXMLNS, __TopXMLNS),
 +    {xmlel, <<"last">>, _attrs, _els}.
 +
 +decode_register_last_cdata(__TopXMLNS, <<>>) -> <<>>;
 +decode_register_last_cdata(__TopXMLNS, _val) -> _val.
 +
 +encode_register_last_cdata(<<>>, _acc) -> _acc;
 +encode_register_last_cdata(_val, _acc) ->
 +    [{xmlcdata, _val} | _acc].
 +
 +decode_register_first(__TopXMLNS, __IgnoreEls,
 +                    {xmlel, <<"first">>, _attrs, _els}) ->
 +    Cdata = decode_register_first_els(__TopXMLNS,
 +                                    __IgnoreEls, _els, <<>>),
 +    Cdata.
 +
 +decode_register_first_els(__TopXMLNS, __IgnoreEls, [],
 +                        Cdata) ->
 +    decode_register_first_cdata(__TopXMLNS, Cdata);
 +decode_register_first_els(__TopXMLNS, __IgnoreEls,
 +                        [{xmlcdata, _data} | _els], Cdata) ->
 +    decode_register_first_els(__TopXMLNS, __IgnoreEls, _els,
 +                            <<Cdata/binary, _data/binary>>);
 +decode_register_first_els(__TopXMLNS, __IgnoreEls,
 +                        [_ | _els], Cdata) ->
 +    decode_register_first_els(__TopXMLNS, __IgnoreEls, _els,
 +                            Cdata).
 +
 +encode_register_first(Cdata, __TopXMLNS) ->
 +    __NewTopXMLNS =
 +      choose_top_xmlns(<<"jabber:iq:register">>, [],
 +                       __TopXMLNS),
 +    _els = encode_register_first_cdata(Cdata, []),
 +    _attrs = enc_xmlns_attrs(__NewTopXMLNS, __TopXMLNS),
 +    {xmlel, <<"first">>, _attrs, _els}.
 +
 +decode_register_first_cdata(__TopXMLNS, <<>>) -> <<>>;
 +decode_register_first_cdata(__TopXMLNS, _val) -> _val.
 +
 +encode_register_first_cdata(<<>>, _acc) -> _acc;
 +encode_register_first_cdata(_val, _acc) ->
 +    [{xmlcdata, _val} | _acc].
 +
 +decode_register_name(__TopXMLNS, __IgnoreEls,
 +                   {xmlel, <<"name">>, _attrs, _els}) ->
 +    Cdata = decode_register_name_els(__TopXMLNS,
 +                                   __IgnoreEls, _els, <<>>),
 +    Cdata.
 +
 +decode_register_name_els(__TopXMLNS, __IgnoreEls, [],
 +                       Cdata) ->
 +    decode_register_name_cdata(__TopXMLNS, Cdata);
 +decode_register_name_els(__TopXMLNS, __IgnoreEls,
 +                       [{xmlcdata, _data} | _els], Cdata) ->
 +    decode_register_name_els(__TopXMLNS, __IgnoreEls, _els,
 +                           <<Cdata/binary, _data/binary>>);
 +decode_register_name_els(__TopXMLNS, __IgnoreEls,
 +                       [_ | _els], Cdata) ->
 +    decode_register_name_els(__TopXMLNS, __IgnoreEls, _els,
 +                           Cdata).
 +
 +encode_register_name(Cdata, __TopXMLNS) ->
 +    __NewTopXMLNS =
 +      choose_top_xmlns(<<"jabber:iq:register">>, [],
 +                       __TopXMLNS),
 +    _els = encode_register_name_cdata(Cdata, []),
 +    _attrs = enc_xmlns_attrs(__NewTopXMLNS, __TopXMLNS),
 +    {xmlel, <<"name">>, _attrs, _els}.
 +
 +decode_register_name_cdata(__TopXMLNS, <<>>) -> <<>>;
 +decode_register_name_cdata(__TopXMLNS, _val) -> _val.
 +
 +encode_register_name_cdata(<<>>, _acc) -> _acc;
 +encode_register_name_cdata(_val, _acc) ->
 +    [{xmlcdata, _val} | _acc].
 +
 +decode_register_password(__TopXMLNS, __IgnoreEls,
 +                       {xmlel, <<"password">>, _attrs, _els}) ->
 +    Cdata = decode_register_password_els(__TopXMLNS,
 +                                       __IgnoreEls, _els, <<>>),
 +    Cdata.
 +
 +decode_register_password_els(__TopXMLNS, __IgnoreEls,
 +                           [], Cdata) ->
 +    decode_register_password_cdata(__TopXMLNS, Cdata);
 +decode_register_password_els(__TopXMLNS, __IgnoreEls,
 +                           [{xmlcdata, _data} | _els], Cdata) ->
 +    decode_register_password_els(__TopXMLNS, __IgnoreEls,
 +                               _els, <<Cdata/binary, _data/binary>>);
 +decode_register_password_els(__TopXMLNS, __IgnoreEls,
 +                           [_ | _els], Cdata) ->
 +    decode_register_password_els(__TopXMLNS, __IgnoreEls,
 +                               _els, Cdata).
 +
 +encode_register_password(Cdata, __TopXMLNS) ->
 +    __NewTopXMLNS =
 +      choose_top_xmlns(<<"jabber:iq:register">>, [],
 +                       __TopXMLNS),
 +    _els = encode_register_password_cdata(Cdata, []),
 +    _attrs = enc_xmlns_attrs(__NewTopXMLNS, __TopXMLNS),
 +    {xmlel, <<"password">>, _attrs, _els}.
 +
 +decode_register_password_cdata(__TopXMLNS, <<>>) ->
 +    <<>>;
 +decode_register_password_cdata(__TopXMLNS, _val) ->
 +    _val.
 +
 +encode_register_password_cdata(<<>>, _acc) -> _acc;
 +encode_register_password_cdata(_val, _acc) ->
 +    [{xmlcdata, _val} | _acc].
 +
 +decode_register_nick(__TopXMLNS, __IgnoreEls,
 +                   {xmlel, <<"nick">>, _attrs, _els}) ->
 +    Cdata = decode_register_nick_els(__TopXMLNS,
 +                                   __IgnoreEls, _els, <<>>),
 +    Cdata.
 +
 +decode_register_nick_els(__TopXMLNS, __IgnoreEls, [],
 +                       Cdata) ->
 +    decode_register_nick_cdata(__TopXMLNS, Cdata);
 +decode_register_nick_els(__TopXMLNS, __IgnoreEls,
 +                       [{xmlcdata, _data} | _els], Cdata) ->
 +    decode_register_nick_els(__TopXMLNS, __IgnoreEls, _els,
 +                           <<Cdata/binary, _data/binary>>);
 +decode_register_nick_els(__TopXMLNS, __IgnoreEls,
 +                       [_ | _els], Cdata) ->
 +    decode_register_nick_els(__TopXMLNS, __IgnoreEls, _els,
 +                           Cdata).
 +
 +encode_register_nick(Cdata, __TopXMLNS) ->
 +    __NewTopXMLNS =
 +      choose_top_xmlns(<<"jabber:iq:register">>, [],
 +                       __TopXMLNS),
 +    _els = encode_register_nick_cdata(Cdata, []),
 +    _attrs = enc_xmlns_attrs(__NewTopXMLNS, __TopXMLNS),
 +    {xmlel, <<"nick">>, _attrs, _els}.
 +
 +decode_register_nick_cdata(__TopXMLNS, <<>>) -> <<>>;
 +decode_register_nick_cdata(__TopXMLNS, _val) -> _val.
 +
 +encode_register_nick_cdata(<<>>, _acc) -> _acc;
 +encode_register_nick_cdata(_val, _acc) ->
 +    [{xmlcdata, _val} | _acc].
 +
 +decode_register_username(__TopXMLNS, __IgnoreEls,
 +                       {xmlel, <<"username">>, _attrs, _els}) ->
 +    Cdata = decode_register_username_els(__TopXMLNS,
 +                                       __IgnoreEls, _els, <<>>),
 +    Cdata.
 +
 +decode_register_username_els(__TopXMLNS, __IgnoreEls,
 +                           [], Cdata) ->
 +    decode_register_username_cdata(__TopXMLNS, Cdata);
 +decode_register_username_els(__TopXMLNS, __IgnoreEls,
 +                           [{xmlcdata, _data} | _els], Cdata) ->
 +    decode_register_username_els(__TopXMLNS, __IgnoreEls,
 +                               _els, <<Cdata/binary, _data/binary>>);
 +decode_register_username_els(__TopXMLNS, __IgnoreEls,
 +                           [_ | _els], Cdata) ->
 +    decode_register_username_els(__TopXMLNS, __IgnoreEls,
 +                               _els, Cdata).
 +
 +encode_register_username(Cdata, __TopXMLNS) ->
 +    __NewTopXMLNS =
 +      choose_top_xmlns(<<"jabber:iq:register">>, [],
 +                       __TopXMLNS),
 +    _els = encode_register_username_cdata(Cdata, []),
 +    _attrs = enc_xmlns_attrs(__NewTopXMLNS, __TopXMLNS),
 +    {xmlel, <<"username">>, _attrs, _els}.
 +
 +decode_register_username_cdata(__TopXMLNS, <<>>) ->
 +    <<>>;
 +decode_register_username_cdata(__TopXMLNS, _val) ->
 +    _val.
 +
 +encode_register_username_cdata(<<>>, _acc) -> _acc;
 +encode_register_username_cdata(_val, _acc) ->
 +    [{xmlcdata, _val} | _acc].
 +
 +decode_register_instructions(__TopXMLNS, __IgnoreEls,
 +                           {xmlel, <<"instructions">>, _attrs, _els}) ->
 +    Cdata = decode_register_instructions_els(__TopXMLNS,
 +                                           __IgnoreEls, _els, <<>>),
 +    Cdata.
 +
 +decode_register_instructions_els(__TopXMLNS,
 +                               __IgnoreEls, [], Cdata) ->
 +    decode_register_instructions_cdata(__TopXMLNS, Cdata);
 +decode_register_instructions_els(__TopXMLNS,
 +                               __IgnoreEls, [{xmlcdata, _data} | _els],
 +                               Cdata) ->
 +    decode_register_instructions_els(__TopXMLNS,
 +                                   __IgnoreEls, _els,
 +                                   <<Cdata/binary, _data/binary>>);
 +decode_register_instructions_els(__TopXMLNS,
 +                               __IgnoreEls, [_ | _els], Cdata) ->
 +    decode_register_instructions_els(__TopXMLNS,
 +                                   __IgnoreEls, _els, Cdata).
 +
 +encode_register_instructions(Cdata, __TopXMLNS) ->
 +    __NewTopXMLNS =
 +      choose_top_xmlns(<<"jabber:iq:register">>, [],
 +                       __TopXMLNS),
 +    _els = encode_register_instructions_cdata(Cdata, []),
 +    _attrs = enc_xmlns_attrs(__NewTopXMLNS, __TopXMLNS),
 +    {xmlel, <<"instructions">>, _attrs, _els}.
 +
 +decode_register_instructions_cdata(__TopXMLNS, <<>>) ->
 +    <<>>;
 +decode_register_instructions_cdata(__TopXMLNS, _val) ->
 +    _val.
 +
 +encode_register_instructions_cdata(<<>>, _acc) -> _acc;
 +encode_register_instructions_cdata(_val, _acc) ->
 +    [{xmlcdata, _val} | _acc].
 +
 +decode_register_remove(__TopXMLNS, __IgnoreEls,
 +                     {xmlel, <<"remove">>, _attrs, _els}) ->
 +    true.
 +
 +encode_register_remove(true, __TopXMLNS) ->
 +    __NewTopXMLNS =
 +      choose_top_xmlns(<<"jabber:iq:register">>, [],
 +                       __TopXMLNS),
 +    _els = [],
 +    _attrs = enc_xmlns_attrs(__NewTopXMLNS, __TopXMLNS),
 +    {xmlel, <<"remove">>, _attrs, _els}.
 +
 +decode_register_registered(__TopXMLNS, __IgnoreEls,
 +                         {xmlel, <<"registered">>, _attrs, _els}) ->
 +    true.
 +
 +encode_register_registered(true, __TopXMLNS) ->
 +    __NewTopXMLNS =
 +      choose_top_xmlns(<<"jabber:iq:register">>, [],
 +                       __TopXMLNS),
 +    _els = [],
 +    _attrs = enc_xmlns_attrs(__NewTopXMLNS, __TopXMLNS),
 +    {xmlel, <<"registered">>, _attrs, _els}.
 +
 +decode_feature_register(__TopXMLNS, __IgnoreEls,
 +                      {xmlel, <<"register">>, _attrs, _els}) ->
 +    {feature_register}.
 +
 +encode_feature_register({feature_register},
 +                      __TopXMLNS) ->
 +    __NewTopXMLNS =
 +      choose_top_xmlns(<<"http://jabber.org/features/iq-register">>,
 +                       [], __TopXMLNS),
 +    _els = [],
 +    _attrs = enc_xmlns_attrs(__NewTopXMLNS, __TopXMLNS),
 +    {xmlel, <<"register">>, _attrs, _els}.
 +
 +decode_caps(__TopXMLNS, __IgnoreEls,
 +          {xmlel, <<"c">>, _attrs, _els}) ->
 +    {Hash, Node, Exts, Version} =
 +      decode_caps_attrs(__TopXMLNS, _attrs, undefined,
 +                        undefined, undefined, undefined),
 +    {caps, Node, Version, Hash, Exts}.
 +
 +decode_caps_attrs(__TopXMLNS,
 +                [{<<"hash">>, _val} | _attrs], _Hash, Node, Exts,
 +                Version) ->
 +    decode_caps_attrs(__TopXMLNS, _attrs, _val, Node, Exts,
 +                    Version);
 +decode_caps_attrs(__TopXMLNS,
 +                [{<<"node">>, _val} | _attrs], Hash, _Node, Exts,
 +                Version) ->
 +    decode_caps_attrs(__TopXMLNS, _attrs, Hash, _val, Exts,
 +                    Version);
 +decode_caps_attrs(__TopXMLNS,
 +                [{<<"ext">>, _val} | _attrs], Hash, Node, _Exts,
 +                Version) ->
 +    decode_caps_attrs(__TopXMLNS, _attrs, Hash, Node, _val,
 +                    Version);
 +decode_caps_attrs(__TopXMLNS,
 +                [{<<"ver">>, _val} | _attrs], Hash, Node, Exts,
 +                _Version) ->
 +    decode_caps_attrs(__TopXMLNS, _attrs, Hash, Node, Exts,
 +                    _val);
 +decode_caps_attrs(__TopXMLNS, [_ | _attrs], Hash, Node,
 +                Exts, Version) ->
 +    decode_caps_attrs(__TopXMLNS, _attrs, Hash, Node, Exts,
 +                    Version);
 +decode_caps_attrs(__TopXMLNS, [], Hash, Node, Exts,
 +                Version) ->
 +    {decode_caps_attr_hash(__TopXMLNS, Hash),
 +     decode_caps_attr_node(__TopXMLNS, Node),
 +     decode_caps_attr_ext(__TopXMLNS, Exts),
 +     decode_caps_attr_ver(__TopXMLNS, Version)}.
 +
 +encode_caps({caps, Node, Version, Hash, Exts},
 +          __TopXMLNS) ->
 +    __NewTopXMLNS =
 +      choose_top_xmlns(<<"http://jabber.org/protocol/caps">>,
 +                       [], __TopXMLNS),
 +    _els = [],
 +    _attrs = encode_caps_attr_ver(Version,
 +                                encode_caps_attr_ext(Exts,
 +                                                     encode_caps_attr_node(Node,
 +                                                                           encode_caps_attr_hash(Hash,
 +                                                                                                 enc_xmlns_attrs(__NewTopXMLNS,
 +                                                                                                                 __TopXMLNS))))),
 +    {xmlel, <<"c">>, _attrs, _els}.
 +
 +decode_caps_attr_hash(__TopXMLNS, undefined) -> <<>>;
 +decode_caps_attr_hash(__TopXMLNS, _val) -> _val.
 +
 +encode_caps_attr_hash(<<>>, _acc) -> _acc;
 +encode_caps_attr_hash(_val, _acc) ->
 +    [{<<"hash">>, _val} | _acc].
 +
 +decode_caps_attr_node(__TopXMLNS, undefined) -> <<>>;
 +decode_caps_attr_node(__TopXMLNS, _val) -> _val.
 +
 +encode_caps_attr_node(<<>>, _acc) -> _acc;
 +encode_caps_attr_node(_val, _acc) ->
 +    [{<<"node">>, _val} | _acc].
 +
 +decode_caps_attr_ext(__TopXMLNS, undefined) -> [];
 +decode_caps_attr_ext(__TopXMLNS, _val) ->
 +    case catch re:split(_val, "\\h+") of
 +      {'EXIT', _} ->
 +        erlang:error({xmpp_codec,
 +                      {bad_attr_value, <<"ext">>, <<"c">>, __TopXMLNS}});
 +      _res -> _res
 +    end.
 +
 +encode_caps_attr_ext([], _acc) -> _acc;
 +encode_caps_attr_ext(_val, _acc) ->
 +    [{<<"ext">>, join(_val, 32)} | _acc].
 +
 +decode_caps_attr_ver(__TopXMLNS, undefined) -> <<>>;
 +decode_caps_attr_ver(__TopXMLNS, _val) -> _val.
 +
 +encode_caps_attr_ver(<<>>, _acc) -> _acc;
 +encode_caps_attr_ver(_val, _acc) ->
 +    [{<<"ver">>, _val} | _acc].
 +
 +decode_p1_ack(__TopXMLNS, __IgnoreEls,
 +            {xmlel, <<"ack">>, _attrs, _els}) ->
 +    {p1_ack}.
 +
 +encode_p1_ack({p1_ack}, __TopXMLNS) ->
 +    __NewTopXMLNS = choose_top_xmlns(<<"p1:ack">>, [],
 +                                   __TopXMLNS),
 +    _els = [],
 +    _attrs = enc_xmlns_attrs(__NewTopXMLNS, __TopXMLNS),
 +    {xmlel, <<"ack">>, _attrs, _els}.
 +
 +decode_p1_rebind(__TopXMLNS, __IgnoreEls,
 +               {xmlel, <<"rebind">>, _attrs, _els}) ->
 +    {p1_rebind}.
 +
 +encode_p1_rebind({p1_rebind}, __TopXMLNS) ->
 +    __NewTopXMLNS = choose_top_xmlns(<<"p1:rebind">>, [],
 +                                   __TopXMLNS),
 +    _els = [],
 +    _attrs = enc_xmlns_attrs(__NewTopXMLNS, __TopXMLNS),
 +    {xmlel, <<"rebind">>, _attrs, _els}.
 +
 +decode_p1_push(__TopXMLNS, __IgnoreEls,
 +             {xmlel, <<"push">>, _attrs, _els}) ->
 +    {p1_push}.
 +
 +encode_p1_push({p1_push}, __TopXMLNS) ->
 +    __NewTopXMLNS = choose_top_xmlns(<<"p1:push">>, [],
 +                                   __TopXMLNS),
 +    _els = [],
 +    _attrs = enc_xmlns_attrs(__NewTopXMLNS, __TopXMLNS),
 +    {xmlel, <<"push">>, _attrs, _els}.
 +
 +decode_stream_features(__TopXMLNS, __IgnoreEls,
 +                     {xmlel, <<"stream:features">>, _attrs, _els}) ->
 +    __Els = decode_stream_features_els(__TopXMLNS,
 +                                     __IgnoreEls, _els, []),
 +    {stream_features, __Els}.
 +
 +decode_stream_features_els(__TopXMLNS, __IgnoreEls, [],
 +                         __Els) ->
 +    lists:reverse(__Els);
 +decode_stream_features_els(__TopXMLNS, __IgnoreEls,
 +                         [{xmlel, _, _, _} = _el | _els], __Els) ->
 +    if __IgnoreEls ->
 +         decode_stream_features_els(__TopXMLNS, __IgnoreEls,
 +                                    _els, [_el | __Els]);
 +       true ->
 +         case is_known_tag(_el, __TopXMLNS) of
 +           true ->
 +               decode_stream_features_els(__TopXMLNS, __IgnoreEls,
 +                                          _els,
 +                                          [decode(_el, __TopXMLNS, [])
 +                                           | __Els]);
 +           false ->
 +               decode_stream_features_els(__TopXMLNS, __IgnoreEls,
 +                                          _els, __Els)
 +         end
 +    end;
 +decode_stream_features_els(__TopXMLNS, __IgnoreEls,
 +                         [_ | _els], __Els) ->
 +    decode_stream_features_els(__TopXMLNS, __IgnoreEls,
 +                             _els, __Els).
 +
 +encode_stream_features({stream_features, __Els},
 +                     __TopXMLNS) ->
 +    __NewTopXMLNS = choose_top_xmlns(<<>>,
 +                                   [<<"jabber:client">>, <<"jabber:server">>],
 +                                   __TopXMLNS),
 +    _els = [encode(_el, __NewTopXMLNS) || _el <- __Els],
 +    _attrs = enc_xmlns_attrs(__NewTopXMLNS, __TopXMLNS),
 +    {xmlel, <<"stream:features">>, _attrs, _els}.
 +
 +decode_compression(__TopXMLNS, __IgnoreEls,
 +                 {xmlel, <<"compression">>, _attrs, _els}) ->
 +    Methods = decode_compression_els(__TopXMLNS,
 +                                   __IgnoreEls, _els, []),
 +    {compression, Methods}.
 +
 +decode_compression_els(__TopXMLNS, __IgnoreEls, [],
 +                     Methods) ->
 +    lists:reverse(Methods);
 +decode_compression_els(__TopXMLNS, __IgnoreEls,
 +                     [{xmlel, <<"method">>, _attrs, _} = _el | _els],
 +                     Methods) ->
 +    case get_attr(<<"xmlns">>, _attrs) of
 +      <<"">>
 +        when __TopXMLNS ==
 +               <<"http://jabber.org/features/compress">> ->
 +        decode_compression_els(__TopXMLNS, __IgnoreEls, _els,
 +                               [decode_compression_method(__TopXMLNS,
 +                                                          __IgnoreEls, _el)
 +                                | Methods]);
 +      <<"http://jabber.org/features/compress">> ->
 +        decode_compression_els(__TopXMLNS, __IgnoreEls, _els,
 +                               [decode_compression_method(<<"http://jabber.org/features/compress">>,
 +                                                          __IgnoreEls, _el)
 +                                | Methods]);
 +      _ ->
 +        decode_compression_els(__TopXMLNS, __IgnoreEls, _els,
 +                               Methods)
 +    end;
 +decode_compression_els(__TopXMLNS, __IgnoreEls,
 +                     [_ | _els], Methods) ->
 +    decode_compression_els(__TopXMLNS, __IgnoreEls, _els,
 +                         Methods).
 +
 +encode_compression({compression, Methods},
 +                 __TopXMLNS) ->
 +    __NewTopXMLNS =
 +      choose_top_xmlns(<<"http://jabber.org/features/compress">>,
 +                       [], __TopXMLNS),
 +    _els =
 +      lists:reverse('encode_compression_$methods'(Methods,
 +                                                  __NewTopXMLNS, [])),
 +    _attrs = enc_xmlns_attrs(__NewTopXMLNS, __TopXMLNS),
 +    {xmlel, <<"compression">>, _attrs, _els}.
 +
 +'encode_compression_$methods'([], __TopXMLNS, _acc) ->
 +    _acc;
 +'encode_compression_$methods'([Methods | _els],
 +                            __TopXMLNS, _acc) ->
 +    'encode_compression_$methods'(_els, __TopXMLNS,
 +                                [encode_compression_method(Methods,
 +                                                           __TopXMLNS)
 +                                 | _acc]).
 +
 +decode_compression_method(__TopXMLNS, __IgnoreEls,
 +                        {xmlel, <<"method">>, _attrs, _els}) ->
 +    Cdata = decode_compression_method_els(__TopXMLNS,
 +                                        __IgnoreEls, _els, <<>>),
 +    Cdata.
 +
 +decode_compression_method_els(__TopXMLNS, __IgnoreEls,
 +                            [], Cdata) ->
 +    decode_compression_method_cdata(__TopXMLNS, Cdata);
 +decode_compression_method_els(__TopXMLNS, __IgnoreEls,
 +                            [{xmlcdata, _data} | _els], Cdata) ->
 +    decode_compression_method_els(__TopXMLNS, __IgnoreEls,
 +                                _els, <<Cdata/binary, _data/binary>>);
 +decode_compression_method_els(__TopXMLNS, __IgnoreEls,
 +                            [_ | _els], Cdata) ->
 +    decode_compression_method_els(__TopXMLNS, __IgnoreEls,
 +                                _els, Cdata).
 +
 +encode_compression_method(Cdata, __TopXMLNS) ->
 +    __NewTopXMLNS =
 +      choose_top_xmlns(<<"http://jabber.org/features/compress">>,
 +                       [], __TopXMLNS),
 +    _els = encode_compression_method_cdata(Cdata, []),
 +    _attrs = enc_xmlns_attrs(__NewTopXMLNS, __TopXMLNS),
 +    {xmlel, <<"method">>, _attrs, _els}.
 +
 +decode_compression_method_cdata(__TopXMLNS, <<>>) ->
 +    <<>>;
 +decode_compression_method_cdata(__TopXMLNS, _val) ->
 +    _val.
 +
 +encode_compression_method_cdata(<<>>, _acc) -> _acc;
 +encode_compression_method_cdata(_val, _acc) ->
 +    [{xmlcdata, _val} | _acc].
 +
 +decode_compressed(__TopXMLNS, __IgnoreEls,
 +                {xmlel, <<"compressed">>, _attrs, _els}) ->
 +    {compressed}.
 +
 +encode_compressed({compressed}, __TopXMLNS) ->
 +    __NewTopXMLNS =
 +      choose_top_xmlns(<<"http://jabber.org/protocol/compress">>,
 +                       [], __TopXMLNS),
 +    _els = [],
 +    _attrs = enc_xmlns_attrs(__NewTopXMLNS, __TopXMLNS),
 +    {xmlel, <<"compressed">>, _attrs, _els}.
 +
 +decode_compress(__TopXMLNS, __IgnoreEls,
 +              {xmlel, <<"compress">>, _attrs, _els}) ->
 +    Methods = decode_compress_els(__TopXMLNS, __IgnoreEls,
 +                                _els, []),
 +    {compress, Methods}.
 +
 +decode_compress_els(__TopXMLNS, __IgnoreEls, [],
 +                  Methods) ->
 +    lists:reverse(Methods);
 +decode_compress_els(__TopXMLNS, __IgnoreEls,
 +                  [{xmlel, <<"method">>, _attrs, _} = _el | _els],
 +                  Methods) ->
 +    case get_attr(<<"xmlns">>, _attrs) of
 +      <<"">>
 +        when __TopXMLNS ==
 +               <<"http://jabber.org/protocol/compress">> ->
 +        decode_compress_els(__TopXMLNS, __IgnoreEls, _els,
 +                            [decode_compress_method(__TopXMLNS, __IgnoreEls,
 +                                                    _el)
 +                             | Methods]);
 +      <<"http://jabber.org/protocol/compress">> ->
 +        decode_compress_els(__TopXMLNS, __IgnoreEls, _els,
 +                            [decode_compress_method(<<"http://jabber.org/protocol/compress">>,
 +                                                    __IgnoreEls, _el)
 +                             | Methods]);
 +      _ ->
 +        decode_compress_els(__TopXMLNS, __IgnoreEls, _els,
 +                            Methods)
 +    end;
 +decode_compress_els(__TopXMLNS, __IgnoreEls, [_ | _els],
 +                  Methods) ->
 +    decode_compress_els(__TopXMLNS, __IgnoreEls, _els,
 +                      Methods).
 +
 +encode_compress({compress, Methods}, __TopXMLNS) ->
 +    __NewTopXMLNS =
 +      choose_top_xmlns(<<"http://jabber.org/protocol/compress">>,
 +                       [], __TopXMLNS),
 +    _els = lists:reverse('encode_compress_$methods'(Methods,
 +                                                  __NewTopXMLNS, [])),
 +    _attrs = enc_xmlns_attrs(__NewTopXMLNS, __TopXMLNS),
 +    {xmlel, <<"compress">>, _attrs, _els}.
 +
 +'encode_compress_$methods'([], __TopXMLNS, _acc) ->
 +    _acc;
 +'encode_compress_$methods'([Methods | _els], __TopXMLNS,
 +                         _acc) ->
 +    'encode_compress_$methods'(_els, __TopXMLNS,
 +                             [encode_compress_method(Methods, __TopXMLNS)
 +                              | _acc]).
 +
 +decode_compress_method(__TopXMLNS, __IgnoreEls,
 +                     {xmlel, <<"method">>, _attrs, _els}) ->
 +    Cdata = decode_compress_method_els(__TopXMLNS,
 +                                     __IgnoreEls, _els, <<>>),
 +    Cdata.
 +
 +decode_compress_method_els(__TopXMLNS, __IgnoreEls, [],
 +                         Cdata) ->
 +    decode_compress_method_cdata(__TopXMLNS, Cdata);
 +decode_compress_method_els(__TopXMLNS, __IgnoreEls,
 +                         [{xmlcdata, _data} | _els], Cdata) ->
 +    decode_compress_method_els(__TopXMLNS, __IgnoreEls,
 +                             _els, <<Cdata/binary, _data/binary>>);
 +decode_compress_method_els(__TopXMLNS, __IgnoreEls,
 +                         [_ | _els], Cdata) ->
 +    decode_compress_method_els(__TopXMLNS, __IgnoreEls,
 +                             _els, Cdata).
 +
 +encode_compress_method(Cdata, __TopXMLNS) ->
 +    __NewTopXMLNS =
 +      choose_top_xmlns(<<"http://jabber.org/protocol/compress">>,
 +                       [], __TopXMLNS),
 +    _els = encode_compress_method_cdata(Cdata, []),
 +    _attrs = enc_xmlns_attrs(__NewTopXMLNS, __TopXMLNS),
 +    {xmlel, <<"method">>, _attrs, _els}.
 +
 +decode_compress_method_cdata(__TopXMLNS, <<>>) -> <<>>;
 +decode_compress_method_cdata(__TopXMLNS, _val) -> _val.
 +
 +encode_compress_method_cdata(<<>>, _acc) -> _acc;
 +encode_compress_method_cdata(_val, _acc) ->
 +    [{xmlcdata, _val} | _acc].
 +
 +decode_compress_failure(__TopXMLNS, __IgnoreEls,
 +                      {xmlel, <<"failure">>, _attrs, _els}) ->
 +    Reason = decode_compress_failure_els(__TopXMLNS,
 +                                       __IgnoreEls, _els, undefined),
 +    {compress_failure, Reason}.
 +
 +decode_compress_failure_els(__TopXMLNS, __IgnoreEls, [],
 +                          Reason) ->
 +    Reason;
 +decode_compress_failure_els(__TopXMLNS, __IgnoreEls,
 +                          [{xmlel, <<"setup-failed">>, _attrs, _} = _el
 +                           | _els],
 +                          Reason) ->
 +    case get_attr(<<"xmlns">>, _attrs) of
 +      <<"">>
 +        when __TopXMLNS ==
 +               <<"http://jabber.org/protocol/compress">> ->
 +        decode_compress_failure_els(__TopXMLNS, __IgnoreEls,
 +                                    _els,
 +                                    decode_compress_failure_setup_failed(__TopXMLNS,
 +                                                                         __IgnoreEls,
 +                                                                         _el));
 +      <<"http://jabber.org/protocol/compress">> ->
 +        decode_compress_failure_els(__TopXMLNS, __IgnoreEls,
 +                                    _els,
 +                                    decode_compress_failure_setup_failed(<<"http://jabber.org/protocol/compress">>,
 +                                                                         __IgnoreEls,
 +                                                                         _el));
 +      _ ->
 +        decode_compress_failure_els(__TopXMLNS, __IgnoreEls,
 +                                    _els, Reason)
 +    end;
 +decode_compress_failure_els(__TopXMLNS, __IgnoreEls,
 +                          [{xmlel, <<"processing-failed">>, _attrs, _} = _el
 +                           | _els],
 +                          Reason) ->
 +    case get_attr(<<"xmlns">>, _attrs) of
 +      <<"">>
 +        when __TopXMLNS ==
 +               <<"http://jabber.org/protocol/compress">> ->
 +        decode_compress_failure_els(__TopXMLNS, __IgnoreEls,
 +                                    _els,
 +                                    decode_compress_failure_processing_failed(__TopXMLNS,
 +                                                                              __IgnoreEls,
 +                                                                              _el));
 +      <<"http://jabber.org/protocol/compress">> ->
 +        decode_compress_failure_els(__TopXMLNS, __IgnoreEls,
 +                                    _els,
 +                                    decode_compress_failure_processing_failed(<<"http://jabber.org/protocol/compress">>,
 +                                                                              __IgnoreEls,
 +                                                                              _el));
 +      _ ->
 +        decode_compress_failure_els(__TopXMLNS, __IgnoreEls,
 +                                    _els, Reason)
 +    end;
 +decode_compress_failure_els(__TopXMLNS, __IgnoreEls,
 +                          [{xmlel, <<"unsupported-method">>, _attrs, _} = _el
 +                           | _els],
 +                          Reason) ->
 +    case get_attr(<<"xmlns">>, _attrs) of
 +      <<"">>
 +        when __TopXMLNS ==
 +               <<"http://jabber.org/protocol/compress">> ->
 +        decode_compress_failure_els(__TopXMLNS, __IgnoreEls,
 +                                    _els,
 +                                    decode_compress_failure_unsupported_method(__TopXMLNS,
 +                                                                               __IgnoreEls,
 +                                                                               _el));
 +      <<"http://jabber.org/protocol/compress">> ->
 +        decode_compress_failure_els(__TopXMLNS, __IgnoreEls,
 +                                    _els,
 +                                    decode_compress_failure_unsupported_method(<<"http://jabber.org/protocol/compress">>,
 +                                                                               __IgnoreEls,
 +                                                                               _el));
 +      _ ->
 +        decode_compress_failure_els(__TopXMLNS, __IgnoreEls,
 +                                    _els, Reason)
 +    end;
 +decode_compress_failure_els(__TopXMLNS, __IgnoreEls,
 +                          [_ | _els], Reason) ->
 +    decode_compress_failure_els(__TopXMLNS, __IgnoreEls,
 +                              _els, Reason).
 +
 +encode_compress_failure({compress_failure, Reason},
 +                      __TopXMLNS) ->
 +    __NewTopXMLNS =
 +      choose_top_xmlns(<<"http://jabber.org/protocol/compress">>,
 +                       [], __TopXMLNS),
 +    _els =
 +      lists:reverse('encode_compress_failure_$reason'(Reason,
 +                                                      __NewTopXMLNS, [])),
 +    _attrs = enc_xmlns_attrs(__NewTopXMLNS, __TopXMLNS),
 +    {xmlel, <<"failure">>, _attrs, _els}.
 +
 +'encode_compress_failure_$reason'(undefined, __TopXMLNS,
 +                                _acc) ->
 +    _acc;
 +'encode_compress_failure_$reason'('setup-failed' =
 +                                    Reason,
 +                                __TopXMLNS, _acc) ->
 +    [encode_compress_failure_setup_failed(Reason,
 +                                        __TopXMLNS)
 +     | _acc];
 +'encode_compress_failure_$reason'('processing-failed' =
 +                                    Reason,
 +                                __TopXMLNS, _acc) ->
 +    [encode_compress_failure_processing_failed(Reason,
 +                                             __TopXMLNS)
 +     | _acc];
 +'encode_compress_failure_$reason'('unsupported-method' =
 +                                    Reason,
 +                                __TopXMLNS, _acc) ->
 +    [encode_compress_failure_unsupported_method(Reason,
 +                                              __TopXMLNS)
 +     | _acc].
 +
 +decode_compress_failure_unsupported_method(__TopXMLNS,
 +                                         __IgnoreEls,
 +                                         {xmlel, <<"unsupported-method">>,
 +                                          _attrs, _els}) ->
 +    'unsupported-method'.
 +
 +encode_compress_failure_unsupported_method('unsupported-method',
 +                                         __TopXMLNS) ->
 +    __NewTopXMLNS =
 +      choose_top_xmlns(<<"http://jabber.org/protocol/compress">>,
 +                       [], __TopXMLNS),
 +    _els = [],
 +    _attrs = enc_xmlns_attrs(__NewTopXMLNS, __TopXMLNS),
 +    {xmlel, <<"unsupported-method">>, _attrs, _els}.
 +
 +decode_compress_failure_processing_failed(__TopXMLNS,
 +                                        __IgnoreEls,
 +                                        {xmlel, <<"processing-failed">>,
 +                                         _attrs, _els}) ->
 +    'processing-failed'.
 +
 +encode_compress_failure_processing_failed('processing-failed',
 +                                        __TopXMLNS) ->
 +    __NewTopXMLNS =
 +      choose_top_xmlns(<<"http://jabber.org/protocol/compress">>,
 +                       [], __TopXMLNS),
 +    _els = [],
 +    _attrs = enc_xmlns_attrs(__NewTopXMLNS, __TopXMLNS),
 +    {xmlel, <<"processing-failed">>, _attrs, _els}.
 +
 +decode_compress_failure_setup_failed(__TopXMLNS,
 +                                   __IgnoreEls,
 +                                   {xmlel, <<"setup-failed">>, _attrs,
 +                                    _els}) ->
 +    'setup-failed'.
 +
 +encode_compress_failure_setup_failed('setup-failed',
 +                                   __TopXMLNS) ->
 +    __NewTopXMLNS =
 +      choose_top_xmlns(<<"http://jabber.org/protocol/compress">>,
 +                       [], __TopXMLNS),
 +    _els = [],
 +    _attrs = enc_xmlns_attrs(__NewTopXMLNS, __TopXMLNS),
 +    {xmlel, <<"setup-failed">>, _attrs, _els}.
 +
 +decode_starttls_failure(__TopXMLNS, __IgnoreEls,
 +                      {xmlel, <<"failure">>, _attrs, _els}) ->
 +    {starttls_failure}.
 +
 +encode_starttls_failure({starttls_failure},
 +                      __TopXMLNS) ->
 +    __NewTopXMLNS =
 +      choose_top_xmlns(<<"urn:ietf:params:xml:ns:xmpp-tls">>,
 +                       [], __TopXMLNS),
 +    _els = [],
 +    _attrs = enc_xmlns_attrs(__NewTopXMLNS, __TopXMLNS),
 +    {xmlel, <<"failure">>, _attrs, _els}.
 +
 +decode_starttls_proceed(__TopXMLNS, __IgnoreEls,
 +                      {xmlel, <<"proceed">>, _attrs, _els}) ->
 +    {starttls_proceed}.
 +
 +encode_starttls_proceed({starttls_proceed},
 +                      __TopXMLNS) ->
 +    __NewTopXMLNS =
 +      choose_top_xmlns(<<"urn:ietf:params:xml:ns:xmpp-tls">>,
 +                       [], __TopXMLNS),
 +    _els = [],
 +    _attrs = enc_xmlns_attrs(__NewTopXMLNS, __TopXMLNS),
 +    {xmlel, <<"proceed">>, _attrs, _els}.
 +
 +decode_starttls(__TopXMLNS, __IgnoreEls,
 +              {xmlel, <<"starttls">>, _attrs, _els}) ->
 +    Required = decode_starttls_els(__TopXMLNS, __IgnoreEls,
 +                                 _els, false),
 +    {starttls, Required}.
 +
 +decode_starttls_els(__TopXMLNS, __IgnoreEls, [],
 +                  Required) ->
 +    Required;
 +decode_starttls_els(__TopXMLNS, __IgnoreEls,
 +                  [{xmlel, <<"required">>, _attrs, _} = _el | _els],
 +                  Required) ->
 +    case get_attr(<<"xmlns">>, _attrs) of
 +      <<"">>
 +        when __TopXMLNS ==
 +               <<"urn:ietf:params:xml:ns:xmpp-tls">> ->
 +        decode_starttls_els(__TopXMLNS, __IgnoreEls, _els,
 +                            decode_starttls_required(__TopXMLNS, __IgnoreEls,
 +                                                     _el));
 +      <<"urn:ietf:params:xml:ns:xmpp-tls">> ->
 +        decode_starttls_els(__TopXMLNS, __IgnoreEls, _els,
 +                            decode_starttls_required(<<"urn:ietf:params:xml:ns:xmpp-tls">>,
 +                                                     __IgnoreEls, _el));
 +      _ ->
 +        decode_starttls_els(__TopXMLNS, __IgnoreEls, _els,
 +                            Required)
 +    end;
 +decode_starttls_els(__TopXMLNS, __IgnoreEls, [_ | _els],
 +                  Required) ->
 +    decode_starttls_els(__TopXMLNS, __IgnoreEls, _els,
 +                      Required).
 +
 +encode_starttls({starttls, Required}, __TopXMLNS) ->
 +    __NewTopXMLNS =
 +      choose_top_xmlns(<<"urn:ietf:params:xml:ns:xmpp-tls">>,
 +                       [], __TopXMLNS),
 +    _els =
 +      lists:reverse('encode_starttls_$required'(Required,
 +                                                __NewTopXMLNS, [])),
 +    _attrs = enc_xmlns_attrs(__NewTopXMLNS, __TopXMLNS),
 +    {xmlel, <<"starttls">>, _attrs, _els}.
 +
 +'encode_starttls_$required'(false, __TopXMLNS, _acc) ->
 +    _acc;
 +'encode_starttls_$required'(Required, __TopXMLNS,
 +                          _acc) ->
 +    [encode_starttls_required(Required, __TopXMLNS) | _acc].
 +
 +decode_starttls_required(__TopXMLNS, __IgnoreEls,
 +                       {xmlel, <<"required">>, _attrs, _els}) ->
 +    true.
 +
 +encode_starttls_required(true, __TopXMLNS) ->
 +    __NewTopXMLNS =
 +      choose_top_xmlns(<<"urn:ietf:params:xml:ns:xmpp-tls">>,
 +                       [], __TopXMLNS),
 +    _els = [],
 +    _attrs = enc_xmlns_attrs(__NewTopXMLNS, __TopXMLNS),
 +    {xmlel, <<"required">>, _attrs, _els}.
 +
 +decode_sasl_mechanisms(__TopXMLNS, __IgnoreEls,
 +                     {xmlel, <<"mechanisms">>, _attrs, _els}) ->
 +    List = decode_sasl_mechanisms_els(__TopXMLNS,
 +                                    __IgnoreEls, _els, []),
 +    {sasl_mechanisms, List}.
 +
 +decode_sasl_mechanisms_els(__TopXMLNS, __IgnoreEls, [],
 +                         List) ->
 +    lists:reverse(List);
 +decode_sasl_mechanisms_els(__TopXMLNS, __IgnoreEls,
 +                         [{xmlel, <<"mechanism">>, _attrs, _} = _el | _els],
 +                         List) ->
 +    case get_attr(<<"xmlns">>, _attrs) of
 +      <<"">>
 +        when __TopXMLNS ==
 +               <<"urn:ietf:params:xml:ns:xmpp-sasl">> ->
 +        decode_sasl_mechanisms_els(__TopXMLNS, __IgnoreEls,
 +                                   _els,
 +                                   [decode_sasl_mechanism(__TopXMLNS,
 +                                                          __IgnoreEls, _el)
 +                                    | List]);
 +      <<"urn:ietf:params:xml:ns:xmpp-sasl">> ->
 +        decode_sasl_mechanisms_els(__TopXMLNS, __IgnoreEls,
 +                                   _els,
 +                                   [decode_sasl_mechanism(<<"urn:ietf:params:xml:ns:xmpp-sasl">>,
 +                                                          __IgnoreEls, _el)
 +                                    | List]);
 +      _ ->
 +        decode_sasl_mechanisms_els(__TopXMLNS, __IgnoreEls,
 +                                   _els, List)
 +    end;
 +decode_sasl_mechanisms_els(__TopXMLNS, __IgnoreEls,
 +                         [_ | _els], List) ->
 +    decode_sasl_mechanisms_els(__TopXMLNS, __IgnoreEls,
 +                             _els, List).
 +
 +encode_sasl_mechanisms({sasl_mechanisms, List},
 +                     __TopXMLNS) ->
 +    __NewTopXMLNS =
 +      choose_top_xmlns(<<"urn:ietf:params:xml:ns:xmpp-sasl">>,
 +                       [], __TopXMLNS),
 +    _els =
 +      lists:reverse('encode_sasl_mechanisms_$list'(List,
 +                                                   __NewTopXMLNS, [])),
 +    _attrs = enc_xmlns_attrs(__NewTopXMLNS, __TopXMLNS),
 +    {xmlel, <<"mechanisms">>, _attrs, _els}.
 +
 +'encode_sasl_mechanisms_$list'([], __TopXMLNS, _acc) ->
 +    _acc;
 +'encode_sasl_mechanisms_$list'([List | _els],
 +                             __TopXMLNS, _acc) ->
 +    'encode_sasl_mechanisms_$list'(_els, __TopXMLNS,
 +                                 [encode_sasl_mechanism(List, __TopXMLNS)
 +                                  | _acc]).
 +
 +decode_sasl_mechanism(__TopXMLNS, __IgnoreEls,
 +                    {xmlel, <<"mechanism">>, _attrs, _els}) ->
 +    Cdata = decode_sasl_mechanism_els(__TopXMLNS,
 +                                    __IgnoreEls, _els, <<>>),
 +    Cdata.
 +
 +decode_sasl_mechanism_els(__TopXMLNS, __IgnoreEls, [],
 +                        Cdata) ->
 +    decode_sasl_mechanism_cdata(__TopXMLNS, Cdata);
 +decode_sasl_mechanism_els(__TopXMLNS, __IgnoreEls,
 +                        [{xmlcdata, _data} | _els], Cdata) ->
 +    decode_sasl_mechanism_els(__TopXMLNS, __IgnoreEls, _els,
 +                            <<Cdata/binary, _data/binary>>);
 +decode_sasl_mechanism_els(__TopXMLNS, __IgnoreEls,
 +                        [_ | _els], Cdata) ->
 +    decode_sasl_mechanism_els(__TopXMLNS, __IgnoreEls, _els,
 +                            Cdata).
 +
 +encode_sasl_mechanism(Cdata, __TopXMLNS) ->
 +    __NewTopXMLNS =
 +      choose_top_xmlns(<<"urn:ietf:params:xml:ns:xmpp-sasl">>,
 +                       [], __TopXMLNS),
 +    _els = encode_sasl_mechanism_cdata(Cdata, []),
 +    _attrs = enc_xmlns_attrs(__NewTopXMLNS, __TopXMLNS),
 +    {xmlel, <<"mechanism">>, _attrs, _els}.
 +
 +decode_sasl_mechanism_cdata(__TopXMLNS, <<>>) -> <<>>;
 +decode_sasl_mechanism_cdata(__TopXMLNS, _val) -> _val.
 +
 +encode_sasl_mechanism_cdata(<<>>, _acc) -> _acc;
 +encode_sasl_mechanism_cdata(_val, _acc) ->
 +    [{xmlcdata, _val} | _acc].
 +
 +decode_sasl_failure(__TopXMLNS, __IgnoreEls,
 +                  {xmlel, <<"failure">>, _attrs, _els}) ->
 +    {Text, Reason} = decode_sasl_failure_els(__TopXMLNS,
 +                                           __IgnoreEls, _els, [], undefined),
 +    {sasl_failure, Reason, Text}.
 +
 +decode_sasl_failure_els(__TopXMLNS, __IgnoreEls, [],
 +                      Text, Reason) ->
 +    {lists:reverse(Text), Reason};
 +decode_sasl_failure_els(__TopXMLNS, __IgnoreEls,
 +                      [{xmlel, <<"text">>, _attrs, _} = _el | _els], Text,
 +                      Reason) ->
 +    case get_attr(<<"xmlns">>, _attrs) of
 +      <<"">>
 +        when __TopXMLNS ==
 +               <<"urn:ietf:params:xml:ns:xmpp-sasl">> ->
 +        decode_sasl_failure_els(__TopXMLNS, __IgnoreEls, _els,
 +                                [decode_sasl_failure_text(__TopXMLNS,
 +                                                          __IgnoreEls, _el)
 +                                 | Text],
 +                                Reason);
 +      <<"urn:ietf:params:xml:ns:xmpp-sasl">> ->
 +        decode_sasl_failure_els(__TopXMLNS, __IgnoreEls, _els,
 +                                [decode_sasl_failure_text(<<"urn:ietf:params:xml:ns:xmpp-sasl">>,
 +                                                          __IgnoreEls, _el)
 +                                 | Text],
 +                                Reason);
 +      _ ->
 +        decode_sasl_failure_els(__TopXMLNS, __IgnoreEls, _els,
 +                                Text, Reason)
 +    end;
 +decode_sasl_failure_els(__TopXMLNS, __IgnoreEls,
 +                      [{xmlel, <<"aborted">>, _attrs, _} = _el | _els], Text,
 +                      Reason) ->
 +    case get_attr(<<"xmlns">>, _attrs) of
 +      <<"">>
 +        when __TopXMLNS ==
 +               <<"urn:ietf:params:xml:ns:xmpp-sasl">> ->
 +        decode_sasl_failure_els(__TopXMLNS, __IgnoreEls, _els,
 +                                Text,
 +                                decode_sasl_failure_aborted(__TopXMLNS,
 +                                                            __IgnoreEls,
 +                                                            _el));
 +      <<"urn:ietf:params:xml:ns:xmpp-sasl">> ->
 +        decode_sasl_failure_els(__TopXMLNS, __IgnoreEls, _els,
 +                                Text,
 +                                decode_sasl_failure_aborted(<<"urn:ietf:params:xml:ns:xmpp-sasl">>,
 +                                                            __IgnoreEls,
 +                                                            _el));
 +      _ ->
 +        decode_sasl_failure_els(__TopXMLNS, __IgnoreEls, _els,
 +                                Text, Reason)
 +    end;
 +decode_sasl_failure_els(__TopXMLNS, __IgnoreEls,
 +                      [{xmlel, <<"account-disabled">>, _attrs, _} = _el
 +                       | _els],
 +                      Text, Reason) ->
 +    case get_attr(<<"xmlns">>, _attrs) of
 +      <<"">>
 +        when __TopXMLNS ==
 +               <<"urn:ietf:params:xml:ns:xmpp-sasl">> ->
 +        decode_sasl_failure_els(__TopXMLNS, __IgnoreEls, _els,
 +                                Text,
 +                                decode_sasl_failure_account_disabled(__TopXMLNS,
 +                                                                     __IgnoreEls,
 +                                                                     _el));
 +      <<"urn:ietf:params:xml:ns:xmpp-sasl">> ->
 +        decode_sasl_failure_els(__TopXMLNS, __IgnoreEls, _els,
 +                                Text,
 +                                decode_sasl_failure_account_disabled(<<"urn:ietf:params:xml:ns:xmpp-sasl">>,
 +                                                                     __IgnoreEls,
 +                                                                     _el));
 +      _ ->
 +        decode_sasl_failure_els(__TopXMLNS, __IgnoreEls, _els,
 +                                Text, Reason)
 +    end;
 +decode_sasl_failure_els(__TopXMLNS, __IgnoreEls,
 +                      [{xmlel, <<"credentials-expired">>, _attrs, _} = _el
 +                       | _els],
 +                      Text, Reason) ->
 +    case get_attr(<<"xmlns">>, _attrs) of
 +      <<"">>
 +        when __TopXMLNS ==
 +               <<"urn:ietf:params:xml:ns:xmpp-sasl">> ->
 +        decode_sasl_failure_els(__TopXMLNS, __IgnoreEls, _els,
 +                                Text,
 +                                decode_sasl_failure_credentials_expired(__TopXMLNS,
 +                                                                        __IgnoreEls,
 +                                                                        _el));
 +      <<"urn:ietf:params:xml:ns:xmpp-sasl">> ->
 +        decode_sasl_failure_els(__TopXMLNS, __IgnoreEls, _els,
 +                                Text,
 +                                decode_sasl_failure_credentials_expired(<<"urn:ietf:params:xml:ns:xmpp-sasl">>,
 +                                                                        __IgnoreEls,
 +                                                                        _el));
 +      _ ->
 +        decode_sasl_failure_els(__TopXMLNS, __IgnoreEls, _els,
 +                                Text, Reason)
 +    end;
 +decode_sasl_failure_els(__TopXMLNS, __IgnoreEls,
 +                      [{xmlel, <<"encryption-required">>, _attrs, _} = _el
 +                       | _els],
 +                      Text, Reason) ->
 +    case get_attr(<<"xmlns">>, _attrs) of
 +      <<"">>
 +        when __TopXMLNS ==
 +               <<"urn:ietf:params:xml:ns:xmpp-sasl">> ->
 +        decode_sasl_failure_els(__TopXMLNS, __IgnoreEls, _els,
 +                                Text,
 +                                decode_sasl_failure_encryption_required(__TopXMLNS,
 +                                                                        __IgnoreEls,
 +                                                                        _el));
 +      <<"urn:ietf:params:xml:ns:xmpp-sasl">> ->
 +        decode_sasl_failure_els(__TopXMLNS, __IgnoreEls, _els,
 +                                Text,
 +                                decode_sasl_failure_encryption_required(<<"urn:ietf:params:xml:ns:xmpp-sasl">>,
 +                                                                        __IgnoreEls,
 +                                                                        _el));
 +      _ ->
 +        decode_sasl_failure_els(__TopXMLNS, __IgnoreEls, _els,
 +                                Text, Reason)
 +    end;
 +decode_sasl_failure_els(__TopXMLNS, __IgnoreEls,
 +                      [{xmlel, <<"incorrect-encoding">>, _attrs, _} = _el
 +                       | _els],
 +                      Text, Reason) ->
 +    case get_attr(<<"xmlns">>, _attrs) of
 +      <<"">>
 +        when __TopXMLNS ==
 +               <<"urn:ietf:params:xml:ns:xmpp-sasl">> ->
 +        decode_sasl_failure_els(__TopXMLNS, __IgnoreEls, _els,
 +                                Text,
 +                                decode_sasl_failure_incorrect_encoding(__TopXMLNS,
 +                                                                       __IgnoreEls,
 +                                                                       _el));
 +      <<"urn:ietf:params:xml:ns:xmpp-sasl">> ->
 +        decode_sasl_failure_els(__TopXMLNS, __IgnoreEls, _els,
 +                                Text,
 +                                decode_sasl_failure_incorrect_encoding(<<"urn:ietf:params:xml:ns:xmpp-sasl">>,
 +                                                                       __IgnoreEls,
 +                                                                       _el));
 +      _ ->
 +        decode_sasl_failure_els(__TopXMLNS, __IgnoreEls, _els,
 +                                Text, Reason)
 +    end;
 +decode_sasl_failure_els(__TopXMLNS, __IgnoreEls,
 +                      [{xmlel, <<"invalid-authzid">>, _attrs, _} = _el
 +                       | _els],
 +                      Text, Reason) ->
 +    case get_attr(<<"xmlns">>, _attrs) of
 +      <<"">>
 +        when __TopXMLNS ==
 +               <<"urn:ietf:params:xml:ns:xmpp-sasl">> ->
 +        decode_sasl_failure_els(__TopXMLNS, __IgnoreEls, _els,
 +                                Text,
 +                                decode_sasl_failure_invalid_authzid(__TopXMLNS,
 +                                                                    __IgnoreEls,
 +                                                                    _el));
 +      <<"urn:ietf:params:xml:ns:xmpp-sasl">> ->
 +        decode_sasl_failure_els(__TopXMLNS, __IgnoreEls, _els,
 +                                Text,
 +                                decode_sasl_failure_invalid_authzid(<<"urn:ietf:params:xml:ns:xmpp-sasl">>,
 +                                                                    __IgnoreEls,
 +                                                                    _el));
 +      _ ->
 +        decode_sasl_failure_els(__TopXMLNS, __IgnoreEls, _els,
 +                                Text, Reason)
 +    end;
 +decode_sasl_failure_els(__TopXMLNS, __IgnoreEls,
 +                      [{xmlel, <<"invalid-mechanism">>, _attrs, _} = _el
 +                       | _els],
 +                      Text, Reason) ->
 +    case get_attr(<<"xmlns">>, _attrs) of
 +      <<"">>
 +        when __TopXMLNS ==
 +               <<"urn:ietf:params:xml:ns:xmpp-sasl">> ->
 +        decode_sasl_failure_els(__TopXMLNS, __IgnoreEls, _els,
 +                                Text,
 +                                decode_sasl_failure_invalid_mechanism(__TopXMLNS,
 +                                                                      __IgnoreEls,
 +                                                                      _el));
 +      <<"urn:ietf:params:xml:ns:xmpp-sasl">> ->
 +        decode_sasl_failure_els(__TopXMLNS, __IgnoreEls, _els,
 +                                Text,
 +                                decode_sasl_failure_invalid_mechanism(<<"urn:ietf:params:xml:ns:xmpp-sasl">>,
 +                                                                      __IgnoreEls,
 +                                                                      _el));
 +      _ ->
 +        decode_sasl_failure_els(__TopXMLNS, __IgnoreEls, _els,
 +                                Text, Reason)
 +    end;
 +decode_sasl_failure_els(__TopXMLNS, __IgnoreEls,
 +                      [{xmlel, <<"malformed-request">>, _attrs, _} = _el
 +                       | _els],
 +                      Text, Reason) ->
 +    case get_attr(<<"xmlns">>, _attrs) of
 +      <<"">>
 +        when __TopXMLNS ==
 +               <<"urn:ietf:params:xml:ns:xmpp-sasl">> ->
 +        decode_sasl_failure_els(__TopXMLNS, __IgnoreEls, _els,
 +                                Text,
 +                                decode_sasl_failure_malformed_request(__TopXMLNS,
 +                                                                      __IgnoreEls,
 +                                                                      _el));
 +      <<"urn:ietf:params:xml:ns:xmpp-sasl">> ->
 +        decode_sasl_failure_els(__TopXMLNS, __IgnoreEls, _els,
 +                                Text,
 +                                decode_sasl_failure_malformed_request(<<"urn:ietf:params:xml:ns:xmpp-sasl">>,
 +                                                                      __IgnoreEls,
 +                                                                      _el));
 +      _ ->
 +        decode_sasl_failure_els(__TopXMLNS, __IgnoreEls, _els,
 +                                Text, Reason)
 +    end;
 +decode_sasl_failure_els(__TopXMLNS, __IgnoreEls,
 +                      [{xmlel, <<"mechanism-too-weak">>, _attrs, _} = _el
 +                       | _els],
 +                      Text, Reason) ->
 +    case get_attr(<<"xmlns">>, _attrs) of
 +      <<"">>
 +        when __TopXMLNS ==
 +               <<"urn:ietf:params:xml:ns:xmpp-sasl">> ->
 +        decode_sasl_failure_els(__TopXMLNS, __IgnoreEls, _els,
 +                                Text,
 +                                decode_sasl_failure_mechanism_too_weak(__TopXMLNS,
 +                                                                       __IgnoreEls,
 +                                                                       _el));
 +      <<"urn:ietf:params:xml:ns:xmpp-sasl">> ->
 +        decode_sasl_failure_els(__TopXMLNS, __IgnoreEls, _els,
 +                                Text,
 +                                decode_sasl_failure_mechanism_too_weak(<<"urn:ietf:params:xml:ns:xmpp-sasl">>,
 +                                                                       __IgnoreEls,
 +                                                                       _el));
 +      _ ->
 +        decode_sasl_failure_els(__TopXMLNS, __IgnoreEls, _els,
 +                                Text, Reason)
 +    end;
 +decode_sasl_failure_els(__TopXMLNS, __IgnoreEls,
 +                      [{xmlel, <<"not-authorized">>, _attrs, _} = _el | _els],
 +                      Text, Reason) ->
 +    case get_attr(<<"xmlns">>, _attrs) of
 +      <<"">>
 +        when __TopXMLNS ==
 +               <<"urn:ietf:params:xml:ns:xmpp-sasl">> ->
 +        decode_sasl_failure_els(__TopXMLNS, __IgnoreEls, _els,
 +                                Text,
 +                                decode_sasl_failure_not_authorized(__TopXMLNS,
 +                                                                   __IgnoreEls,
 +                                                                   _el));
 +      <<"urn:ietf:params:xml:ns:xmpp-sasl">> ->
 +        decode_sasl_failure_els(__TopXMLNS, __IgnoreEls, _els,
 +                                Text,
 +                                decode_sasl_failure_not_authorized(<<"urn:ietf:params:xml:ns:xmpp-sasl">>,
 +                                                                   __IgnoreEls,
 +                                                                   _el));
 +      _ ->
 +        decode_sasl_failure_els(__TopXMLNS, __IgnoreEls, _els,
 +                                Text, Reason)
 +    end;
 +decode_sasl_failure_els(__TopXMLNS, __IgnoreEls,
 +                      [{xmlel, <<"bad-protocol">>, _attrs, _} = _el | _els],
 +                      Text, Reason) ->
 +    case get_attr(<<"xmlns">>, _attrs) of
 +      <<"">>
 +        when __TopXMLNS ==
 +               <<"urn:ietf:params:xml:ns:xmpp-sasl">> ->
 +        decode_sasl_failure_els(__TopXMLNS, __IgnoreEls, _els,
 +                                Text,
 +                                decode_sasl_failure_bad_protocol(__TopXMLNS,
 +                                                                 __IgnoreEls,
 +                                                                 _el));
 +      <<"urn:ietf:params:xml:ns:xmpp-sasl">> ->
 +        decode_sasl_failure_els(__TopXMLNS, __IgnoreEls, _els,
 +                                Text,
 +                                decode_sasl_failure_bad_protocol(<<"urn:ietf:params:xml:ns:xmpp-sasl">>,
 +                                                                 __IgnoreEls,
 +                                                                 _el));
 +      _ ->
 +        decode_sasl_failure_els(__TopXMLNS, __IgnoreEls, _els,
 +                                Text, Reason)
 +    end;
 +decode_sasl_failure_els(__TopXMLNS, __IgnoreEls,
 +                      [{xmlel, <<"temporary-auth-failure">>, _attrs, _} = _el
 +                       | _els],
 +                      Text, Reason) ->
 +    case get_attr(<<"xmlns">>, _attrs) of
 +      <<"">>
 +        when __TopXMLNS ==
 +               <<"urn:ietf:params:xml:ns:xmpp-sasl">> ->
 +        decode_sasl_failure_els(__TopXMLNS, __IgnoreEls, _els,
 +                                Text,
 +                                decode_sasl_failure_temporary_auth_failure(__TopXMLNS,
 +                                                                           __IgnoreEls,
 +                                                                           _el));
 +      <<"urn:ietf:params:xml:ns:xmpp-sasl">> ->
 +        decode_sasl_failure_els(__TopXMLNS, __IgnoreEls, _els,
 +                                Text,
 +                                decode_sasl_failure_temporary_auth_failure(<<"urn:ietf:params:xml:ns:xmpp-sasl">>,
 +                                                                           __IgnoreEls,
 +                                                                           _el));
 +      _ ->
 +        decode_sasl_failure_els(__TopXMLNS, __IgnoreEls, _els,
 +                                Text, Reason)
 +    end;
 +decode_sasl_failure_els(__TopXMLNS, __IgnoreEls,
 +                      [_ | _els], Text, Reason) ->
 +    decode_sasl_failure_els(__TopXMLNS, __IgnoreEls, _els,
 +                          Text, Reason).
 +
 +encode_sasl_failure({sasl_failure, Reason, Text},
 +                  __TopXMLNS) ->
 +    __NewTopXMLNS =
 +      choose_top_xmlns(<<"urn:ietf:params:xml:ns:xmpp-sasl">>,
 +                       [], __TopXMLNS),
 +    _els = lists:reverse('encode_sasl_failure_$text'(Text,
 +                                                   __NewTopXMLNS,
 +                                                   'encode_sasl_failure_$reason'(Reason,
 +                                                                                 __NewTopXMLNS,
 +                                                                                 []))),
 +    _attrs = enc_xmlns_attrs(__NewTopXMLNS, __TopXMLNS),
 +    {xmlel, <<"failure">>, _attrs, _els}.
 +
 +'encode_sasl_failure_$text'([], __TopXMLNS, _acc) ->
 +    _acc;
 +'encode_sasl_failure_$text'([Text | _els], __TopXMLNS,
 +                          _acc) ->
 +    'encode_sasl_failure_$text'(_els, __TopXMLNS,
 +                              [encode_sasl_failure_text(Text, __TopXMLNS)
 +                               | _acc]).
 +
 +'encode_sasl_failure_$reason'(undefined, __TopXMLNS,
 +                            _acc) ->
 +    _acc;
 +'encode_sasl_failure_$reason'(aborted = Reason,
 +                            __TopXMLNS, _acc) ->
 +    [encode_sasl_failure_aborted(Reason, __TopXMLNS)
 +     | _acc];
 +'encode_sasl_failure_$reason'('account-disabled' =
 +                                Reason,
 +                            __TopXMLNS, _acc) ->
 +    [encode_sasl_failure_account_disabled(Reason,
 +                                        __TopXMLNS)
 +     | _acc];
 +'encode_sasl_failure_$reason'('credentials-expired' =
 +                                Reason,
 +                            __TopXMLNS, _acc) ->
 +    [encode_sasl_failure_credentials_expired(Reason,
 +                                           __TopXMLNS)
 +     | _acc];
 +'encode_sasl_failure_$reason'('encryption-required' =
 +                                Reason,
 +                            __TopXMLNS, _acc) ->
 +    [encode_sasl_failure_encryption_required(Reason,
 +                                           __TopXMLNS)
 +     | _acc];
 +'encode_sasl_failure_$reason'('incorrect-encoding' =
 +                                Reason,
 +                            __TopXMLNS, _acc) ->
 +    [encode_sasl_failure_incorrect_encoding(Reason,
 +                                          __TopXMLNS)
 +     | _acc];
 +'encode_sasl_failure_$reason'('invalid-authzid' =
 +                                Reason,
 +                            __TopXMLNS, _acc) ->
 +    [encode_sasl_failure_invalid_authzid(Reason, __TopXMLNS)
 +     | _acc];
 +'encode_sasl_failure_$reason'('invalid-mechanism' =
 +                                Reason,
 +                            __TopXMLNS, _acc) ->
 +    [encode_sasl_failure_invalid_mechanism(Reason,
 +                                         __TopXMLNS)
 +     | _acc];
 +'encode_sasl_failure_$reason'('malformed-request' =
 +                                Reason,
 +                            __TopXMLNS, _acc) ->
 +    [encode_sasl_failure_malformed_request(Reason,
 +                                         __TopXMLNS)
 +     | _acc];
 +'encode_sasl_failure_$reason'('mechanism-too-weak' =
 +                                Reason,
 +                            __TopXMLNS, _acc) ->
 +    [encode_sasl_failure_mechanism_too_weak(Reason,
 +                                          __TopXMLNS)
 +     | _acc];
 +'encode_sasl_failure_$reason'('not-authorized' = Reason,
 +                            __TopXMLNS, _acc) ->
 +    [encode_sasl_failure_not_authorized(Reason, __TopXMLNS)
 +     | _acc];
 +'encode_sasl_failure_$reason'('bad-protocol' = Reason,
 +                            __TopXMLNS, _acc) ->
 +    [encode_sasl_failure_bad_protocol(Reason, __TopXMLNS)
 +     | _acc];
 +'encode_sasl_failure_$reason'('temporary-auth-failure' =
 +                                Reason,
 +                            __TopXMLNS, _acc) ->
 +    [encode_sasl_failure_temporary_auth_failure(Reason,
 +                                              __TopXMLNS)
 +     | _acc].
 +
 +decode_sasl_failure_temporary_auth_failure(__TopXMLNS,
 +                                         __IgnoreEls,
 +                                         {xmlel, <<"temporary-auth-failure">>,
 +                                          _attrs, _els}) ->
 +    'temporary-auth-failure'.
 +
 +encode_sasl_failure_temporary_auth_failure('temporary-auth-failure',
 +                                         __TopXMLNS) ->
 +    __NewTopXMLNS =
 +      choose_top_xmlns(<<"urn:ietf:params:xml:ns:xmpp-sasl">>,
 +                       [], __TopXMLNS),
 +    _els = [],
 +    _attrs = enc_xmlns_attrs(__NewTopXMLNS, __TopXMLNS),
 +    {xmlel, <<"temporary-auth-failure">>, _attrs, _els}.
 +
 +decode_sasl_failure_bad_protocol(__TopXMLNS,
 +                               __IgnoreEls,
 +                               {xmlel, <<"bad-protocol">>, _attrs, _els}) ->
 +    'bad-protocol'.
 +
 +encode_sasl_failure_bad_protocol('bad-protocol',
 +                               __TopXMLNS) ->
 +    __NewTopXMLNS =
 +      choose_top_xmlns(<<"urn:ietf:params:xml:ns:xmpp-sasl">>,
 +                       [], __TopXMLNS),
 +    _els = [],
 +    _attrs = enc_xmlns_attrs(__NewTopXMLNS, __TopXMLNS),
 +    {xmlel, <<"bad-protocol">>, _attrs, _els}.
 +
 +decode_sasl_failure_not_authorized(__TopXMLNS,
 +                                 __IgnoreEls,
 +                                 {xmlel, <<"not-authorized">>, _attrs,
 +                                  _els}) ->
 +    'not-authorized'.
 +
 +encode_sasl_failure_not_authorized('not-authorized',
 +                                 __TopXMLNS) ->
 +    __NewTopXMLNS =
 +      choose_top_xmlns(<<"urn:ietf:params:xml:ns:xmpp-sasl">>,
 +                       [], __TopXMLNS),
 +    _els = [],
 +    _attrs = enc_xmlns_attrs(__NewTopXMLNS, __TopXMLNS),
 +    {xmlel, <<"not-authorized">>, _attrs, _els}.
 +
 +decode_sasl_failure_mechanism_too_weak(__TopXMLNS,
 +                                     __IgnoreEls,
 +                                     {xmlel, <<"mechanism-too-weak">>, _attrs,
 +                                      _els}) ->
 +    'mechanism-too-weak'.
 +
 +encode_sasl_failure_mechanism_too_weak('mechanism-too-weak',
 +                                     __TopXMLNS) ->
 +    __NewTopXMLNS =
 +      choose_top_xmlns(<<"urn:ietf:params:xml:ns:xmpp-sasl">>,
 +                       [], __TopXMLNS),
 +    _els = [],
 +    _attrs = enc_xmlns_attrs(__NewTopXMLNS, __TopXMLNS),
 +    {xmlel, <<"mechanism-too-weak">>, _attrs, _els}.
 +
 +decode_sasl_failure_malformed_request(__TopXMLNS,
 +                                    __IgnoreEls,
 +                                    {xmlel, <<"malformed-request">>, _attrs,
 +                                     _els}) ->
 +    'malformed-request'.
 +
 +encode_sasl_failure_malformed_request('malformed-request',
 +                                    __TopXMLNS) ->
 +    __NewTopXMLNS =
 +      choose_top_xmlns(<<"urn:ietf:params:xml:ns:xmpp-sasl">>,
 +                       [], __TopXMLNS),
 +    _els = [],
 +    _attrs = enc_xmlns_attrs(__NewTopXMLNS, __TopXMLNS),
 +    {xmlel, <<"malformed-request">>, _attrs, _els}.
 +
 +decode_sasl_failure_invalid_mechanism(__TopXMLNS,
 +                                    __IgnoreEls,
 +                                    {xmlel, <<"invalid-mechanism">>, _attrs,
 +                                     _els}) ->
 +    'invalid-mechanism'.
 +
 +encode_sasl_failure_invalid_mechanism('invalid-mechanism',
 +                                    __TopXMLNS) ->
 +    __NewTopXMLNS =
 +      choose_top_xmlns(<<"urn:ietf:params:xml:ns:xmpp-sasl">>,
 +                       [], __TopXMLNS),
 +    _els = [],
 +    _attrs = enc_xmlns_attrs(__NewTopXMLNS, __TopXMLNS),
 +    {xmlel, <<"invalid-mechanism">>, _attrs, _els}.
 +
 +decode_sasl_failure_invalid_authzid(__TopXMLNS,
 +                                  __IgnoreEls,
 +                                  {xmlel, <<"invalid-authzid">>, _attrs,
 +                                   _els}) ->
 +    'invalid-authzid'.
 +
 +encode_sasl_failure_invalid_authzid('invalid-authzid',
 +                                  __TopXMLNS) ->
 +    __NewTopXMLNS =
 +      choose_top_xmlns(<<"urn:ietf:params:xml:ns:xmpp-sasl">>,
 +                       [], __TopXMLNS),
 +    _els = [],
 +    _attrs = enc_xmlns_attrs(__NewTopXMLNS, __TopXMLNS),
 +    {xmlel, <<"invalid-authzid">>, _attrs, _els}.
 +
 +decode_sasl_failure_incorrect_encoding(__TopXMLNS,
 +                                     __IgnoreEls,
 +                                     {xmlel, <<"incorrect-encoding">>, _attrs,
 +                                      _els}) ->
 +    'incorrect-encoding'.
 +
 +encode_sasl_failure_incorrect_encoding('incorrect-encoding',
 +                                     __TopXMLNS) ->
 +    __NewTopXMLNS =
 +      choose_top_xmlns(<<"urn:ietf:params:xml:ns:xmpp-sasl">>,
 +                       [], __TopXMLNS),
 +    _els = [],
 +    _attrs = enc_xmlns_attrs(__NewTopXMLNS, __TopXMLNS),
 +    {xmlel, <<"incorrect-encoding">>, _attrs, _els}.
 +
 +decode_sasl_failure_encryption_required(__TopXMLNS,
 +                                      __IgnoreEls,
 +                                      {xmlel, <<"encryption-required">>,
 +                                       _attrs, _els}) ->
 +    'encryption-required'.
 +
 +encode_sasl_failure_encryption_required('encryption-required',
 +                                      __TopXMLNS) ->
 +    __NewTopXMLNS =
 +      choose_top_xmlns(<<"urn:ietf:params:xml:ns:xmpp-sasl">>,
 +                       [], __TopXMLNS),
 +    _els = [],
 +    _attrs = enc_xmlns_attrs(__NewTopXMLNS, __TopXMLNS),
 +    {xmlel, <<"encryption-required">>, _attrs, _els}.
 +
 +decode_sasl_failure_credentials_expired(__TopXMLNS,
 +                                      __IgnoreEls,
 +                                      {xmlel, <<"credentials-expired">>,
 +                                       _attrs, _els}) ->
 +    'credentials-expired'.
 +
 +encode_sasl_failure_credentials_expired('credentials-expired',
 +                                      __TopXMLNS) ->
 +    __NewTopXMLNS =
 +      choose_top_xmlns(<<"urn:ietf:params:xml:ns:xmpp-sasl">>,
 +                       [], __TopXMLNS),
 +    _els = [],
 +    _attrs = enc_xmlns_attrs(__NewTopXMLNS, __TopXMLNS),
 +    {xmlel, <<"credentials-expired">>, _attrs, _els}.
 +
 +decode_sasl_failure_account_disabled(__TopXMLNS,
 +                                   __IgnoreEls,
 +                                   {xmlel, <<"account-disabled">>, _attrs,
 +                                    _els}) ->
 +    'account-disabled'.
 +
 +encode_sasl_failure_account_disabled('account-disabled',
 +                                   __TopXMLNS) ->
 +    __NewTopXMLNS =
 +      choose_top_xmlns(<<"urn:ietf:params:xml:ns:xmpp-sasl">>,
 +                       [], __TopXMLNS),
 +    _els = [],
 +    _attrs = enc_xmlns_attrs(__NewTopXMLNS, __TopXMLNS),
 +    {xmlel, <<"account-disabled">>, _attrs, _els}.
 +
 +decode_sasl_failure_aborted(__TopXMLNS, __IgnoreEls,
 +                          {xmlel, <<"aborted">>, _attrs, _els}) ->
 +    aborted.
 +
 +encode_sasl_failure_aborted(aborted, __TopXMLNS) ->
 +    __NewTopXMLNS =
 +      choose_top_xmlns(<<"urn:ietf:params:xml:ns:xmpp-sasl">>,
 +                       [], __TopXMLNS),
 +    _els = [],
 +    _attrs = enc_xmlns_attrs(__NewTopXMLNS, __TopXMLNS),
 +    {xmlel, <<"aborted">>, _attrs, _els}.
 +
 +decode_sasl_failure_text(__TopXMLNS, __IgnoreEls,
 +                       {xmlel, <<"text">>, _attrs, _els}) ->
 +    Data = decode_sasl_failure_text_els(__TopXMLNS,
 +                                      __IgnoreEls, _els, <<>>),
 +    Lang = decode_sasl_failure_text_attrs(__TopXMLNS,
 +                                        _attrs, undefined),
 +    {text, Lang, Data}.
 +
 +decode_sasl_failure_text_els(__TopXMLNS, __IgnoreEls,
 +                           [], Data) ->
 +    decode_sasl_failure_text_cdata(__TopXMLNS, Data);
 +decode_sasl_failure_text_els(__TopXMLNS, __IgnoreEls,
 +                           [{xmlcdata, _data} | _els], Data) ->
 +    decode_sasl_failure_text_els(__TopXMLNS, __IgnoreEls,
 +                               _els, <<Data/binary, _data/binary>>);
 +decode_sasl_failure_text_els(__TopXMLNS, __IgnoreEls,
 +                           [_ | _els], Data) ->
 +    decode_sasl_failure_text_els(__TopXMLNS, __IgnoreEls,
 +                               _els, Data).
 +
 +decode_sasl_failure_text_attrs(__TopXMLNS,
 +                             [{<<"xml:lang">>, _val} | _attrs], _Lang) ->
 +    decode_sasl_failure_text_attrs(__TopXMLNS, _attrs,
 +                                 _val);
 +decode_sasl_failure_text_attrs(__TopXMLNS, [_ | _attrs],
 +                             Lang) ->
 +    decode_sasl_failure_text_attrs(__TopXMLNS, _attrs,
 +                                 Lang);
 +decode_sasl_failure_text_attrs(__TopXMLNS, [], Lang) ->
 +    'decode_sasl_failure_text_attr_xml:lang'(__TopXMLNS,
 +                                           Lang).
 +
 +encode_sasl_failure_text({text, Lang, Data},
 +                       __TopXMLNS) ->
 +    __NewTopXMLNS =
 +      choose_top_xmlns(<<"urn:ietf:params:xml:ns:xmpp-sasl">>,
 +                       [], __TopXMLNS),
 +    _els = encode_sasl_failure_text_cdata(Data, []),
 +    _attrs = 'encode_sasl_failure_text_attr_xml:lang'(Lang,
 +                                                    enc_xmlns_attrs(__NewTopXMLNS,
 +                                                                    __TopXMLNS)),
 +    {xmlel, <<"text">>, _attrs, _els}.
 +
 +'decode_sasl_failure_text_attr_xml:lang'(__TopXMLNS,
 +                                       undefined) ->
 +    <<>>;
 +'decode_sasl_failure_text_attr_xml:lang'(__TopXMLNS,
 +                                       _val) ->
 +    _val.
 +
 +'encode_sasl_failure_text_attr_xml:lang'(<<>>, _acc) ->
 +    _acc;
 +'encode_sasl_failure_text_attr_xml:lang'(_val, _acc) ->
 +    [{<<"xml:lang">>, _val} | _acc].
 +
 +decode_sasl_failure_text_cdata(__TopXMLNS, <<>>) ->
 +    <<>>;
 +decode_sasl_failure_text_cdata(__TopXMLNS, _val) ->
 +    _val.
 +
 +encode_sasl_failure_text_cdata(<<>>, _acc) -> _acc;
 +encode_sasl_failure_text_cdata(_val, _acc) ->
 +    [{xmlcdata, _val} | _acc].
 +
 +decode_sasl_success(__TopXMLNS, __IgnoreEls,
 +                  {xmlel, <<"success">>, _attrs, _els}) ->
 +    Text = decode_sasl_success_els(__TopXMLNS, __IgnoreEls,
 +                                 _els, <<>>),
 +    {sasl_success, Text}.
 +
 +decode_sasl_success_els(__TopXMLNS, __IgnoreEls, [],
 +                      Text) ->
 +    decode_sasl_success_cdata(__TopXMLNS, Text);
 +decode_sasl_success_els(__TopXMLNS, __IgnoreEls,
 +                      [{xmlcdata, _data} | _els], Text) ->
 +    decode_sasl_success_els(__TopXMLNS, __IgnoreEls, _els,
 +                          <<Text/binary, _data/binary>>);
 +decode_sasl_success_els(__TopXMLNS, __IgnoreEls,
 +                      [_ | _els], Text) ->
 +    decode_sasl_success_els(__TopXMLNS, __IgnoreEls, _els,
 +                          Text).
 +
 +encode_sasl_success({sasl_success, Text}, __TopXMLNS) ->
 +    __NewTopXMLNS =
 +      choose_top_xmlns(<<"urn:ietf:params:xml:ns:xmpp-sasl">>,
 +                       [], __TopXMLNS),
 +    _els = encode_sasl_success_cdata(Text, []),
 +    _attrs = enc_xmlns_attrs(__NewTopXMLNS, __TopXMLNS),
 +    {xmlel, <<"success">>, _attrs, _els}.
 +
 +decode_sasl_success_cdata(__TopXMLNS, <<>>) -> <<>>;
 +decode_sasl_success_cdata(__TopXMLNS, _val) ->
 +    case catch base64:mime_decode(_val) of
 +      {'EXIT', _} ->
 +        erlang:error({xmpp_codec,
 +                      {bad_cdata_value, <<>>, <<"success">>, __TopXMLNS}});
 +      _res -> _res
 +    end.
 +
 +encode_sasl_success_cdata(<<>>, _acc) -> _acc;
 +encode_sasl_success_cdata(_val, _acc) ->
 +    [{xmlcdata, base64:encode(_val)} | _acc].
 +
 +decode_sasl_response(__TopXMLNS, __IgnoreEls,
 +                   {xmlel, <<"response">>, _attrs, _els}) ->
 +    Text = decode_sasl_response_els(__TopXMLNS, __IgnoreEls,
 +                                  _els, <<>>),
 +    {sasl_response, Text}.
 +
 +decode_sasl_response_els(__TopXMLNS, __IgnoreEls, [],
 +                       Text) ->
 +    decode_sasl_response_cdata(__TopXMLNS, Text);
 +decode_sasl_response_els(__TopXMLNS, __IgnoreEls,
 +                       [{xmlcdata, _data} | _els], Text) ->
 +    decode_sasl_response_els(__TopXMLNS, __IgnoreEls, _els,
 +                           <<Text/binary, _data/binary>>);
 +decode_sasl_response_els(__TopXMLNS, __IgnoreEls,
 +                       [_ | _els], Text) ->
 +    decode_sasl_response_els(__TopXMLNS, __IgnoreEls, _els,
 +                           Text).
 +
 +encode_sasl_response({sasl_response, Text},
 +                   __TopXMLNS) ->
 +    __NewTopXMLNS =
 +      choose_top_xmlns(<<"urn:ietf:params:xml:ns:xmpp-sasl">>,
 +                       [], __TopXMLNS),
 +    _els = encode_sasl_response_cdata(Text, []),
 +    _attrs = enc_xmlns_attrs(__NewTopXMLNS, __TopXMLNS),
 +    {xmlel, <<"response">>, _attrs, _els}.
 +
 +decode_sasl_response_cdata(__TopXMLNS, <<>>) -> <<>>;
 +decode_sasl_response_cdata(__TopXMLNS, _val) ->
 +    case catch base64:mime_decode(_val) of
 +      {'EXIT', _} ->
 +        erlang:error({xmpp_codec,
 +                      {bad_cdata_value, <<>>, <<"response">>, __TopXMLNS}});
 +      _res -> _res
 +    end.
 +
 +encode_sasl_response_cdata(<<>>, _acc) -> _acc;
 +encode_sasl_response_cdata(_val, _acc) ->
 +    [{xmlcdata, base64:encode(_val)} | _acc].
 +
 +decode_sasl_challenge(__TopXMLNS, __IgnoreEls,
 +                    {xmlel, <<"challenge">>, _attrs, _els}) ->
 +    Text = decode_sasl_challenge_els(__TopXMLNS,
 +                                   __IgnoreEls, _els, <<>>),
 +    {sasl_challenge, Text}.
 +
 +decode_sasl_challenge_els(__TopXMLNS, __IgnoreEls, [],
 +                        Text) ->
 +    decode_sasl_challenge_cdata(__TopXMLNS, Text);
 +decode_sasl_challenge_els(__TopXMLNS, __IgnoreEls,
 +                        [{xmlcdata, _data} | _els], Text) ->
 +    decode_sasl_challenge_els(__TopXMLNS, __IgnoreEls, _els,
 +                            <<Text/binary, _data/binary>>);
 +decode_sasl_challenge_els(__TopXMLNS, __IgnoreEls,
 +                        [_ | _els], Text) ->
 +    decode_sasl_challenge_els(__TopXMLNS, __IgnoreEls, _els,
 +                            Text).
 +
 +encode_sasl_challenge({sasl_challenge, Text},
 +                    __TopXMLNS) ->
 +    __NewTopXMLNS =
 +      choose_top_xmlns(<<"urn:ietf:params:xml:ns:xmpp-sasl">>,
 +                       [], __TopXMLNS),
 +    _els = encode_sasl_challenge_cdata(Text, []),
 +    _attrs = enc_xmlns_attrs(__NewTopXMLNS, __TopXMLNS),
 +    {xmlel, <<"challenge">>, _attrs, _els}.
 +
 +decode_sasl_challenge_cdata(__TopXMLNS, <<>>) -> <<>>;
 +decode_sasl_challenge_cdata(__TopXMLNS, _val) ->
 +    case catch base64:mime_decode(_val) of
 +      {'EXIT', _} ->
 +        erlang:error({xmpp_codec,
 +                      {bad_cdata_value, <<>>, <<"challenge">>, __TopXMLNS}});
 +      _res -> _res
 +    end.
 +
 +encode_sasl_challenge_cdata(<<>>, _acc) -> _acc;
 +encode_sasl_challenge_cdata(_val, _acc) ->
 +    [{xmlcdata, base64:encode(_val)} | _acc].
 +
 +decode_sasl_abort(__TopXMLNS, __IgnoreEls,
 +                {xmlel, <<"abort">>, _attrs, _els}) ->
 +    {sasl_abort}.
 +
 +encode_sasl_abort({sasl_abort}, __TopXMLNS) ->
 +    __NewTopXMLNS =
 +      choose_top_xmlns(<<"urn:ietf:params:xml:ns:xmpp-sasl">>,
 +                       [], __TopXMLNS),
 +    _els = [],
 +    _attrs = enc_xmlns_attrs(__NewTopXMLNS, __TopXMLNS),
 +    {xmlel, <<"abort">>, _attrs, _els}.
 +
 +decode_sasl_auth(__TopXMLNS, __IgnoreEls,
 +               {xmlel, <<"auth">>, _attrs, _els}) ->
 +    Text = decode_sasl_auth_els(__TopXMLNS, __IgnoreEls,
 +                              _els, <<>>),
 +    Mechanism = decode_sasl_auth_attrs(__TopXMLNS, _attrs,
 +                                     undefined),
 +    {sasl_auth, Mechanism, Text}.
 +
 +decode_sasl_auth_els(__TopXMLNS, __IgnoreEls, [],
 +                   Text) ->
 +    decode_sasl_auth_cdata(__TopXMLNS, Text);
 +decode_sasl_auth_els(__TopXMLNS, __IgnoreEls,
 +                   [{xmlcdata, _data} | _els], Text) ->
 +    decode_sasl_auth_els(__TopXMLNS, __IgnoreEls, _els,
 +                       <<Text/binary, _data/binary>>);
 +decode_sasl_auth_els(__TopXMLNS, __IgnoreEls,
 +                   [_ | _els], Text) ->
 +    decode_sasl_auth_els(__TopXMLNS, __IgnoreEls, _els,
 +                       Text).
 +
 +decode_sasl_auth_attrs(__TopXMLNS,
 +                     [{<<"mechanism">>, _val} | _attrs], _Mechanism) ->
 +    decode_sasl_auth_attrs(__TopXMLNS, _attrs, _val);
 +decode_sasl_auth_attrs(__TopXMLNS, [_ | _attrs],
 +                     Mechanism) ->
 +    decode_sasl_auth_attrs(__TopXMLNS, _attrs, Mechanism);
 +decode_sasl_auth_attrs(__TopXMLNS, [], Mechanism) ->
 +    decode_sasl_auth_attr_mechanism(__TopXMLNS, Mechanism).
 +
 +encode_sasl_auth({sasl_auth, Mechanism, Text},
 +               __TopXMLNS) ->
 +    __NewTopXMLNS =
 +      choose_top_xmlns(<<"urn:ietf:params:xml:ns:xmpp-sasl">>,
 +                       [], __TopXMLNS),
 +    _els = encode_sasl_auth_cdata(Text, []),
 +    _attrs = encode_sasl_auth_attr_mechanism(Mechanism,
 +                                           enc_xmlns_attrs(__NewTopXMLNS,
 +                                                           __TopXMLNS)),
 +    {xmlel, <<"auth">>, _attrs, _els}.
 +
 +decode_sasl_auth_attr_mechanism(__TopXMLNS,
 +                              undefined) ->
 +    erlang:error({xmpp_codec,
 +                {missing_attr, <<"mechanism">>, <<"auth">>,
 +                 __TopXMLNS}});
 +decode_sasl_auth_attr_mechanism(__TopXMLNS, _val) ->
 +    _val.
 +
 +encode_sasl_auth_attr_mechanism(_val, _acc) ->
 +    [{<<"mechanism">>, _val} | _acc].
 +
 +decode_sasl_auth_cdata(__TopXMLNS, <<>>) -> <<>>;
 +decode_sasl_auth_cdata(__TopXMLNS, _val) ->
 +    case catch base64:mime_decode(_val) of
 +      {'EXIT', _} ->
 +        erlang:error({xmpp_codec,
 +                      {bad_cdata_value, <<>>, <<"auth">>, __TopXMLNS}});
 +      _res -> _res
 +    end.
 +
 +encode_sasl_auth_cdata(<<>>, _acc) -> _acc;
 +encode_sasl_auth_cdata(_val, _acc) ->
 +    [{xmlcdata, base64:encode(_val)} | _acc].
 +
 +decode_legacy_auth(__TopXMLNS, __IgnoreEls,
 +                 {xmlel, <<"query">>, _attrs, _els}) ->
 +    {Digest, Password, Resource, Username} =
 +      decode_legacy_auth_els(__TopXMLNS, __IgnoreEls, _els,
 +                             undefined, undefined, undefined, undefined),
 +    {legacy_auth, Username, Password, Digest, Resource}.
 +
 +decode_legacy_auth_els(__TopXMLNS, __IgnoreEls, [],
 +                     Digest, Password, Resource, Username) ->
 +    {Digest, Password, Resource, Username};
 +decode_legacy_auth_els(__TopXMLNS, __IgnoreEls,
 +                     [{xmlel, <<"username">>, _attrs, _} = _el | _els],
 +                     Digest, Password, Resource, Username) ->
 +    case get_attr(<<"xmlns">>, _attrs) of
 +      <<"">> when __TopXMLNS == <<"jabber:iq:auth">> ->
 +        decode_legacy_auth_els(__TopXMLNS, __IgnoreEls, _els,
 +                               Digest, Password, Resource,
 +                               decode_legacy_auth_username(__TopXMLNS,
 +                                                           __IgnoreEls, _el));
 +      <<"jabber:iq:auth">> ->
 +        decode_legacy_auth_els(__TopXMLNS, __IgnoreEls, _els,
 +                               Digest, Password, Resource,
 +                               decode_legacy_auth_username(<<"jabber:iq:auth">>,
 +                                                           __IgnoreEls, _el));
 +      _ ->
 +        decode_legacy_auth_els(__TopXMLNS, __IgnoreEls, _els,
 +                               Digest, Password, Resource, Username)
 +    end;
 +decode_legacy_auth_els(__TopXMLNS, __IgnoreEls,
 +                     [{xmlel, <<"password">>, _attrs, _} = _el | _els],
 +                     Digest, Password, Resource, Username) ->
 +    case get_attr(<<"xmlns">>, _attrs) of
 +      <<"">> when __TopXMLNS == <<"jabber:iq:auth">> ->
 +        decode_legacy_auth_els(__TopXMLNS, __IgnoreEls, _els,
 +                               Digest,
 +                               decode_legacy_auth_password(__TopXMLNS,
 +                                                           __IgnoreEls, _el),
 +                               Resource, Username);
 +      <<"jabber:iq:auth">> ->
 +        decode_legacy_auth_els(__TopXMLNS, __IgnoreEls, _els,
 +                               Digest,
 +                               decode_legacy_auth_password(<<"jabber:iq:auth">>,
 +                                                           __IgnoreEls, _el),
 +                               Resource, Username);
 +      _ ->
 +        decode_legacy_auth_els(__TopXMLNS, __IgnoreEls, _els,
 +                               Digest, Password, Resource, Username)
 +    end;
 +decode_legacy_auth_els(__TopXMLNS, __IgnoreEls,
 +                     [{xmlel, <<"digest">>, _attrs, _} = _el | _els], Digest,
 +                     Password, Resource, Username) ->
 +    case get_attr(<<"xmlns">>, _attrs) of
 +      <<"">> when __TopXMLNS == <<"jabber:iq:auth">> ->
 +        decode_legacy_auth_els(__TopXMLNS, __IgnoreEls, _els,
 +                               decode_legacy_auth_digest(__TopXMLNS,
 +                                                         __IgnoreEls, _el),
 +                               Password, Resource, Username);
 +      <<"jabber:iq:auth">> ->
 +        decode_legacy_auth_els(__TopXMLNS, __IgnoreEls, _els,
 +                               decode_legacy_auth_digest(<<"jabber:iq:auth">>,
 +                                                         __IgnoreEls, _el),
 +                               Password, Resource, Username);
 +      _ ->
 +        decode_legacy_auth_els(__TopXMLNS, __IgnoreEls, _els,
 +                               Digest, Password, Resource, Username)
 +    end;
 +decode_legacy_auth_els(__TopXMLNS, __IgnoreEls,
 +                     [{xmlel, <<"resource">>, _attrs, _} = _el | _els],
 +                     Digest, Password, Resource, Username) ->
 +    case get_attr(<<"xmlns">>, _attrs) of
 +      <<"">> when __TopXMLNS == <<"jabber:iq:auth">> ->
 +        decode_legacy_auth_els(__TopXMLNS, __IgnoreEls, _els,
 +                               Digest, Password,
 +                               decode_legacy_auth_resource(__TopXMLNS,
 +                                                           __IgnoreEls, _el),
 +                               Username);
 +      <<"jabber:iq:auth">> ->
 +        decode_legacy_auth_els(__TopXMLNS, __IgnoreEls, _els,
 +                               Digest, Password,
 +                               decode_legacy_auth_resource(<<"jabber:iq:auth">>,
 +                                                           __IgnoreEls, _el),
 +                               Username);
 +      _ ->
 +        decode_legacy_auth_els(__TopXMLNS, __IgnoreEls, _els,
 +                               Digest, Password, Resource, Username)
 +    end;
 +decode_legacy_auth_els(__TopXMLNS, __IgnoreEls,
 +                     [_ | _els], Digest, Password, Resource, Username) ->
 +    decode_legacy_auth_els(__TopXMLNS, __IgnoreEls, _els,
 +                         Digest, Password, Resource, Username).
 +
 +encode_legacy_auth({legacy_auth, Username, Password,
 +                  Digest, Resource},
 +                 __TopXMLNS) ->
 +    __NewTopXMLNS = choose_top_xmlns(<<"jabber:iq:auth">>,
 +                                   [], __TopXMLNS),
 +    _els =
 +      lists:reverse('encode_legacy_auth_$digest'(Digest,
 +                                                 __NewTopXMLNS,
 +                                                 'encode_legacy_auth_$password'(Password,
 +                                                                                __NewTopXMLNS,
 +                                                                                'encode_legacy_auth_$resource'(Resource,
 +                                                                                                               __NewTopXMLNS,
 +                                                                                                               'encode_legacy_auth_$username'(Username,
 +                                                                                                                                              __NewTopXMLNS,
 +                                                                                                                                              []))))),
 +    _attrs = enc_xmlns_attrs(__NewTopXMLNS, __TopXMLNS),
 +    {xmlel, <<"query">>, _attrs, _els}.
 +
 +'encode_legacy_auth_$digest'(undefined, __TopXMLNS,
 +                           _acc) ->
 +    _acc;
 +'encode_legacy_auth_$digest'(Digest, __TopXMLNS,
 +                           _acc) ->
 +    [encode_legacy_auth_digest(Digest, __TopXMLNS) | _acc].
 +
 +'encode_legacy_auth_$password'(undefined, __TopXMLNS,
 +                             _acc) ->
 +    _acc;
 +'encode_legacy_auth_$password'(Password, __TopXMLNS,
 +                             _acc) ->
 +    [encode_legacy_auth_password(Password, __TopXMLNS)
 +     | _acc].
 +
 +'encode_legacy_auth_$resource'(undefined, __TopXMLNS,
 +                             _acc) ->
 +    _acc;
 +'encode_legacy_auth_$resource'(Resource, __TopXMLNS,
 +                             _acc) ->
 +    [encode_legacy_auth_resource(Resource, __TopXMLNS)
 +     | _acc].
 +
 +'encode_legacy_auth_$username'(undefined, __TopXMLNS,
 +                             _acc) ->
 +    _acc;
 +'encode_legacy_auth_$username'(Username, __TopXMLNS,
 +                             _acc) ->
 +    [encode_legacy_auth_username(Username, __TopXMLNS)
 +     | _acc].
 +
 +decode_legacy_auth_resource(__TopXMLNS, __IgnoreEls,
 +                          {xmlel, <<"resource">>, _attrs, _els}) ->
 +    Cdata = decode_legacy_auth_resource_els(__TopXMLNS,
 +                                          __IgnoreEls, _els, <<>>),
 +    Cdata.
 +
 +decode_legacy_auth_resource_els(__TopXMLNS, __IgnoreEls,
 +                              [], Cdata) ->
 +    decode_legacy_auth_resource_cdata(__TopXMLNS, Cdata);
 +decode_legacy_auth_resource_els(__TopXMLNS, __IgnoreEls,
 +                              [{xmlcdata, _data} | _els], Cdata) ->
 +    decode_legacy_auth_resource_els(__TopXMLNS, __IgnoreEls,
 +                                  _els, <<Cdata/binary, _data/binary>>);
 +decode_legacy_auth_resource_els(__TopXMLNS, __IgnoreEls,
 +                              [_ | _els], Cdata) ->
 +    decode_legacy_auth_resource_els(__TopXMLNS, __IgnoreEls,
 +                                  _els, Cdata).
 +
 +encode_legacy_auth_resource(Cdata, __TopXMLNS) ->
 +    __NewTopXMLNS = choose_top_xmlns(<<"jabber:iq:auth">>,
 +                                   [], __TopXMLNS),
 +    _els = encode_legacy_auth_resource_cdata(Cdata, []),
 +    _attrs = enc_xmlns_attrs(__NewTopXMLNS, __TopXMLNS),
 +    {xmlel, <<"resource">>, _attrs, _els}.
 +
 +decode_legacy_auth_resource_cdata(__TopXMLNS, <<>>) ->
 +    <<>>;
 +decode_legacy_auth_resource_cdata(__TopXMLNS, _val) ->
 +    _val.
 +
 +encode_legacy_auth_resource_cdata(<<>>, _acc) -> _acc;
 +encode_legacy_auth_resource_cdata(_val, _acc) ->
 +    [{xmlcdata, _val} | _acc].
 +
 +decode_legacy_auth_digest(__TopXMLNS, __IgnoreEls,
 +                        {xmlel, <<"digest">>, _attrs, _els}) ->
 +    Cdata = decode_legacy_auth_digest_els(__TopXMLNS,
 +                                        __IgnoreEls, _els, <<>>),
 +    Cdata.
 +
 +decode_legacy_auth_digest_els(__TopXMLNS, __IgnoreEls,
 +                            [], Cdata) ->
 +    decode_legacy_auth_digest_cdata(__TopXMLNS, Cdata);
 +decode_legacy_auth_digest_els(__TopXMLNS, __IgnoreEls,
 +                            [{xmlcdata, _data} | _els], Cdata) ->
 +    decode_legacy_auth_digest_els(__TopXMLNS, __IgnoreEls,
 +                                _els, <<Cdata/binary, _data/binary>>);
 +decode_legacy_auth_digest_els(__TopXMLNS, __IgnoreEls,
 +                            [_ | _els], Cdata) ->
 +    decode_legacy_auth_digest_els(__TopXMLNS, __IgnoreEls,
 +                                _els, Cdata).
 +
 +encode_legacy_auth_digest(Cdata, __TopXMLNS) ->
 +    __NewTopXMLNS = choose_top_xmlns(<<"jabber:iq:auth">>,
 +                                   [], __TopXMLNS),
 +    _els = encode_legacy_auth_digest_cdata(Cdata, []),
 +    _attrs = enc_xmlns_attrs(__NewTopXMLNS, __TopXMLNS),
 +    {xmlel, <<"digest">>, _attrs, _els}.
 +
 +decode_legacy_auth_digest_cdata(__TopXMLNS, <<>>) ->
 +    <<>>;
 +decode_legacy_auth_digest_cdata(__TopXMLNS, _val) ->
 +    _val.
 +
 +encode_legacy_auth_digest_cdata(<<>>, _acc) -> _acc;
 +encode_legacy_auth_digest_cdata(_val, _acc) ->
 +    [{xmlcdata, _val} | _acc].
 +
 +decode_legacy_auth_password(__TopXMLNS, __IgnoreEls,
 +                          {xmlel, <<"password">>, _attrs, _els}) ->
 +    Cdata = decode_legacy_auth_password_els(__TopXMLNS,
 +                                          __IgnoreEls, _els, <<>>),
 +    Cdata.
 +
 +decode_legacy_auth_password_els(__TopXMLNS, __IgnoreEls,
 +                              [], Cdata) ->
 +    decode_legacy_auth_password_cdata(__TopXMLNS, Cdata);
 +decode_legacy_auth_password_els(__TopXMLNS, __IgnoreEls,
 +                              [{xmlcdata, _data} | _els], Cdata) ->
 +    decode_legacy_auth_password_els(__TopXMLNS, __IgnoreEls,
 +                                  _els, <<Cdata/binary, _data/binary>>);
 +decode_legacy_auth_password_els(__TopXMLNS, __IgnoreEls,
 +                              [_ | _els], Cdata) ->
 +    decode_legacy_auth_password_els(__TopXMLNS, __IgnoreEls,
 +                                  _els, Cdata).
 +
 +encode_legacy_auth_password(Cdata, __TopXMLNS) ->
 +    __NewTopXMLNS = choose_top_xmlns(<<"jabber:iq:auth">>,
 +                                   [], __TopXMLNS),
 +    _els = encode_legacy_auth_password_cdata(Cdata, []),
 +    _attrs = enc_xmlns_attrs(__NewTopXMLNS, __TopXMLNS),
 +    {xmlel, <<"password">>, _attrs, _els}.
 +
 +decode_legacy_auth_password_cdata(__TopXMLNS, <<>>) ->
 +    <<>>;
 +decode_legacy_auth_password_cdata(__TopXMLNS, _val) ->
 +    _val.
 +
 +encode_legacy_auth_password_cdata(<<>>, _acc) -> _acc;
 +encode_legacy_auth_password_cdata(_val, _acc) ->
 +    [{xmlcdata, _val} | _acc].
 +
 +decode_legacy_auth_username(__TopXMLNS, __IgnoreEls,
 +                          {xmlel, <<"username">>, _attrs, _els}) ->
 +    Cdata = decode_legacy_auth_username_els(__TopXMLNS,
 +                                          __IgnoreEls, _els, <<>>),
 +    Cdata.
 +
 +decode_legacy_auth_username_els(__TopXMLNS, __IgnoreEls,
 +                              [], Cdata) ->
 +    decode_legacy_auth_username_cdata(__TopXMLNS, Cdata);
 +decode_legacy_auth_username_els(__TopXMLNS, __IgnoreEls,
 +                              [{xmlcdata, _data} | _els], Cdata) ->
 +    decode_legacy_auth_username_els(__TopXMLNS, __IgnoreEls,
 +                                  _els, <<Cdata/binary, _data/binary>>);
 +decode_legacy_auth_username_els(__TopXMLNS, __IgnoreEls,
 +                              [_ | _els], Cdata) ->
 +    decode_legacy_auth_username_els(__TopXMLNS, __IgnoreEls,
 +                                  _els, Cdata).
 +
 +encode_legacy_auth_username(Cdata, __TopXMLNS) ->
 +    __NewTopXMLNS = choose_top_xmlns(<<"jabber:iq:auth">>,
 +                                   [], __TopXMLNS),
 +    _els = encode_legacy_auth_username_cdata(Cdata, []),
 +    _attrs = enc_xmlns_attrs(__NewTopXMLNS, __TopXMLNS),
 +    {xmlel, <<"username">>, _attrs, _els}.
 +
 +decode_legacy_auth_username_cdata(__TopXMLNS, <<>>) ->
 +    <<>>;
 +decode_legacy_auth_username_cdata(__TopXMLNS, _val) ->
 +    _val.
 +
 +encode_legacy_auth_username_cdata(<<>>, _acc) -> _acc;
 +encode_legacy_auth_username_cdata(_val, _acc) ->
 +    [{xmlcdata, _val} | _acc].
 +
 +decode_bind(__TopXMLNS, __IgnoreEls,
 +          {xmlel, <<"bind">>, _attrs, _els}) ->
 +    {Jid, Resource} = decode_bind_els(__TopXMLNS,
 +                                    __IgnoreEls, _els, undefined, <<>>),
 +    {bind, Jid, Resource}.
 +
 +decode_bind_els(__TopXMLNS, __IgnoreEls, [], Jid,
 +              Resource) ->
 +    {Jid, Resource};
 +decode_bind_els(__TopXMLNS, __IgnoreEls,
 +              [{xmlel, <<"jid">>, _attrs, _} = _el | _els], Jid,
 +              Resource) ->
 +    case get_attr(<<"xmlns">>, _attrs) of
 +      <<"">>
 +        when __TopXMLNS ==
 +               <<"urn:ietf:params:xml:ns:xmpp-bind">> ->
 +        decode_bind_els(__TopXMLNS, __IgnoreEls, _els,
 +                        decode_bind_jid(__TopXMLNS, __IgnoreEls, _el),
 +                        Resource);
 +      <<"urn:ietf:params:xml:ns:xmpp-bind">> ->
 +        decode_bind_els(__TopXMLNS, __IgnoreEls, _els,
 +                        decode_bind_jid(<<"urn:ietf:params:xml:ns:xmpp-bind">>,
 +                                        __IgnoreEls, _el),
 +                        Resource);
 +      _ ->
 +        decode_bind_els(__TopXMLNS, __IgnoreEls, _els, Jid,
 +                        Resource)
 +    end;
 +decode_bind_els(__TopXMLNS, __IgnoreEls,
 +              [{xmlel, <<"resource">>, _attrs, _} = _el | _els], Jid,
 +              Resource) ->
 +    case get_attr(<<"xmlns">>, _attrs) of
 +      <<"">>
 +        when __TopXMLNS ==
 +               <<"urn:ietf:params:xml:ns:xmpp-bind">> ->
 +        decode_bind_els(__TopXMLNS, __IgnoreEls, _els, Jid,
 +                        decode_bind_resource(__TopXMLNS, __IgnoreEls, _el));
 +      <<"urn:ietf:params:xml:ns:xmpp-bind">> ->
 +        decode_bind_els(__TopXMLNS, __IgnoreEls, _els, Jid,
 +                        decode_bind_resource(<<"urn:ietf:params:xml:ns:xmpp-bind">>,
 +                                             __IgnoreEls, _el));
 +      _ ->
 +        decode_bind_els(__TopXMLNS, __IgnoreEls, _els, Jid,
 +                        Resource)
 +    end;
 +decode_bind_els(__TopXMLNS, __IgnoreEls, [_ | _els],
 +              Jid, Resource) ->
 +    decode_bind_els(__TopXMLNS, __IgnoreEls, _els, Jid,
 +                  Resource).
 +
 +encode_bind({bind, Jid, Resource}, __TopXMLNS) ->
 +    __NewTopXMLNS =
 +      choose_top_xmlns(<<"urn:ietf:params:xml:ns:xmpp-bind">>,
 +                       [], __TopXMLNS),
 +    _els = lists:reverse('encode_bind_$jid'(Jid,
 +                                          __NewTopXMLNS,
 +                                          'encode_bind_$resource'(Resource,
 +                                                                  __NewTopXMLNS,
 +                                                                  []))),
 +    _attrs = enc_xmlns_attrs(__NewTopXMLNS, __TopXMLNS),
 +    {xmlel, <<"bind">>, _attrs, _els}.
 +
 +'encode_bind_$jid'(undefined, __TopXMLNS, _acc) -> _acc;
 +'encode_bind_$jid'(Jid, __TopXMLNS, _acc) ->
 +    [encode_bind_jid(Jid, __TopXMLNS) | _acc].
 +
 +'encode_bind_$resource'(<<>>, __TopXMLNS, _acc) -> _acc;
 +'encode_bind_$resource'(Resource, __TopXMLNS, _acc) ->
 +    [encode_bind_resource(Resource, __TopXMLNS) | _acc].
 +
 +decode_bind_resource(__TopXMLNS, __IgnoreEls,
 +                   {xmlel, <<"resource">>, _attrs, _els}) ->
 +    Cdata = decode_bind_resource_els(__TopXMLNS,
 +                                   __IgnoreEls, _els, <<>>),
 +    Cdata.
 +
 +decode_bind_resource_els(__TopXMLNS, __IgnoreEls, [],
 +                       Cdata) ->
 +    decode_bind_resource_cdata(__TopXMLNS, Cdata);
 +decode_bind_resource_els(__TopXMLNS, __IgnoreEls,
 +                       [{xmlcdata, _data} | _els], Cdata) ->
 +    decode_bind_resource_els(__TopXMLNS, __IgnoreEls, _els,
 +                           <<Cdata/binary, _data/binary>>);
 +decode_bind_resource_els(__TopXMLNS, __IgnoreEls,
 +                       [_ | _els], Cdata) ->
 +    decode_bind_resource_els(__TopXMLNS, __IgnoreEls, _els,
 +                           Cdata).
 +
 +encode_bind_resource(Cdata, __TopXMLNS) ->
 +    __NewTopXMLNS =
 +      choose_top_xmlns(<<"urn:ietf:params:xml:ns:xmpp-bind">>,
 +                       [], __TopXMLNS),
 +    _els = encode_bind_resource_cdata(Cdata, []),
 +    _attrs = enc_xmlns_attrs(__NewTopXMLNS, __TopXMLNS),
 +    {xmlel, <<"resource">>, _attrs, _els}.
 +
 +decode_bind_resource_cdata(__TopXMLNS, <<>>) -> <<>>;
 +decode_bind_resource_cdata(__TopXMLNS, _val) ->
 +    case catch resourceprep(_val) of
 +      {'EXIT', _} ->
 +        erlang:error({xmpp_codec,
 +                      {bad_cdata_value, <<>>, <<"resource">>, __TopXMLNS}});
 +      _res -> _res
 +    end.
 +
 +encode_bind_resource_cdata(<<>>, _acc) -> _acc;
 +encode_bind_resource_cdata(_val, _acc) ->
 +    [{xmlcdata, resourceprep(_val)} | _acc].
 +
 +decode_bind_jid(__TopXMLNS, __IgnoreEls,
 +              {xmlel, <<"jid">>, _attrs, _els}) ->
 +    Cdata = decode_bind_jid_els(__TopXMLNS, __IgnoreEls,
 +                              _els, <<>>),
 +    Cdata.
 +
 +decode_bind_jid_els(__TopXMLNS, __IgnoreEls, [],
 +                  Cdata) ->
 +    decode_bind_jid_cdata(__TopXMLNS, Cdata);
 +decode_bind_jid_els(__TopXMLNS, __IgnoreEls,
 +                  [{xmlcdata, _data} | _els], Cdata) ->
 +    decode_bind_jid_els(__TopXMLNS, __IgnoreEls, _els,
 +                      <<Cdata/binary, _data/binary>>);
 +decode_bind_jid_els(__TopXMLNS, __IgnoreEls, [_ | _els],
 +                  Cdata) ->
 +    decode_bind_jid_els(__TopXMLNS, __IgnoreEls, _els,
 +                      Cdata).
 +
 +encode_bind_jid(Cdata, __TopXMLNS) ->
 +    __NewTopXMLNS =
 +      choose_top_xmlns(<<"urn:ietf:params:xml:ns:xmpp-bind">>,
 +                       [], __TopXMLNS),
 +    _els = encode_bind_jid_cdata(Cdata, []),
 +    _attrs = enc_xmlns_attrs(__NewTopXMLNS, __TopXMLNS),
 +    {xmlel, <<"jid">>, _attrs, _els}.
 +
 +decode_bind_jid_cdata(__TopXMLNS, <<>>) -> undefined;
 +decode_bind_jid_cdata(__TopXMLNS, _val) ->
 +    case catch dec_jid(_val) of
 +      {'EXIT', _} ->
 +        erlang:error({xmpp_codec,
 +                      {bad_cdata_value, <<>>, <<"jid">>, __TopXMLNS}});
 +      _res -> _res
 +    end.
 +
 +encode_bind_jid_cdata(undefined, _acc) -> _acc;
 +encode_bind_jid_cdata(_val, _acc) ->
 +    [{xmlcdata, enc_jid(_val)} | _acc].
 +
 +decode_error(__TopXMLNS, __IgnoreEls,
 +           {xmlel, <<"error">>, _attrs, _els}) ->
 +    {Text, Reason, __Els} = decode_error_els(__TopXMLNS,
 +                                           __IgnoreEls, _els, undefined,
 +                                           undefined, []),
 +    {Type, Code, By} = decode_error_attrs(__TopXMLNS,
 +                                        _attrs, undefined, undefined,
 +                                        undefined),
 +    {stanza_error, Type, Code, By, Reason, Text, __Els}.
 +
 +decode_error_els(__TopXMLNS, __IgnoreEls, [], Text,
 +               Reason, __Els) ->
 +    {Text, Reason, lists:reverse(__Els)};
 +decode_error_els(__TopXMLNS, __IgnoreEls,
 +               [{xmlel, <<"text">>, _attrs, _} = _el | _els], Text,
 +               Reason, __Els) ->
 +    case get_attr(<<"xmlns">>, _attrs) of
 +      <<"urn:ietf:params:xml:ns:xmpp-stanzas">> ->
 +        decode_error_els(__TopXMLNS, __IgnoreEls, _els,
 +                         decode_error_text(<<"urn:ietf:params:xml:ns:xmpp-stanzas">>,
 +                                           __IgnoreEls, _el),
 +                         Reason, __Els);
 +      _ ->
 +        decode_error_els(__TopXMLNS, __IgnoreEls, _els, Text,
 +                         Reason, __Els)
 +    end;
 +decode_error_els(__TopXMLNS, __IgnoreEls,
 +               [{xmlel, <<"bad-request">>, _attrs, _} = _el | _els],
 +               Text, Reason, __Els) ->
 +    case get_attr(<<"xmlns">>, _attrs) of
 +      <<"urn:ietf:params:xml:ns:xmpp-stanzas">> ->
 +        decode_error_els(__TopXMLNS, __IgnoreEls, _els, Text,
 +                         decode_error_bad_request(<<"urn:ietf:params:xml:ns:xmpp-stanzas">>,
 +                                                  __IgnoreEls, _el),
 +                         __Els);
 +      _ ->
 +        decode_error_els(__TopXMLNS, __IgnoreEls, _els, Text,
 +                         Reason, __Els)
 +    end;
 +decode_error_els(__TopXMLNS, __IgnoreEls,
 +               [{xmlel, <<"conflict">>, _attrs, _} = _el | _els], Text,
 +               Reason, __Els) ->
 +    case get_attr(<<"xmlns">>, _attrs) of
 +      <<"urn:ietf:params:xml:ns:xmpp-stanzas">> ->
 +        decode_error_els(__TopXMLNS, __IgnoreEls, _els, Text,
 +                         decode_error_conflict(<<"urn:ietf:params:xml:ns:xmpp-stanzas">>,
 +                                               __IgnoreEls, _el),
 +                         __Els);
 +      _ ->
 +        decode_error_els(__TopXMLNS, __IgnoreEls, _els, Text,
 +                         Reason, __Els)
 +    end;
 +decode_error_els(__TopXMLNS, __IgnoreEls,
 +               [{xmlel, <<"feature-not-implemented">>, _attrs, _} = _el
 +                | _els],
 +               Text, Reason, __Els) ->
 +    case get_attr(<<"xmlns">>, _attrs) of
 +      <<"urn:ietf:params:xml:ns:xmpp-stanzas">> ->
 +        decode_error_els(__TopXMLNS, __IgnoreEls, _els, Text,
 +                         decode_error_feature_not_implemented(<<"urn:ietf:params:xml:ns:xmpp-stanzas">>,
 +                                                              __IgnoreEls,
 +                                                              _el),
 +                         __Els);
 +      _ ->
 +        decode_error_els(__TopXMLNS, __IgnoreEls, _els, Text,
 +                         Reason, __Els)
 +    end;
 +decode_error_els(__TopXMLNS, __IgnoreEls,
 +               [{xmlel, <<"forbidden">>, _attrs, _} = _el | _els],
 +               Text, Reason, __Els) ->
 +    case get_attr(<<"xmlns">>, _attrs) of
 +      <<"urn:ietf:params:xml:ns:xmpp-stanzas">> ->
 +        decode_error_els(__TopXMLNS, __IgnoreEls, _els, Text,
 +                         decode_error_forbidden(<<"urn:ietf:params:xml:ns:xmpp-stanzas">>,
 +                                                __IgnoreEls, _el),
 +                         __Els);
 +      _ ->
 +        decode_error_els(__TopXMLNS, __IgnoreEls, _els, Text,
 +                         Reason, __Els)
 +    end;
 +decode_error_els(__TopXMLNS, __IgnoreEls,
 +               [{xmlel, <<"gone">>, _attrs, _} = _el | _els], Text,
 +               Reason, __Els) ->
 +    case get_attr(<<"xmlns">>, _attrs) of
 +      <<"urn:ietf:params:xml:ns:xmpp-stanzas">> ->
 +        decode_error_els(__TopXMLNS, __IgnoreEls, _els, Text,
 +                         decode_error_gone(<<"urn:ietf:params:xml:ns:xmpp-stanzas">>,
 +                                           __IgnoreEls, _el),
 +                         __Els);
 +      _ ->
 +        decode_error_els(__TopXMLNS, __IgnoreEls, _els, Text,
 +                         Reason, __Els)
 +    end;
 +decode_error_els(__TopXMLNS, __IgnoreEls,
 +               [{xmlel, <<"internal-server-error">>, _attrs, _} = _el
 +                | _els],
 +               Text, Reason, __Els) ->
 +    case get_attr(<<"xmlns">>, _attrs) of
 +      <<"urn:ietf:params:xml:ns:xmpp-stanzas">> ->
 +        decode_error_els(__TopXMLNS, __IgnoreEls, _els, Text,
 +                         decode_error_internal_server_error(<<"urn:ietf:params:xml:ns:xmpp-stanzas">>,
 +                                                            __IgnoreEls, _el),
 +                         __Els);
 +      _ ->
 +        decode_error_els(__TopXMLNS, __IgnoreEls, _els, Text,
 +                         Reason, __Els)
 +    end;
 +decode_error_els(__TopXMLNS, __IgnoreEls,
 +               [{xmlel, <<"item-not-found">>, _attrs, _} = _el | _els],
 +               Text, Reason, __Els) ->
 +    case get_attr(<<"xmlns">>, _attrs) of
 +      <<"urn:ietf:params:xml:ns:xmpp-stanzas">> ->
 +        decode_error_els(__TopXMLNS, __IgnoreEls, _els, Text,
 +                         decode_error_item_not_found(<<"urn:ietf:params:xml:ns:xmpp-stanzas">>,
 +                                                     __IgnoreEls, _el),
 +                         __Els);
 +      _ ->
 +        decode_error_els(__TopXMLNS, __IgnoreEls, _els, Text,
 +                         Reason, __Els)
 +    end;
 +decode_error_els(__TopXMLNS, __IgnoreEls,
 +               [{xmlel, <<"jid-malformed">>, _attrs, _} = _el | _els],
 +               Text, Reason, __Els) ->
 +    case get_attr(<<"xmlns">>, _attrs) of
 +      <<"urn:ietf:params:xml:ns:xmpp-stanzas">> ->
 +        decode_error_els(__TopXMLNS, __IgnoreEls, _els, Text,
 +                         decode_error_jid_malformed(<<"urn:ietf:params:xml:ns:xmpp-stanzas">>,
 +                                                    __IgnoreEls, _el),
 +                         __Els);
 +      _ ->
 +        decode_error_els(__TopXMLNS, __IgnoreEls, _els, Text,
 +                         Reason, __Els)
 +    end;
 +decode_error_els(__TopXMLNS, __IgnoreEls,
 +               [{xmlel, <<"not-acceptable">>, _attrs, _} = _el | _els],
 +               Text, Reason, __Els) ->
 +    case get_attr(<<"xmlns">>, _attrs) of
 +      <<"urn:ietf:params:xml:ns:xmpp-stanzas">> ->
 +        decode_error_els(__TopXMLNS, __IgnoreEls, _els, Text,
 +                         decode_error_not_acceptable(<<"urn:ietf:params:xml:ns:xmpp-stanzas">>,
 +                                                     __IgnoreEls, _el),
 +                         __Els);
 +      _ ->
 +        decode_error_els(__TopXMLNS, __IgnoreEls, _els, Text,
 +                         Reason, __Els)
 +    end;
 +decode_error_els(__TopXMLNS, __IgnoreEls,
 +               [{xmlel, <<"not-allowed">>, _attrs, _} = _el | _els],
 +               Text, Reason, __Els) ->
 +    case get_attr(<<"xmlns">>, _attrs) of
 +      <<"urn:ietf:params:xml:ns:xmpp-stanzas">> ->
 +        decode_error_els(__TopXMLNS, __IgnoreEls, _els, Text,
 +                         decode_error_not_allowed(<<"urn:ietf:params:xml:ns:xmpp-stanzas">>,
 +                                                  __IgnoreEls, _el),
 +                         __Els);
 +      _ ->
 +        decode_error_els(__TopXMLNS, __IgnoreEls, _els, Text,
 +                         Reason, __Els)
 +    end;
 +decode_error_els(__TopXMLNS, __IgnoreEls,
 +               [{xmlel, <<"not-authorized">>, _attrs, _} = _el | _els],
 +               Text, Reason, __Els) ->
 +    case get_attr(<<"xmlns">>, _attrs) of
 +      <<"urn:ietf:params:xml:ns:xmpp-stanzas">> ->
 +        decode_error_els(__TopXMLNS, __IgnoreEls, _els, Text,
 +                         decode_error_not_authorized(<<"urn:ietf:params:xml:ns:xmpp-stanzas">>,
 +                                                     __IgnoreEls, _el),
 +                         __Els);
 +      _ ->
 +        decode_error_els(__TopXMLNS, __IgnoreEls, _els, Text,
 +                         Reason, __Els)
 +    end;
 +decode_error_els(__TopXMLNS, __IgnoreEls,
 +               [{xmlel, <<"payment-required">>, _attrs, _} = _el
 +                | _els],
 +               Text, Reason, __Els) ->
 +    case get_attr(<<"xmlns">>, _attrs) of
 +      <<"urn:ietf:params:xml:ns:xmpp-stanzas">> ->
 +        decode_error_els(__TopXMLNS, __IgnoreEls, _els, Text,
 +                         decode_error_payment_required(<<"urn:ietf:params:xml:ns:xmpp-stanzas">>,
 +                                                       __IgnoreEls, _el),
 +                         __Els);
 +      _ ->
 +        decode_error_els(__TopXMLNS, __IgnoreEls, _els, Text,
 +                         Reason, __Els)
 +    end;
 +decode_error_els(__TopXMLNS, __IgnoreEls,
 +               [{xmlel, <<"policy-violation">>, _attrs, _} = _el
 +                | _els],
 +               Text, Reason, __Els) ->
 +    case get_attr(<<"xmlns">>, _attrs) of
 +      <<"urn:ietf:params:xml:ns:xmpp-stanzas">> ->
 +        decode_error_els(__TopXMLNS, __IgnoreEls, _els, Text,
 +                         decode_error_policy_violation(<<"urn:ietf:params:xml:ns:xmpp-stanzas">>,
 +                                                       __IgnoreEls, _el),
 +                         __Els);
 +      _ ->
 +        decode_error_els(__TopXMLNS, __IgnoreEls, _els, Text,
 +                         Reason, __Els)
 +    end;
 +decode_error_els(__TopXMLNS, __IgnoreEls,
 +               [{xmlel, <<"recipient-unavailable">>, _attrs, _} = _el
 +                | _els],
 +               Text, Reason, __Els) ->
 +    case get_attr(<<"xmlns">>, _attrs) of
 +      <<"urn:ietf:params:xml:ns:xmpp-stanzas">> ->
 +        decode_error_els(__TopXMLNS, __IgnoreEls, _els, Text,
 +                         decode_error_recipient_unavailable(<<"urn:ietf:params:xml:ns:xmpp-stanzas">>,
 +                                                            __IgnoreEls, _el),
 +                         __Els);
 +      _ ->
 +        decode_error_els(__TopXMLNS, __IgnoreEls, _els, Text,
 +                         Reason, __Els)
 +    end;
 +decode_error_els(__TopXMLNS, __IgnoreEls,
 +               [{xmlel, <<"redirect">>, _attrs, _} = _el | _els], Text,
 +               Reason, __Els) ->
 +    case get_attr(<<"xmlns">>, _attrs) of
 +      <<"urn:ietf:params:xml:ns:xmpp-stanzas">> ->
 +        decode_error_els(__TopXMLNS, __IgnoreEls, _els, Text,
 +                         decode_error_redirect(<<"urn:ietf:params:xml:ns:xmpp-stanzas">>,
 +                                               __IgnoreEls, _el),
 +                         __Els);
 +      _ ->
 +        decode_error_els(__TopXMLNS, __IgnoreEls, _els, Text,
 +                         Reason, __Els)
 +    end;
 +decode_error_els(__TopXMLNS, __IgnoreEls,
 +               [{xmlel, <<"registration-required">>, _attrs, _} = _el
 +                | _els],
 +               Text, Reason, __Els) ->
 +    case get_attr(<<"xmlns">>, _attrs) of
 +      <<"urn:ietf:params:xml:ns:xmpp-stanzas">> ->
 +        decode_error_els(__TopXMLNS, __IgnoreEls, _els, Text,
 +                         decode_error_registration_required(<<"urn:ietf:params:xml:ns:xmpp-stanzas">>,
 +                                                            __IgnoreEls, _el),
 +                         __Els);
 +      _ ->
 +        decode_error_els(__TopXMLNS, __IgnoreEls, _els, Text,
 +                         Reason, __Els)
 +    end;
 +decode_error_els(__TopXMLNS, __IgnoreEls,
 +               [{xmlel, <<"remote-server-not-found">>, _attrs, _} = _el
 +                | _els],
 +               Text, Reason, __Els) ->
 +    case get_attr(<<"xmlns">>, _attrs) of
 +      <<"urn:ietf:params:xml:ns:xmpp-stanzas">> ->
 +        decode_error_els(__TopXMLNS, __IgnoreEls, _els, Text,
 +                         decode_error_remote_server_not_found(<<"urn:ietf:params:xml:ns:xmpp-stanzas">>,
 +                                                              __IgnoreEls,
 +                                                              _el),
 +                         __Els);
 +      _ ->
 +        decode_error_els(__TopXMLNS, __IgnoreEls, _els, Text,
 +                         Reason, __Els)
 +    end;
 +decode_error_els(__TopXMLNS, __IgnoreEls,
 +               [{xmlel, <<"remote-server-timeout">>, _attrs, _} = _el
 +                | _els],
 +               Text, Reason, __Els) ->
 +    case get_attr(<<"xmlns">>, _attrs) of
 +      <<"urn:ietf:params:xml:ns:xmpp-stanzas">> ->
 +        decode_error_els(__TopXMLNS, __IgnoreEls, _els, Text,
 +                         decode_error_remote_server_timeout(<<"urn:ietf:params:xml:ns:xmpp-stanzas">>,
 +                                                            __IgnoreEls, _el),
 +                         __Els);
 +      _ ->
 +        decode_error_els(__TopXMLNS, __IgnoreEls, _els, Text,
 +                         Reason, __Els)
 +    end;
 +decode_error_els(__TopXMLNS, __IgnoreEls,
 +               [{xmlel, <<"resource-constraint">>, _attrs, _} = _el
 +                | _els],
 +               Text, Reason, __Els) ->
 +    case get_attr(<<"xmlns">>, _attrs) of
 +      <<"urn:ietf:params:xml:ns:xmpp-stanzas">> ->
 +        decode_error_els(__TopXMLNS, __IgnoreEls, _els, Text,
 +                         decode_error_resource_constraint(<<"urn:ietf:params:xml:ns:xmpp-stanzas">>,
 +                                                          __IgnoreEls, _el),
 +                         __Els);
 +      _ ->
 +        decode_error_els(__TopXMLNS, __IgnoreEls, _els, Text,
 +                         Reason, __Els)
 +    end;
 +decode_error_els(__TopXMLNS, __IgnoreEls,
 +               [{xmlel, <<"service-unavailable">>, _attrs, _} = _el
 +                | _els],
 +               Text, Reason, __Els) ->
 +    case get_attr(<<"xmlns">>, _attrs) of
 +      <<"urn:ietf:params:xml:ns:xmpp-stanzas">> ->
 +        decode_error_els(__TopXMLNS, __IgnoreEls, _els, Text,
 +                         decode_error_service_unavailable(<<"urn:ietf:params:xml:ns:xmpp-stanzas">>,
 +                                                          __IgnoreEls, _el),
 +                         __Els);
 +      _ ->
 +        decode_error_els(__TopXMLNS, __IgnoreEls, _els, Text,
 +                         Reason, __Els)
 +    end;
 +decode_error_els(__TopXMLNS, __IgnoreEls,
 +               [{xmlel, <<"subscription-required">>, _attrs, _} = _el
 +                | _els],
 +               Text, Reason, __Els) ->
 +    case get_attr(<<"xmlns">>, _attrs) of
 +      <<"urn:ietf:params:xml:ns:xmpp-stanzas">> ->
 +        decode_error_els(__TopXMLNS, __IgnoreEls, _els, Text,
 +                         decode_error_subscription_required(<<"urn:ietf:params:xml:ns:xmpp-stanzas">>,
 +                                                            __IgnoreEls, _el),
 +                         __Els);
 +      _ ->
 +        decode_error_els(__TopXMLNS, __IgnoreEls, _els, Text,
 +                         Reason, __Els)
 +    end;
 +decode_error_els(__TopXMLNS, __IgnoreEls,
 +               [{xmlel, <<"undefined-condition">>, _attrs, _} = _el
 +                | _els],
 +               Text, Reason, __Els) ->
 +    case get_attr(<<"xmlns">>, _attrs) of
 +      <<"urn:ietf:params:xml:ns:xmpp-stanzas">> ->
 +        decode_error_els(__TopXMLNS, __IgnoreEls, _els, Text,
 +                         decode_error_undefined_condition(<<"urn:ietf:params:xml:ns:xmpp-stanzas">>,
 +                                                          __IgnoreEls, _el),
 +                         __Els);
 +      _ ->
 +        decode_error_els(__TopXMLNS, __IgnoreEls, _els, Text,
 +                         Reason, __Els)
 +    end;
 +decode_error_els(__TopXMLNS, __IgnoreEls,
 +               [{xmlel, <<"unexpected-request">>, _attrs, _} = _el
 +                | _els],
 +               Text, Reason, __Els) ->
 +    case get_attr(<<"xmlns">>, _attrs) of
 +      <<"urn:ietf:params:xml:ns:xmpp-stanzas">> ->
 +        decode_error_els(__TopXMLNS, __IgnoreEls, _els, Text,
 +                         decode_error_unexpected_request(<<"urn:ietf:params:xml:ns:xmpp-stanzas">>,
 +                                                         __IgnoreEls, _el),
 +                         __Els);
 +      _ ->
 +        decode_error_els(__TopXMLNS, __IgnoreEls, _els, Text,
 +                         Reason, __Els)
 +    end;
 +decode_error_els(__TopXMLNS, __IgnoreEls,
 +               [{xmlel, _, _, _} = _el | _els], Text, Reason, __Els) ->
 +    if __IgnoreEls ->
 +         decode_error_els(__TopXMLNS, __IgnoreEls, _els, Text,
 +                          Reason, [_el | __Els]);
 +       true ->
 +         case is_known_tag(_el, __TopXMLNS) of
 +           true ->
 +               decode_error_els(__TopXMLNS, __IgnoreEls, _els, Text,
 +                                Reason,
 +                                [decode(_el, __TopXMLNS, []) | __Els]);
 +           false ->
 +               decode_error_els(__TopXMLNS, __IgnoreEls, _els, Text,
 +                                Reason, __Els)
 +         end
 +    end;
 +decode_error_els(__TopXMLNS, __IgnoreEls, [_ | _els],
 +               Text, Reason, __Els) ->
 +    decode_error_els(__TopXMLNS, __IgnoreEls, _els, Text,
 +                   Reason, __Els).
 +
 +decode_error_attrs(__TopXMLNS,
 +                 [{<<"type">>, _val} | _attrs], _Type, Code, By) ->
 +    decode_error_attrs(__TopXMLNS, _attrs, _val, Code, By);
 +decode_error_attrs(__TopXMLNS,
 +                 [{<<"code">>, _val} | _attrs], Type, _Code, By) ->
 +    decode_error_attrs(__TopXMLNS, _attrs, Type, _val, By);
 +decode_error_attrs(__TopXMLNS,
 +                 [{<<"by">>, _val} | _attrs], Type, Code, _By) ->
 +    decode_error_attrs(__TopXMLNS, _attrs, Type, Code,
 +                     _val);
 +decode_error_attrs(__TopXMLNS, [_ | _attrs], Type, Code,
 +                 By) ->
 +    decode_error_attrs(__TopXMLNS, _attrs, Type, Code, By);
 +decode_error_attrs(__TopXMLNS, [], Type, Code, By) ->
 +    {decode_error_attr_type(__TopXMLNS, Type),
 +     decode_error_attr_code(__TopXMLNS, Code),
 +     decode_error_attr_by(__TopXMLNS, By)}.
 +
 +encode_error({stanza_error, Type, Code, By, Reason,
 +            Text, __Els},
 +           __TopXMLNS) ->
 +    __NewTopXMLNS = choose_top_xmlns(<<>>,
 +                                   [<<"jabber:client">>, <<"jabber:server">>,
 +                                    <<"jabber:component:accept">>],
 +                                   __TopXMLNS),
 +    _els = [encode(_el, __NewTopXMLNS) || _el <- __Els] ++
 +           lists:reverse('encode_error_$text'(Text, __NewTopXMLNS,
 +                                              'encode_error_$reason'(Reason,
 +                                                                     __NewTopXMLNS,
 +                                                                     []))),
 +    _attrs = encode_error_attr_by(By,
 +                                encode_error_attr_code(Code,
 +                                                       encode_error_attr_type(Type,
 +                                                                              enc_xmlns_attrs(__NewTopXMLNS,
 +                                                                                              __TopXMLNS)))),
 +    {xmlel, <<"error">>, _attrs, _els}.
 +
 +'encode_error_$text'(undefined, __TopXMLNS, _acc) ->
 +    _acc;
 +'encode_error_$text'(Text, __TopXMLNS, _acc) ->
 +    [encode_error_text(Text, __TopXMLNS) | _acc].
 +
 +'encode_error_$reason'(undefined, __TopXMLNS, _acc) ->
 +    _acc;
 +'encode_error_$reason'('bad-request' = Reason,
 +                     __TopXMLNS, _acc) ->
 +    [encode_error_bad_request(Reason, __TopXMLNS) | _acc];
 +'encode_error_$reason'(conflict = Reason, __TopXMLNS,
 +                     _acc) ->
 +    [encode_error_conflict(Reason, __TopXMLNS) | _acc];
 +'encode_error_$reason'('feature-not-implemented' =
 +                         Reason,
 +                     __TopXMLNS, _acc) ->
 +    [encode_error_feature_not_implemented(Reason,
 +                                        __TopXMLNS)
 +     | _acc];
 +'encode_error_$reason'(forbidden = Reason, __TopXMLNS,
 +                     _acc) ->
 +    [encode_error_forbidden(Reason, __TopXMLNS) | _acc];
 +'encode_error_$reason'({gone, _} = Reason, __TopXMLNS,
 +                     _acc) ->
 +    [encode_error_gone(Reason, __TopXMLNS) | _acc];
 +'encode_error_$reason'('internal-server-error' = Reason,
 +                     __TopXMLNS, _acc) ->
 +    [encode_error_internal_server_error(Reason, __TopXMLNS)
 +     | _acc];
 +'encode_error_$reason'('item-not-found' = Reason,
 +                     __TopXMLNS, _acc) ->
 +    [encode_error_item_not_found(Reason, __TopXMLNS)
 +     | _acc];
 +'encode_error_$reason'('jid-malformed' = Reason,
 +                     __TopXMLNS, _acc) ->
 +    [encode_error_jid_malformed(Reason, __TopXMLNS) | _acc];
 +'encode_error_$reason'('not-acceptable' = Reason,
 +                     __TopXMLNS, _acc) ->
 +    [encode_error_not_acceptable(Reason, __TopXMLNS)
 +     | _acc];
 +'encode_error_$reason'('not-allowed' = Reason,
 +                     __TopXMLNS, _acc) ->
 +    [encode_error_not_allowed(Reason, __TopXMLNS) | _acc];
 +'encode_error_$reason'('not-authorized' = Reason,
 +                     __TopXMLNS, _acc) ->
 +    [encode_error_not_authorized(Reason, __TopXMLNS)
 +     | _acc];
 +'encode_error_$reason'('payment-required' = Reason,
 +                     __TopXMLNS, _acc) ->
 +    [encode_error_payment_required(Reason, __TopXMLNS)
 +     | _acc];
 +'encode_error_$reason'('policy-violation' = Reason,
 +                     __TopXMLNS, _acc) ->
 +    [encode_error_policy_violation(Reason, __TopXMLNS)
 +     | _acc];
 +'encode_error_$reason'('recipient-unavailable' = Reason,
 +                     __TopXMLNS, _acc) ->
 +    [encode_error_recipient_unavailable(Reason, __TopXMLNS)
 +     | _acc];
 +'encode_error_$reason'({redirect, _} = Reason,
 +                     __TopXMLNS, _acc) ->
 +    [encode_error_redirect(Reason, __TopXMLNS) | _acc];
 +'encode_error_$reason'('registration-required' = Reason,
 +                     __TopXMLNS, _acc) ->
 +    [encode_error_registration_required(Reason, __TopXMLNS)
 +     | _acc];
 +'encode_error_$reason'('remote-server-not-found' =
 +                         Reason,
 +                     __TopXMLNS, _acc) ->
 +    [encode_error_remote_server_not_found(Reason,
 +                                        __TopXMLNS)
 +     | _acc];
 +'encode_error_$reason'('remote-server-timeout' = Reason,
 +                     __TopXMLNS, _acc) ->
 +    [encode_error_remote_server_timeout(Reason, __TopXMLNS)
 +     | _acc];
 +'encode_error_$reason'('resource-constraint' = Reason,
 +                     __TopXMLNS, _acc) ->
 +    [encode_error_resource_constraint(Reason, __TopXMLNS)
 +     | _acc];
 +'encode_error_$reason'('service-unavailable' = Reason,
 +                     __TopXMLNS, _acc) ->
 +    [encode_error_service_unavailable(Reason, __TopXMLNS)
 +     | _acc];
 +'encode_error_$reason'('subscription-required' = Reason,
 +                     __TopXMLNS, _acc) ->
 +    [encode_error_subscription_required(Reason, __TopXMLNS)
 +     | _acc];
 +'encode_error_$reason'('undefined-condition' = Reason,
 +                     __TopXMLNS, _acc) ->
 +    [encode_error_undefined_condition(Reason, __TopXMLNS)
 +     | _acc];
 +'encode_error_$reason'('unexpected-request' = Reason,
 +                     __TopXMLNS, _acc) ->
 +    [encode_error_unexpected_request(Reason, __TopXMLNS)
 +     | _acc].
 +
 +decode_error_attr_type(__TopXMLNS, undefined) ->
 +    erlang:error({xmpp_codec,
 +                {missing_attr, <<"type">>, <<"error">>, __TopXMLNS}});
 +decode_error_attr_type(__TopXMLNS, _val) ->
 +    case catch dec_enum(_val,
 +                      [auth, cancel, continue, modify, wait])
 +      of
 +      {'EXIT', _} ->
 +        erlang:error({xmpp_codec,
 +                      {bad_attr_value, <<"type">>, <<"error">>, __TopXMLNS}});
 +      _res -> _res
 +    end.
 +
 +encode_error_attr_type(_val, _acc) ->
 +    [{<<"type">>, enc_enum(_val)} | _acc].
 +
 +decode_error_attr_code(__TopXMLNS, undefined) ->
 +    undefined;
 +decode_error_attr_code(__TopXMLNS, _val) ->
 +    case catch dec_int(_val, 0, infinity) of
 +      {'EXIT', _} ->
 +        erlang:error({xmpp_codec,
 +                      {bad_attr_value, <<"code">>, <<"error">>, __TopXMLNS}});
 +      _res -> _res
 +    end.
 +
 +encode_error_attr_code(undefined, _acc) -> _acc;
 +encode_error_attr_code(_val, _acc) ->
 +    [{<<"code">>, enc_int(_val)} | _acc].
 +
 +decode_error_attr_by(__TopXMLNS, undefined) -> <<>>;
 +decode_error_attr_by(__TopXMLNS, _val) -> _val.
 +
 +encode_error_attr_by(<<>>, _acc) -> _acc;
 +encode_error_attr_by(_val, _acc) ->
 +    [{<<"by">>, _val} | _acc].
 +
 +decode_error_text(__TopXMLNS, __IgnoreEls,
 +                {xmlel, <<"text">>, _attrs, _els}) ->
 +    Data = decode_error_text_els(__TopXMLNS, __IgnoreEls,
 +                               _els, <<>>),
 +    Lang = decode_error_text_attrs(__TopXMLNS, _attrs,
 +                                 undefined),
 +    {text, Lang, Data}.
 +
 +decode_error_text_els(__TopXMLNS, __IgnoreEls, [],
 +                    Data) ->
 +    decode_error_text_cdata(__TopXMLNS, Data);
 +decode_error_text_els(__TopXMLNS, __IgnoreEls,
 +                    [{xmlcdata, _data} | _els], Data) ->
 +    decode_error_text_els(__TopXMLNS, __IgnoreEls, _els,
 +                        <<Data/binary, _data/binary>>);
 +decode_error_text_els(__TopXMLNS, __IgnoreEls,
 +                    [_ | _els], Data) ->
 +    decode_error_text_els(__TopXMLNS, __IgnoreEls, _els,
 +                        Data).
 +
 +decode_error_text_attrs(__TopXMLNS,
 +                      [{<<"xml:lang">>, _val} | _attrs], _Lang) ->
 +    decode_error_text_attrs(__TopXMLNS, _attrs, _val);
 +decode_error_text_attrs(__TopXMLNS, [_ | _attrs],
 +                      Lang) ->
 +    decode_error_text_attrs(__TopXMLNS, _attrs, Lang);
 +decode_error_text_attrs(__TopXMLNS, [], Lang) ->
 +    'decode_error_text_attr_xml:lang'(__TopXMLNS, Lang).
 +
 +encode_error_text({text, Lang, Data}, __TopXMLNS) ->
 +    __NewTopXMLNS =
 +      choose_top_xmlns(<<"urn:ietf:params:xml:ns:xmpp-stanzas">>,
 +                       [], __TopXMLNS),
 +    _els = encode_error_text_cdata(Data, []),
 +    _attrs = 'encode_error_text_attr_xml:lang'(Lang,
 +                                             enc_xmlns_attrs(__NewTopXMLNS,
 +                                                             __TopXMLNS)),
 +    {xmlel, <<"text">>, _attrs, _els}.
 +
 +'decode_error_text_attr_xml:lang'(__TopXMLNS,
 +                                undefined) ->
 +    <<>>;
 +'decode_error_text_attr_xml:lang'(__TopXMLNS, _val) ->
 +    _val.
 +
 +'encode_error_text_attr_xml:lang'(<<>>, _acc) -> _acc;
 +'encode_error_text_attr_xml:lang'(_val, _acc) ->
 +    [{<<"xml:lang">>, _val} | _acc].
 +
 +decode_error_text_cdata(__TopXMLNS, <<>>) -> <<>>;
 +decode_error_text_cdata(__TopXMLNS, _val) -> _val.
 +
 +encode_error_text_cdata(<<>>, _acc) -> _acc;
 +encode_error_text_cdata(_val, _acc) ->
 +    [{xmlcdata, _val} | _acc].
 +
 +decode_error_unexpected_request(__TopXMLNS, __IgnoreEls,
 +                              {xmlel, <<"unexpected-request">>, _attrs,
 +                               _els}) ->
 +    'unexpected-request'.
 +
 +encode_error_unexpected_request('unexpected-request',
 +                              __TopXMLNS) ->
 +    __NewTopXMLNS =
 +      choose_top_xmlns(<<"urn:ietf:params:xml:ns:xmpp-stanzas">>,
 +                       [], __TopXMLNS),
 +    _els = [],
 +    _attrs = enc_xmlns_attrs(__NewTopXMLNS, __TopXMLNS),
 +    {xmlel, <<"unexpected-request">>, _attrs, _els}.
 +
 +decode_error_undefined_condition(__TopXMLNS,
 +                               __IgnoreEls,
 +                               {xmlel, <<"undefined-condition">>, _attrs,
 +                                _els}) ->
 +    'undefined-condition'.
 +
 +encode_error_undefined_condition('undefined-condition',
 +                               __TopXMLNS) ->
 +    __NewTopXMLNS =
 +      choose_top_xmlns(<<"urn:ietf:params:xml:ns:xmpp-stanzas">>,
 +                       [], __TopXMLNS),
 +    _els = [],
 +    _attrs = enc_xmlns_attrs(__NewTopXMLNS, __TopXMLNS),
 +    {xmlel, <<"undefined-condition">>, _attrs, _els}.
 +
 +decode_error_subscription_required(__TopXMLNS,
 +                                 __IgnoreEls,
 +                                 {xmlel, <<"subscription-required">>, _attrs,
 +                                  _els}) ->
 +    'subscription-required'.
 +
 +encode_error_subscription_required('subscription-required',
 +                                 __TopXMLNS) ->
 +    __NewTopXMLNS =
 +      choose_top_xmlns(<<"urn:ietf:params:xml:ns:xmpp-stanzas">>,
 +                       [], __TopXMLNS),
 +    _els = [],
 +    _attrs = enc_xmlns_attrs(__NewTopXMLNS, __TopXMLNS),
 +    {xmlel, <<"subscription-required">>, _attrs, _els}.
 +
 +decode_error_service_unavailable(__TopXMLNS,
 +                               __IgnoreEls,
 +                               {xmlel, <<"service-unavailable">>, _attrs,
 +                                _els}) ->
 +    'service-unavailable'.
 +
 +encode_error_service_unavailable('service-unavailable',
 +                               __TopXMLNS) ->
 +    __NewTopXMLNS =
 +      choose_top_xmlns(<<"urn:ietf:params:xml:ns:xmpp-stanzas">>,
 +                       [], __TopXMLNS),
 +    _els = [],
 +    _attrs = enc_xmlns_attrs(__NewTopXMLNS, __TopXMLNS),
 +    {xmlel, <<"service-unavailable">>, _attrs, _els}.
 +
 +decode_error_resource_constraint(__TopXMLNS,
 +                               __IgnoreEls,
 +                               {xmlel, <<"resource-constraint">>, _attrs,
 +                                _els}) ->
 +    'resource-constraint'.
 +
 +encode_error_resource_constraint('resource-constraint',
 +                               __TopXMLNS) ->
 +    __NewTopXMLNS =
 +      choose_top_xmlns(<<"urn:ietf:params:xml:ns:xmpp-stanzas">>,
 +                       [], __TopXMLNS),
 +    _els = [],
 +    _attrs = enc_xmlns_attrs(__NewTopXMLNS, __TopXMLNS),
 +    {xmlel, <<"resource-constraint">>, _attrs, _els}.
 +
 +decode_error_remote_server_timeout(__TopXMLNS,
 +                                 __IgnoreEls,
 +                                 {xmlel, <<"remote-server-timeout">>, _attrs,
 +                                  _els}) ->
 +    'remote-server-timeout'.
 +
 +encode_error_remote_server_timeout('remote-server-timeout',
 +                                 __TopXMLNS) ->
 +    __NewTopXMLNS =
 +      choose_top_xmlns(<<"urn:ietf:params:xml:ns:xmpp-stanzas">>,
 +                       [], __TopXMLNS),
 +    _els = [],
 +    _attrs = enc_xmlns_attrs(__NewTopXMLNS, __TopXMLNS),
 +    {xmlel, <<"remote-server-timeout">>, _attrs, _els}.
 +
 +decode_error_remote_server_not_found(__TopXMLNS,
 +                                   __IgnoreEls,
 +                                   {xmlel, <<"remote-server-not-found">>,
 +                                    _attrs, _els}) ->
 +    'remote-server-not-found'.
 +
 +encode_error_remote_server_not_found('remote-server-not-found',
 +                                   __TopXMLNS) ->
 +    __NewTopXMLNS =
 +      choose_top_xmlns(<<"urn:ietf:params:xml:ns:xmpp-stanzas">>,
 +                       [], __TopXMLNS),
 +    _els = [],
 +    _attrs = enc_xmlns_attrs(__NewTopXMLNS, __TopXMLNS),
 +    {xmlel, <<"remote-server-not-found">>, _attrs, _els}.
 +
 +decode_error_registration_required(__TopXMLNS,
 +                                 __IgnoreEls,
 +                                 {xmlel, <<"registration-required">>, _attrs,
 +                                  _els}) ->
 +    'registration-required'.
 +
 +encode_error_registration_required('registration-required',
 +                                 __TopXMLNS) ->
 +    __NewTopXMLNS =
 +      choose_top_xmlns(<<"urn:ietf:params:xml:ns:xmpp-stanzas">>,
 +                       [], __TopXMLNS),
 +    _els = [],
 +    _attrs = enc_xmlns_attrs(__NewTopXMLNS, __TopXMLNS),
 +    {xmlel, <<"registration-required">>, _attrs, _els}.
 +
 +decode_error_redirect(__TopXMLNS, __IgnoreEls,
 +                    {xmlel, <<"redirect">>, _attrs, _els}) ->
 +    Uri = decode_error_redirect_els(__TopXMLNS, __IgnoreEls,
 +                                  _els, <<>>),
 +    {redirect, Uri}.
 +
 +decode_error_redirect_els(__TopXMLNS, __IgnoreEls, [],
 +                        Uri) ->
 +    decode_error_redirect_cdata(__TopXMLNS, Uri);
 +decode_error_redirect_els(__TopXMLNS, __IgnoreEls,
 +                        [{xmlcdata, _data} | _els], Uri) ->
 +    decode_error_redirect_els(__TopXMLNS, __IgnoreEls, _els,
 +                            <<Uri/binary, _data/binary>>);
 +decode_error_redirect_els(__TopXMLNS, __IgnoreEls,
 +                        [_ | _els], Uri) ->
 +    decode_error_redirect_els(__TopXMLNS, __IgnoreEls, _els,
 +                            Uri).
 +
 +encode_error_redirect({redirect, Uri}, __TopXMLNS) ->
 +    __NewTopXMLNS =
 +      choose_top_xmlns(<<"urn:ietf:params:xml:ns:xmpp-stanzas">>,
 +                       [], __TopXMLNS),
 +    _els = encode_error_redirect_cdata(Uri, []),
 +    _attrs = enc_xmlns_attrs(__NewTopXMLNS, __TopXMLNS),
 +    {xmlel, <<"redirect">>, _attrs, _els}.
 +
 +decode_error_redirect_cdata(__TopXMLNS, <<>>) -> <<>>;
 +decode_error_redirect_cdata(__TopXMLNS, _val) -> _val.
 +
 +encode_error_redirect_cdata(<<>>, _acc) -> _acc;
 +encode_error_redirect_cdata(_val, _acc) ->
 +    [{xmlcdata, _val} | _acc].
 +
 +decode_error_recipient_unavailable(__TopXMLNS,
 +                                 __IgnoreEls,
 +                                 {xmlel, <<"recipient-unavailable">>, _attrs,
 +                                  _els}) ->
 +    'recipient-unavailable'.
 +
 +encode_error_recipient_unavailable('recipient-unavailable',
 +                                 __TopXMLNS) ->
 +    __NewTopXMLNS =
 +      choose_top_xmlns(<<"urn:ietf:params:xml:ns:xmpp-stanzas">>,
 +                       [], __TopXMLNS),
 +    _els = [],
 +    _attrs = enc_xmlns_attrs(__NewTopXMLNS, __TopXMLNS),
 +    {xmlel, <<"recipient-unavailable">>, _attrs, _els}.
 +
 +decode_error_policy_violation(__TopXMLNS, __IgnoreEls,
 +                            {xmlel, <<"policy-violation">>, _attrs, _els}) ->
 +    'policy-violation'.
 +
 +encode_error_policy_violation('policy-violation',
 +                            __TopXMLNS) ->
 +    __NewTopXMLNS =
 +      choose_top_xmlns(<<"urn:ietf:params:xml:ns:xmpp-stanzas">>,
 +                       [], __TopXMLNS),
 +    _els = [],
 +    _attrs = enc_xmlns_attrs(__NewTopXMLNS, __TopXMLNS),
 +    {xmlel, <<"policy-violation">>, _attrs, _els}.
 +
 +decode_error_payment_required(__TopXMLNS, __IgnoreEls,
 +                            {xmlel, <<"payment-required">>, _attrs, _els}) ->
 +    'payment-required'.
 +
 +encode_error_payment_required('payment-required',
 +                            __TopXMLNS) ->
 +    __NewTopXMLNS =
 +      choose_top_xmlns(<<"urn:ietf:params:xml:ns:xmpp-stanzas">>,
 +                       [], __TopXMLNS),
 +    _els = [],
 +    _attrs = enc_xmlns_attrs(__NewTopXMLNS, __TopXMLNS),
 +    {xmlel, <<"payment-required">>, _attrs, _els}.
 +
 +decode_error_not_authorized(__TopXMLNS, __IgnoreEls,
 +                          {xmlel, <<"not-authorized">>, _attrs, _els}) ->
 +    'not-authorized'.
 +
 +encode_error_not_authorized('not-authorized',
 +                          __TopXMLNS) ->
 +    __NewTopXMLNS =
 +      choose_top_xmlns(<<"urn:ietf:params:xml:ns:xmpp-stanzas">>,
 +                       [], __TopXMLNS),
 +    _els = [],
 +    _attrs = enc_xmlns_attrs(__NewTopXMLNS, __TopXMLNS),
 +    {xmlel, <<"not-authorized">>, _attrs, _els}.
 +
 +decode_error_not_allowed(__TopXMLNS, __IgnoreEls,
 +                       {xmlel, <<"not-allowed">>, _attrs, _els}) ->
 +    'not-allowed'.
 +
 +encode_error_not_allowed('not-allowed', __TopXMLNS) ->
 +    __NewTopXMLNS =
 +      choose_top_xmlns(<<"urn:ietf:params:xml:ns:xmpp-stanzas">>,
 +                       [], __TopXMLNS),
 +    _els = [],
 +    _attrs = enc_xmlns_attrs(__NewTopXMLNS, __TopXMLNS),
 +    {xmlel, <<"not-allowed">>, _attrs, _els}.
 +
 +decode_error_not_acceptable(__TopXMLNS, __IgnoreEls,
 +                          {xmlel, <<"not-acceptable">>, _attrs, _els}) ->
 +    'not-acceptable'.
 +
 +encode_error_not_acceptable('not-acceptable',
 +                          __TopXMLNS) ->
 +    __NewTopXMLNS =
 +      choose_top_xmlns(<<"urn:ietf:params:xml:ns:xmpp-stanzas">>,
 +                       [], __TopXMLNS),
 +    _els = [],
 +    _attrs = enc_xmlns_attrs(__NewTopXMLNS, __TopXMLNS),
 +    {xmlel, <<"not-acceptable">>, _attrs, _els}.
 +
 +decode_error_jid_malformed(__TopXMLNS, __IgnoreEls,
 +                         {xmlel, <<"jid-malformed">>, _attrs, _els}) ->
 +    'jid-malformed'.
 +
 +encode_error_jid_malformed('jid-malformed',
 +                         __TopXMLNS) ->
 +    __NewTopXMLNS =
 +      choose_top_xmlns(<<"urn:ietf:params:xml:ns:xmpp-stanzas">>,
 +                       [], __TopXMLNS),
 +    _els = [],
 +    _attrs = enc_xmlns_attrs(__NewTopXMLNS, __TopXMLNS),
 +    {xmlel, <<"jid-malformed">>, _attrs, _els}.
 +
 +decode_error_item_not_found(__TopXMLNS, __IgnoreEls,
 +                          {xmlel, <<"item-not-found">>, _attrs, _els}) ->
 +    'item-not-found'.
 +
 +encode_error_item_not_found('item-not-found',
 +                          __TopXMLNS) ->
 +    __NewTopXMLNS =
 +      choose_top_xmlns(<<"urn:ietf:params:xml:ns:xmpp-stanzas">>,
 +                       [], __TopXMLNS),
 +    _els = [],
 +    _attrs = enc_xmlns_attrs(__NewTopXMLNS, __TopXMLNS),
 +    {xmlel, <<"item-not-found">>, _attrs, _els}.
 +
 +decode_error_internal_server_error(__TopXMLNS,
 +                                 __IgnoreEls,
 +                                 {xmlel, <<"internal-server-error">>, _attrs,
 +                                  _els}) ->
 +    'internal-server-error'.
 +
 +encode_error_internal_server_error('internal-server-error',
 +                                 __TopXMLNS) ->
 +    __NewTopXMLNS =
 +      choose_top_xmlns(<<"urn:ietf:params:xml:ns:xmpp-stanzas">>,
 +                       [], __TopXMLNS),
 +    _els = [],
 +    _attrs = enc_xmlns_attrs(__NewTopXMLNS, __TopXMLNS),
 +    {xmlel, <<"internal-server-error">>, _attrs, _els}.
 +
 +decode_error_gone(__TopXMLNS, __IgnoreEls,
 +                {xmlel, <<"gone">>, _attrs, _els}) ->
 +    Uri = decode_error_gone_els(__TopXMLNS, __IgnoreEls,
 +                              _els, <<>>),
 +    {gone, Uri}.
 +
 +decode_error_gone_els(__TopXMLNS, __IgnoreEls, [],
 +                    Uri) ->
 +    decode_error_gone_cdata(__TopXMLNS, Uri);
 +decode_error_gone_els(__TopXMLNS, __IgnoreEls,
 +                    [{xmlcdata, _data} | _els], Uri) ->
 +    decode_error_gone_els(__TopXMLNS, __IgnoreEls, _els,
 +                        <<Uri/binary, _data/binary>>);
 +decode_error_gone_els(__TopXMLNS, __IgnoreEls,
 +                    [_ | _els], Uri) ->
 +    decode_error_gone_els(__TopXMLNS, __IgnoreEls, _els,
 +                        Uri).
 +
 +encode_error_gone({gone, Uri}, __TopXMLNS) ->
 +    __NewTopXMLNS =
 +      choose_top_xmlns(<<"urn:ietf:params:xml:ns:xmpp-stanzas">>,
 +                       [], __TopXMLNS),
 +    _els = encode_error_gone_cdata(Uri, []),
 +    _attrs = enc_xmlns_attrs(__NewTopXMLNS, __TopXMLNS),
 +    {xmlel, <<"gone">>, _attrs, _els}.
 +
 +decode_error_gone_cdata(__TopXMLNS, <<>>) -> <<>>;
 +decode_error_gone_cdata(__TopXMLNS, _val) -> _val.
 +
 +encode_error_gone_cdata(<<>>, _acc) -> _acc;
 +encode_error_gone_cdata(_val, _acc) ->
 +    [{xmlcdata, _val} | _acc].
 +
 +decode_error_forbidden(__TopXMLNS, __IgnoreEls,
 +                     {xmlel, <<"forbidden">>, _attrs, _els}) ->
 +    forbidden.
 +
 +encode_error_forbidden(forbidden, __TopXMLNS) ->
 +    __NewTopXMLNS =
 +      choose_top_xmlns(<<"urn:ietf:params:xml:ns:xmpp-stanzas">>,
 +                       [], __TopXMLNS),
 +    _els = [],
 +    _attrs = enc_xmlns_attrs(__NewTopXMLNS, __TopXMLNS),
 +    {xmlel, <<"forbidden">>, _attrs, _els}.
 +
 +decode_error_feature_not_implemented(__TopXMLNS,
 +                                   __IgnoreEls,
 +                                   {xmlel, <<"feature-not-implemented">>,
 +                                    _attrs, _els}) ->
 +    'feature-not-implemented'.
 +
 +encode_error_feature_not_implemented('feature-not-implemented',
 +                                   __TopXMLNS) ->
 +    __NewTopXMLNS =
 +      choose_top_xmlns(<<"urn:ietf:params:xml:ns:xmpp-stanzas">>,
 +                       [], __TopXMLNS),
 +    _els = [],
 +    _attrs = enc_xmlns_attrs(__NewTopXMLNS, __TopXMLNS),
 +    {xmlel, <<"feature-not-implemented">>, _attrs, _els}.
 +
 +decode_error_conflict(__TopXMLNS, __IgnoreEls,
 +                    {xmlel, <<"conflict">>, _attrs, _els}) ->
 +    conflict.
 +
 +encode_error_conflict(conflict, __TopXMLNS) ->
 +    __NewTopXMLNS =
 +      choose_top_xmlns(<<"urn:ietf:params:xml:ns:xmpp-stanzas">>,
 +                       [], __TopXMLNS),
 +    _els = [],
 +    _attrs = enc_xmlns_attrs(__NewTopXMLNS, __TopXMLNS),
 +    {xmlel, <<"conflict">>, _attrs, _els}.
 +
 +decode_error_bad_request(__TopXMLNS, __IgnoreEls,
 +                       {xmlel, <<"bad-request">>, _attrs, _els}) ->
 +    'bad-request'.
 +
 +encode_error_bad_request('bad-request', __TopXMLNS) ->
 +    __NewTopXMLNS =
 +      choose_top_xmlns(<<"urn:ietf:params:xml:ns:xmpp-stanzas">>,
 +                       [], __TopXMLNS),
 +    _els = [],
 +    _attrs = enc_xmlns_attrs(__NewTopXMLNS, __TopXMLNS),
 +    {xmlel, <<"bad-request">>, _attrs, _els}.
 +
 +decode_presence(__TopXMLNS, __IgnoreEls,
 +              {xmlel, <<"presence">>, _attrs, _els}) ->
 +    {Status, Show, Priority, __Els} =
 +      decode_presence_els(__TopXMLNS, __IgnoreEls, _els, [],
 +                          undefined, undefined, []),
 +    {Id, Type, From, To, Lang} =
 +      decode_presence_attrs(__TopXMLNS, _attrs, undefined,
 +                            undefined, undefined, undefined, undefined),
 +    {presence, Id, Type, Lang, From, To, Show, Status,
 +     Priority, __Els}.
 +
 +decode_presence_els(__TopXMLNS, __IgnoreEls, [], Status,
 +                  Show, Priority, __Els) ->
 +    {lists:reverse(Status), Show, Priority,
 +     lists:reverse(__Els)};
 +decode_presence_els(__TopXMLNS, __IgnoreEls,
 +                  [{xmlel, <<"show">>, _attrs, _} = _el | _els], Status,
 +                  Show, Priority, __Els) ->
 +    case get_attr(<<"xmlns">>, _attrs) of
 +      <<"">>
 +        when __TopXMLNS == <<"jabber:server">>;
 +             __TopXMLNS == <<"jabber:component:accept">>;
 +             __TopXMLNS == <<"jabber:client">> ->
 +        decode_presence_els(__TopXMLNS, __IgnoreEls, _els,
 +                            Status,
 +                            decode_presence_show(__TopXMLNS, __IgnoreEls,
 +                                                 _el),
 +                            Priority, __Els);
 +      <<"jabber:client">> ->
 +        decode_presence_els(__TopXMLNS, __IgnoreEls, _els,
 +                            Status,
 +                            decode_presence_show(<<"jabber:client">>,
 +                                                 __IgnoreEls, _el),
 +                            Priority, __Els);
 +      <<"jabber:server">> ->
 +        decode_presence_els(__TopXMLNS, __IgnoreEls, _els,
 +                            Status,
 +                            decode_presence_show(<<"jabber:server">>,
 +                                                 __IgnoreEls, _el),
 +                            Priority, __Els);
 +      <<"jabber:component:accept">> ->
 +        decode_presence_els(__TopXMLNS, __IgnoreEls, _els,
 +                            Status,
 +                            decode_presence_show(<<"jabber:component:accept">>,
 +                                                 __IgnoreEls, _el),
 +                            Priority, __Els);
 +      _ ->
 +        decode_presence_els(__TopXMLNS, __IgnoreEls, _els,
 +                            Status, Show, Priority, __Els)
 +    end;
 +decode_presence_els(__TopXMLNS, __IgnoreEls,
 +                  [{xmlel, <<"status">>, _attrs, _} = _el | _els], Status,
 +                  Show, Priority, __Els) ->
 +    case get_attr(<<"xmlns">>, _attrs) of
 +      <<"">>
 +        when __TopXMLNS == <<"jabber:server">>;
 +             __TopXMLNS == <<"jabber:component:accept">>;
 +             __TopXMLNS == <<"jabber:client">> ->
 +        decode_presence_els(__TopXMLNS, __IgnoreEls, _els,
 +                            [decode_presence_status(__TopXMLNS, __IgnoreEls,
 +                                                    _el)
 +                             | Status],
 +                            Show, Priority, __Els);
 +      <<"jabber:client">> ->
 +        decode_presence_els(__TopXMLNS, __IgnoreEls, _els,
 +                            [decode_presence_status(<<"jabber:client">>,
 +                                                    __IgnoreEls, _el)
 +                             | Status],
 +                            Show, Priority, __Els);
 +      <<"jabber:server">> ->
 +        decode_presence_els(__TopXMLNS, __IgnoreEls, _els,
 +                            [decode_presence_status(<<"jabber:server">>,
 +                                                    __IgnoreEls, _el)
 +                             | Status],
 +                            Show, Priority, __Els);
 +      <<"jabber:component:accept">> ->
 +        decode_presence_els(__TopXMLNS, __IgnoreEls, _els,
 +                            [decode_presence_status(<<"jabber:component:accept">>,
 +                                                    __IgnoreEls, _el)
 +                             | Status],
 +                            Show, Priority, __Els);
 +      _ ->
 +        decode_presence_els(__TopXMLNS, __IgnoreEls, _els,
 +                            Status, Show, Priority, __Els)
 +    end;
 +decode_presence_els(__TopXMLNS, __IgnoreEls,
 +                  [{xmlel, <<"priority">>, _attrs, _} = _el | _els],
 +                  Status, Show, Priority, __Els) ->
 +    case get_attr(<<"xmlns">>, _attrs) of
 +      <<"">>
 +        when __TopXMLNS == <<"jabber:server">>;
 +             __TopXMLNS == <<"jabber:component:accept">>;
 +             __TopXMLNS == <<"jabber:client">> ->
 +        decode_presence_els(__TopXMLNS, __IgnoreEls, _els,
 +                            Status, Show,
 +                            decode_presence_priority(__TopXMLNS, __IgnoreEls,
 +                                                     _el),
 +                            __Els);
 +      <<"jabber:client">> ->
 +        decode_presence_els(__TopXMLNS, __IgnoreEls, _els,
 +                            Status, Show,
 +                            decode_presence_priority(<<"jabber:client">>,
 +                                                     __IgnoreEls, _el),
 +                            __Els);
 +      <<"jabber:server">> ->
 +        decode_presence_els(__TopXMLNS, __IgnoreEls, _els,
 +                            Status, Show,
 +                            decode_presence_priority(<<"jabber:server">>,
 +                                                     __IgnoreEls, _el),
 +                            __Els);
 +      <<"jabber:component:accept">> ->
 +        decode_presence_els(__TopXMLNS, __IgnoreEls, _els,
 +                            Status, Show,
 +                            decode_presence_priority(<<"jabber:component:accept">>,
 +                                                     __IgnoreEls, _el),
 +                            __Els);
 +      _ ->
 +        decode_presence_els(__TopXMLNS, __IgnoreEls, _els,
 +                            Status, Show, Priority, __Els)
 +    end;
 +decode_presence_els(__TopXMLNS, __IgnoreEls,
 +                  [{xmlel, _, _, _} = _el | _els], Status, Show, Priority,
 +                  __Els) ->
 +    if __IgnoreEls ->
 +         decode_presence_els(__TopXMLNS, __IgnoreEls, _els,
 +                             Status, Show, Priority, [_el | __Els]);
 +       true ->
 +         case is_known_tag(_el, __TopXMLNS) of
 +           true ->
 +               decode_presence_els(__TopXMLNS, __IgnoreEls, _els,
 +                                   Status, Show, Priority,
 +                                   [decode(_el, __TopXMLNS, []) | __Els]);
 +           false ->
 +               decode_presence_els(__TopXMLNS, __IgnoreEls, _els,
 +                                   Status, Show, Priority, __Els)
 +         end
 +    end;
 +decode_presence_els(__TopXMLNS, __IgnoreEls, [_ | _els],
 +                  Status, Show, Priority, __Els) ->
 +    decode_presence_els(__TopXMLNS, __IgnoreEls, _els,
 +                      Status, Show, Priority, __Els).
 +
 +decode_presence_attrs(__TopXMLNS,
 +                    [{<<"id">>, _val} | _attrs], _Id, Type, From, To,
 +                    Lang) ->
 +    decode_presence_attrs(__TopXMLNS, _attrs, _val, Type,
 +                        From, To, Lang);
 +decode_presence_attrs(__TopXMLNS,
 +                    [{<<"type">>, _val} | _attrs], Id, _Type, From, To,
 +                    Lang) ->
 +    decode_presence_attrs(__TopXMLNS, _attrs, Id, _val,
 +                        From, To, Lang);
 +decode_presence_attrs(__TopXMLNS,
 +                    [{<<"from">>, _val} | _attrs], Id, Type, _From, To,
 +                    Lang) ->
 +    decode_presence_attrs(__TopXMLNS, _attrs, Id, Type,
 +                        _val, To, Lang);
 +decode_presence_attrs(__TopXMLNS,
 +                    [{<<"to">>, _val} | _attrs], Id, Type, From, _To,
 +                    Lang) ->
 +    decode_presence_attrs(__TopXMLNS, _attrs, Id, Type,
 +                        From, _val, Lang);
 +decode_presence_attrs(__TopXMLNS,
 +                    [{<<"xml:lang">>, _val} | _attrs], Id, Type, From, To,
 +                    _Lang) ->
 +    decode_presence_attrs(__TopXMLNS, _attrs, Id, Type,
 +                        From, To, _val);
 +decode_presence_attrs(__TopXMLNS, [_ | _attrs], Id,
 +                    Type, From, To, Lang) ->
 +    decode_presence_attrs(__TopXMLNS, _attrs, Id, Type,
 +                        From, To, Lang);
 +decode_presence_attrs(__TopXMLNS, [], Id, Type, From,
 +                    To, Lang) ->
 +    {decode_presence_attr_id(__TopXMLNS, Id),
 +     decode_presence_attr_type(__TopXMLNS, Type),
 +     decode_presence_attr_from(__TopXMLNS, From),
 +     decode_presence_attr_to(__TopXMLNS, To),
 +     'decode_presence_attr_xml:lang'(__TopXMLNS, Lang)}.
 +
 +encode_presence({presence, Id, Type, Lang, From, To,
 +               Show, Status, Priority, __Els},
 +              __TopXMLNS) ->
 +    __NewTopXMLNS = choose_top_xmlns(<<>>,
 +                                   [<<"jabber:client">>, <<"jabber:server">>,
 +                                    <<"jabber:component:accept">>],
 +                                   __TopXMLNS),
 +    _els = [encode(_el, __NewTopXMLNS) || _el <- __Els] ++
 +           lists:reverse('encode_presence_$status'(Status,
 +                                                   __NewTopXMLNS,
 +                                                   'encode_presence_$show'(Show,
 +                                                                           __NewTopXMLNS,
 +                                                                           'encode_presence_$priority'(Priority,
 +                                                                                                       __NewTopXMLNS,
 +                                                                                                       [])))),
 +    _attrs = 'encode_presence_attr_xml:lang'(Lang,
 +                                           encode_presence_attr_to(To,
 +                                                                   encode_presence_attr_from(From,
 +                                                                                             encode_presence_attr_type(Type,
 +                                                                                                                       encode_presence_attr_id(Id,
 +                                                                                                                                               enc_xmlns_attrs(__NewTopXMLNS,
 +                                                                                                                                                               __TopXMLNS)))))),
 +    {xmlel, <<"presence">>, _attrs, _els}.
 +
 +'encode_presence_$status'([], __TopXMLNS, _acc) -> _acc;
 +'encode_presence_$status'([Status | _els], __TopXMLNS,
 +                        _acc) ->
 +    'encode_presence_$status'(_els, __TopXMLNS,
 +                            [encode_presence_status(Status, __TopXMLNS)
 +                             | _acc]).
 +
 +'encode_presence_$show'(undefined, __TopXMLNS, _acc) ->
 +    _acc;
 +'encode_presence_$show'(Show, __TopXMLNS, _acc) ->
 +    [encode_presence_show(Show, __TopXMLNS) | _acc].
 +
 +'encode_presence_$priority'(undefined, __TopXMLNS,
 +                          _acc) ->
 +    _acc;
 +'encode_presence_$priority'(Priority, __TopXMLNS,
 +                          _acc) ->
 +    [encode_presence_priority(Priority, __TopXMLNS) | _acc].
 +
 +decode_presence_attr_id(__TopXMLNS, undefined) -> <<>>;
 +decode_presence_attr_id(__TopXMLNS, _val) -> _val.
 +
 +encode_presence_attr_id(<<>>, _acc) -> _acc;
 +encode_presence_attr_id(_val, _acc) ->
 +    [{<<"id">>, _val} | _acc].
 +
 +decode_presence_attr_type(__TopXMLNS, undefined) ->
 +    available;
 +decode_presence_attr_type(__TopXMLNS, _val) ->
 +    case catch dec_enum(_val,
 +                      [unavailable, subscribe, subscribed, unsubscribe,
 +                       unsubscribed, available, probe, error])
 +      of
 +      {'EXIT', _} ->
 +        erlang:error({xmpp_codec,
 +                      {bad_attr_value, <<"type">>, <<"presence">>,
 +                       __TopXMLNS}});
 +      _res -> _res
 +    end.
 +
 +encode_presence_attr_type(available, _acc) -> _acc;
 +encode_presence_attr_type(_val, _acc) ->
 +    [{<<"type">>, enc_enum(_val)} | _acc].
 +
 +decode_presence_attr_from(__TopXMLNS, undefined) ->
 +    undefined;
 +decode_presence_attr_from(__TopXMLNS, _val) ->
 +    case catch dec_jid(_val) of
 +      {'EXIT', _} ->
 +        erlang:error({xmpp_codec,
 +                      {bad_attr_value, <<"from">>, <<"presence">>,
 +                       __TopXMLNS}});
 +      _res -> _res
 +    end.
 +
 +encode_presence_attr_from(undefined, _acc) -> _acc;
 +encode_presence_attr_from(_val, _acc) ->
 +    [{<<"from">>, enc_jid(_val)} | _acc].
 +
 +decode_presence_attr_to(__TopXMLNS, undefined) ->
 +    undefined;
 +decode_presence_attr_to(__TopXMLNS, _val) ->
 +    case catch dec_jid(_val) of
 +      {'EXIT', _} ->
 +        erlang:error({xmpp_codec,
 +                      {bad_attr_value, <<"to">>, <<"presence">>,
 +                       __TopXMLNS}});
 +      _res -> _res
 +    end.
 +
 +encode_presence_attr_to(undefined, _acc) -> _acc;
 +encode_presence_attr_to(_val, _acc) ->
 +    [{<<"to">>, enc_jid(_val)} | _acc].
 +
 +'decode_presence_attr_xml:lang'(__TopXMLNS,
 +                              undefined) ->
 +    <<>>;
 +'decode_presence_attr_xml:lang'(__TopXMLNS, _val) ->
 +    _val.
 +
 +'encode_presence_attr_xml:lang'(<<>>, _acc) -> _acc;
 +'encode_presence_attr_xml:lang'(_val, _acc) ->
 +    [{<<"xml:lang">>, _val} | _acc].
 +
 +decode_presence_priority(__TopXMLNS, __IgnoreEls,
 +                       {xmlel, <<"priority">>, _attrs, _els}) ->
 +    Cdata = decode_presence_priority_els(__TopXMLNS,
 +                                       __IgnoreEls, _els, <<>>),
 +    Cdata.
 +
 +decode_presence_priority_els(__TopXMLNS, __IgnoreEls,
 +                           [], Cdata) ->
 +    decode_presence_priority_cdata(__TopXMLNS, Cdata);
 +decode_presence_priority_els(__TopXMLNS, __IgnoreEls,
 +                           [{xmlcdata, _data} | _els], Cdata) ->
 +    decode_presence_priority_els(__TopXMLNS, __IgnoreEls,
 +                               _els, <<Cdata/binary, _data/binary>>);
 +decode_presence_priority_els(__TopXMLNS, __IgnoreEls,
 +                           [_ | _els], Cdata) ->
 +    decode_presence_priority_els(__TopXMLNS, __IgnoreEls,
 +                               _els, Cdata).
 +
 +encode_presence_priority(Cdata, __TopXMLNS) ->
 +    __NewTopXMLNS = choose_top_xmlns(<<>>,
 +                                   [<<"jabber:client">>, <<"jabber:server">>,
 +                                    <<"jabber:component:accept">>],
 +                                   __TopXMLNS),
 +    _els = encode_presence_priority_cdata(Cdata, []),
 +    _attrs = enc_xmlns_attrs(__NewTopXMLNS, __TopXMLNS),
 +    {xmlel, <<"priority">>, _attrs, _els}.
 +
 +decode_presence_priority_cdata(__TopXMLNS, <<>>) ->
 +    undefined;
 +decode_presence_priority_cdata(__TopXMLNS, _val) ->
 +    case catch dec_int(_val) of
 +      {'EXIT', _} ->
 +        erlang:error({xmpp_codec,
 +                      {bad_cdata_value, <<>>, <<"priority">>, __TopXMLNS}});
 +      _res -> _res
 +    end.
 +
 +encode_presence_priority_cdata(undefined, _acc) -> _acc;
 +encode_presence_priority_cdata(_val, _acc) ->
 +    [{xmlcdata, enc_int(_val)} | _acc].
 +
 +decode_presence_status(__TopXMLNS, __IgnoreEls,
 +                     {xmlel, <<"status">>, _attrs, _els}) ->
 +    Data = decode_presence_status_els(__TopXMLNS,
 +                                    __IgnoreEls, _els, <<>>),
 +    Lang = decode_presence_status_attrs(__TopXMLNS, _attrs,
 +                                      undefined),
 +    {text, Lang, Data}.
 +
 +decode_presence_status_els(__TopXMLNS, __IgnoreEls, [],
 +                         Data) ->
 +    decode_presence_status_cdata(__TopXMLNS, Data);
 +decode_presence_status_els(__TopXMLNS, __IgnoreEls,
 +                         [{xmlcdata, _data} | _els], Data) ->
 +    decode_presence_status_els(__TopXMLNS, __IgnoreEls,
 +                             _els, <<Data/binary, _data/binary>>);
 +decode_presence_status_els(__TopXMLNS, __IgnoreEls,
 +                         [_ | _els], Data) ->
 +    decode_presence_status_els(__TopXMLNS, __IgnoreEls,
 +                             _els, Data).
 +
 +decode_presence_status_attrs(__TopXMLNS,
 +                           [{<<"xml:lang">>, _val} | _attrs], _Lang) ->
 +    decode_presence_status_attrs(__TopXMLNS, _attrs, _val);
 +decode_presence_status_attrs(__TopXMLNS, [_ | _attrs],
 +                           Lang) ->
 +    decode_presence_status_attrs(__TopXMLNS, _attrs, Lang);
 +decode_presence_status_attrs(__TopXMLNS, [], Lang) ->
 +    'decode_presence_status_attr_xml:lang'(__TopXMLNS,
 +                                         Lang).
 +
 +encode_presence_status({text, Lang, Data},
 +                     __TopXMLNS) ->
 +    __NewTopXMLNS = choose_top_xmlns(<<>>,
 +                                   [<<"jabber:client">>, <<"jabber:server">>,
 +                                    <<"jabber:component:accept">>],
 +                                   __TopXMLNS),
 +    _els = encode_presence_status_cdata(Data, []),
 +    _attrs = 'encode_presence_status_attr_xml:lang'(Lang,
 +                                                  enc_xmlns_attrs(__NewTopXMLNS,
 +                                                                  __TopXMLNS)),
 +    {xmlel, <<"status">>, _attrs, _els}.
 +
 +'decode_presence_status_attr_xml:lang'(__TopXMLNS,
 +                                     undefined) ->
 +    <<>>;
 +'decode_presence_status_attr_xml:lang'(__TopXMLNS,
 +                                     _val) ->
 +    _val.
 +
 +'encode_presence_status_attr_xml:lang'(<<>>, _acc) ->
 +    _acc;
 +'encode_presence_status_attr_xml:lang'(_val, _acc) ->
 +    [{<<"xml:lang">>, _val} | _acc].
 +
 +decode_presence_status_cdata(__TopXMLNS, <<>>) -> <<>>;
 +decode_presence_status_cdata(__TopXMLNS, _val) -> _val.
 +
 +encode_presence_status_cdata(<<>>, _acc) -> _acc;
 +encode_presence_status_cdata(_val, _acc) ->
 +    [{xmlcdata, _val} | _acc].
 +
 +decode_presence_show(__TopXMLNS, __IgnoreEls,
 +                   {xmlel, <<"show">>, _attrs, _els}) ->
 +    Cdata = decode_presence_show_els(__TopXMLNS,
 +                                   __IgnoreEls, _els, <<>>),
 +    Cdata.
 +
 +decode_presence_show_els(__TopXMLNS, __IgnoreEls, [],
 +                       Cdata) ->
 +    decode_presence_show_cdata(__TopXMLNS, Cdata);
 +decode_presence_show_els(__TopXMLNS, __IgnoreEls,
 +                       [{xmlcdata, _data} | _els], Cdata) ->
 +    decode_presence_show_els(__TopXMLNS, __IgnoreEls, _els,
 +                           <<Cdata/binary, _data/binary>>);
 +decode_presence_show_els(__TopXMLNS, __IgnoreEls,
 +                       [_ | _els], Cdata) ->
 +    decode_presence_show_els(__TopXMLNS, __IgnoreEls, _els,
 +                           Cdata).
 +
 +encode_presence_show(Cdata, __TopXMLNS) ->
 +    __NewTopXMLNS = choose_top_xmlns(<<>>,
 +                                   [<<"jabber:client">>, <<"jabber:server">>,
 +                                    <<"jabber:component:accept">>],
 +                                   __TopXMLNS),
 +    _els = encode_presence_show_cdata(Cdata, []),
 +    _attrs = enc_xmlns_attrs(__NewTopXMLNS, __TopXMLNS),
 +    {xmlel, <<"show">>, _attrs, _els}.
 +
 +decode_presence_show_cdata(__TopXMLNS, <<>>) ->
 +    undefined;
 +decode_presence_show_cdata(__TopXMLNS, _val) ->
 +    case catch dec_enum(_val, [away, chat, dnd, xa]) of
 +      {'EXIT', _} ->
 +        erlang:error({xmpp_codec,
 +                      {bad_cdata_value, <<>>, <<"show">>, __TopXMLNS}});
 +      _res -> _res
 +    end.
 +
 +encode_presence_show_cdata(undefined, _acc) -> _acc;
 +encode_presence_show_cdata(_val, _acc) ->
 +    [{xmlcdata, enc_enum(_val)} | _acc].
 +
 +decode_message(__TopXMLNS, __IgnoreEls,
 +             {xmlel, <<"message">>, _attrs, _els}) ->
 +    {Thread, Subject, Body, __Els} =
 +      decode_message_els(__TopXMLNS, __IgnoreEls, _els,
 +                         undefined, [], [], []),
 +    {Id, Type, From, To, Lang} =
 +      decode_message_attrs(__TopXMLNS, _attrs, undefined,
 +                           undefined, undefined, undefined, undefined),
 +    {message, Id, Type, Lang, From, To, Subject, Body,
 +     Thread, __Els}.
 +
 +decode_message_els(__TopXMLNS, __IgnoreEls, [], Thread,
 +                 Subject, Body, __Els) ->
 +    {Thread, lists:reverse(Subject), lists:reverse(Body),
 +     lists:reverse(__Els)};
 +decode_message_els(__TopXMLNS, __IgnoreEls,
 +                 [{xmlel, <<"subject">>, _attrs, _} = _el | _els],
 +                 Thread, Subject, Body, __Els) ->
 +    case get_attr(<<"xmlns">>, _attrs) of
 +      <<"">>
 +        when __TopXMLNS == <<"jabber:server">>;
 +             __TopXMLNS == <<"jabber:component:accept">>;
 +             __TopXMLNS == <<"jabber:client">> ->
 +        decode_message_els(__TopXMLNS, __IgnoreEls, _els,
 +                           Thread,
 +                           [decode_message_subject(__TopXMLNS, __IgnoreEls,
 +                                                   _el)
 +                            | Subject],
 +                           Body, __Els);
 +      <<"jabber:client">> ->
 +        decode_message_els(__TopXMLNS, __IgnoreEls, _els,
 +                           Thread,
 +                           [decode_message_subject(<<"jabber:client">>,
 +                                                   __IgnoreEls, _el)
 +                            | Subject],
 +                           Body, __Els);
 +      <<"jabber:server">> ->
 +        decode_message_els(__TopXMLNS, __IgnoreEls, _els,
 +                           Thread,
 +                           [decode_message_subject(<<"jabber:server">>,
 +                                                   __IgnoreEls, _el)
 +                            | Subject],
 +                           Body, __Els);
 +      <<"jabber:component:accept">> ->
 +        decode_message_els(__TopXMLNS, __IgnoreEls, _els,
 +                           Thread,
 +                           [decode_message_subject(<<"jabber:component:accept">>,
 +                                                   __IgnoreEls, _el)
 +                            | Subject],
 +                           Body, __Els);
 +      _ ->
 +        decode_message_els(__TopXMLNS, __IgnoreEls, _els,
 +                           Thread, Subject, Body, __Els)
 +    end;
 +decode_message_els(__TopXMLNS, __IgnoreEls,
 +                 [{xmlel, <<"thread">>, _attrs, _} = _el | _els], Thread,
 +                 Subject, Body, __Els) ->
 +    case get_attr(<<"xmlns">>, _attrs) of
 +      <<"">>
 +        when __TopXMLNS == <<"jabber:server">>;
 +             __TopXMLNS == <<"jabber:component:accept">>;
 +             __TopXMLNS == <<"jabber:client">> ->
 +        decode_message_els(__TopXMLNS, __IgnoreEls, _els,
 +                           decode_message_thread(__TopXMLNS, __IgnoreEls,
 +                                                 _el),
 +                           Subject, Body, __Els);
 +      <<"jabber:client">> ->
 +        decode_message_els(__TopXMLNS, __IgnoreEls, _els,
 +                           decode_message_thread(<<"jabber:client">>,
 +                                                 __IgnoreEls, _el),
 +                           Subject, Body, __Els);
 +      <<"jabber:server">> ->
 +        decode_message_els(__TopXMLNS, __IgnoreEls, _els,
 +                           decode_message_thread(<<"jabber:server">>,
 +                                                 __IgnoreEls, _el),
 +                           Subject, Body, __Els);
 +      <<"jabber:component:accept">> ->
 +        decode_message_els(__TopXMLNS, __IgnoreEls, _els,
 +                           decode_message_thread(<<"jabber:component:accept">>,
 +                                                 __IgnoreEls, _el),
 +                           Subject, Body, __Els);
 +      _ ->
 +        decode_message_els(__TopXMLNS, __IgnoreEls, _els,
 +                           Thread, Subject, Body, __Els)
 +    end;
 +decode_message_els(__TopXMLNS, __IgnoreEls,
 +                 [{xmlel, <<"body">>, _attrs, _} = _el | _els], Thread,
 +                 Subject, Body, __Els) ->
 +    case get_attr(<<"xmlns">>, _attrs) of
 +      <<"">>
 +        when __TopXMLNS == <<"jabber:server">>;
 +             __TopXMLNS == <<"jabber:component:accept">>;
 +             __TopXMLNS == <<"jabber:client">> ->
 +        decode_message_els(__TopXMLNS, __IgnoreEls, _els,
 +                           Thread, Subject,
 +                           [decode_message_body(__TopXMLNS, __IgnoreEls, _el)
 +                            | Body],
 +                           __Els);
 +      <<"jabber:client">> ->
 +        decode_message_els(__TopXMLNS, __IgnoreEls, _els,
 +                           Thread, Subject,
 +                           [decode_message_body(<<"jabber:client">>,
 +                                                __IgnoreEls, _el)
 +                            | Body],
 +                           __Els);
 +      <<"jabber:server">> ->
 +        decode_message_els(__TopXMLNS, __IgnoreEls, _els,
 +                           Thread, Subject,
 +                           [decode_message_body(<<"jabber:server">>,
 +                                                __IgnoreEls, _el)
 +                            | Body],
 +                           __Els);
 +      <<"jabber:component:accept">> ->
 +        decode_message_els(__TopXMLNS, __IgnoreEls, _els,
 +                           Thread, Subject,
 +                           [decode_message_body(<<"jabber:component:accept">>,
 +                                                __IgnoreEls, _el)
 +                            | Body],
 +                           __Els);
 +      _ ->
 +        decode_message_els(__TopXMLNS, __IgnoreEls, _els,
 +                           Thread, Subject, Body, __Els)
 +    end;
 +decode_message_els(__TopXMLNS, __IgnoreEls,
 +                 [{xmlel, _, _, _} = _el | _els], Thread, Subject, Body,
 +                 __Els) ->
 +    if __IgnoreEls ->
 +         decode_message_els(__TopXMLNS, __IgnoreEls, _els,
 +                            Thread, Subject, Body, [_el | __Els]);
 +       true ->
 +         case is_known_tag(_el, __TopXMLNS) of
 +           true ->
 +               decode_message_els(__TopXMLNS, __IgnoreEls, _els,
 +                                  Thread, Subject, Body,
 +                                  [decode(_el, __TopXMLNS, []) | __Els]);
 +           false ->
 +               decode_message_els(__TopXMLNS, __IgnoreEls, _els,
 +                                  Thread, Subject, Body, __Els)
 +         end
 +    end;
 +decode_message_els(__TopXMLNS, __IgnoreEls, [_ | _els],
 +                 Thread, Subject, Body, __Els) ->
 +    decode_message_els(__TopXMLNS, __IgnoreEls, _els,
 +                     Thread, Subject, Body, __Els).
 +
 +decode_message_attrs(__TopXMLNS,
 +                   [{<<"id">>, _val} | _attrs], _Id, Type, From, To,
 +                   Lang) ->
 +    decode_message_attrs(__TopXMLNS, _attrs, _val, Type,
 +                       From, To, Lang);
 +decode_message_attrs(__TopXMLNS,
 +                   [{<<"type">>, _val} | _attrs], Id, _Type, From, To,
 +                   Lang) ->
 +    decode_message_attrs(__TopXMLNS, _attrs, Id, _val, From,
 +                       To, Lang);
 +decode_message_attrs(__TopXMLNS,
 +                   [{<<"from">>, _val} | _attrs], Id, Type, _From, To,
 +                   Lang) ->
 +    decode_message_attrs(__TopXMLNS, _attrs, Id, Type, _val,
 +                       To, Lang);
 +decode_message_attrs(__TopXMLNS,
 +                   [{<<"to">>, _val} | _attrs], Id, Type, From, _To,
 +                   Lang) ->
 +    decode_message_attrs(__TopXMLNS, _attrs, Id, Type, From,
 +                       _val, Lang);
 +decode_message_attrs(__TopXMLNS,
 +                   [{<<"xml:lang">>, _val} | _attrs], Id, Type, From, To,
 +                   _Lang) ->
 +    decode_message_attrs(__TopXMLNS, _attrs, Id, Type, From,
 +                       To, _val);
 +decode_message_attrs(__TopXMLNS, [_ | _attrs], Id, Type,
 +                   From, To, Lang) ->
 +    decode_message_attrs(__TopXMLNS, _attrs, Id, Type, From,
 +                       To, Lang);
 +decode_message_attrs(__TopXMLNS, [], Id, Type, From, To,
 +                   Lang) ->
 +    {decode_message_attr_id(__TopXMLNS, Id),
 +     decode_message_attr_type(__TopXMLNS, Type),
 +     decode_message_attr_from(__TopXMLNS, From),
 +     decode_message_attr_to(__TopXMLNS, To),
 +     'decode_message_attr_xml:lang'(__TopXMLNS, Lang)}.
 +
 +encode_message({message, Id, Type, Lang, From, To,
 +              Subject, Body, Thread, __Els},
 +             __TopXMLNS) ->
 +    __NewTopXMLNS = choose_top_xmlns(<<>>,
 +                                   [<<"jabber:client">>, <<"jabber:server">>,
 +                                    <<"jabber:component:accept">>],
 +                                   __TopXMLNS),
 +    _els = [encode(_el, __NewTopXMLNS) || _el <- __Els] ++
 +           lists:reverse('encode_message_$thread'(Thread,
 +                                                  __NewTopXMLNS,
 +                                                  'encode_message_$subject'(Subject,
 +                                                                            __NewTopXMLNS,
 +                                                                            'encode_message_$body'(Body,
 +                                                                                                   __NewTopXMLNS,
 +                                                                                                   [])))),
 +    _attrs = 'encode_message_attr_xml:lang'(Lang,
 +                                          encode_message_attr_to(To,
 +                                                                 encode_message_attr_from(From,
 +                                                                                          encode_message_attr_type(Type,
 +                                                                                                                   encode_message_attr_id(Id,
 +                                                                                                                                          enc_xmlns_attrs(__NewTopXMLNS,
 +                                                                                                                                                          __TopXMLNS)))))),
 +    {xmlel, <<"message">>, _attrs, _els}.
 +
 +'encode_message_$thread'(undefined, __TopXMLNS, _acc) ->
 +    _acc;
 +'encode_message_$thread'(Thread, __TopXMLNS, _acc) ->
 +    [encode_message_thread(Thread, __TopXMLNS) | _acc].
 +
 +'encode_message_$subject'([], __TopXMLNS, _acc) -> _acc;
 +'encode_message_$subject'([Subject | _els], __TopXMLNS,
 +                        _acc) ->
 +    'encode_message_$subject'(_els, __TopXMLNS,
 +                            [encode_message_subject(Subject, __TopXMLNS)
 +                             | _acc]).
 +
 +'encode_message_$body'([], __TopXMLNS, _acc) -> _acc;
 +'encode_message_$body'([Body | _els], __TopXMLNS,
 +                     _acc) ->
 +    'encode_message_$body'(_els, __TopXMLNS,
 +                         [encode_message_body(Body, __TopXMLNS) | _acc]).
 +
 +decode_message_attr_id(__TopXMLNS, undefined) -> <<>>;
 +decode_message_attr_id(__TopXMLNS, _val) -> _val.
 +
 +encode_message_attr_id(<<>>, _acc) -> _acc;
 +encode_message_attr_id(_val, _acc) ->
 +    [{<<"id">>, _val} | _acc].
 +
 +decode_message_attr_type(__TopXMLNS, undefined) ->
 +    normal;
 +decode_message_attr_type(__TopXMLNS, _val) ->
 +    case catch dec_enum(_val,
 +                      [chat, normal, groupchat, headline, error])
 +      of
 +      {'EXIT', _} ->
 +        erlang:error({xmpp_codec,
 +                      {bad_attr_value, <<"type">>, <<"message">>,
 +                       __TopXMLNS}});
 +      _res -> _res
 +    end.
 +
 +encode_message_attr_type(normal, _acc) -> _acc;
 +encode_message_attr_type(_val, _acc) ->
 +    [{<<"type">>, enc_enum(_val)} | _acc].
 +
 +decode_message_attr_from(__TopXMLNS, undefined) ->
 +    undefined;
 +decode_message_attr_from(__TopXMLNS, _val) ->
 +    case catch dec_jid(_val) of
 +      {'EXIT', _} ->
 +        erlang:error({xmpp_codec,
 +                      {bad_attr_value, <<"from">>, <<"message">>,
 +                       __TopXMLNS}});
 +      _res -> _res
 +    end.
 +
 +encode_message_attr_from(undefined, _acc) -> _acc;
 +encode_message_attr_from(_val, _acc) ->
 +    [{<<"from">>, enc_jid(_val)} | _acc].
 +
 +decode_message_attr_to(__TopXMLNS, undefined) ->
 +    undefined;
 +decode_message_attr_to(__TopXMLNS, _val) ->
 +    case catch dec_jid(_val) of
 +      {'EXIT', _} ->
 +        erlang:error({xmpp_codec,
 +                      {bad_attr_value, <<"to">>, <<"message">>, __TopXMLNS}});
 +      _res -> _res
 +    end.
 +
 +encode_message_attr_to(undefined, _acc) -> _acc;
 +encode_message_attr_to(_val, _acc) ->
 +    [{<<"to">>, enc_jid(_val)} | _acc].
 +
 +'decode_message_attr_xml:lang'(__TopXMLNS, undefined) ->
 +    <<>>;
 +'decode_message_attr_xml:lang'(__TopXMLNS, _val) ->
 +    _val.
 +
 +'encode_message_attr_xml:lang'(<<>>, _acc) -> _acc;
 +'encode_message_attr_xml:lang'(_val, _acc) ->
 +    [{<<"xml:lang">>, _val} | _acc].
 +
 +decode_message_thread(__TopXMLNS, __IgnoreEls,
 +                    {xmlel, <<"thread">>, _attrs, _els}) ->
 +    Cdata = decode_message_thread_els(__TopXMLNS,
 +                                    __IgnoreEls, _els, <<>>),
 +    Cdata.
 +
 +decode_message_thread_els(__TopXMLNS, __IgnoreEls, [],
 +                        Cdata) ->
 +    decode_message_thread_cdata(__TopXMLNS, Cdata);
 +decode_message_thread_els(__TopXMLNS, __IgnoreEls,
 +                        [{xmlcdata, _data} | _els], Cdata) ->
 +    decode_message_thread_els(__TopXMLNS, __IgnoreEls, _els,
 +                            <<Cdata/binary, _data/binary>>);
 +decode_message_thread_els(__TopXMLNS, __IgnoreEls,
 +                        [_ | _els], Cdata) ->
 +    decode_message_thread_els(__TopXMLNS, __IgnoreEls, _els,
 +                            Cdata).
 +
 +encode_message_thread(Cdata, __TopXMLNS) ->
 +    __NewTopXMLNS = choose_top_xmlns(<<>>,
 +                                   [<<"jabber:client">>, <<"jabber:server">>,
 +                                    <<"jabber:component:accept">>],
 +                                   __TopXMLNS),
 +    _els = encode_message_thread_cdata(Cdata, []),
 +    _attrs = enc_xmlns_attrs(__NewTopXMLNS, __TopXMLNS),
 +    {xmlel, <<"thread">>, _attrs, _els}.
 +
 +decode_message_thread_cdata(__TopXMLNS, <<>>) -> <<>>;
 +decode_message_thread_cdata(__TopXMLNS, _val) -> _val.
 +
 +encode_message_thread_cdata(<<>>, _acc) -> _acc;
 +encode_message_thread_cdata(_val, _acc) ->
 +    [{xmlcdata, _val} | _acc].
 +
 +decode_message_body(__TopXMLNS, __IgnoreEls,
 +                  {xmlel, <<"body">>, _attrs, _els}) ->
 +    Data = decode_message_body_els(__TopXMLNS, __IgnoreEls,
 +                                 _els, <<>>),
 +    Lang = decode_message_body_attrs(__TopXMLNS, _attrs,
 +                                   undefined),
 +    {text, Lang, Data}.
 +
 +decode_message_body_els(__TopXMLNS, __IgnoreEls, [],
 +                      Data) ->
 +    decode_message_body_cdata(__TopXMLNS, Data);
 +decode_message_body_els(__TopXMLNS, __IgnoreEls,
 +                      [{xmlcdata, _data} | _els], Data) ->
 +    decode_message_body_els(__TopXMLNS, __IgnoreEls, _els,
 +                          <<Data/binary, _data/binary>>);
 +decode_message_body_els(__TopXMLNS, __IgnoreEls,
 +                      [_ | _els], Data) ->
 +    decode_message_body_els(__TopXMLNS, __IgnoreEls, _els,
 +                          Data).
 +
 +decode_message_body_attrs(__TopXMLNS,
 +                        [{<<"xml:lang">>, _val} | _attrs], _Lang) ->
 +    decode_message_body_attrs(__TopXMLNS, _attrs, _val);
 +decode_message_body_attrs(__TopXMLNS, [_ | _attrs],
 +                        Lang) ->
 +    decode_message_body_attrs(__TopXMLNS, _attrs, Lang);
 +decode_message_body_attrs(__TopXMLNS, [], Lang) ->
 +    'decode_message_body_attr_xml:lang'(__TopXMLNS, Lang).
 +
 +encode_message_body({text, Lang, Data}, __TopXMLNS) ->
 +    __NewTopXMLNS = choose_top_xmlns(<<>>,
 +                                   [<<"jabber:client">>, <<"jabber:server">>,
 +                                    <<"jabber:component:accept">>],
 +                                   __TopXMLNS),
 +    _els = encode_message_body_cdata(Data, []),
 +    _attrs = 'encode_message_body_attr_xml:lang'(Lang,
 +                                               enc_xmlns_attrs(__NewTopXMLNS,
 +                                                               __TopXMLNS)),
 +    {xmlel, <<"body">>, _attrs, _els}.
 +
 +'decode_message_body_attr_xml:lang'(__TopXMLNS,
 +                                  undefined) ->
 +    <<>>;
 +'decode_message_body_attr_xml:lang'(__TopXMLNS, _val) ->
 +    _val.
 +
 +'encode_message_body_attr_xml:lang'(<<>>, _acc) -> _acc;
 +'encode_message_body_attr_xml:lang'(_val, _acc) ->
 +    [{<<"xml:lang">>, _val} | _acc].
 +
 +decode_message_body_cdata(__TopXMLNS, <<>>) -> <<>>;
 +decode_message_body_cdata(__TopXMLNS, _val) -> _val.
 +
 +encode_message_body_cdata(<<>>, _acc) -> _acc;
 +encode_message_body_cdata(_val, _acc) ->
 +    [{xmlcdata, _val} | _acc].
 +
 +decode_message_subject(__TopXMLNS, __IgnoreEls,
 +                     {xmlel, <<"subject">>, _attrs, _els}) ->
 +    Data = decode_message_subject_els(__TopXMLNS,
 +                                    __IgnoreEls, _els, <<>>),
 +    Lang = decode_message_subject_attrs(__TopXMLNS, _attrs,
 +                                      undefined),
 +    {text, Lang, Data}.
 +
 +decode_message_subject_els(__TopXMLNS, __IgnoreEls, [],
 +                         Data) ->
 +    decode_message_subject_cdata(__TopXMLNS, Data);
 +decode_message_subject_els(__TopXMLNS, __IgnoreEls,
 +                         [{xmlcdata, _data} | _els], Data) ->
 +    decode_message_subject_els(__TopXMLNS, __IgnoreEls,
 +                             _els, <<Data/binary, _data/binary>>);
 +decode_message_subject_els(__TopXMLNS, __IgnoreEls,
 +                         [_ | _els], Data) ->
 +    decode_message_subject_els(__TopXMLNS, __IgnoreEls,
 +                             _els, Data).
 +
 +decode_message_subject_attrs(__TopXMLNS,
 +                           [{<<"xml:lang">>, _val} | _attrs], _Lang) ->
 +    decode_message_subject_attrs(__TopXMLNS, _attrs, _val);
 +decode_message_subject_attrs(__TopXMLNS, [_ | _attrs],
 +                           Lang) ->
 +    decode_message_subject_attrs(__TopXMLNS, _attrs, Lang);
 +decode_message_subject_attrs(__TopXMLNS, [], Lang) ->
 +    'decode_message_subject_attr_xml:lang'(__TopXMLNS,
 +                                         Lang).
 +
 +encode_message_subject({text, Lang, Data},
 +                     __TopXMLNS) ->
 +    __NewTopXMLNS = choose_top_xmlns(<<>>,
 +                                   [<<"jabber:client">>, <<"jabber:server">>,
 +                                    <<"jabber:component:accept">>],
 +                                   __TopXMLNS),
 +    _els = encode_message_subject_cdata(Data, []),
 +    _attrs = 'encode_message_subject_attr_xml:lang'(Lang,
 +                                                  enc_xmlns_attrs(__NewTopXMLNS,
 +                                                                  __TopXMLNS)),
 +    {xmlel, <<"subject">>, _attrs, _els}.
 +
 +'decode_message_subject_attr_xml:lang'(__TopXMLNS,
 +                                     undefined) ->
 +    <<>>;
 +'decode_message_subject_attr_xml:lang'(__TopXMLNS,
 +                                     _val) ->
 +    _val.
 +
 +'encode_message_subject_attr_xml:lang'(<<>>, _acc) ->
 +    _acc;
 +'encode_message_subject_attr_xml:lang'(_val, _acc) ->
 +    [{<<"xml:lang">>, _val} | _acc].
 +
 +decode_message_subject_cdata(__TopXMLNS, <<>>) -> <<>>;
 +decode_message_subject_cdata(__TopXMLNS, _val) -> _val.
 +
 +encode_message_subject_cdata(<<>>, _acc) -> _acc;
 +encode_message_subject_cdata(_val, _acc) ->
 +    [{xmlcdata, _val} | _acc].
 +
 +decode_iq(__TopXMLNS, __IgnoreEls,
 +        {xmlel, <<"iq">>, _attrs, _els}) ->
 +    __Els = decode_iq_els(__TopXMLNS, __IgnoreEls, _els,
 +                        []),
 +    {Id, Type, From, To, Lang} = decode_iq_attrs(__TopXMLNS,
 +                                               _attrs, undefined, undefined,
 +                                               undefined, undefined,
 +                                               undefined),
 +    {iq, Id, Type, Lang, From, To, __Els}.
 +
 +decode_iq_els(__TopXMLNS, __IgnoreEls, [], __Els) ->
 +    lists:reverse(__Els);
 +decode_iq_els(__TopXMLNS, __IgnoreEls,
 +            [{xmlel, _, _, _} = _el | _els], __Els) ->
 +    if __IgnoreEls ->
 +         decode_iq_els(__TopXMLNS, __IgnoreEls, _els,
 +                       [_el | __Els]);
 +       true ->
 +         case is_known_tag(_el, __TopXMLNS) of
 +           true ->
 +               decode_iq_els(__TopXMLNS, __IgnoreEls, _els,
 +                             [decode(_el, __TopXMLNS, []) | __Els]);
 +           false ->
 +               decode_iq_els(__TopXMLNS, __IgnoreEls, _els, __Els)
 +         end
 +    end;
 +decode_iq_els(__TopXMLNS, __IgnoreEls, [_ | _els],
 +            __Els) ->
 +    decode_iq_els(__TopXMLNS, __IgnoreEls, _els, __Els).
 +
 +decode_iq_attrs(__TopXMLNS, [{<<"id">>, _val} | _attrs],
 +              _Id, Type, From, To, Lang) ->
 +    decode_iq_attrs(__TopXMLNS, _attrs, _val, Type, From,
 +                  To, Lang);
 +decode_iq_attrs(__TopXMLNS,
 +              [{<<"type">>, _val} | _attrs], Id, _Type, From, To,
 +              Lang) ->
 +    decode_iq_attrs(__TopXMLNS, _attrs, Id, _val, From, To,
 +                  Lang);
 +decode_iq_attrs(__TopXMLNS,
 +              [{<<"from">>, _val} | _attrs], Id, Type, _From, To,
 +              Lang) ->
 +    decode_iq_attrs(__TopXMLNS, _attrs, Id, Type, _val, To,
 +                  Lang);
 +decode_iq_attrs(__TopXMLNS, [{<<"to">>, _val} | _attrs],
 +              Id, Type, From, _To, Lang) ->
 +    decode_iq_attrs(__TopXMLNS, _attrs, Id, Type, From,
 +                  _val, Lang);
 +decode_iq_attrs(__TopXMLNS,
 +              [{<<"xml:lang">>, _val} | _attrs], Id, Type, From, To,
 +              _Lang) ->
 +    decode_iq_attrs(__TopXMLNS, _attrs, Id, Type, From, To,
 +                  _val);
 +decode_iq_attrs(__TopXMLNS, [_ | _attrs], Id, Type,
 +              From, To, Lang) ->
 +    decode_iq_attrs(__TopXMLNS, _attrs, Id, Type, From, To,
 +                  Lang);
 +decode_iq_attrs(__TopXMLNS, [], Id, Type, From, To,
 +              Lang) ->
 +    {decode_iq_attr_id(__TopXMLNS, Id),
 +     decode_iq_attr_type(__TopXMLNS, Type),
 +     decode_iq_attr_from(__TopXMLNS, From),
 +     decode_iq_attr_to(__TopXMLNS, To),
 +     'decode_iq_attr_xml:lang'(__TopXMLNS, Lang)}.
 +
 +encode_iq({iq, Id, Type, Lang, From, To, __Els},
 +        __TopXMLNS) ->
 +    __NewTopXMLNS = choose_top_xmlns(<<>>,
 +                                   [<<"jabber:client">>, <<"jabber:server">>,
 +                                    <<"jabber:component:accept">>],
 +                                   __TopXMLNS),
 +    _els = [encode(_el, __NewTopXMLNS) || _el <- __Els],
 +    _attrs = 'encode_iq_attr_xml:lang'(Lang,
 +                                     encode_iq_attr_to(To,
 +                                                       encode_iq_attr_from(From,
 +                                                                           encode_iq_attr_type(Type,
 +                                                                                               encode_iq_attr_id(Id,
 +                                                                                                                 enc_xmlns_attrs(__NewTopXMLNS,
 +                                                                                                                                 __TopXMLNS)))))),
 +    {xmlel, <<"iq">>, _attrs, _els}.
 +
 +decode_iq_attr_id(__TopXMLNS, undefined) ->
 +    erlang:error({xmpp_codec,
 +                {missing_attr, <<"id">>, <<"iq">>, __TopXMLNS}});
 +decode_iq_attr_id(__TopXMLNS, _val) -> _val.
 +
 +encode_iq_attr_id(_val, _acc) ->
 +    [{<<"id">>, _val} | _acc].
 +
 +decode_iq_attr_type(__TopXMLNS, undefined) ->
 +    erlang:error({xmpp_codec,
 +                {missing_attr, <<"type">>, <<"iq">>, __TopXMLNS}});
 +decode_iq_attr_type(__TopXMLNS, _val) ->
 +    case catch dec_enum(_val, [get, set, result, error]) of
 +      {'EXIT', _} ->
 +        erlang:error({xmpp_codec,
 +                      {bad_attr_value, <<"type">>, <<"iq">>, __TopXMLNS}});
 +      _res -> _res
 +    end.
 +
 +encode_iq_attr_type(_val, _acc) ->
 +    [{<<"type">>, enc_enum(_val)} | _acc].
 +
 +decode_iq_attr_from(__TopXMLNS, undefined) -> undefined;
 +decode_iq_attr_from(__TopXMLNS, _val) ->
 +    case catch dec_jid(_val) of
 +      {'EXIT', _} ->
 +        erlang:error({xmpp_codec,
 +                      {bad_attr_value, <<"from">>, <<"iq">>, __TopXMLNS}});
 +      _res -> _res
 +    end.
 +
 +encode_iq_attr_from(undefined, _acc) -> _acc;
 +encode_iq_attr_from(_val, _acc) ->
 +    [{<<"from">>, enc_jid(_val)} | _acc].
 +
 +decode_iq_attr_to(__TopXMLNS, undefined) -> undefined;
 +decode_iq_attr_to(__TopXMLNS, _val) ->
 +    case catch dec_jid(_val) of
 +      {'EXIT', _} ->
 +        erlang:error({xmpp_codec,
 +                      {bad_attr_value, <<"to">>, <<"iq">>, __TopXMLNS}});
 +      _res -> _res
 +    end.
 +
 +encode_iq_attr_to(undefined, _acc) -> _acc;
 +encode_iq_attr_to(_val, _acc) ->
 +    [{<<"to">>, enc_jid(_val)} | _acc].
 +
 +'decode_iq_attr_xml:lang'(__TopXMLNS, undefined) ->
 +    <<>>;
 +'decode_iq_attr_xml:lang'(__TopXMLNS, _val) -> _val.
 +
 +'encode_iq_attr_xml:lang'(<<>>, _acc) -> _acc;
 +'encode_iq_attr_xml:lang'(_val, _acc) ->
 +    [{<<"xml:lang">>, _val} | _acc].
 +
 +decode_stats(__TopXMLNS, __IgnoreEls,
 +           {xmlel, <<"query">>, _attrs, _els}) ->
 +    List = decode_stats_els(__TopXMLNS, __IgnoreEls, _els,
 +                          []),
 +    Node = decode_stats_attrs(__TopXMLNS, _attrs,
 +                            undefined),
 +    {stats, List, Node}.
 +
 +decode_stats_els(__TopXMLNS, __IgnoreEls, [], List) ->
 +    lists:reverse(List);
 +decode_stats_els(__TopXMLNS, __IgnoreEls,
 +               [{xmlel, <<"stat">>, _attrs, _} = _el | _els], List) ->
 +    case get_attr(<<"xmlns">>, _attrs) of
 +      <<"">>
 +        when __TopXMLNS ==
 +               <<"http://jabber.org/protocol/stats">> ->
 +        decode_stats_els(__TopXMLNS, __IgnoreEls, _els,
 +                         [decode_stat(__TopXMLNS, __IgnoreEls, _el) | List]);
 +      <<"http://jabber.org/protocol/stats">> ->
 +        decode_stats_els(__TopXMLNS, __IgnoreEls, _els,
 +                         [decode_stat(<<"http://jabber.org/protocol/stats">>,
 +                                      __IgnoreEls, _el)
 +                          | List]);
 +      _ ->
 +        decode_stats_els(__TopXMLNS, __IgnoreEls, _els, List)
 +    end;
 +decode_stats_els(__TopXMLNS, __IgnoreEls, [_ | _els],
 +               List) ->
 +    decode_stats_els(__TopXMLNS, __IgnoreEls, _els, List).
 +
 +decode_stats_attrs(__TopXMLNS,
 +                 [{<<"node">>, _val} | _attrs], _Node) ->
 +    decode_stats_attrs(__TopXMLNS, _attrs, _val);
 +decode_stats_attrs(__TopXMLNS, [_ | _attrs], Node) ->
 +    decode_stats_attrs(__TopXMLNS, _attrs, Node);
 +decode_stats_attrs(__TopXMLNS, [], Node) ->
 +    decode_stats_attr_node(__TopXMLNS, Node).
 +
 +encode_stats({stats, List, Node}, __TopXMLNS) ->
 +    __NewTopXMLNS =
 +      choose_top_xmlns(<<"http://jabber.org/protocol/stats">>,
 +                       [], __TopXMLNS),
 +    _els = lists:reverse('encode_stats_$list'(List,
 +                                            __NewTopXMLNS, [])),
 +    _attrs = encode_stats_attr_node(Node,
 +                                  enc_xmlns_attrs(__NewTopXMLNS, __TopXMLNS)),
 +    {xmlel, <<"query">>, _attrs, _els}.
 +
 +'encode_stats_$list'([], __TopXMLNS, _acc) -> _acc;
 +'encode_stats_$list'([List | _els], __TopXMLNS, _acc) ->
 +    'encode_stats_$list'(_els, __TopXMLNS,
 +                       [encode_stat(List, __TopXMLNS) | _acc]).
 +
 +decode_stats_attr_node(__TopXMLNS, undefined) -> <<>>;
 +decode_stats_attr_node(__TopXMLNS, _val) -> _val.
 +
 +encode_stats_attr_node(<<>>, _acc) -> _acc;
 +encode_stats_attr_node(_val, _acc) ->
 +    [{<<"node">>, _val} | _acc].
 +
 +decode_stat(__TopXMLNS, __IgnoreEls,
 +          {xmlel, <<"stat">>, _attrs, _els}) ->
 +    Error = decode_stat_els(__TopXMLNS, __IgnoreEls, _els,
 +                          undefined),
 +    {Name, Units, Value} = decode_stat_attrs(__TopXMLNS,
 +                                           _attrs, undefined, undefined,
 +                                           undefined),
 +    {stat, Name, Units, Value, Error}.
 +
 +decode_stat_els(__TopXMLNS, __IgnoreEls, [], Error) ->
 +    Error;
 +decode_stat_els(__TopXMLNS, __IgnoreEls,
 +              [{xmlel, <<"error">>, _attrs, _} = _el | _els],
 +              Error) ->
 +    case get_attr(<<"xmlns">>, _attrs) of
 +      <<"">>
 +        when __TopXMLNS ==
 +               <<"http://jabber.org/protocol/stats">> ->
 +        decode_stat_els(__TopXMLNS, __IgnoreEls, _els,
 +                        decode_stat_error(__TopXMLNS, __IgnoreEls, _el));
 +      <<"http://jabber.org/protocol/stats">> ->
 +        decode_stat_els(__TopXMLNS, __IgnoreEls, _els,
 +                        decode_stat_error(<<"http://jabber.org/protocol/stats">>,
 +                                          __IgnoreEls, _el));
 +      _ ->
 +        decode_stat_els(__TopXMLNS, __IgnoreEls, _els, Error)
 +    end;
 +decode_stat_els(__TopXMLNS, __IgnoreEls, [_ | _els],
 +              Error) ->
 +    decode_stat_els(__TopXMLNS, __IgnoreEls, _els, Error).
 +
 +decode_stat_attrs(__TopXMLNS,
 +                [{<<"name">>, _val} | _attrs], _Name, Units, Value) ->
 +    decode_stat_attrs(__TopXMLNS, _attrs, _val, Units,
 +                    Value);
 +decode_stat_attrs(__TopXMLNS,
 +                [{<<"units">>, _val} | _attrs], Name, _Units, Value) ->
 +    decode_stat_attrs(__TopXMLNS, _attrs, Name, _val,
 +                    Value);
 +decode_stat_attrs(__TopXMLNS,
 +                [{<<"value">>, _val} | _attrs], Name, Units, _Value) ->
 +    decode_stat_attrs(__TopXMLNS, _attrs, Name, Units,
 +                    _val);
 +decode_stat_attrs(__TopXMLNS, [_ | _attrs], Name, Units,
 +                Value) ->
 +    decode_stat_attrs(__TopXMLNS, _attrs, Name, Units,
 +                    Value);
 +decode_stat_attrs(__TopXMLNS, [], Name, Units, Value) ->
 +    {decode_stat_attr_name(__TopXMLNS, Name),
 +     decode_stat_attr_units(__TopXMLNS, Units),
 +     decode_stat_attr_value(__TopXMLNS, Value)}.
 +
 +encode_stat({stat, Name, Units, Value, Error},
 +          __TopXMLNS) ->
 +    __NewTopXMLNS =
 +      choose_top_xmlns(<<"http://jabber.org/protocol/stats">>,
 +                       [], __TopXMLNS),
 +    _els = lists:reverse('encode_stat_$error'(Error,
 +                                            __NewTopXMLNS, [])),
 +    _attrs = encode_stat_attr_value(Value,
 +                                  encode_stat_attr_units(Units,
 +                                                         encode_stat_attr_name(Name,
 +                                                                               enc_xmlns_attrs(__NewTopXMLNS,
 +                                                                                               __TopXMLNS)))),
 +    {xmlel, <<"stat">>, _attrs, _els}.
 +
 +'encode_stat_$error'(undefined, __TopXMLNS, _acc) ->
 +    _acc;
 +'encode_stat_$error'(Error, __TopXMLNS, _acc) ->
 +    [encode_stat_error(Error, __TopXMLNS) | _acc].
 +
 +decode_stat_attr_name(__TopXMLNS, undefined) ->
 +    erlang:error({xmpp_codec,
 +                {missing_attr, <<"name">>, <<"stat">>, __TopXMLNS}});
 +decode_stat_attr_name(__TopXMLNS, _val) -> _val.
 +
 +encode_stat_attr_name(_val, _acc) ->
 +    [{<<"name">>, _val} | _acc].
 +
 +decode_stat_attr_units(__TopXMLNS, undefined) -> <<>>;
 +decode_stat_attr_units(__TopXMLNS, _val) -> _val.
 +
 +encode_stat_attr_units(<<>>, _acc) -> _acc;
 +encode_stat_attr_units(_val, _acc) ->
 +    [{<<"units">>, _val} | _acc].
 +
 +decode_stat_attr_value(__TopXMLNS, undefined) -> <<>>;
 +decode_stat_attr_value(__TopXMLNS, _val) -> _val.
 +
 +encode_stat_attr_value(<<>>, _acc) -> _acc;
 +encode_stat_attr_value(_val, _acc) ->
 +    [{<<"value">>, _val} | _acc].
 +
 +decode_stat_error(__TopXMLNS, __IgnoreEls,
 +                {xmlel, <<"error">>, _attrs, _els}) ->
 +    Reason = decode_stat_error_els(__TopXMLNS, __IgnoreEls,
 +                                 _els, <<>>),
 +    Code = decode_stat_error_attrs(__TopXMLNS, _attrs,
 +                                 undefined),
 +    {stat_error, Code, Reason}.
 +
 +decode_stat_error_els(__TopXMLNS, __IgnoreEls, [],
 +                    Reason) ->
 +    decode_stat_error_cdata(__TopXMLNS, Reason);
 +decode_stat_error_els(__TopXMLNS, __IgnoreEls,
 +                    [{xmlcdata, _data} | _els], Reason) ->
 +    decode_stat_error_els(__TopXMLNS, __IgnoreEls, _els,
 +                        <<Reason/binary, _data/binary>>);
 +decode_stat_error_els(__TopXMLNS, __IgnoreEls,
 +                    [_ | _els], Reason) ->
 +    decode_stat_error_els(__TopXMLNS, __IgnoreEls, _els,
 +                        Reason).
 +
 +decode_stat_error_attrs(__TopXMLNS,
 +                      [{<<"code">>, _val} | _attrs], _Code) ->
 +    decode_stat_error_attrs(__TopXMLNS, _attrs, _val);
 +decode_stat_error_attrs(__TopXMLNS, [_ | _attrs],
 +                      Code) ->
 +    decode_stat_error_attrs(__TopXMLNS, _attrs, Code);
 +decode_stat_error_attrs(__TopXMLNS, [], Code) ->
 +    decode_stat_error_attr_code(__TopXMLNS, Code).
 +
 +encode_stat_error({stat_error, Code, Reason},
 +                __TopXMLNS) ->
 +    __NewTopXMLNS =
 +      choose_top_xmlns(<<"http://jabber.org/protocol/stats">>,
 +                       [], __TopXMLNS),
 +    _els = encode_stat_error_cdata(Reason, []),
 +    _attrs = encode_stat_error_attr_code(Code,
 +                                       enc_xmlns_attrs(__NewTopXMLNS,
 +                                                       __TopXMLNS)),
 +    {xmlel, <<"error">>, _attrs, _els}.
 +
 +decode_stat_error_attr_code(__TopXMLNS, undefined) ->
 +    erlang:error({xmpp_codec,
 +                {missing_attr, <<"code">>, <<"error">>, __TopXMLNS}});
 +decode_stat_error_attr_code(__TopXMLNS, _val) ->
 +    case catch dec_int(_val) of
 +      {'EXIT', _} ->
 +        erlang:error({xmpp_codec,
 +                      {bad_attr_value, <<"code">>, <<"error">>, __TopXMLNS}});
 +      _res -> _res
 +    end.
 +
 +encode_stat_error_attr_code(_val, _acc) ->
 +    [{<<"code">>, enc_int(_val)} | _acc].
 +
 +decode_stat_error_cdata(__TopXMLNS, <<>>) -> <<>>;
 +decode_stat_error_cdata(__TopXMLNS, _val) -> _val.
 +
 +encode_stat_error_cdata(<<>>, _acc) -> _acc;
 +encode_stat_error_cdata(_val, _acc) ->
 +    [{xmlcdata, _val} | _acc].
 +
 +decode_bookmarks_storage(__TopXMLNS, __IgnoreEls,
 +                       {xmlel, <<"storage">>, _attrs, _els}) ->
 +    {Conference, Url} =
 +      decode_bookmarks_storage_els(__TopXMLNS, __IgnoreEls,
 +                                   _els, [], []),
 +    {bookmark_storage, Conference, Url}.
 +
 +decode_bookmarks_storage_els(__TopXMLNS, __IgnoreEls,
 +                           [], Conference, Url) ->
 +    {lists:reverse(Conference), lists:reverse(Url)};
 +decode_bookmarks_storage_els(__TopXMLNS, __IgnoreEls,
 +                           [{xmlel, <<"conference">>, _attrs, _} = _el
 +                            | _els],
 +                           Conference, Url) ->
 +    case get_attr(<<"xmlns">>, _attrs) of
 +      <<"">> when __TopXMLNS == <<"storage:bookmarks">> ->
 +        decode_bookmarks_storage_els(__TopXMLNS, __IgnoreEls,
 +                                     _els,
 +                                     [decode_bookmark_conference(__TopXMLNS,
 +                                                                 __IgnoreEls,
 +                                                                 _el)
 +                                      | Conference],
 +                                     Url);
 +      <<"storage:bookmarks">> ->
 +        decode_bookmarks_storage_els(__TopXMLNS, __IgnoreEls,
 +                                     _els,
 +                                     [decode_bookmark_conference(<<"storage:bookmarks">>,
 +                                                                 __IgnoreEls,
 +                                                                 _el)
 +                                      | Conference],
 +                                     Url);
 +      _ ->
 +        decode_bookmarks_storage_els(__TopXMLNS, __IgnoreEls,
 +                                     _els, Conference, Url)
 +    end;
 +decode_bookmarks_storage_els(__TopXMLNS, __IgnoreEls,
 +                           [{xmlel, <<"url">>, _attrs, _} = _el | _els],
 +                           Conference, Url) ->
 +    case get_attr(<<"xmlns">>, _attrs) of
 +      <<"">> when __TopXMLNS == <<"storage:bookmarks">> ->
 +        decode_bookmarks_storage_els(__TopXMLNS, __IgnoreEls,
 +                                     _els, Conference,
 +                                     [decode_bookmark_url(__TopXMLNS,
 +                                                          __IgnoreEls, _el)
 +                                      | Url]);
 +      <<"storage:bookmarks">> ->
 +        decode_bookmarks_storage_els(__TopXMLNS, __IgnoreEls,
 +                                     _els, Conference,
 +                                     [decode_bookmark_url(<<"storage:bookmarks">>,
 +                                                          __IgnoreEls, _el)
 +                                      | Url]);
 +      _ ->
 +        decode_bookmarks_storage_els(__TopXMLNS, __IgnoreEls,
 +                                     _els, Conference, Url)
 +    end;
 +decode_bookmarks_storage_els(__TopXMLNS, __IgnoreEls,
 +                           [_ | _els], Conference, Url) ->
 +    decode_bookmarks_storage_els(__TopXMLNS, __IgnoreEls,
 +                               _els, Conference, Url).
 +
 +encode_bookmarks_storage({bookmark_storage, Conference,
 +                        Url},
 +                       __TopXMLNS) ->
 +    __NewTopXMLNS =
 +      choose_top_xmlns(<<"storage:bookmarks">>, [],
 +                       __TopXMLNS),
 +    _els =
 +      lists:reverse('encode_bookmarks_storage_$conference'(Conference,
 +                                                           __NewTopXMLNS,
 +                                                           'encode_bookmarks_storage_$url'(Url,
 +                                                                                           __NewTopXMLNS,
 +                                                                                           []))),
 +    _attrs = enc_xmlns_attrs(__NewTopXMLNS, __TopXMLNS),
 +    {xmlel, <<"storage">>, _attrs, _els}.
 +
 +'encode_bookmarks_storage_$conference'([], __TopXMLNS,
 +                                     _acc) ->
 +    _acc;
 +'encode_bookmarks_storage_$conference'([Conference
 +                                      | _els],
 +                                     __TopXMLNS, _acc) ->
 +    'encode_bookmarks_storage_$conference'(_els, __TopXMLNS,
 +                                         [encode_bookmark_conference(Conference,
 +                                                                     __TopXMLNS)
 +                                          | _acc]).
 +
 +'encode_bookmarks_storage_$url'([], __TopXMLNS, _acc) ->
 +    _acc;
 +'encode_bookmarks_storage_$url'([Url | _els],
 +                              __TopXMLNS, _acc) ->
 +    'encode_bookmarks_storage_$url'(_els, __TopXMLNS,
 +                                  [encode_bookmark_url(Url, __TopXMLNS)
 +                                   | _acc]).
 +
 +decode_bookmark_url(__TopXMLNS, __IgnoreEls,
 +                  {xmlel, <<"url">>, _attrs, _els}) ->
 +    {Name, Url} = decode_bookmark_url_attrs(__TopXMLNS,
 +                                          _attrs, undefined, undefined),
 +    {bookmark_url, Name, Url}.
 +
 +decode_bookmark_url_attrs(__TopXMLNS,
 +                        [{<<"name">>, _val} | _attrs], _Name, Url) ->
 +    decode_bookmark_url_attrs(__TopXMLNS, _attrs, _val,
 +                            Url);
 +decode_bookmark_url_attrs(__TopXMLNS,
 +                        [{<<"url">>, _val} | _attrs], Name, _Url) ->
 +    decode_bookmark_url_attrs(__TopXMLNS, _attrs, Name,
 +                            _val);
 +decode_bookmark_url_attrs(__TopXMLNS, [_ | _attrs],
 +                        Name, Url) ->
 +    decode_bookmark_url_attrs(__TopXMLNS, _attrs, Name,
 +                            Url);
 +decode_bookmark_url_attrs(__TopXMLNS, [], Name, Url) ->
 +    {decode_bookmark_url_attr_name(__TopXMLNS, Name),
 +     decode_bookmark_url_attr_url(__TopXMLNS, Url)}.
 +
 +encode_bookmark_url({bookmark_url, Name, Url},
 +                  __TopXMLNS) ->
 +    __NewTopXMLNS =
 +      choose_top_xmlns(<<"storage:bookmarks">>, [],
 +                       __TopXMLNS),
 +    _els = [],
 +    _attrs = encode_bookmark_url_attr_url(Url,
 +                                        encode_bookmark_url_attr_name(Name,
 +                                                                      enc_xmlns_attrs(__NewTopXMLNS,
 +                                                                                      __TopXMLNS))),
 +    {xmlel, <<"url">>, _attrs, _els}.
 +
 +decode_bookmark_url_attr_name(__TopXMLNS, undefined) ->
 +    erlang:error({xmpp_codec,
 +                {missing_attr, <<"name">>, <<"url">>, __TopXMLNS}});
 +decode_bookmark_url_attr_name(__TopXMLNS, _val) -> _val.
 +
 +encode_bookmark_url_attr_name(_val, _acc) ->
 +    [{<<"name">>, _val} | _acc].
 +
 +decode_bookmark_url_attr_url(__TopXMLNS, undefined) ->
 +    erlang:error({xmpp_codec,
 +                {missing_attr, <<"url">>, <<"url">>, __TopXMLNS}});
 +decode_bookmark_url_attr_url(__TopXMLNS, _val) -> _val.
 +
 +encode_bookmark_url_attr_url(_val, _acc) ->
 +    [{<<"url">>, _val} | _acc].
 +
 +decode_bookmark_conference(__TopXMLNS, __IgnoreEls,
 +                         {xmlel, <<"conference">>, _attrs, _els}) ->
 +    {Password, Nick} =
 +      decode_bookmark_conference_els(__TopXMLNS, __IgnoreEls,
 +                                     _els, undefined, undefined),
 +    {Name, Jid, Autojoin} =
 +      decode_bookmark_conference_attrs(__TopXMLNS, _attrs,
 +                                       undefined, undefined, undefined),
 +    {bookmark_conference, Name, Jid, Autojoin, Nick,
 +     Password}.
 +
 +decode_bookmark_conference_els(__TopXMLNS, __IgnoreEls,
 +                             [], Password, Nick) ->
 +    {Password, Nick};
 +decode_bookmark_conference_els(__TopXMLNS, __IgnoreEls,
 +                             [{xmlel, <<"nick">>, _attrs, _} = _el | _els],
 +                             Password, Nick) ->
 +    case get_attr(<<"xmlns">>, _attrs) of
 +      <<"">> when __TopXMLNS == <<"storage:bookmarks">> ->
 +        decode_bookmark_conference_els(__TopXMLNS, __IgnoreEls,
 +                                       _els, Password,
 +                                       decode_conference_nick(__TopXMLNS,
 +                                                              __IgnoreEls,
 +                                                              _el));
 +      <<"storage:bookmarks">> ->
 +        decode_bookmark_conference_els(__TopXMLNS, __IgnoreEls,
 +                                       _els, Password,
 +                                       decode_conference_nick(<<"storage:bookmarks">>,
 +                                                              __IgnoreEls,
 +                                                              _el));
 +      _ ->
 +        decode_bookmark_conference_els(__TopXMLNS, __IgnoreEls,
 +                                       _els, Password, Nick)
 +    end;
 +decode_bookmark_conference_els(__TopXMLNS, __IgnoreEls,
 +                             [{xmlel, <<"password">>, _attrs, _} = _el
 +                              | _els],
 +                             Password, Nick) ->
 +    case get_attr(<<"xmlns">>, _attrs) of
 +      <<"">> when __TopXMLNS == <<"storage:bookmarks">> ->
 +        decode_bookmark_conference_els(__TopXMLNS, __IgnoreEls,
 +                                       _els,
 +                                       decode_conference_password(__TopXMLNS,
 +                                                                  __IgnoreEls,
 +                                                                  _el),
 +                                       Nick);
 +      <<"storage:bookmarks">> ->
 +        decode_bookmark_conference_els(__TopXMLNS, __IgnoreEls,
 +                                       _els,
 +                                       decode_conference_password(<<"storage:bookmarks">>,
 +                                                                  __IgnoreEls,
 +                                                                  _el),
 +                                       Nick);
 +      _ ->
 +        decode_bookmark_conference_els(__TopXMLNS, __IgnoreEls,
 +                                       _els, Password, Nick)
 +    end;
 +decode_bookmark_conference_els(__TopXMLNS, __IgnoreEls,
 +                             [_ | _els], Password, Nick) ->
 +    decode_bookmark_conference_els(__TopXMLNS, __IgnoreEls,
 +                                 _els, Password, Nick).
 +
 +decode_bookmark_conference_attrs(__TopXMLNS,
 +                               [{<<"name">>, _val} | _attrs], _Name, Jid,
 +                               Autojoin) ->
 +    decode_bookmark_conference_attrs(__TopXMLNS, _attrs,
 +                                   _val, Jid, Autojoin);
 +decode_bookmark_conference_attrs(__TopXMLNS,
 +                               [{<<"jid">>, _val} | _attrs], Name, _Jid,
 +                               Autojoin) ->
 +    decode_bookmark_conference_attrs(__TopXMLNS, _attrs,
 +                                   Name, _val, Autojoin);
 +decode_bookmark_conference_attrs(__TopXMLNS,
 +                               [{<<"autojoin">>, _val} | _attrs], Name, Jid,
 +                               _Autojoin) ->
 +    decode_bookmark_conference_attrs(__TopXMLNS, _attrs,
 +                                   Name, Jid, _val);
 +decode_bookmark_conference_attrs(__TopXMLNS,
 +                               [_ | _attrs], Name, Jid, Autojoin) ->
 +    decode_bookmark_conference_attrs(__TopXMLNS, _attrs,
 +                                   Name, Jid, Autojoin);
 +decode_bookmark_conference_attrs(__TopXMLNS, [], Name,
 +                               Jid, Autojoin) ->
 +    {decode_bookmark_conference_attr_name(__TopXMLNS, Name),
 +     decode_bookmark_conference_attr_jid(__TopXMLNS, Jid),
 +     decode_bookmark_conference_attr_autojoin(__TopXMLNS,
 +                                            Autojoin)}.
 +
 +encode_bookmark_conference({bookmark_conference, Name,
 +                          Jid, Autojoin, Nick, Password},
 +                         __TopXMLNS) ->
 +    __NewTopXMLNS =
 +      choose_top_xmlns(<<"storage:bookmarks">>, [],
 +                       __TopXMLNS),
 +    _els =
 +      lists:reverse('encode_bookmark_conference_$password'(Password,
 +                                                           __NewTopXMLNS,
 +                                                           'encode_bookmark_conference_$nick'(Nick,
 +                                                                                              __NewTopXMLNS,
 +                                                                                              []))),
 +    _attrs =
 +      encode_bookmark_conference_attr_autojoin(Autojoin,
 +                                               encode_bookmark_conference_attr_jid(Jid,
 +                                                                                   encode_bookmark_conference_attr_name(Name,
 +                                                                                                                        enc_xmlns_attrs(__NewTopXMLNS,
 +                                                                                                                                        __TopXMLNS)))),
 +    {xmlel, <<"conference">>, _attrs, _els}.
 +
 +'encode_bookmark_conference_$password'(undefined,
 +                                     __TopXMLNS, _acc) ->
 +    _acc;
 +'encode_bookmark_conference_$password'(Password,
 +                                     __TopXMLNS, _acc) ->
 +    [encode_conference_password(Password, __TopXMLNS)
 +     | _acc].
 +
 +'encode_bookmark_conference_$nick'(undefined,
 +                                 __TopXMLNS, _acc) ->
 +    _acc;
 +'encode_bookmark_conference_$nick'(Nick, __TopXMLNS,
 +                                 _acc) ->
 +    [encode_conference_nick(Nick, __TopXMLNS) | _acc].
 +
 +decode_bookmark_conference_attr_name(__TopXMLNS,
 +                                   undefined) ->
 +    erlang:error({xmpp_codec,
 +                {missing_attr, <<"name">>, <<"conference">>,
 +                 __TopXMLNS}});
 +decode_bookmark_conference_attr_name(__TopXMLNS,
 +                                   _val) ->
 +    _val.
 +
 +encode_bookmark_conference_attr_name(_val, _acc) ->
 +    [{<<"name">>, _val} | _acc].
 +
 +decode_bookmark_conference_attr_jid(__TopXMLNS,
 +                                  undefined) ->
 +    erlang:error({xmpp_codec,
 +                {missing_attr, <<"jid">>, <<"conference">>,
 +                 __TopXMLNS}});
 +decode_bookmark_conference_attr_jid(__TopXMLNS, _val) ->
 +    case catch dec_jid(_val) of
 +      {'EXIT', _} ->
 +        erlang:error({xmpp_codec,
 +                      {bad_attr_value, <<"jid">>, <<"conference">>,
 +                       __TopXMLNS}});
 +      _res -> _res
 +    end.
 +
 +encode_bookmark_conference_attr_jid(_val, _acc) ->
 +    [{<<"jid">>, enc_jid(_val)} | _acc].
 +
 +decode_bookmark_conference_attr_autojoin(__TopXMLNS,
 +                                       undefined) ->
 +    false;
 +decode_bookmark_conference_attr_autojoin(__TopXMLNS,
 +                                       _val) ->
 +    case catch dec_bool(_val) of
 +      {'EXIT', _} ->
 +        erlang:error({xmpp_codec,
 +                      {bad_attr_value, <<"autojoin">>, <<"conference">>,
 +                       __TopXMLNS}});
 +      _res -> _res
 +    end.
 +
 +encode_bookmark_conference_attr_autojoin(false, _acc) ->
 +    _acc;
 +encode_bookmark_conference_attr_autojoin(_val, _acc) ->
 +    [{<<"autojoin">>, enc_bool(_val)} | _acc].
 +
 +decode_conference_password(__TopXMLNS, __IgnoreEls,
 +                         {xmlel, <<"password">>, _attrs, _els}) ->
 +    Cdata = decode_conference_password_els(__TopXMLNS,
 +                                         __IgnoreEls, _els, <<>>),
 +    Cdata.
 +
 +decode_conference_password_els(__TopXMLNS, __IgnoreEls,
 +                             [], Cdata) ->
 +    decode_conference_password_cdata(__TopXMLNS, Cdata);
 +decode_conference_password_els(__TopXMLNS, __IgnoreEls,
 +                             [{xmlcdata, _data} | _els], Cdata) ->
 +    decode_conference_password_els(__TopXMLNS, __IgnoreEls,
 +                                 _els, <<Cdata/binary, _data/binary>>);
 +decode_conference_password_els(__TopXMLNS, __IgnoreEls,
 +                             [_ | _els], Cdata) ->
 +    decode_conference_password_els(__TopXMLNS, __IgnoreEls,
 +                                 _els, Cdata).
 +
 +encode_conference_password(Cdata, __TopXMLNS) ->
 +    __NewTopXMLNS =
 +      choose_top_xmlns(<<"storage:bookmarks">>, [],
 +                       __TopXMLNS),
 +    _els = encode_conference_password_cdata(Cdata, []),
 +    _attrs = enc_xmlns_attrs(__NewTopXMLNS, __TopXMLNS),
 +    {xmlel, <<"password">>, _attrs, _els}.
 +
 +decode_conference_password_cdata(__TopXMLNS, <<>>) ->
 +    <<>>;
 +decode_conference_password_cdata(__TopXMLNS, _val) ->
 +    _val.
 +
 +encode_conference_password_cdata(<<>>, _acc) -> _acc;
 +encode_conference_password_cdata(_val, _acc) ->
 +    [{xmlcdata, _val} | _acc].
 +
 +decode_conference_nick(__TopXMLNS, __IgnoreEls,
 +                     {xmlel, <<"nick">>, _attrs, _els}) ->
 +    Cdata = decode_conference_nick_els(__TopXMLNS,
 +                                     __IgnoreEls, _els, <<>>),
 +    Cdata.
 +
 +decode_conference_nick_els(__TopXMLNS, __IgnoreEls, [],
 +                         Cdata) ->
 +    decode_conference_nick_cdata(__TopXMLNS, Cdata);
 +decode_conference_nick_els(__TopXMLNS, __IgnoreEls,
 +                         [{xmlcdata, _data} | _els], Cdata) ->
 +    decode_conference_nick_els(__TopXMLNS, __IgnoreEls,
 +                             _els, <<Cdata/binary, _data/binary>>);
 +decode_conference_nick_els(__TopXMLNS, __IgnoreEls,
 +                         [_ | _els], Cdata) ->
 +    decode_conference_nick_els(__TopXMLNS, __IgnoreEls,
 +                             _els, Cdata).
 +
 +encode_conference_nick(Cdata, __TopXMLNS) ->
 +    __NewTopXMLNS =
 +      choose_top_xmlns(<<"storage:bookmarks">>, [],
 +                       __TopXMLNS),
 +    _els = encode_conference_nick_cdata(Cdata, []),
 +    _attrs = enc_xmlns_attrs(__NewTopXMLNS, __TopXMLNS),
 +    {xmlel, <<"nick">>, _attrs, _els}.
 +
 +decode_conference_nick_cdata(__TopXMLNS, <<>>) -> <<>>;
 +decode_conference_nick_cdata(__TopXMLNS, _val) -> _val.
 +
 +encode_conference_nick_cdata(<<>>, _acc) -> _acc;
 +encode_conference_nick_cdata(_val, _acc) ->
 +    [{xmlcdata, _val} | _acc].
 +
 +decode_private(__TopXMLNS, __IgnoreEls,
 +             {xmlel, <<"query">>, _attrs, _els}) ->
 +    __Xmls = decode_private_els(__TopXMLNS, __IgnoreEls,
 +                              _els, []),
 +    {private, __Xmls}.
 +
 +decode_private_els(__TopXMLNS, __IgnoreEls, [],
 +                 __Xmls) ->
 +    lists:reverse(__Xmls);
 +decode_private_els(__TopXMLNS, __IgnoreEls,
 +                 [{xmlel, _, _, _} = _el | _els], __Xmls) ->
 +    decode_private_els(__TopXMLNS, __IgnoreEls, _els,
 +                     [_el | __Xmls]);
 +decode_private_els(__TopXMLNS, __IgnoreEls, [_ | _els],
 +                 __Xmls) ->
 +    decode_private_els(__TopXMLNS, __IgnoreEls, _els,
 +                     __Xmls).
 +
 +encode_private({private, __Xmls}, __TopXMLNS) ->
 +    __NewTopXMLNS =
 +      choose_top_xmlns(<<"jabber:iq:private">>, [],
 +                       __TopXMLNS),
 +    _els = __Xmls,
 +    _attrs = enc_xmlns_attrs(__NewTopXMLNS, __TopXMLNS),
 +    {xmlel, <<"query">>, _attrs, _els}.
 +
 +decode_disco_items(__TopXMLNS, __IgnoreEls,
 +                 {xmlel, <<"query">>, _attrs, _els}) ->
 +    {Items, Rsm} = decode_disco_items_els(__TopXMLNS,
 +                                        __IgnoreEls, _els, [], undefined),
 +    Node = decode_disco_items_attrs(__TopXMLNS, _attrs,
 +                                  undefined),
 +    {disco_items, Node, Items, Rsm}.
 +
 +decode_disco_items_els(__TopXMLNS, __IgnoreEls, [],
 +                     Items, Rsm) ->
 +    {lists:reverse(Items), Rsm};
 +decode_disco_items_els(__TopXMLNS, __IgnoreEls,
 +                     [{xmlel, <<"item">>, _attrs, _} = _el | _els], Items,
 +                     Rsm) ->
 +    case get_attr(<<"xmlns">>, _attrs) of
 +      <<"">>
 +        when __TopXMLNS ==
 +               <<"http://jabber.org/protocol/disco#items">> ->
 +        decode_disco_items_els(__TopXMLNS, __IgnoreEls, _els,
 +                               [decode_disco_item(__TopXMLNS, __IgnoreEls,
 +                                                  _el)
 +                                | Items],
 +                               Rsm);
 +      <<"http://jabber.org/protocol/disco#items">> ->
 +        decode_disco_items_els(__TopXMLNS, __IgnoreEls, _els,
 +                               [decode_disco_item(<<"http://jabber.org/protocol/disco#items">>,
 +                                                  __IgnoreEls, _el)
 +                                | Items],
 +                               Rsm);
 +      _ ->
 +        decode_disco_items_els(__TopXMLNS, __IgnoreEls, _els,
 +                               Items, Rsm)
 +    end;
 +decode_disco_items_els(__TopXMLNS, __IgnoreEls,
 +                     [{xmlel, <<"set">>, _attrs, _} = _el | _els], Items,
 +                     Rsm) ->
 +    case get_attr(<<"xmlns">>, _attrs) of
 +      <<"http://jabber.org/protocol/rsm">> ->
 +        decode_disco_items_els(__TopXMLNS, __IgnoreEls, _els,
 +                               Items,
 +                               decode_rsm_set(<<"http://jabber.org/protocol/rsm">>,
 +                                              __IgnoreEls, _el));
 +      _ ->
 +        decode_disco_items_els(__TopXMLNS, __IgnoreEls, _els,
 +                               Items, Rsm)
 +    end;
 +decode_disco_items_els(__TopXMLNS, __IgnoreEls,
 +                     [_ | _els], Items, Rsm) ->
 +    decode_disco_items_els(__TopXMLNS, __IgnoreEls, _els,
 +                         Items, Rsm).
 +
 +decode_disco_items_attrs(__TopXMLNS,
 +                       [{<<"node">>, _val} | _attrs], _Node) ->
 +    decode_disco_items_attrs(__TopXMLNS, _attrs, _val);
 +decode_disco_items_attrs(__TopXMLNS, [_ | _attrs],
 +                       Node) ->
 +    decode_disco_items_attrs(__TopXMLNS, _attrs, Node);
 +decode_disco_items_attrs(__TopXMLNS, [], Node) ->
 +    decode_disco_items_attr_node(__TopXMLNS, Node).
 +
 +encode_disco_items({disco_items, Node, Items, Rsm},
 +                 __TopXMLNS) ->
 +    __NewTopXMLNS =
 +      choose_top_xmlns(<<"http://jabber.org/protocol/disco#items">>,
 +                       [], __TopXMLNS),
 +    _els = lists:reverse('encode_disco_items_$items'(Items,
 +                                                   __NewTopXMLNS,
 +                                                   'encode_disco_items_$rsm'(Rsm,
 +                                                                             __NewTopXMLNS,
 +                                                                             []))),
 +    _attrs = encode_disco_items_attr_node(Node,
 +                                        enc_xmlns_attrs(__NewTopXMLNS,
 +                                                        __TopXMLNS)),
 +    {xmlel, <<"query">>, _attrs, _els}.
 +
 +'encode_disco_items_$items'([], __TopXMLNS, _acc) ->
 +    _acc;
 +'encode_disco_items_$items'([Items | _els], __TopXMLNS,
 +                          _acc) ->
 +    'encode_disco_items_$items'(_els, __TopXMLNS,
 +                              [encode_disco_item(Items, __TopXMLNS) | _acc]).
 +
 +'encode_disco_items_$rsm'(undefined, __TopXMLNS,
 +                        _acc) ->
 +    _acc;
 +'encode_disco_items_$rsm'(Rsm, __TopXMLNS, _acc) ->
 +    [encode_rsm_set(Rsm, __TopXMLNS) | _acc].
 +
 +decode_disco_items_attr_node(__TopXMLNS, undefined) ->
 +    <<>>;
 +decode_disco_items_attr_node(__TopXMLNS, _val) -> _val.
 +
 +encode_disco_items_attr_node(<<>>, _acc) -> _acc;
 +encode_disco_items_attr_node(_val, _acc) ->
 +    [{<<"node">>, _val} | _acc].
 +
 +decode_disco_item(__TopXMLNS, __IgnoreEls,
 +                {xmlel, <<"item">>, _attrs, _els}) ->
 +    {Jid, Name, Node} = decode_disco_item_attrs(__TopXMLNS,
 +                                              _attrs, undefined, undefined,
 +                                              undefined),
 +    {disco_item, Jid, Name, Node}.
 +
 +decode_disco_item_attrs(__TopXMLNS,
 +                      [{<<"jid">>, _val} | _attrs], _Jid, Name, Node) ->
 +    decode_disco_item_attrs(__TopXMLNS, _attrs, _val, Name,
 +                          Node);
 +decode_disco_item_attrs(__TopXMLNS,
 +                      [{<<"name">>, _val} | _attrs], Jid, _Name, Node) ->
 +    decode_disco_item_attrs(__TopXMLNS, _attrs, Jid, _val,
 +                          Node);
 +decode_disco_item_attrs(__TopXMLNS,
 +                      [{<<"node">>, _val} | _attrs], Jid, Name, _Node) ->
 +    decode_disco_item_attrs(__TopXMLNS, _attrs, Jid, Name,
 +                          _val);
 +decode_disco_item_attrs(__TopXMLNS, [_ | _attrs], Jid,
 +                      Name, Node) ->
 +    decode_disco_item_attrs(__TopXMLNS, _attrs, Jid, Name,
 +                          Node);
 +decode_disco_item_attrs(__TopXMLNS, [], Jid, Name,
 +                      Node) ->
 +    {decode_disco_item_attr_jid(__TopXMLNS, Jid),
 +     decode_disco_item_attr_name(__TopXMLNS, Name),
 +     decode_disco_item_attr_node(__TopXMLNS, Node)}.
 +
 +encode_disco_item({disco_item, Jid, Name, Node},
 +                __TopXMLNS) ->
 +    __NewTopXMLNS =
 +      choose_top_xmlns(<<"http://jabber.org/protocol/disco#items">>,
 +                       [], __TopXMLNS),
 +    _els = [],
 +    _attrs = encode_disco_item_attr_node(Node,
 +                                       encode_disco_item_attr_name(Name,
 +                                                                   encode_disco_item_attr_jid(Jid,
 +                                                                                              enc_xmlns_attrs(__NewTopXMLNS,
 +                                                                                                              __TopXMLNS)))),
 +    {xmlel, <<"item">>, _attrs, _els}.
 +
 +decode_disco_item_attr_jid(__TopXMLNS, undefined) ->
 +    erlang:error({xmpp_codec,
 +                {missing_attr, <<"jid">>, <<"item">>, __TopXMLNS}});
 +decode_disco_item_attr_jid(__TopXMLNS, _val) ->
 +    case catch dec_jid(_val) of
 +      {'EXIT', _} ->
 +        erlang:error({xmpp_codec,
 +                      {bad_attr_value, <<"jid">>, <<"item">>, __TopXMLNS}});
 +      _res -> _res
 +    end.
 +
 +encode_disco_item_attr_jid(_val, _acc) ->
 +    [{<<"jid">>, enc_jid(_val)} | _acc].
 +
 +decode_disco_item_attr_name(__TopXMLNS, undefined) ->
 +    <<>>;
 +decode_disco_item_attr_name(__TopXMLNS, _val) -> _val.
 +
 +encode_disco_item_attr_name(<<>>, _acc) -> _acc;
 +encode_disco_item_attr_name(_val, _acc) ->
 +    [{<<"name">>, _val} | _acc].
 +
 +decode_disco_item_attr_node(__TopXMLNS, undefined) ->
 +    <<>>;
 +decode_disco_item_attr_node(__TopXMLNS, _val) -> _val.
 +
 +encode_disco_item_attr_node(<<>>, _acc) -> _acc;
 +encode_disco_item_attr_node(_val, _acc) ->
 +    [{<<"node">>, _val} | _acc].
 +
 +decode_disco_info(__TopXMLNS, __IgnoreEls,
 +                {xmlel, <<"query">>, _attrs, _els}) ->
 +    {Xdata, Features, Identities} =
 +      decode_disco_info_els(__TopXMLNS, __IgnoreEls, _els, [],
 +                            [], []),
 +    Node = decode_disco_info_attrs(__TopXMLNS, _attrs,
 +                                 undefined),
 +    {disco_info, Node, Identities, Features, Xdata}.
 +
 +decode_disco_info_els(__TopXMLNS, __IgnoreEls, [],
 +                    Xdata, Features, Identities) ->
 +    {lists:reverse(Xdata), lists:reverse(Features),
 +     lists:reverse(Identities)};
 +decode_disco_info_els(__TopXMLNS, __IgnoreEls,
 +                    [{xmlel, <<"identity">>, _attrs, _} = _el | _els],
 +                    Xdata, Features, Identities) ->
 +    case get_attr(<<"xmlns">>, _attrs) of
 +      <<"">>
 +        when __TopXMLNS ==
 +               <<"http://jabber.org/protocol/disco#info">> ->
 +        decode_disco_info_els(__TopXMLNS, __IgnoreEls, _els,
 +                              Xdata, Features,
 +                              [decode_disco_identity(__TopXMLNS, __IgnoreEls,
 +                                                     _el)
 +                               | Identities]);
 +      <<"http://jabber.org/protocol/disco#info">> ->
 +        decode_disco_info_els(__TopXMLNS, __IgnoreEls, _els,
 +                              Xdata, Features,
 +                              [decode_disco_identity(<<"http://jabber.org/protocol/disco#info">>,
 +                                                     __IgnoreEls, _el)
 +                               | Identities]);
 +      _ ->
 +        decode_disco_info_els(__TopXMLNS, __IgnoreEls, _els,
 +                              Xdata, Features, Identities)
 +    end;
 +decode_disco_info_els(__TopXMLNS, __IgnoreEls,
 +                    [{xmlel, <<"feature">>, _attrs, _} = _el | _els], Xdata,
 +                    Features, Identities) ->
 +    case get_attr(<<"xmlns">>, _attrs) of
 +      <<"">>
 +        when __TopXMLNS ==
 +               <<"http://jabber.org/protocol/disco#info">> ->
 +        decode_disco_info_els(__TopXMLNS, __IgnoreEls, _els,
 +                              Xdata,
 +                              [decode_disco_feature(__TopXMLNS, __IgnoreEls,
 +                                                    _el)
 +                               | Features],
 +                              Identities);
 +      <<"http://jabber.org/protocol/disco#info">> ->
 +        decode_disco_info_els(__TopXMLNS, __IgnoreEls, _els,
 +                              Xdata,
 +                              [decode_disco_feature(<<"http://jabber.org/protocol/disco#info">>,
 +                                                    __IgnoreEls, _el)
 +                               | Features],
 +                              Identities);
 +      _ ->
 +        decode_disco_info_els(__TopXMLNS, __IgnoreEls, _els,
 +                              Xdata, Features, Identities)
 +    end;
 +decode_disco_info_els(__TopXMLNS, __IgnoreEls,
 +                    [{xmlel, <<"x">>, _attrs, _} = _el | _els], Xdata,
 +                    Features, Identities) ->
 +    case get_attr(<<"xmlns">>, _attrs) of
 +      <<"jabber:x:data">> ->
 +        decode_disco_info_els(__TopXMLNS, __IgnoreEls, _els,
 +                              [decode_xdata(<<"jabber:x:data">>, __IgnoreEls,
 +                                            _el)
 +                               | Xdata],
 +                              Features, Identities);
 +      _ ->
 +        decode_disco_info_els(__TopXMLNS, __IgnoreEls, _els,
 +                              Xdata, Features, Identities)
 +    end;
 +decode_disco_info_els(__TopXMLNS, __IgnoreEls,
 +                    [_ | _els], Xdata, Features, Identities) ->
 +    decode_disco_info_els(__TopXMLNS, __IgnoreEls, _els,
 +                        Xdata, Features, Identities).
 +
 +decode_disco_info_attrs(__TopXMLNS,
 +                      [{<<"node">>, _val} | _attrs], _Node) ->
 +    decode_disco_info_attrs(__TopXMLNS, _attrs, _val);
 +decode_disco_info_attrs(__TopXMLNS, [_ | _attrs],
 +                      Node) ->
 +    decode_disco_info_attrs(__TopXMLNS, _attrs, Node);
 +decode_disco_info_attrs(__TopXMLNS, [], Node) ->
 +    decode_disco_info_attr_node(__TopXMLNS, Node).
 +
 +encode_disco_info({disco_info, Node, Identities,
 +                 Features, Xdata},
 +                __TopXMLNS) ->
 +    __NewTopXMLNS =
 +      choose_top_xmlns(<<"http://jabber.org/protocol/disco#info">>,
 +                       [], __TopXMLNS),
 +    _els = lists:reverse('encode_disco_info_$xdata'(Xdata,
 +                                                  __NewTopXMLNS,
 +                                                  'encode_disco_info_$features'(Features,
 +                                                                                __NewTopXMLNS,
 +                                                                                'encode_disco_info_$identities'(Identities,
 +                                                                                                                __NewTopXMLNS,
 +                                                                                                                [])))),
 +    _attrs = encode_disco_info_attr_node(Node,
 +                                       enc_xmlns_attrs(__NewTopXMLNS,
 +                                                       __TopXMLNS)),
 +    {xmlel, <<"query">>, _attrs, _els}.
 +
 +'encode_disco_info_$xdata'([], __TopXMLNS, _acc) ->
 +    _acc;
 +'encode_disco_info_$xdata'([Xdata | _els], __TopXMLNS,
 +                         _acc) ->
 +    'encode_disco_info_$xdata'(_els, __TopXMLNS,
 +                             [encode_xdata(Xdata, __TopXMLNS) | _acc]).
 +
 +'encode_disco_info_$features'([], __TopXMLNS, _acc) ->
 +    _acc;
 +'encode_disco_info_$features'([Features | _els],
 +                            __TopXMLNS, _acc) ->
 +    'encode_disco_info_$features'(_els, __TopXMLNS,
 +                                [encode_disco_feature(Features, __TopXMLNS)
 +                                 | _acc]).
 +
 +'encode_disco_info_$identities'([], __TopXMLNS, _acc) ->
 +    _acc;
 +'encode_disco_info_$identities'([Identities | _els],
 +                              __TopXMLNS, _acc) ->
 +    'encode_disco_info_$identities'(_els, __TopXMLNS,
 +                                  [encode_disco_identity(Identities,
 +                                                         __TopXMLNS)
 +                                   | _acc]).
 +
 +decode_disco_info_attr_node(__TopXMLNS, undefined) ->
 +    <<>>;
 +decode_disco_info_attr_node(__TopXMLNS, _val) -> _val.
 +
 +encode_disco_info_attr_node(<<>>, _acc) -> _acc;
 +encode_disco_info_attr_node(_val, _acc) ->
 +    [{<<"node">>, _val} | _acc].
 +
 +decode_disco_feature(__TopXMLNS, __IgnoreEls,
 +                   {xmlel, <<"feature">>, _attrs, _els}) ->
 +    Var = decode_disco_feature_attrs(__TopXMLNS, _attrs,
 +                                   undefined),
 +    Var.
 +
 +decode_disco_feature_attrs(__TopXMLNS,
 +                         [{<<"var">>, _val} | _attrs], _Var) ->
 +    decode_disco_feature_attrs(__TopXMLNS, _attrs, _val);
 +decode_disco_feature_attrs(__TopXMLNS, [_ | _attrs],
 +                         Var) ->
 +    decode_disco_feature_attrs(__TopXMLNS, _attrs, Var);
 +decode_disco_feature_attrs(__TopXMLNS, [], Var) ->
 +    decode_disco_feature_attr_var(__TopXMLNS, Var).
 +
 +encode_disco_feature(Var, __TopXMLNS) ->
 +    __NewTopXMLNS =
 +      choose_top_xmlns(<<"http://jabber.org/protocol/disco#info">>,
 +                       [], __TopXMLNS),
 +    _els = [],
 +    _attrs = encode_disco_feature_attr_var(Var,
 +                                         enc_xmlns_attrs(__NewTopXMLNS,
 +                                                         __TopXMLNS)),
 +    {xmlel, <<"feature">>, _attrs, _els}.
 +
 +decode_disco_feature_attr_var(__TopXMLNS, undefined) ->
 +    erlang:error({xmpp_codec,
 +                {missing_attr, <<"var">>, <<"feature">>, __TopXMLNS}});
 +decode_disco_feature_attr_var(__TopXMLNS, _val) -> _val.
 +
 +encode_disco_feature_attr_var(_val, _acc) ->
 +    [{<<"var">>, _val} | _acc].
 +
 +decode_disco_identity(__TopXMLNS, __IgnoreEls,
 +                    {xmlel, <<"identity">>, _attrs, _els}) ->
 +    {Category, Type, Lang, Name} =
 +      decode_disco_identity_attrs(__TopXMLNS, _attrs,
 +                                  undefined, undefined, undefined, undefined),
 +    {identity, Category, Type, Lang, Name}.
 +
 +decode_disco_identity_attrs(__TopXMLNS,
 +                          [{<<"category">>, _val} | _attrs], _Category, Type,
 +                          Lang, Name) ->
 +    decode_disco_identity_attrs(__TopXMLNS, _attrs, _val,
 +                              Type, Lang, Name);
 +decode_disco_identity_attrs(__TopXMLNS,
 +                          [{<<"type">>, _val} | _attrs], Category, _Type,
 +                          Lang, Name) ->
 +    decode_disco_identity_attrs(__TopXMLNS, _attrs,
 +                              Category, _val, Lang, Name);
 +decode_disco_identity_attrs(__TopXMLNS,
 +                          [{<<"xml:lang">>, _val} | _attrs], Category, Type,
 +                          _Lang, Name) ->
 +    decode_disco_identity_attrs(__TopXMLNS, _attrs,
 +                              Category, Type, _val, Name);
 +decode_disco_identity_attrs(__TopXMLNS,
 +                          [{<<"name">>, _val} | _attrs], Category, Type, Lang,
 +                          _Name) ->
 +    decode_disco_identity_attrs(__TopXMLNS, _attrs,
 +                              Category, Type, Lang, _val);
 +decode_disco_identity_attrs(__TopXMLNS, [_ | _attrs],
 +                          Category, Type, Lang, Name) ->
 +    decode_disco_identity_attrs(__TopXMLNS, _attrs,
 +                              Category, Type, Lang, Name);
 +decode_disco_identity_attrs(__TopXMLNS, [], Category,
 +                          Type, Lang, Name) ->
 +    {decode_disco_identity_attr_category(__TopXMLNS,
 +                                       Category),
 +     decode_disco_identity_attr_type(__TopXMLNS, Type),
 +     'decode_disco_identity_attr_xml:lang'(__TopXMLNS, Lang),
 +     decode_disco_identity_attr_name(__TopXMLNS, Name)}.
 +
 +encode_disco_identity({identity, Category, Type, Lang,
 +                     Name},
 +                    __TopXMLNS) ->
 +    __NewTopXMLNS =
 +      choose_top_xmlns(<<"http://jabber.org/protocol/disco#info">>,
 +                       [], __TopXMLNS),
 +    _els = [],
 +    _attrs = encode_disco_identity_attr_name(Name,
 +                                           'encode_disco_identity_attr_xml:lang'(Lang,
 +                                                                                 encode_disco_identity_attr_type(Type,
 +                                                                                                                 encode_disco_identity_attr_category(Category,
 +                                                                                                                                                     enc_xmlns_attrs(__NewTopXMLNS,
 +                                                                                                                                                                     __TopXMLNS))))),
 +    {xmlel, <<"identity">>, _attrs, _els}.
 +
 +decode_disco_identity_attr_category(__TopXMLNS,
 +                                  undefined) ->
 +    erlang:error({xmpp_codec,
 +                {missing_attr, <<"category">>, <<"identity">>,
 +                 __TopXMLNS}});
 +decode_disco_identity_attr_category(__TopXMLNS, _val) ->
 +    _val.
 +
 +encode_disco_identity_attr_category(_val, _acc) ->
 +    [{<<"category">>, _val} | _acc].
 +
 +decode_disco_identity_attr_type(__TopXMLNS,
 +                              undefined) ->
 +    erlang:error({xmpp_codec,
 +                {missing_attr, <<"type">>, <<"identity">>,
 +                 __TopXMLNS}});
 +decode_disco_identity_attr_type(__TopXMLNS, _val) ->
 +    _val.
 +
 +encode_disco_identity_attr_type(_val, _acc) ->
 +    [{<<"type">>, _val} | _acc].
 +
 +'decode_disco_identity_attr_xml:lang'(__TopXMLNS,
 +                                    undefined) ->
 +    <<>>;
 +'decode_disco_identity_attr_xml:lang'(__TopXMLNS,
 +                                    _val) ->
 +    _val.
 +
 +'encode_disco_identity_attr_xml:lang'(<<>>, _acc) ->
 +    _acc;
 +'encode_disco_identity_attr_xml:lang'(_val, _acc) ->
 +    [{<<"xml:lang">>, _val} | _acc].
 +
 +decode_disco_identity_attr_name(__TopXMLNS,
 +                              undefined) ->
 +    <<>>;
 +decode_disco_identity_attr_name(__TopXMLNS, _val) ->
 +    _val.
 +
 +encode_disco_identity_attr_name(<<>>, _acc) -> _acc;
 +encode_disco_identity_attr_name(_val, _acc) ->
 +    [{<<"name">>, _val} | _acc].
 +
 +decode_block_list(__TopXMLNS, __IgnoreEls,
 +                {xmlel, <<"blocklist">>, _attrs, _els}) ->
 +    Items = decode_block_list_els(__TopXMLNS, __IgnoreEls,
 +                                _els, []),
 +    {block_list, Items}.
 +
 +decode_block_list_els(__TopXMLNS, __IgnoreEls, [],
 +                    Items) ->
 +    lists:reverse(Items);
 +decode_block_list_els(__TopXMLNS, __IgnoreEls,
 +                    [{xmlel, <<"item">>, _attrs, _} = _el | _els], Items) ->
 +    case get_attr(<<"xmlns">>, _attrs) of
 +      <<"">> when __TopXMLNS == <<"urn:xmpp:blocking">> ->
 +        decode_block_list_els(__TopXMLNS, __IgnoreEls, _els,
 +                              [decode_block_item(__TopXMLNS, __IgnoreEls, _el)
 +                               | Items]);
 +      <<"urn:xmpp:blocking">> ->
 +        decode_block_list_els(__TopXMLNS, __IgnoreEls, _els,
 +                              [decode_block_item(<<"urn:xmpp:blocking">>,
 +                                                 __IgnoreEls, _el)
 +                               | Items]);
 +      _ ->
 +        decode_block_list_els(__TopXMLNS, __IgnoreEls, _els,
 +                              Items)
 +    end;
 +decode_block_list_els(__TopXMLNS, __IgnoreEls,
 +                    [_ | _els], Items) ->
 +    decode_block_list_els(__TopXMLNS, __IgnoreEls, _els,
 +                        Items).
 +
 +encode_block_list({block_list, Items}, __TopXMLNS) ->
 +    __NewTopXMLNS =
 +      choose_top_xmlns(<<"urn:xmpp:blocking">>, [],
 +                       __TopXMLNS),
 +    _els = lists:reverse('encode_block_list_$items'(Items,
 +                                                  __NewTopXMLNS, [])),
 +    _attrs = enc_xmlns_attrs(__NewTopXMLNS, __TopXMLNS),
 +    {xmlel, <<"blocklist">>, _attrs, _els}.
 +
 +'encode_block_list_$items'([], __TopXMLNS, _acc) ->
 +    _acc;
 +'encode_block_list_$items'([Items | _els], __TopXMLNS,
 +                         _acc) ->
 +    'encode_block_list_$items'(_els, __TopXMLNS,
 +                             [encode_block_item(Items, __TopXMLNS) | _acc]).
 +
 +decode_unblock(__TopXMLNS, __IgnoreEls,
 +             {xmlel, <<"unblock">>, _attrs, _els}) ->
 +    Items = decode_unblock_els(__TopXMLNS, __IgnoreEls,
 +                             _els, []),
 +    {unblock, Items}.
 +
 +decode_unblock_els(__TopXMLNS, __IgnoreEls, [],
 +                 Items) ->
 +    lists:reverse(Items);
 +decode_unblock_els(__TopXMLNS, __IgnoreEls,
 +                 [{xmlel, <<"item">>, _attrs, _} = _el | _els], Items) ->
 +    case get_attr(<<"xmlns">>, _attrs) of
 +      <<"">> when __TopXMLNS == <<"urn:xmpp:blocking">> ->
 +        decode_unblock_els(__TopXMLNS, __IgnoreEls, _els,
 +                           [decode_block_item(__TopXMLNS, __IgnoreEls, _el)
 +                            | Items]);
 +      <<"urn:xmpp:blocking">> ->
 +        decode_unblock_els(__TopXMLNS, __IgnoreEls, _els,
 +                           [decode_block_item(<<"urn:xmpp:blocking">>,
 +                                              __IgnoreEls, _el)
 +                            | Items]);
 +      _ ->
 +        decode_unblock_els(__TopXMLNS, __IgnoreEls, _els, Items)
 +    end;
 +decode_unblock_els(__TopXMLNS, __IgnoreEls, [_ | _els],
 +                 Items) ->
 +    decode_unblock_els(__TopXMLNS, __IgnoreEls, _els,
 +                     Items).
 +
 +encode_unblock({unblock, Items}, __TopXMLNS) ->
 +    __NewTopXMLNS =
 +      choose_top_xmlns(<<"urn:xmpp:blocking">>, [],
 +                       __TopXMLNS),
 +    _els = lists:reverse('encode_unblock_$items'(Items,
 +                                               __NewTopXMLNS, [])),
 +    _attrs = enc_xmlns_attrs(__NewTopXMLNS, __TopXMLNS),
 +    {xmlel, <<"unblock">>, _attrs, _els}.
 +
 +'encode_unblock_$items'([], __TopXMLNS, _acc) -> _acc;
 +'encode_unblock_$items'([Items | _els], __TopXMLNS,
 +                      _acc) ->
 +    'encode_unblock_$items'(_els, __TopXMLNS,
 +                          [encode_block_item(Items, __TopXMLNS) | _acc]).
 +
 +decode_block(__TopXMLNS, __IgnoreEls,
 +           {xmlel, <<"block">>, _attrs, _els}) ->
 +    Items = decode_block_els(__TopXMLNS, __IgnoreEls, _els,
 +                           []),
 +    {block, Items}.
 +
 +decode_block_els(__TopXMLNS, __IgnoreEls, [], Items) ->
 +    lists:reverse(Items);
 +decode_block_els(__TopXMLNS, __IgnoreEls,
 +               [{xmlel, <<"item">>, _attrs, _} = _el | _els], Items) ->
 +    case get_attr(<<"xmlns">>, _attrs) of
 +      <<"">> when __TopXMLNS == <<"urn:xmpp:blocking">> ->
 +        decode_block_els(__TopXMLNS, __IgnoreEls, _els,
 +                         [decode_block_item(__TopXMLNS, __IgnoreEls, _el)
 +                          | Items]);
 +      <<"urn:xmpp:blocking">> ->
 +        decode_block_els(__TopXMLNS, __IgnoreEls, _els,
 +                         [decode_block_item(<<"urn:xmpp:blocking">>,
 +                                            __IgnoreEls, _el)
 +                          | Items]);
 +      _ ->
 +        decode_block_els(__TopXMLNS, __IgnoreEls, _els, Items)
 +    end;
 +decode_block_els(__TopXMLNS, __IgnoreEls, [_ | _els],
 +               Items) ->
 +    decode_block_els(__TopXMLNS, __IgnoreEls, _els, Items).
 +
 +encode_block({block, Items}, __TopXMLNS) ->
 +    __NewTopXMLNS =
 +      choose_top_xmlns(<<"urn:xmpp:blocking">>, [],
 +                       __TopXMLNS),
 +    _els = lists:reverse('encode_block_$items'(Items,
 +                                             __NewTopXMLNS, [])),
 +    _attrs = enc_xmlns_attrs(__NewTopXMLNS, __TopXMLNS),
 +    {xmlel, <<"block">>, _attrs, _els}.
 +
 +'encode_block_$items'([], __TopXMLNS, _acc) -> _acc;
 +'encode_block_$items'([Items | _els], __TopXMLNS,
 +                    _acc) ->
 +    'encode_block_$items'(_els, __TopXMLNS,
 +                        [encode_block_item(Items, __TopXMLNS) | _acc]).
 +
 +decode_block_item(__TopXMLNS, __IgnoreEls,
 +                {xmlel, <<"item">>, _attrs, _els}) ->
 +    Jid = decode_block_item_attrs(__TopXMLNS, _attrs,
 +                                undefined),
 +    Jid.
 +
 +decode_block_item_attrs(__TopXMLNS,
 +                      [{<<"jid">>, _val} | _attrs], _Jid) ->
 +    decode_block_item_attrs(__TopXMLNS, _attrs, _val);
 +decode_block_item_attrs(__TopXMLNS, [_ | _attrs],
 +                      Jid) ->
 +    decode_block_item_attrs(__TopXMLNS, _attrs, Jid);
 +decode_block_item_attrs(__TopXMLNS, [], Jid) ->
 +    decode_block_item_attr_jid(__TopXMLNS, Jid).
 +
 +encode_block_item(Jid, __TopXMLNS) ->
 +    __NewTopXMLNS =
 +      choose_top_xmlns(<<"urn:xmpp:blocking">>, [],
 +                       __TopXMLNS),
 +    _els = [],
 +    _attrs = encode_block_item_attr_jid(Jid,
 +                                      enc_xmlns_attrs(__NewTopXMLNS,
 +                                                      __TopXMLNS)),
 +    {xmlel, <<"item">>, _attrs, _els}.
 +
 +decode_block_item_attr_jid(__TopXMLNS, undefined) ->
 +    erlang:error({xmpp_codec,
 +                {missing_attr, <<"jid">>, <<"item">>, __TopXMLNS}});
 +decode_block_item_attr_jid(__TopXMLNS, _val) ->
 +    case catch dec_jid(_val) of
 +      {'EXIT', _} ->
 +        erlang:error({xmpp_codec,
 +                      {bad_attr_value, <<"jid">>, <<"item">>, __TopXMLNS}});
 +      _res -> _res
 +    end.
 +
 +encode_block_item_attr_jid(_val, _acc) ->
 +    [{<<"jid">>, enc_jid(_val)} | _acc].
 +
 +decode_privacy(__TopXMLNS, __IgnoreEls,
 +             {xmlel, <<"query">>, _attrs, _els}) ->
 +    {Lists, Default, Active} =
 +      decode_privacy_els(__TopXMLNS, __IgnoreEls, _els, [],
 +                         undefined, undefined),
 +    {privacy_query, Lists, Default, Active}.
 +
 +decode_privacy_els(__TopXMLNS, __IgnoreEls, [], Lists,
 +                 Default, Active) ->
 +    {lists:reverse(Lists), Default, Active};
 +decode_privacy_els(__TopXMLNS, __IgnoreEls,
 +                 [{xmlel, <<"list">>, _attrs, _} = _el | _els], Lists,
 +                 Default, Active) ->
 +    case get_attr(<<"xmlns">>, _attrs) of
 +      <<"">> when __TopXMLNS == <<"jabber:iq:privacy">> ->
 +        decode_privacy_els(__TopXMLNS, __IgnoreEls, _els,
 +                           [decode_privacy_list(__TopXMLNS, __IgnoreEls, _el)
 +                            | Lists],
 +                           Default, Active);
 +      <<"jabber:iq:privacy">> ->
 +        decode_privacy_els(__TopXMLNS, __IgnoreEls, _els,
 +                           [decode_privacy_list(<<"jabber:iq:privacy">>,
 +                                                __IgnoreEls, _el)
 +                            | Lists],
 +                           Default, Active);
 +      _ ->
 +        decode_privacy_els(__TopXMLNS, __IgnoreEls, _els, Lists,
 +                           Default, Active)
 +    end;
 +decode_privacy_els(__TopXMLNS, __IgnoreEls,
 +                 [{xmlel, <<"default">>, _attrs, _} = _el | _els], Lists,
 +                 Default, Active) ->
 +    case get_attr(<<"xmlns">>, _attrs) of
 +      <<"">> when __TopXMLNS == <<"jabber:iq:privacy">> ->
 +        decode_privacy_els(__TopXMLNS, __IgnoreEls, _els, Lists,
 +                           decode_privacy_default_list(__TopXMLNS,
 +                                                       __IgnoreEls, _el),
 +                           Active);
 +      <<"jabber:iq:privacy">> ->
 +        decode_privacy_els(__TopXMLNS, __IgnoreEls, _els, Lists,
 +                           decode_privacy_default_list(<<"jabber:iq:privacy">>,
 +                                                       __IgnoreEls, _el),
 +                           Active);
 +      _ ->
 +        decode_privacy_els(__TopXMLNS, __IgnoreEls, _els, Lists,
 +                           Default, Active)
 +    end;
 +decode_privacy_els(__TopXMLNS, __IgnoreEls,
 +                 [{xmlel, <<"active">>, _attrs, _} = _el | _els], Lists,
 +                 Default, Active) ->
 +    case get_attr(<<"xmlns">>, _attrs) of
 +      <<"">> when __TopXMLNS == <<"jabber:iq:privacy">> ->
 +        decode_privacy_els(__TopXMLNS, __IgnoreEls, _els, Lists,
 +                           Default,
 +                           decode_privacy_active_list(__TopXMLNS, __IgnoreEls,
 +                                                      _el));
 +      <<"jabber:iq:privacy">> ->
 +        decode_privacy_els(__TopXMLNS, __IgnoreEls, _els, Lists,
 +                           Default,
 +                           decode_privacy_active_list(<<"jabber:iq:privacy">>,
 +                                                      __IgnoreEls, _el));
 +      _ ->
 +        decode_privacy_els(__TopXMLNS, __IgnoreEls, _els, Lists,
 +                           Default, Active)
 +    end;
 +decode_privacy_els(__TopXMLNS, __IgnoreEls, [_ | _els],
 +                 Lists, Default, Active) ->
 +    decode_privacy_els(__TopXMLNS, __IgnoreEls, _els, Lists,
 +                     Default, Active).
 +
 +encode_privacy({privacy_query, Lists, Default, Active},
 +             __TopXMLNS) ->
 +    __NewTopXMLNS =
 +      choose_top_xmlns(<<"jabber:iq:privacy">>, [],
 +                       __TopXMLNS),
 +    _els = lists:reverse('encode_privacy_$lists'(Lists,
 +                                               __NewTopXMLNS,
 +                                               'encode_privacy_$default'(Default,
 +                                                                         __NewTopXMLNS,
 +                                                                         'encode_privacy_$active'(Active,
 +                                                                                                  __NewTopXMLNS,
 +                                                                                                  [])))),
 +    _attrs = enc_xmlns_attrs(__NewTopXMLNS, __TopXMLNS),
 +    {xmlel, <<"query">>, _attrs, _els}.
 +
 +'encode_privacy_$lists'([], __TopXMLNS, _acc) -> _acc;
 +'encode_privacy_$lists'([Lists | _els], __TopXMLNS,
 +                      _acc) ->
 +    'encode_privacy_$lists'(_els, __TopXMLNS,
 +                          [encode_privacy_list(Lists, __TopXMLNS) | _acc]).
 +
 +'encode_privacy_$default'(undefined, __TopXMLNS,
 +                        _acc) ->
 +    _acc;
 +'encode_privacy_$default'(Default, __TopXMLNS, _acc) ->
 +    [encode_privacy_default_list(Default, __TopXMLNS)
 +     | _acc].
 +
 +'encode_privacy_$active'(undefined, __TopXMLNS, _acc) ->
 +    _acc;
 +'encode_privacy_$active'(Active, __TopXMLNS, _acc) ->
 +    [encode_privacy_active_list(Active, __TopXMLNS) | _acc].
 +
 +decode_privacy_active_list(__TopXMLNS, __IgnoreEls,
 +                         {xmlel, <<"active">>, _attrs, _els}) ->
 +    Name = decode_privacy_active_list_attrs(__TopXMLNS,
 +                                          _attrs, undefined),
 +    Name.
 +
 +decode_privacy_active_list_attrs(__TopXMLNS,
 +                               [{<<"name">>, _val} | _attrs], _Name) ->
 +    decode_privacy_active_list_attrs(__TopXMLNS, _attrs,
 +                                   _val);
 +decode_privacy_active_list_attrs(__TopXMLNS,
 +                               [_ | _attrs], Name) ->
 +    decode_privacy_active_list_attrs(__TopXMLNS, _attrs,
 +                                   Name);
 +decode_privacy_active_list_attrs(__TopXMLNS, [],
 +                               Name) ->
 +    decode_privacy_active_list_attr_name(__TopXMLNS, Name).
 +
 +encode_privacy_active_list(Name, __TopXMLNS) ->
 +    __NewTopXMLNS =
 +      choose_top_xmlns(<<"jabber:iq:privacy">>, [],
 +                       __TopXMLNS),
 +    _els = [],
 +    _attrs = encode_privacy_active_list_attr_name(Name,
 +                                                enc_xmlns_attrs(__NewTopXMLNS,
 +                                                                __TopXMLNS)),
 +    {xmlel, <<"active">>, _attrs, _els}.
 +
 +decode_privacy_active_list_attr_name(__TopXMLNS,
 +                                   undefined) ->
 +    none;
 +decode_privacy_active_list_attr_name(__TopXMLNS,
 +                                   _val) ->
 +    _val.
 +
 +encode_privacy_active_list_attr_name(none, _acc) ->
 +    _acc;
 +encode_privacy_active_list_attr_name(_val, _acc) ->
 +    [{<<"name">>, _val} | _acc].
 +
 +decode_privacy_default_list(__TopXMLNS, __IgnoreEls,
 +                          {xmlel, <<"default">>, _attrs, _els}) ->
 +    Name = decode_privacy_default_list_attrs(__TopXMLNS,
 +                                           _attrs, undefined),
 +    Name.
 +
 +decode_privacy_default_list_attrs(__TopXMLNS,
 +                                [{<<"name">>, _val} | _attrs], _Name) ->
 +    decode_privacy_default_list_attrs(__TopXMLNS, _attrs,
 +                                    _val);
 +decode_privacy_default_list_attrs(__TopXMLNS,
 +                                [_ | _attrs], Name) ->
 +    decode_privacy_default_list_attrs(__TopXMLNS, _attrs,
 +                                    Name);
 +decode_privacy_default_list_attrs(__TopXMLNS, [],
 +                                Name) ->
 +    decode_privacy_default_list_attr_name(__TopXMLNS, Name).
 +
 +encode_privacy_default_list(Name, __TopXMLNS) ->
 +    __NewTopXMLNS =
 +      choose_top_xmlns(<<"jabber:iq:privacy">>, [],
 +                       __TopXMLNS),
 +    _els = [],
 +    _attrs = encode_privacy_default_list_attr_name(Name,
 +                                                 enc_xmlns_attrs(__NewTopXMLNS,
 +                                                                 __TopXMLNS)),
 +    {xmlel, <<"default">>, _attrs, _els}.
 +
 +decode_privacy_default_list_attr_name(__TopXMLNS,
 +                                    undefined) ->
 +    none;
 +decode_privacy_default_list_attr_name(__TopXMLNS,
 +                                    _val) ->
 +    _val.
 +
 +encode_privacy_default_list_attr_name(none, _acc) ->
 +    _acc;
 +encode_privacy_default_list_attr_name(_val, _acc) ->
 +    [{<<"name">>, _val} | _acc].
 +
 +decode_privacy_list(__TopXMLNS, __IgnoreEls,
 +                  {xmlel, <<"list">>, _attrs, _els}) ->
 +    Items = decode_privacy_list_els(__TopXMLNS, __IgnoreEls,
 +                                  _els, []),
 +    Name = decode_privacy_list_attrs(__TopXMLNS, _attrs,
 +                                   undefined),
 +    {privacy_list, Name, Items}.
 +
 +decode_privacy_list_els(__TopXMLNS, __IgnoreEls, [],
 +                      Items) ->
 +    lists:reverse(Items);
 +decode_privacy_list_els(__TopXMLNS, __IgnoreEls,
 +                      [{xmlel, <<"item">>, _attrs, _} = _el | _els], Items) ->
 +    case get_attr(<<"xmlns">>, _attrs) of
 +      <<"">> when __TopXMLNS == <<"jabber:iq:privacy">> ->
 +        decode_privacy_list_els(__TopXMLNS, __IgnoreEls, _els,
 +                                [decode_privacy_item(__TopXMLNS, __IgnoreEls,
 +                                                     _el)
 +                                 | Items]);
 +      <<"jabber:iq:privacy">> ->
 +        decode_privacy_list_els(__TopXMLNS, __IgnoreEls, _els,
 +                                [decode_privacy_item(<<"jabber:iq:privacy">>,
 +                                                     __IgnoreEls, _el)
 +                                 | Items]);
 +      _ ->
 +        decode_privacy_list_els(__TopXMLNS, __IgnoreEls, _els,
 +                                Items)
 +    end;
 +decode_privacy_list_els(__TopXMLNS, __IgnoreEls,
 +                      [_ | _els], Items) ->
 +    decode_privacy_list_els(__TopXMLNS, __IgnoreEls, _els,
 +                          Items).
 +
 +decode_privacy_list_attrs(__TopXMLNS,
 +                        [{<<"name">>, _val} | _attrs], _Name) ->
 +    decode_privacy_list_attrs(__TopXMLNS, _attrs, _val);
 +decode_privacy_list_attrs(__TopXMLNS, [_ | _attrs],
 +                        Name) ->
 +    decode_privacy_list_attrs(__TopXMLNS, _attrs, Name);
 +decode_privacy_list_attrs(__TopXMLNS, [], Name) ->
 +    decode_privacy_list_attr_name(__TopXMLNS, Name).
 +
 +encode_privacy_list({privacy_list, Name, Items},
 +                  __TopXMLNS) ->
 +    __NewTopXMLNS =
 +      choose_top_xmlns(<<"jabber:iq:privacy">>, [],
 +                       __TopXMLNS),
 +    _els = lists:reverse('encode_privacy_list_$items'(Items,
 +                                                    __NewTopXMLNS, [])),
 +    _attrs = encode_privacy_list_attr_name(Name,
 +                                         enc_xmlns_attrs(__NewTopXMLNS,
 +                                                         __TopXMLNS)),
 +    {xmlel, <<"list">>, _attrs, _els}.
 +
 +'encode_privacy_list_$items'([], __TopXMLNS, _acc) ->
 +    _acc;
 +'encode_privacy_list_$items'([Items | _els], __TopXMLNS,
 +                           _acc) ->
 +    'encode_privacy_list_$items'(_els, __TopXMLNS,
 +                               [encode_privacy_item(Items, __TopXMLNS)
 +                                | _acc]).
 +
 +decode_privacy_list_attr_name(__TopXMLNS, undefined) ->
 +    erlang:error({xmpp_codec,
 +                {missing_attr, <<"name">>, <<"list">>, __TopXMLNS}});
 +decode_privacy_list_attr_name(__TopXMLNS, _val) -> _val.
 +
 +encode_privacy_list_attr_name(_val, _acc) ->
 +    [{<<"name">>, _val} | _acc].
 +
 +decode_privacy_item(__TopXMLNS, __IgnoreEls,
 +                  {xmlel, <<"item">>, _attrs, _els}) ->
 +    {Iq, Presence_out, Message, Presence_in} =
 +      decode_privacy_item_els(__TopXMLNS, __IgnoreEls, _els,
 +                              false, false, false, false),
 +    {Action, Order, Type, Value} =
 +      decode_privacy_item_attrs(__TopXMLNS, _attrs, undefined,
 +                                undefined, undefined, undefined),
 +    {privacy_item, Order, Action, Type, Value, Message, Iq,
 +     Presence_in, Presence_out}.
 +
 +decode_privacy_item_els(__TopXMLNS, __IgnoreEls, [], Iq,
 +                      Presence_out, Message, Presence_in) ->
 +    {Iq, Presence_out, Message, Presence_in};
 +decode_privacy_item_els(__TopXMLNS, __IgnoreEls,
 +                      [{xmlel, <<"message">>, _attrs, _} = _el | _els], Iq,
 +                      Presence_out, Message, Presence_in) ->
 +    case get_attr(<<"xmlns">>, _attrs) of
 +      <<"">> when __TopXMLNS == <<"jabber:iq:privacy">> ->
 +        decode_privacy_item_els(__TopXMLNS, __IgnoreEls, _els,
 +                                Iq, Presence_out,
 +                                decode_privacy_message(__TopXMLNS,
 +                                                       __IgnoreEls, _el),
 +                                Presence_in);
 +      <<"jabber:iq:privacy">> ->
 +        decode_privacy_item_els(__TopXMLNS, __IgnoreEls, _els,
 +                                Iq, Presence_out,
 +                                decode_privacy_message(<<"jabber:iq:privacy">>,
 +                                                       __IgnoreEls, _el),
 +                                Presence_in);
 +      _ ->
 +        decode_privacy_item_els(__TopXMLNS, __IgnoreEls, _els,
 +                                Iq, Presence_out, Message, Presence_in)
 +    end;
 +decode_privacy_item_els(__TopXMLNS, __IgnoreEls,
 +                      [{xmlel, <<"iq">>, _attrs, _} = _el | _els], Iq,
 +                      Presence_out, Message, Presence_in) ->
 +    case get_attr(<<"xmlns">>, _attrs) of
 +      <<"">> when __TopXMLNS == <<"jabber:iq:privacy">> ->
 +        decode_privacy_item_els(__TopXMLNS, __IgnoreEls, _els,
 +                                decode_privacy_iq(__TopXMLNS, __IgnoreEls,
 +                                                  _el),
 +                                Presence_out, Message, Presence_in);
 +      <<"jabber:iq:privacy">> ->
 +        decode_privacy_item_els(__TopXMLNS, __IgnoreEls, _els,
 +                                decode_privacy_iq(<<"jabber:iq:privacy">>,
 +                                                  __IgnoreEls, _el),
 +                                Presence_out, Message, Presence_in);
 +      _ ->
 +        decode_privacy_item_els(__TopXMLNS, __IgnoreEls, _els,
 +                                Iq, Presence_out, Message, Presence_in)
 +    end;
 +decode_privacy_item_els(__TopXMLNS, __IgnoreEls,
 +                      [{xmlel, <<"presence-in">>, _attrs, _} = _el | _els],
 +                      Iq, Presence_out, Message, Presence_in) ->
 +    case get_attr(<<"xmlns">>, _attrs) of
 +      <<"">> when __TopXMLNS == <<"jabber:iq:privacy">> ->
 +        decode_privacy_item_els(__TopXMLNS, __IgnoreEls, _els,
 +                                Iq, Presence_out, Message,
 +                                decode_privacy_presence_in(__TopXMLNS,
 +                                                           __IgnoreEls, _el));
 +      <<"jabber:iq:privacy">> ->
 +        decode_privacy_item_els(__TopXMLNS, __IgnoreEls, _els,
 +                                Iq, Presence_out, Message,
 +                                decode_privacy_presence_in(<<"jabber:iq:privacy">>,
 +                                                           __IgnoreEls, _el));
 +      _ ->
 +        decode_privacy_item_els(__TopXMLNS, __IgnoreEls, _els,
 +                                Iq, Presence_out, Message, Presence_in)
 +    end;
 +decode_privacy_item_els(__TopXMLNS, __IgnoreEls,
 +                      [{xmlel, <<"presence-out">>, _attrs, _} = _el | _els],
 +                      Iq, Presence_out, Message, Presence_in) ->
 +    case get_attr(<<"xmlns">>, _attrs) of
 +      <<"">> when __TopXMLNS == <<"jabber:iq:privacy">> ->
 +        decode_privacy_item_els(__TopXMLNS, __IgnoreEls, _els,
 +                                Iq,
 +                                decode_privacy_presence_out(__TopXMLNS,
 +                                                            __IgnoreEls, _el),
 +                                Message, Presence_in);
 +      <<"jabber:iq:privacy">> ->
 +        decode_privacy_item_els(__TopXMLNS, __IgnoreEls, _els,
 +                                Iq,
 +                                decode_privacy_presence_out(<<"jabber:iq:privacy">>,
 +                                                            __IgnoreEls, _el),
 +                                Message, Presence_in);
 +      _ ->
 +        decode_privacy_item_els(__TopXMLNS, __IgnoreEls, _els,
 +                                Iq, Presence_out, Message, Presence_in)
 +    end;
 +decode_privacy_item_els(__TopXMLNS, __IgnoreEls,
 +                      [_ | _els], Iq, Presence_out, Message, Presence_in) ->
 +    decode_privacy_item_els(__TopXMLNS, __IgnoreEls, _els,
 +                          Iq, Presence_out, Message, Presence_in).
 +
 +decode_privacy_item_attrs(__TopXMLNS,
 +                        [{<<"action">>, _val} | _attrs], _Action, Order, Type,
 +                        Value) ->
 +    decode_privacy_item_attrs(__TopXMLNS, _attrs, _val,
 +                            Order, Type, Value);
 +decode_privacy_item_attrs(__TopXMLNS,
 +                        [{<<"order">>, _val} | _attrs], Action, _Order, Type,
 +                        Value) ->
 +    decode_privacy_item_attrs(__TopXMLNS, _attrs, Action,
 +                            _val, Type, Value);
 +decode_privacy_item_attrs(__TopXMLNS,
 +                        [{<<"type">>, _val} | _attrs], Action, Order, _Type,
 +                        Value) ->
 +    decode_privacy_item_attrs(__TopXMLNS, _attrs, Action,
 +                            Order, _val, Value);
 +decode_privacy_item_attrs(__TopXMLNS,
 +                        [{<<"value">>, _val} | _attrs], Action, Order, Type,
 +                        _Value) ->
 +    decode_privacy_item_attrs(__TopXMLNS, _attrs, Action,
 +                            Order, Type, _val);
 +decode_privacy_item_attrs(__TopXMLNS, [_ | _attrs],
 +                        Action, Order, Type, Value) ->
 +    decode_privacy_item_attrs(__TopXMLNS, _attrs, Action,
 +                            Order, Type, Value);
 +decode_privacy_item_attrs(__TopXMLNS, [], Action, Order,
 +                        Type, Value) ->
 +    {decode_privacy_item_attr_action(__TopXMLNS, Action),
 +     decode_privacy_item_attr_order(__TopXMLNS, Order),
 +     decode_privacy_item_attr_type(__TopXMLNS, Type),
 +     decode_privacy_item_attr_value(__TopXMLNS, Value)}.
 +
 +encode_privacy_item({privacy_item, Order, Action, Type,
 +                   Value, Message, Iq, Presence_in, Presence_out},
 +                  __TopXMLNS) ->
 +    __NewTopXMLNS =
 +      choose_top_xmlns(<<"jabber:iq:privacy">>, [],
 +                       __TopXMLNS),
 +    _els = lists:reverse('encode_privacy_item_$iq'(Iq,
 +                                                 __NewTopXMLNS,
 +                                                 'encode_privacy_item_$presence_out'(Presence_out,
 +                                                                                     __NewTopXMLNS,
 +                                                                                     'encode_privacy_item_$message'(Message,
 +                                                                                                                    __NewTopXMLNS,
 +                                                                                                                    'encode_privacy_item_$presence_in'(Presence_in,
 +                                                                                                                                                       __NewTopXMLNS,
 +                                                                                                                                                       []))))),
 +    _attrs = encode_privacy_item_attr_value(Value,
 +                                          encode_privacy_item_attr_type(Type,
 +                                                                        encode_privacy_item_attr_order(Order,
 +                                                                                                       encode_privacy_item_attr_action(Action,
 +                                                                                                                                       enc_xmlns_attrs(__NewTopXMLNS,
 +                                                                                                                                                       __TopXMLNS))))),
 +    {xmlel, <<"item">>, _attrs, _els}.
 +
 +'encode_privacy_item_$iq'(false, __TopXMLNS, _acc) ->
 +    _acc;
 +'encode_privacy_item_$iq'(Iq, __TopXMLNS, _acc) ->
 +    [encode_privacy_iq(Iq, __TopXMLNS) | _acc].
 +
 +'encode_privacy_item_$presence_out'(false, __TopXMLNS,
 +                                  _acc) ->
 +    _acc;
 +'encode_privacy_item_$presence_out'(Presence_out,
 +                                  __TopXMLNS, _acc) ->
 +    [encode_privacy_presence_out(Presence_out, __TopXMLNS)
 +     | _acc].
 +
 +'encode_privacy_item_$message'(false, __TopXMLNS,
 +                             _acc) ->
 +    _acc;
 +'encode_privacy_item_$message'(Message, __TopXMLNS,
 +                             _acc) ->
 +    [encode_privacy_message(Message, __TopXMLNS) | _acc].
 +
 +'encode_privacy_item_$presence_in'(false, __TopXMLNS,
 +                                 _acc) ->
 +    _acc;
 +'encode_privacy_item_$presence_in'(Presence_in,
 +                                 __TopXMLNS, _acc) ->
 +    [encode_privacy_presence_in(Presence_in, __TopXMLNS)
 +     | _acc].
 +
 +decode_privacy_item_attr_action(__TopXMLNS,
 +                              undefined) ->
 +    erlang:error({xmpp_codec,
 +                {missing_attr, <<"action">>, <<"item">>, __TopXMLNS}});
 +decode_privacy_item_attr_action(__TopXMLNS, _val) ->
 +    case catch dec_enum(_val, [allow, deny]) of
 +      {'EXIT', _} ->
 +        erlang:error({xmpp_codec,
 +                      {bad_attr_value, <<"action">>, <<"item">>,
 +                       __TopXMLNS}});
 +      _res -> _res
 +    end.
 +
 +encode_privacy_item_attr_action(_val, _acc) ->
 +    [{<<"action">>, enc_enum(_val)} | _acc].
 +
 +decode_privacy_item_attr_order(__TopXMLNS, undefined) ->
 +    erlang:error({xmpp_codec,
 +                {missing_attr, <<"order">>, <<"item">>, __TopXMLNS}});
 +decode_privacy_item_attr_order(__TopXMLNS, _val) ->
 +    case catch dec_int(_val, 0, infinity) of
 +      {'EXIT', _} ->
 +        erlang:error({xmpp_codec,
 +                      {bad_attr_value, <<"order">>, <<"item">>, __TopXMLNS}});
 +      _res -> _res
 +    end.
 +
 +encode_privacy_item_attr_order(_val, _acc) ->
 +    [{<<"order">>, enc_int(_val)} | _acc].
 +
 +decode_privacy_item_attr_type(__TopXMLNS, undefined) ->
 +    undefined;
 +decode_privacy_item_attr_type(__TopXMLNS, _val) ->
 +    case catch dec_enum(_val, [group, jid, subscription]) of
 +      {'EXIT', _} ->
 +        erlang:error({xmpp_codec,
 +                      {bad_attr_value, <<"type">>, <<"item">>, __TopXMLNS}});
 +      _res -> _res
 +    end.
 +
 +encode_privacy_item_attr_type(undefined, _acc) -> _acc;
 +encode_privacy_item_attr_type(_val, _acc) ->
 +    [{<<"type">>, enc_enum(_val)} | _acc].
 +
 +decode_privacy_item_attr_value(__TopXMLNS, undefined) ->
 +    <<>>;
 +decode_privacy_item_attr_value(__TopXMLNS, _val) ->
 +    _val.
 +
 +encode_privacy_item_attr_value(<<>>, _acc) -> _acc;
 +encode_privacy_item_attr_value(_val, _acc) ->
 +    [{<<"value">>, _val} | _acc].
 +
 +decode_privacy_presence_out(__TopXMLNS, __IgnoreEls,
 +                          {xmlel, <<"presence-out">>, _attrs, _els}) ->
 +    true.
 +
 +encode_privacy_presence_out(true, __TopXMLNS) ->
 +    __NewTopXMLNS =
 +      choose_top_xmlns(<<"jabber:iq:privacy">>, [],
 +                       __TopXMLNS),
 +    _els = [],
 +    _attrs = enc_xmlns_attrs(__NewTopXMLNS, __TopXMLNS),
 +    {xmlel, <<"presence-out">>, _attrs, _els}.
 +
 +decode_privacy_presence_in(__TopXMLNS, __IgnoreEls,
 +                         {xmlel, <<"presence-in">>, _attrs, _els}) ->
 +    true.
 +
 +encode_privacy_presence_in(true, __TopXMLNS) ->
 +    __NewTopXMLNS =
 +      choose_top_xmlns(<<"jabber:iq:privacy">>, [],
 +                       __TopXMLNS),
 +    _els = [],
 +    _attrs = enc_xmlns_attrs(__NewTopXMLNS, __TopXMLNS),
 +    {xmlel, <<"presence-in">>, _attrs, _els}.
 +
 +decode_privacy_iq(__TopXMLNS, __IgnoreEls,
 +                {xmlel, <<"iq">>, _attrs, _els}) ->
 +    true.
 +
 +encode_privacy_iq(true, __TopXMLNS) ->
 +    __NewTopXMLNS =
 +      choose_top_xmlns(<<"jabber:iq:privacy">>, [],
 +                       __TopXMLNS),
 +    _els = [],
 +    _attrs = enc_xmlns_attrs(__NewTopXMLNS, __TopXMLNS),
 +    {xmlel, <<"iq">>, _attrs, _els}.
 +
 +decode_privacy_message(__TopXMLNS, __IgnoreEls,
 +                     {xmlel, <<"message">>, _attrs, _els}) ->
 +    true.
 +
 +encode_privacy_message(true, __TopXMLNS) ->
 +    __NewTopXMLNS =
 +      choose_top_xmlns(<<"jabber:iq:privacy">>, [],
 +                       __TopXMLNS),
 +    _els = [],
 +    _attrs = enc_xmlns_attrs(__NewTopXMLNS, __TopXMLNS),
 +    {xmlel, <<"message">>, _attrs, _els}.
 +
 +decode_rosterver_feature(__TopXMLNS, __IgnoreEls,
 +                       {xmlel, <<"ver">>, _attrs, _els}) ->
 +    {rosterver_feature}.
 +
 +encode_rosterver_feature({rosterver_feature},
 +                       __TopXMLNS) ->
 +    __NewTopXMLNS =
 +      choose_top_xmlns(<<"urn:xmpp:features:rosterver">>, [],
 +                       __TopXMLNS),
 +    _els = [],
 +    _attrs = enc_xmlns_attrs(__NewTopXMLNS, __TopXMLNS),
 +    {xmlel, <<"ver">>, _attrs, _els}.
 +
 +decode_roster_query(__TopXMLNS, __IgnoreEls,
 +                  {xmlel, <<"query">>, _attrs, _els}) ->
 +    Items = decode_roster_query_els(__TopXMLNS, __IgnoreEls,
 +                                  _els, []),
 +    Ver = decode_roster_query_attrs(__TopXMLNS, _attrs,
 +                                  undefined),
 +    {roster_query, Items, Ver}.
 +
 +decode_roster_query_els(__TopXMLNS, __IgnoreEls, [],
 +                      Items) ->
 +    lists:reverse(Items);
 +decode_roster_query_els(__TopXMLNS, __IgnoreEls,
 +                      [{xmlel, <<"item">>, _attrs, _} = _el | _els], Items) ->
 +    case get_attr(<<"xmlns">>, _attrs) of
 +      <<"">> when __TopXMLNS == <<"jabber:iq:roster">> ->
 +        decode_roster_query_els(__TopXMLNS, __IgnoreEls, _els,
 +                                [decode_roster_item(__TopXMLNS, __IgnoreEls,
 +                                                    _el)
 +                                 | Items]);
 +      <<"jabber:iq:roster">> ->
 +        decode_roster_query_els(__TopXMLNS, __IgnoreEls, _els,
 +                                [decode_roster_item(<<"jabber:iq:roster">>,
 +                                                    __IgnoreEls, _el)
 +                                 | Items]);
 +      _ ->
 +        decode_roster_query_els(__TopXMLNS, __IgnoreEls, _els,
 +                                Items)
 +    end;
 +decode_roster_query_els(__TopXMLNS, __IgnoreEls,
 +                      [_ | _els], Items) ->
 +    decode_roster_query_els(__TopXMLNS, __IgnoreEls, _els,
 +                          Items).
 +
 +decode_roster_query_attrs(__TopXMLNS,
 +                        [{<<"ver">>, _val} | _attrs], _Ver) ->
 +    decode_roster_query_attrs(__TopXMLNS, _attrs, _val);
 +decode_roster_query_attrs(__TopXMLNS, [_ | _attrs],
 +                        Ver) ->
 +    decode_roster_query_attrs(__TopXMLNS, _attrs, Ver);
 +decode_roster_query_attrs(__TopXMLNS, [], Ver) ->
 +    decode_roster_query_attr_ver(__TopXMLNS, Ver).
 +
 +encode_roster_query({roster_query, Items, Ver},
 +                  __TopXMLNS) ->
 +    __NewTopXMLNS = choose_top_xmlns(<<"jabber:iq:roster">>,
 +                                   [], __TopXMLNS),
 +    _els = lists:reverse('encode_roster_query_$items'(Items,
 +                                                    __NewTopXMLNS, [])),
 +    _attrs = encode_roster_query_attr_ver(Ver,
 +                                        enc_xmlns_attrs(__NewTopXMLNS,
 +                                                        __TopXMLNS)),
 +    {xmlel, <<"query">>, _attrs, _els}.
 +
 +'encode_roster_query_$items'([], __TopXMLNS, _acc) ->
 +    _acc;
 +'encode_roster_query_$items'([Items | _els], __TopXMLNS,
 +                           _acc) ->
 +    'encode_roster_query_$items'(_els, __TopXMLNS,
 +                               [encode_roster_item(Items, __TopXMLNS)
 +                                | _acc]).
 +
 +decode_roster_query_attr_ver(__TopXMLNS, undefined) ->
 +    undefined;
 +decode_roster_query_attr_ver(__TopXMLNS, _val) -> _val.
 +
 +encode_roster_query_attr_ver(undefined, _acc) -> _acc;
 +encode_roster_query_attr_ver(_val, _acc) ->
 +    [{<<"ver">>, _val} | _acc].
 +
 +decode_roster_item(__TopXMLNS, __IgnoreEls,
 +                 {xmlel, <<"item">>, _attrs, _els}) ->
 +    Groups = decode_roster_item_els(__TopXMLNS, __IgnoreEls,
 +                                  _els, []),
 +    {Jid, Name, Subscription, Ask} =
 +      decode_roster_item_attrs(__TopXMLNS, _attrs, undefined,
 +                               undefined, undefined, undefined),
 +    {roster_item, Jid, Name, Groups, Subscription, Ask}.
 +
 +decode_roster_item_els(__TopXMLNS, __IgnoreEls, [],
 +                     Groups) ->
 +    lists:reverse(Groups);
 +decode_roster_item_els(__TopXMLNS, __IgnoreEls,
 +                     [{xmlel, <<"group">>, _attrs, _} = _el | _els],
 +                     Groups) ->
 +    case get_attr(<<"xmlns">>, _attrs) of
 +      <<"">> when __TopXMLNS == <<"jabber:iq:roster">> ->
 +        decode_roster_item_els(__TopXMLNS, __IgnoreEls, _els,
 +                               [decode_roster_group(__TopXMLNS, __IgnoreEls,
 +                                                    _el)
 +                                | Groups]);
 +      <<"jabber:iq:roster">> ->
 +        decode_roster_item_els(__TopXMLNS, __IgnoreEls, _els,
 +                               [decode_roster_group(<<"jabber:iq:roster">>,
 +                                                    __IgnoreEls, _el)
 +                                | Groups]);
 +      _ ->
 +        decode_roster_item_els(__TopXMLNS, __IgnoreEls, _els,
 +                               Groups)
 +    end;
 +decode_roster_item_els(__TopXMLNS, __IgnoreEls,
 +                     [_ | _els], Groups) ->
 +    decode_roster_item_els(__TopXMLNS, __IgnoreEls, _els,
 +                         Groups).
 +
 +decode_roster_item_attrs(__TopXMLNS,
 +                       [{<<"jid">>, _val} | _attrs], _Jid, Name, Subscription,
 +                       Ask) ->
 +    decode_roster_item_attrs(__TopXMLNS, _attrs, _val, Name,
 +                           Subscription, Ask);
 +decode_roster_item_attrs(__TopXMLNS,
 +                       [{<<"name">>, _val} | _attrs], Jid, _Name,
 +                       Subscription, Ask) ->
 +    decode_roster_item_attrs(__TopXMLNS, _attrs, Jid, _val,
 +                           Subscription, Ask);
 +decode_roster_item_attrs(__TopXMLNS,
 +                       [{<<"subscription">>, _val} | _attrs], Jid, Name,
 +                       _Subscription, Ask) ->
 +    decode_roster_item_attrs(__TopXMLNS, _attrs, Jid, Name,
 +                           _val, Ask);
 +decode_roster_item_attrs(__TopXMLNS,
 +                       [{<<"ask">>, _val} | _attrs], Jid, Name, Subscription,
 +                       _Ask) ->
 +    decode_roster_item_attrs(__TopXMLNS, _attrs, Jid, Name,
 +                           Subscription, _val);
 +decode_roster_item_attrs(__TopXMLNS, [_ | _attrs], Jid,
 +                       Name, Subscription, Ask) ->
 +    decode_roster_item_attrs(__TopXMLNS, _attrs, Jid, Name,
 +                           Subscription, Ask);
 +decode_roster_item_attrs(__TopXMLNS, [], Jid, Name,
 +                       Subscription, Ask) ->
 +    {decode_roster_item_attr_jid(__TopXMLNS, Jid),
 +     decode_roster_item_attr_name(__TopXMLNS, Name),
 +     decode_roster_item_attr_subscription(__TopXMLNS,
 +                                        Subscription),
 +     decode_roster_item_attr_ask(__TopXMLNS, Ask)}.
 +
 +encode_roster_item({roster_item, Jid, Name, Groups,
 +                  Subscription, Ask},
 +                 __TopXMLNS) ->
 +    __NewTopXMLNS = choose_top_xmlns(<<"jabber:iq:roster">>,
 +                                   [], __TopXMLNS),
 +    _els =
 +      lists:reverse('encode_roster_item_$groups'(Groups,
 +                                                 __NewTopXMLNS, [])),
 +    _attrs = encode_roster_item_attr_ask(Ask,
 +                                       encode_roster_item_attr_subscription(Subscription,
 +                                                                            encode_roster_item_attr_name(Name,
 +                                                                                                         encode_roster_item_attr_jid(Jid,
 +                                                                                                                                     enc_xmlns_attrs(__NewTopXMLNS,
 +                                                                                                                                                     __TopXMLNS))))),
 +    {xmlel, <<"item">>, _attrs, _els}.
 +
 +'encode_roster_item_$groups'([], __TopXMLNS, _acc) ->
 +    _acc;
 +'encode_roster_item_$groups'([Groups | _els],
 +                           __TopXMLNS, _acc) ->
 +    'encode_roster_item_$groups'(_els, __TopXMLNS,
 +                               [encode_roster_group(Groups, __TopXMLNS)
 +                                | _acc]).
 +
 +decode_roster_item_attr_jid(__TopXMLNS, undefined) ->
 +    erlang:error({xmpp_codec,
 +                {missing_attr, <<"jid">>, <<"item">>, __TopXMLNS}});
 +decode_roster_item_attr_jid(__TopXMLNS, _val) ->
 +    case catch dec_jid(_val) of
 +      {'EXIT', _} ->
 +        erlang:error({xmpp_codec,
 +                      {bad_attr_value, <<"jid">>, <<"item">>, __TopXMLNS}});
 +      _res -> _res
 +    end.
 +
 +encode_roster_item_attr_jid(_val, _acc) ->
 +    [{<<"jid">>, enc_jid(_val)} | _acc].
 +
 +decode_roster_item_attr_name(__TopXMLNS, undefined) ->
 +    <<>>;
 +decode_roster_item_attr_name(__TopXMLNS, _val) -> _val.
 +
 +encode_roster_item_attr_name(<<>>, _acc) -> _acc;
 +encode_roster_item_attr_name(_val, _acc) ->
 +    [{<<"name">>, _val} | _acc].
 +
 +decode_roster_item_attr_subscription(__TopXMLNS,
 +                                   undefined) ->
 +    none;
 +decode_roster_item_attr_subscription(__TopXMLNS,
 +                                   _val) ->
 +    case catch dec_enum(_val,
 +                      [none, to, from, both, remove])
 +      of
 +      {'EXIT', _} ->
 +        erlang:error({xmpp_codec,
 +                      {bad_attr_value, <<"subscription">>, <<"item">>,
 +                       __TopXMLNS}});
 +      _res -> _res
 +    end.
 +
 +encode_roster_item_attr_subscription(none, _acc) ->
 +    _acc;
 +encode_roster_item_attr_subscription(_val, _acc) ->
 +    [{<<"subscription">>, enc_enum(_val)} | _acc].
 +
 +decode_roster_item_attr_ask(__TopXMLNS, undefined) ->
 +    undefined;
 +decode_roster_item_attr_ask(__TopXMLNS, _val) ->
 +    case catch dec_enum(_val, [subscribe]) of
 +      {'EXIT', _} ->
 +        erlang:error({xmpp_codec,
 +                      {bad_attr_value, <<"ask">>, <<"item">>, __TopXMLNS}});
 +      _res -> _res
 +    end.
 +
 +encode_roster_item_attr_ask(undefined, _acc) -> _acc;
 +encode_roster_item_attr_ask(_val, _acc) ->
 +    [{<<"ask">>, enc_enum(_val)} | _acc].
 +
 +decode_roster_group(__TopXMLNS, __IgnoreEls,
 +                  {xmlel, <<"group">>, _attrs, _els}) ->
 +    Cdata = decode_roster_group_els(__TopXMLNS, __IgnoreEls,
 +                                  _els, <<>>),
 +    Cdata.
 +
 +decode_roster_group_els(__TopXMLNS, __IgnoreEls, [],
 +                      Cdata) ->
 +    decode_roster_group_cdata(__TopXMLNS, Cdata);
 +decode_roster_group_els(__TopXMLNS, __IgnoreEls,
 +                      [{xmlcdata, _data} | _els], Cdata) ->
 +    decode_roster_group_els(__TopXMLNS, __IgnoreEls, _els,
 +                          <<Cdata/binary, _data/binary>>);
 +decode_roster_group_els(__TopXMLNS, __IgnoreEls,
 +                      [_ | _els], Cdata) ->
 +    decode_roster_group_els(__TopXMLNS, __IgnoreEls, _els,
 +                          Cdata).
 +
 +encode_roster_group(Cdata, __TopXMLNS) ->
 +    __NewTopXMLNS = choose_top_xmlns(<<"jabber:iq:roster">>,
 +                                   [], __TopXMLNS),
 +    _els = encode_roster_group_cdata(Cdata, []),
 +    _attrs = enc_xmlns_attrs(__NewTopXMLNS, __TopXMLNS),
 +    {xmlel, <<"group">>, _attrs, _els}.
 +
 +decode_roster_group_cdata(__TopXMLNS, <<>>) ->
 +    erlang:error({xmpp_codec,
 +                {missing_cdata, <<>>, <<"group">>, __TopXMLNS}});
 +decode_roster_group_cdata(__TopXMLNS, _val) -> _val.
 +
 +encode_roster_group_cdata(_val, _acc) ->
 +    [{xmlcdata, _val} | _acc].
 +
 +decode_version(__TopXMLNS, __IgnoreEls,
 +             {xmlel, <<"query">>, _attrs, _els}) ->
 +    {Ver, Os, Name} = decode_version_els(__TopXMLNS,
 +                                       __IgnoreEls, _els, undefined,
 +                                       undefined, undefined),
 +    {version, Name, Ver, Os}.
 +
 +decode_version_els(__TopXMLNS, __IgnoreEls, [], Ver, Os,
 +                 Name) ->
 +    {Ver, Os, Name};
 +decode_version_els(__TopXMLNS, __IgnoreEls,
 +                 [{xmlel, <<"name">>, _attrs, _} = _el | _els], Ver, Os,
 +                 Name) ->
 +    case get_attr(<<"xmlns">>, _attrs) of
 +      <<"">> when __TopXMLNS == <<"jabber:iq:version">> ->
 +        decode_version_els(__TopXMLNS, __IgnoreEls, _els, Ver,
 +                           Os,
 +                           decode_version_name(__TopXMLNS, __IgnoreEls, _el));
 +      <<"jabber:iq:version">> ->
 +        decode_version_els(__TopXMLNS, __IgnoreEls, _els, Ver,
 +                           Os,
 +                           decode_version_name(<<"jabber:iq:version">>,
 +                                               __IgnoreEls, _el));
 +      _ ->
 +        decode_version_els(__TopXMLNS, __IgnoreEls, _els, Ver,
 +                           Os, Name)
 +    end;
 +decode_version_els(__TopXMLNS, __IgnoreEls,
 +                 [{xmlel, <<"version">>, _attrs, _} = _el | _els], Ver,
 +                 Os, Name) ->
 +    case get_attr(<<"xmlns">>, _attrs) of
 +      <<"">> when __TopXMLNS == <<"jabber:iq:version">> ->
 +        decode_version_els(__TopXMLNS, __IgnoreEls, _els,
 +                           decode_version_ver(__TopXMLNS, __IgnoreEls, _el),
 +                           Os, Name);
 +      <<"jabber:iq:version">> ->
 +        decode_version_els(__TopXMLNS, __IgnoreEls, _els,
 +                           decode_version_ver(<<"jabber:iq:version">>,
 +                                              __IgnoreEls, _el),
 +                           Os, Name);
 +      _ ->
 +        decode_version_els(__TopXMLNS, __IgnoreEls, _els, Ver,
 +                           Os, Name)
 +    end;
 +decode_version_els(__TopXMLNS, __IgnoreEls,
 +                 [{xmlel, <<"os">>, _attrs, _} = _el | _els], Ver, Os,
 +                 Name) ->
 +    case get_attr(<<"xmlns">>, _attrs) of
 +      <<"">> when __TopXMLNS == <<"jabber:iq:version">> ->
 +        decode_version_els(__TopXMLNS, __IgnoreEls, _els, Ver,
 +                           decode_version_os(__TopXMLNS, __IgnoreEls, _el),
 +                           Name);
 +      <<"jabber:iq:version">> ->
 +        decode_version_els(__TopXMLNS, __IgnoreEls, _els, Ver,
 +                           decode_version_os(<<"jabber:iq:version">>,
 +                                             __IgnoreEls, _el),
 +                           Name);
 +      _ ->
 +        decode_version_els(__TopXMLNS, __IgnoreEls, _els, Ver,
 +                           Os, Name)
 +    end;
 +decode_version_els(__TopXMLNS, __IgnoreEls, [_ | _els],
 +                 Ver, Os, Name) ->
 +    decode_version_els(__TopXMLNS, __IgnoreEls, _els, Ver,
 +                     Os, Name).
 +
 +encode_version({version, Name, Ver, Os}, __TopXMLNS) ->
 +    __NewTopXMLNS =
 +      choose_top_xmlns(<<"jabber:iq:version">>, [],
 +                       __TopXMLNS),
 +    _els = lists:reverse('encode_version_$ver'(Ver,
 +                                             __NewTopXMLNS,
 +                                             'encode_version_$os'(Os,
 +                                                                  __NewTopXMLNS,
 +                                                                  'encode_version_$name'(Name,
 +                                                                                         __NewTopXMLNS,
 +                                                                                         [])))),
 +    _attrs = enc_xmlns_attrs(__NewTopXMLNS, __TopXMLNS),
 +    {xmlel, <<"query">>, _attrs, _els}.
 +
 +'encode_version_$ver'(undefined, __TopXMLNS, _acc) ->
 +    _acc;
 +'encode_version_$ver'(Ver, __TopXMLNS, _acc) ->
 +    [encode_version_ver(Ver, __TopXMLNS) | _acc].
 +
 +'encode_version_$os'(undefined, __TopXMLNS, _acc) ->
 +    _acc;
 +'encode_version_$os'(Os, __TopXMLNS, _acc) ->
 +    [encode_version_os(Os, __TopXMLNS) | _acc].
 +
 +'encode_version_$name'(undefined, __TopXMLNS, _acc) ->
 +    _acc;
 +'encode_version_$name'(Name, __TopXMLNS, _acc) ->
 +    [encode_version_name(Name, __TopXMLNS) | _acc].
 +
 +decode_version_os(__TopXMLNS, __IgnoreEls,
 +                {xmlel, <<"os">>, _attrs, _els}) ->
 +    Cdata = decode_version_os_els(__TopXMLNS, __IgnoreEls,
 +                                _els, <<>>),
 +    Cdata.
 +
 +decode_version_os_els(__TopXMLNS, __IgnoreEls, [],
 +                    Cdata) ->
 +    decode_version_os_cdata(__TopXMLNS, Cdata);
 +decode_version_os_els(__TopXMLNS, __IgnoreEls,
 +                    [{xmlcdata, _data} | _els], Cdata) ->
 +    decode_version_os_els(__TopXMLNS, __IgnoreEls, _els,
 +                        <<Cdata/binary, _data/binary>>);
 +decode_version_os_els(__TopXMLNS, __IgnoreEls,
 +                    [_ | _els], Cdata) ->
 +    decode_version_os_els(__TopXMLNS, __IgnoreEls, _els,
 +                        Cdata).
 +
 +encode_version_os(Cdata, __TopXMLNS) ->
 +    __NewTopXMLNS =
 +      choose_top_xmlns(<<"jabber:iq:version">>, [],
 +                       __TopXMLNS),
 +    _els = encode_version_os_cdata(Cdata, []),
 +    _attrs = enc_xmlns_attrs(__NewTopXMLNS, __TopXMLNS),
 +    {xmlel, <<"os">>, _attrs, _els}.
 +
 +decode_version_os_cdata(__TopXMLNS, <<>>) ->
 +    erlang:error({xmpp_codec,
 +                {missing_cdata, <<>>, <<"os">>, __TopXMLNS}});
 +decode_version_os_cdata(__TopXMLNS, _val) -> _val.
 +
 +encode_version_os_cdata(_val, _acc) ->
 +    [{xmlcdata, _val} | _acc].
 +
 +decode_version_ver(__TopXMLNS, __IgnoreEls,
 +                 {xmlel, <<"version">>, _attrs, _els}) ->
 +    Cdata = decode_version_ver_els(__TopXMLNS, __IgnoreEls,
 +                                 _els, <<>>),
 +    Cdata.
 +
 +decode_version_ver_els(__TopXMLNS, __IgnoreEls, [],
 +                     Cdata) ->
 +    decode_version_ver_cdata(__TopXMLNS, Cdata);
 +decode_version_ver_els(__TopXMLNS, __IgnoreEls,
 +                     [{xmlcdata, _data} | _els], Cdata) ->
 +    decode_version_ver_els(__TopXMLNS, __IgnoreEls, _els,
 +                         <<Cdata/binary, _data/binary>>);
 +decode_version_ver_els(__TopXMLNS, __IgnoreEls,
 +                     [_ | _els], Cdata) ->
 +    decode_version_ver_els(__TopXMLNS, __IgnoreEls, _els,
 +                         Cdata).
 +
 +encode_version_ver(Cdata, __TopXMLNS) ->
 +    __NewTopXMLNS =
 +      choose_top_xmlns(<<"jabber:iq:version">>, [],
 +                       __TopXMLNS),
 +    _els = encode_version_ver_cdata(Cdata, []),
 +    _attrs = enc_xmlns_attrs(__NewTopXMLNS, __TopXMLNS),
 +    {xmlel, <<"version">>, _attrs, _els}.
 +
 +decode_version_ver_cdata(__TopXMLNS, <<>>) ->
 +    erlang:error({xmpp_codec,
 +                {missing_cdata, <<>>, <<"version">>, __TopXMLNS}});
 +decode_version_ver_cdata(__TopXMLNS, _val) -> _val.
 +
 +encode_version_ver_cdata(_val, _acc) ->
 +    [{xmlcdata, _val} | _acc].
 +
 +decode_version_name(__TopXMLNS, __IgnoreEls,
 +                  {xmlel, <<"name">>, _attrs, _els}) ->
 +    Cdata = decode_version_name_els(__TopXMLNS, __IgnoreEls,
 +                                  _els, <<>>),
 +    Cdata.
 +
 +decode_version_name_els(__TopXMLNS, __IgnoreEls, [],
 +                      Cdata) ->
 +    decode_version_name_cdata(__TopXMLNS, Cdata);
 +decode_version_name_els(__TopXMLNS, __IgnoreEls,
 +                      [{xmlcdata, _data} | _els], Cdata) ->
 +    decode_version_name_els(__TopXMLNS, __IgnoreEls, _els,
 +                          <<Cdata/binary, _data/binary>>);
 +decode_version_name_els(__TopXMLNS, __IgnoreEls,
 +                      [_ | _els], Cdata) ->
 +    decode_version_name_els(__TopXMLNS, __IgnoreEls, _els,
 +                          Cdata).
 +
 +encode_version_name(Cdata, __TopXMLNS) ->
 +    __NewTopXMLNS =
 +      choose_top_xmlns(<<"jabber:iq:version">>, [],
 +                       __TopXMLNS),
 +    _els = encode_version_name_cdata(Cdata, []),
 +    _attrs = enc_xmlns_attrs(__NewTopXMLNS, __TopXMLNS),
 +    {xmlel, <<"name">>, _attrs, _els}.
 +
 +decode_version_name_cdata(__TopXMLNS, <<>>) ->
 +    erlang:error({xmpp_codec,
 +                {missing_cdata, <<>>, <<"name">>, __TopXMLNS}});
 +decode_version_name_cdata(__TopXMLNS, _val) -> _val.
 +
 +encode_version_name_cdata(_val, _acc) ->
 +    [{xmlcdata, _val} | _acc].
 +
 +decode_last(__TopXMLNS, __IgnoreEls,
 +          {xmlel, <<"query">>, _attrs, _els}) ->
 +    Status = decode_last_els(__TopXMLNS, __IgnoreEls, _els,
 +                           <<>>),
 +    Seconds = decode_last_attrs(__TopXMLNS, _attrs,
 +                              undefined),
 +    {last, Seconds, Status}.
 +
 +decode_last_els(__TopXMLNS, __IgnoreEls, [], Status) ->
 +    decode_last_cdata(__TopXMLNS, Status);
 +decode_last_els(__TopXMLNS, __IgnoreEls,
 +              [{xmlcdata, _data} | _els], Status) ->
 +    decode_last_els(__TopXMLNS, __IgnoreEls, _els,
 +                  <<Status/binary, _data/binary>>);
 +decode_last_els(__TopXMLNS, __IgnoreEls, [_ | _els],
 +              Status) ->
 +    decode_last_els(__TopXMLNS, __IgnoreEls, _els, Status).
 +
 +decode_last_attrs(__TopXMLNS,
 +                [{<<"seconds">>, _val} | _attrs], _Seconds) ->
 +    decode_last_attrs(__TopXMLNS, _attrs, _val);
 +decode_last_attrs(__TopXMLNS, [_ | _attrs], Seconds) ->
 +    decode_last_attrs(__TopXMLNS, _attrs, Seconds);
 +decode_last_attrs(__TopXMLNS, [], Seconds) ->
 +    decode_last_attr_seconds(__TopXMLNS, Seconds).
 +
 +encode_last({last, Seconds, Status}, __TopXMLNS) ->
 +    __NewTopXMLNS = choose_top_xmlns(<<"jabber:iq:last">>,
 +                                   [], __TopXMLNS),
 +    _els = encode_last_cdata(Status, []),
 +    _attrs = encode_last_attr_seconds(Seconds,
 +                                    enc_xmlns_attrs(__NewTopXMLNS,
 +                                                    __TopXMLNS)),
 +    {xmlel, <<"query">>, _attrs, _els}.
 +
 +decode_last_attr_seconds(__TopXMLNS, undefined) ->
 +    undefined;
 +decode_last_attr_seconds(__TopXMLNS, _val) ->
 +    case catch dec_int(_val, 0, infinity) of
 +      {'EXIT', _} ->
 +        erlang:error({xmpp_codec,
 +                      {bad_attr_value, <<"seconds">>, <<"query">>,
 +                       __TopXMLNS}});
 +      _res -> _res
 +    end.
 +
 +encode_last_attr_seconds(undefined, _acc) -> _acc;
 +encode_last_attr_seconds(_val, _acc) ->
 +    [{<<"seconds">>, enc_int(_val)} | _acc].
 +
 +decode_last_cdata(__TopXMLNS, <<>>) -> <<>>;
 +decode_last_cdata(__TopXMLNS, _val) -> _val.
 +
 +encode_last_cdata(<<>>, _acc) -> _acc;
 +encode_last_cdata(_val, _acc) ->
 +    [{xmlcdata, _val} | _acc].
index fb3bbc7ab41dfa12d2d5ea8e481c090f6b2ab4c2,0000000000000000000000000000000000000000..7b3e0e892e0ff1a9b29da586ec381301613412a3
mode 100644,000000..100644
--- /dev/null
@@@ -1,161 -1,0 +1,169 @@@
-     Command#adhoc_command{lang = Lang, node = Node, sid = SID}.
 +%%%-------------------------------------------------------------------
 +%%% @author Evgeny Khramtsov <ekhramtsov@process-one.net>
 +%%% @copyright (C) 2016, Evgeny Khramtsov
 +%%% @doc
 +%%%
 +%%% @end
 +%%% Created : 12 Jul 2016 by Evgeny Khramtsov <ekhramtsov@process-one.net>
 +%%%-------------------------------------------------------------------
 +-module(xmpp_util).
 +
 +%% API
 +-export([add_delay_info/3, add_delay_info/4, unwrap_carbon/1,
 +       is_standalone_chat_state/1, get_xdata_values/2,
 +       has_xdata_var/2, make_adhoc_response/1, make_adhoc_response/2,
 +       decode_timestamp/1, encode_timestamp/1]).
 +
 +-include("xmpp.hrl").
 +
 +%%%===================================================================
 +%%% API
 +%%%===================================================================
 +-spec add_delay_info(stanza(), jid(), erlang:timestamp()) -> stanza().
 +add_delay_info(Stz, From, Time) ->
 +    add_delay_info(Stz, From, Time, <<"">>).
 +
 +-spec add_delay_info(stanza(), jid(),
 +                   erlang:timestamp(), binary()) -> stanza().
 +
 +add_delay_info(Stz, From, Time, Desc) ->
 +    case xmpp:get_subtag(Stz, #delay{}) of
 +      #delay{from = OldFrom, desc = OldDesc} = Delay ->
 +          case jid:tolower(From) == jid:tolower(OldFrom) of
 +              true when Desc == <<"">> ->
 +                  Stz;
 +              true when OldDesc == <<"">> ->
 +                  xmpp:set_subtag(Stz, Delay#delay{desc = Desc});
 +              true ->
 +                  case binary:match(OldDesc, Desc) of
 +                      nomatch ->
 +                          NewDesc = <<OldDesc/binary, ", ", Desc/binary>>,
 +                          xmpp:set_subtag(Stz, Delay#delay{desc = NewDesc});
 +                      _ ->
 +                          Stz
 +                  end;
 +              false ->
 +                  NewDelay = #delay{stamp = Time, from = From, desc = Desc},
 +                  xmpp:set_subtag(Stz, NewDelay)
 +          end;
 +      false ->
 +          Delay = #delay{stamp = Time, from = From, desc = Desc},
 +          xmpp:set_subtag(Stz, Delay)
 +    end.
 +
 +-spec unwrap_carbon(stanza()) -> xmpp_element().
 +unwrap_carbon(#message{} = Msg) ->
 +    case xmpp:get_subtag(Msg, #carbons_sent{}) of
 +      #carbons_sent{forwarded = #forwarded{sub_els = [El]}} ->
 +          El;
 +      _ ->
 +          case xmpp:get_subtag(Msg, #carbons_received{}) of
 +              #carbons_received{forwarded = #forwarded{sub_els = [El]}} ->
 +                  El;
 +              _ ->
 +                  Msg
 +          end
 +    end;
 +unwrap_carbon(Stanza) -> Stanza.
 +
 +-spec is_standalone_chat_state(stanza()) -> boolean().
 +is_standalone_chat_state(Stanza) ->
 +    case unwrap_carbon(Stanza) of
 +      #message{body = [], subject = [], sub_els = Els} ->
 +          IgnoreNS = [?NS_CHATSTATES, ?NS_DELAY, ?NS_EVENT],
 +          Stripped = [El || El <- Els,
 +                            not lists:member(xmpp:get_ns(El), IgnoreNS)],
 +          Stripped == [];
 +      _ ->
 +          false
 +    end.
 +
 +-spec get_xdata_values(binary(), xdata()) -> [binary()].
 +get_xdata_values(Var, #xdata{fields = Fields}) ->
 +    case lists:keyfind(Var, #xdata_field.var, Fields) of
 +      #xdata_field{values = Vals} -> Vals;
 +      false -> []
 +    end.
 +
 +-spec has_xdata_var(binary(), xdata()) -> boolean().
 +has_xdata_var(Var, #xdata{fields = Fields}) ->
 +    lists:keymember(Var, #xdata_field.var, Fields).
 +
 +-spec make_adhoc_response(adhoc_command(), adhoc_command()) -> adhoc_command().
 +make_adhoc_response(#adhoc_command{lang = Lang, node = Node, sid = SID},
 +                  Command) ->
- make_adhoc_response(#adhoc_command{sid = <<"">>} = Command) ->
++    make_adhoc_response(
++      Command#adhoc_command{lang = Lang, node = Node, sid = SID}).
 +
 +-spec make_adhoc_response(adhoc_command()) -> adhoc_command().
-     Command#adhoc_command{sid = SID};
++make_adhoc_response(#adhoc_command{sid = <<"">>,
++                                 status = Status,
++                                 actions = Actions} = Command) ->
 +    SID = encode_timestamp(p1_time_compat:timestamp()),
++    NewActions = if Actions == undefined, Status /= completed ->
++                       #adhoc_actions{execute = complete, complete = true};
++                  true ->
++                       undefined
++               end,
++    Command#adhoc_command{sid = SID, actions = NewActions};
 +make_adhoc_response(Command) ->
 +    Command.
 +
 +-spec decode_timestamp(binary()) -> erlang:timestamp().
 +decode_timestamp(S) ->
 +    try try_decode_timestamp(S)
 +    catch _:_ -> erlang:error({bad_timestamp, S})
 +    end.
 +
 +-spec encode_timestamp(erlang:timestamp()) -> binary().
 +encode_timestamp({MegaSecs, Secs, MicroSecs}) ->
 +    {{Year, Month, Day}, {Hour, Minute, Second}} =
 +        calendar:now_to_universal_time({MegaSecs, Secs, MicroSecs}),
 +    Fraction = if MicroSecs > 0 ->
 +                     io_lib:format(".~6..0B", [MicroSecs]);
 +                true ->
 +                     ""
 +             end,
 +    list_to_binary(io_lib:format("~4..0B-~2..0B-~2..0BT"
 +                               "~2..0B:~2..0B:~2..0B~sZ",
 +                               [Year, Month, Day, Hour, Minute, Second,
 +                                Fraction])).
 +
 +%%%===================================================================
 +%%% Internal functions
 +%%%===================================================================
 +try_decode_timestamp(<<Y:4/binary, $-, Mo:2/binary, $-, D:2/binary, $T,
 +                     H:2/binary, $:, Mi:2/binary, $:, S:2/binary, T/binary>>) ->
 +    Date = {to_integer(Y, 1970, 9999), to_integer(Mo, 1, 12), to_integer(D, 1, 31)},
 +    Time = {to_integer(H, 0, 23), to_integer(Mi, 0, 59), to_integer(S, 0, 59)},
 +    {MS, {TZH, TZM}} = try_decode_fraction(T),
 +    Seconds = calendar:datetime_to_gregorian_seconds({Date, Time}) -
 +      calendar:datetime_to_gregorian_seconds({{1970,1,1}, {0,0,0}}) -
 +      TZH * 60 * 60 - TZM * 60,
 +    {Seconds div 1000000, Seconds rem 1000000, MS};
 +try_decode_timestamp(<<Y:4/binary, Mo:2/binary, D:2/binary, $T,
 +                     H:2/binary, $:, Mi:2/binary, $:, S:2/binary>>) ->
 +    try_decode_timestamp(<<Y:4/binary, $-, Mo:2/binary, $-, D:2/binary, $T,
 +                         H:2/binary, $:, Mi:2/binary, $:, S:2/binary, $Z>>).
 +
 +try_decode_fraction(<<$., T/binary>>) ->
 +    {match, [V]} = re:run(T, <<"^[0-9]+">>, [{capture, [0], binary}]),
 +    Size = size(V),
 +    <<V:Size/binary, TZD/binary>> = T,
 +    {to_integer(binary:part(V, 0, min(6, Size)), 0, 999999),
 +     try_decode_tzd(TZD)};
 +try_decode_fraction(TZD) ->
 +    {0, try_decode_tzd(TZD)}.
 +
 +try_decode_tzd(<<$Z>>) ->
 +    {0, 0};
 +try_decode_tzd(<<$-, H:2/binary, $:, M:2/binary>>) ->
 +    {-1 * to_integer(H, 0, 12), to_integer(M, 0, 59)};
 +try_decode_tzd(<<$+, H:2/binary, $:, M:2/binary>>) ->
 +    {to_integer(H, 0, 12), to_integer(M, 0, 59)}.
 +
 +to_integer(S, Min, Max) ->
 +    case binary_to_integer(S) of
 +      I when I >= Min, I =< Max ->
 +          I
 +    end.