anchor.diff:  parse_component_jid(User) ->
     case string:tokens(User, "_") of
       ["agent"|_] = Props -> lists:zip([component, version, cores, jobs, uuid, ukn], lists:map(fun bson:utf8/1, Props));
  -    [Component|_] -> [{component, Component}]
  +    [Component|_] -> [{component, bson:utf8(Component)}]
     end.
   
   %@doc Creates a MonoDB document describing the connection
  
positive.code: hash_xml_attribute({"to", _} = Attr) -> Attr;
  hash_xml_attribute({"from", _} = Attr) -> Attr;
  hash_xml_attribute({"noack", _} = Attr) -> Attr;
  hash_xml_attribute({Attr, Value}) -> {Attr, "_BASE64:" ++  base64:encode_to_string(Value)}.
  
  %@doc Prepares the reportEvent command
  prepare_event_command(Event) -> prepare_event_command(Event, "").
  prepare_event_command(Event, Type) -> lists:keydelete(Type, 1, prepare_event_command(Event, Type, "")).
  prepare_event_command(Event, Type, Value) ->
    [{"command", "reportEvent" ++ ucfirst(Type)},
     {"component", "copilot.ejabberd"},
     {"event", Event},
     {Type, Value}].
  
  %@doc Sends a reportEvent command to the Monitor
  report_event(Server, Event) ->
    To = gen_mod:get_module_opt(Server, ?MODULE, monitor_jid, "mon@localhost"),
    XmlBody = {xmlelement, "message", [{"from", ?JID},
                                       {"to", To},
                                       {"noack", "1"}],
                                       [{xmlelement, "info", prepare_event_command(Event), []}]},
    route_to_copilot_component(To, XmlBody),
    ok.
  report_event(Server, Event, Value, Type) ->
    To = gen_mod:get_module_opt(Server, ?MODULE, monitor_jid, "mon@localhost"),
    XmlBody = {xmlelement, "message", [{"from", ?JID},
                                       {"to", To},
                                       {"noack", "1"},
                                      [{xmlelement, "info", prepare_event_command(Event, Value, Type), []}]]},
    route_to_copilot_component(To, XmlBody),
    ok.
  
negative.code: 
    ok.
  
  on_set_presence(User, Host, Resource, _Packet) ->
    {IPAddress, _} = ejabberd_sm:get_user_ip(User, Host, Resource),
    handle_presence(connect, {User, Host, Resource}, IPAddress).
  on_unset_presence(User, Host, Resource, _Status) ->
    handle_presence(disconnect, {User, Host, Resource}, null).
  
  %@doc Handles presence stanzas sent by users
  handle_presence(UserState, {_User, Host, _Resource} = JID, IPAddress) ->
    % Processes the stanza in the gen_server
    gen_server:cast(?MODULE, {UserState, JID, IPAddress}),
    report_event(Host, atom_to_list(UserState)),
    ok.
  
  %%% gen_server %%%
  