anchor.diff:           server/1,
            resource/1]).
   
  -% spawn exports
  --export([client_loop/2]).
  -
   -define(WAIT_FOR_STANZA_TIMOUT, 1000).
   
   -include("escalus.hrl").
  
positive.code:     {ok, _RealJid} = exmpp_session:login(Session, AuthMethod).
  
  start(Config, UserSpec, Resource) ->
      Session = escalus_overridables:do(Config, start_session,
                                        [Config, UserSpec, Resource],
                                        {?MODULE, start_session}),
      {ok, JID} = login(Config, Session, UserSpec),
      ClientRef = make_ref(),
      ClientPid = spawn(?MODULE, client_loop, [ClientRef, self()]),
      exmpp_session:set_controlling_process(Session, ClientPid),
      copy_packet_messages(ClientPid),
      Client = #client{session=Session,
                       jid=JID#jid.raw,
                       pid=ClientPid,
                       ref=ClientRef},
      escalus_cleaner:add_client(Config, Client),
      Client.
  
  start_for(Config, Username, Resource) ->
      {Username, UserSpec} = escalus_users:get_user_by_name(Username),
  
negative.code: %% helpers
  %%--------------------------------------------------------------------
  
  regexp_get(Jid, Regex) ->
      {match, [ShortJid]} =
          re:run(Jid, Regex, [{capture, all_but_first, binary}]),
  