anchor.diff:  
   
   %% =================================================
  +%% Connect
  +%% =================================================
  +
  +authorize(#'CONNECT'{client_id = ClientId,
  +                     password = Password,
  +                     username = Username},
  +          S = #state{security = {Security,SecConf}}) ->
  +    %%=======================================================================
  +    %% @todo: authorize Will?!?!?
  +    %%=======================================================================
  +    case Security:authenticate(SecConf,ClientId,Username,Password) of
  +        {error,Reason} ->
  +            Code = case Reason of
  +                       bad_credentials -> ?CONNACK_BAD_USERNAME_OR_PASSWORD;
  +                       _               -> ?CONNACK_UNAUTHORIZED
  +                   end,
  +            send_to_client(S,#'CONNACK'{session_present = false,return_code = Code}),
  +            throw({bad_auth,S});
  +        {ok, AuthCtx} ->
  +            S#state{auth_ctx = AuthCtx}
  +    end.
  +
  +establish_session(#'CONNECT'{client_id = ClientId,
  +                             clean_session = CleanSession,
  +                             will = Will},
  +                  S) ->
  +    SessionPresent = not CleanSession,
  +    NewState = S#state{clean_session = CleanSession,
  +                       client_id = ClientId,
  +                       session_in = mqtt_publish:new(ClientId,Will),
  +                       session_out = new_session(S,ClientId,CleanSession)},
  +
  +    %% @todo:  Determine session present
  +    send_to_client(NewState, #'CONNACK'{return_code = ?CONNACK_ACCEPTED,
  +                                        session_present = SessionPresent}),
  +    NewState.
  +
  +%% =================================================
   %% Publish
   %% =================================================
   
  
positive.code: combine_results([], [], Acc) ->
      Acc;
  
  combine_results([AR|ART], SubResults = [SR|SRT], Acc) ->
      case AR of
          ok  ->
              Result =
                  case SR of
                      {ok,QoS}  -> QoS;
                      {error,_} -> ?SUBSCRIPTION_FAILURE
                  end,
              combine_results(ART,SRT,[Result|Acc]);
          {error,_} ->
              combine_results(ART,SubResults,[?SUBSCRIPTION_FAILURE|Acc])
      end.
  
negative.code: 
  
  %% Valid complete packet!
  handle_packet(Packet = #'CONNECT'{},
                S = #state{connect_state = connecting}) ->
  
      %%=======================================================================
      %% @todo: validate connect packet
      %%=======================================================================
      NewState =
              try
                  S1 = authorize(Packet,S),
                  S2 = establish_session(Packet,S1),
                  S3 = maybe_start_keep_alive(S2, Packet#'CONNECT'.keep_alive * 1000),
                  S3#state{connect_state = connected}
              catch
                  throw:{Reason,NewS}-> prevent_connection(NewS,Reason)
              end,
      {noreply,NewState};
  
  %% Catch- all case
  handle_packet(Packet, S = #state{ connect_state = connecting})
  