anchor.diff:  handle_info({tcp, _Socket, Data}, #state{xml_stream=undefined}=State) ->
       {ok, Parser0} = exml_stream:new_parser(),
       {ok, Parser1, Xml} = exml_stream:parse(Parser0, Data),
  -    %% lager:info("Xml ~p", [Xml]),
  +    lager:info("NEW STREAM Xml ~p", [Xml]),
       parse_xml(Xml, State),
       {noreply, State#state{xml_stream = Parser1}};
   
  
positive.code:     end;
  
  parse_xml(Data, _) ->
      lager:info("RECV XML: ~n~p~n", [Data]).
  
  
  %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  %% Parse XML Packets
  %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  
  xml_packet(ping, {Name, Server}) ->
      JID = <<Name/binary, "@", Server/binary, "/erlang">>,
      <<"<iq from='", JID/binary, "' to='", Server/binary, "' id='c2s1' type='get'><ping xmlns='urn:xmpp:ping'/></iq>">>;
  
  xml_packet(stream, {Name, Server}) ->
      JID = <<Name/binary, "@", Server/binary>>,
      <<"<stream:stream xmlns='jabber:client' from='", JID/binary, "' to='", Server/binary, "' version='1.0' xmlns:stream='http://etherx.jabber.org/streams' >">>;
  
  xml_packet(bind, Id) ->
      <<"<iq type='set' id='97460001'><bind xmlns='urn:ietf:params:xml:ns:xmpp-bind'><resource>erlang</resource> </bind></iq>">>;
  
  xml_packet(session, Id) ->
      <<"<iq type='set' id='97460002'><session xmlns='urn:ietf:params:xml:ns:xmpp-session' /></iq>">>.
  
  %% xml_packet(close, stream) ->
  %%     <<"</stream:stream>">>;
  
  
  xml_packet(auth, 'PLAIN', {Name, Password}) ->
      lager:info("Name ~p, Password ~p", [Name, Password]),
      BaseData = base64:encode(<<0, Name/binary, 0, Password/binary>>),
      <<"<auth xmlns='urn:ietf:params:xml:ns:xmpp-sasl' mechanism='PLAIN'>", BaseData/binary, "</auth>">>.
  
  
  ping_scheduler(Name, Server) ->
      XmlPacket = xml_packet(ping, {Name, Server}),
      timer:send_after(?TIMER_DELAY, {timer, XmlPacket}).
  
negative.code: %%%===================================================================
  
  %% Stream is started we need authenticated.
  parse_xml([#xmlel{name= <<"stream:features">>, children=[#xmlel{name= <<"starttls">>}|_]}], State) ->
      lager:info("State ~p", [State]),
      AuthPlain = xml_packet(auth, 'PLAIN', State),
      gen_server:cast(self(), {send, AuthPlain});
  
  %% Second stream is started we need bind it.
  parse_xml([#xmlel{name= <<"stream:features">>}], State) ->
      lager:info("Second stream started!!"),
      XmlBind = xml_packet(bind, State),
      gen_server:cast(self(), {send, XmlBind});
  
  parse_xml([#xmlel{name= <<"success">>}], State) ->
      XmlPacket = xml_packet(stream, State),
      %% lager:info("New stream ~p", [XmlPacket]),
      gen_server:cast(self(), {new_stream, XmlPacket});
  
  %% Session is started, we start rooms' workers.
  parse_xml([#xmlel{name= <<"iq">>, attrs=[{<<"type">>, <<"result">>}|_]}]=Xml,
  	  #state{rooms=Rooms}=State) ->
      lager:info("New sessions started, we are starting rooms ~p!!!", [Rooms]),
      %% Start ping scheduler
      ping_scheduler(State),
      [ Pid ! {get_data, Xml} || {_Room, Pid} <- Rooms ];
  
      
  parse_xml([#xmlel{name= <<"iq">>, attrs=[{<<"from">>, AServer}|_]}],
  	  #state{server=Server, tref=TRef}=State) when AServer =:= Server ->
      lager:info("We got ping from ~p server!!", [Server]),
      %% First we cancel error TRef
      {ok, cancel} = timer:cancel(TRef),
      %% Start ping scheduler again
      ping_scheduler(State);
  
  parse_xml([#xmlel{name= <<"iq">>}], State) ->
      XmlPacket = xml_packet(session, State),
      gen_server:cast(self(), {send, XmlPacket});
  
  parse_xml([#xmlel{name= <<"message">>}=Data]=Xml, #state{rooms=Rooms}=_State) ->
  