anchor.diff:          throw:invalid -> invalid
       end.
   
  -% %% @private
  -% find_sep([$_|Rest], Acc) -> {list_to_binary(lists:reverse(Acc)), Rest};
  -% find_sep([], Acc) -> {list_to_binary(lists:reverse(Acc)), []};
  -% find_sep([Ch|Rest], Acc) -> find_sep(Rest, [Ch|Acc]).
  -
  -
  +
  +
  
positive.code: -author('Carlos Gonzalez <carlosj.gf@gmail.com>').
  
  -export([get_id/1, app_id/1, app_name/1, call_id/1, meta/2]).
  -export([get_all/0, get_all/2]).
  -export([parse_id/1, get_subscription/1, make_id/1, find/2, subscription_state/1, remote_id/2]).
  -export_type([id/0, status/0, subscription_state/0, terminated_reason/0]).
  
  -include("nksip.hrl").
  
  
  %% ===================================================================
  
negative.code:     end.
  
  
  %% @doc Gets the subscription object corresponding to a request or subscription and a call
  -spec get_subscription(nksip:request()|nksip:response()|nksip:subscription(), nksip:call()) ->
      nksip:subscription()|error.
  
  get_subscription({uses_subs, _Subs, _Dialog}=UserSubs, _) ->
      UserSubs;
  
  get_subscription(#sipmsg{}=SipMsg, #call{}=Call) ->
      case nksip_dialog:get_dialog(SipMsg, Call) of
          {ok, Dialog} ->
              SubsId = make_id(SipMsg),
              case find(SubsId, Dialog) of
                  #subscription{}=Subs ->
                      {user_subs, Subs, Dialog};
                  not_found ->
                      error
              end;
          error ->
              error
      end.
  
  
  %% @doc Gets all started subscription ids.
  -spec get_all() ->
      [nksip:id()].
  