anchor.diff:           server/1,
            resource/1]).
   
  -% spawn exports
  --export([client_loop/2]).
  -
   -define(WAIT_FOR_STANZA_TIMOUT, 1000).
   
   -include("escalus.hrl").
  
positive.code: %% helpers
  %%--------------------------------------------------------------------
  
  copy_packet_messages(TargetPid) ->
      receive
          #received_packet{} = Packet ->
              error_logger:info_msg("got packet: ~p~n", [Packet]),
              TargetPid ! Packet,
              copy_packet_messages(TargetPid)
      after 0 ->
          done
  end.
  
  regexp_get(Jid, Regex) ->
      {match, [ShortJid]} =
          re:run(Jid, Regex, [{capture, all_but_first, binary}]),
  
negative.code:     {ok, _RealJid} = exmpp_session:login(Session, AuthMethod).
  
  start(Config, UserSpec, Resource) ->
      Master = self(),
      ClientRef = make_ref(),
      ClientPid = spawn_link(fun() ->
          Session = escalus_overridables:do(Config, start_session,
                                            [Config, UserSpec, Resource],
                                            {?MODULE, start_session}),
          {ok, JID} = login(Config, Session, UserSpec),
          Master ! {logged_in, ClientRef, JID, Session},
          client_loop(ClientRef, Master)
      end),
      receive
          {logged_in, ClientRef, JID, Session} ->
              unlink(ClientPid),
              Client = #client{session=Session,
                               jid=JID#jid.raw,
                               pid=ClientPid,
                               ref=ClientRef},
              escalus_cleaner:add_client(Config, Client),
              Client
      end.
  
  start_for(Config, Username, Resource) ->
      {Username, UserSpec} = escalus_users:get_user_by_name(Username),
  