<commit_before># invite-router.cfg -- INVITE handler for a generic router
# Copyright (C) 2009  <NAME>
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program.  If not, see <http://www.gnu.org/licenses/>.

# -----------------------------------------------------------------
# INVITE Message Handler
# -----------------------------------------------------------------

route[invite-handler]
{
    xlog("L_DBG","DEBUG -- route(invite-handler) $ru -- INVITE Message Handler");

    sl_send_reply("100", "Trying");

    t_on_failure("1");
    t_on_reply("1");

    xlog("L_DBG","DEBUG -- route(invite-handler): From ip: $si - From URI: $fu");

    route(pre-route-invite);
    route(route-invite);
    route(mid-route-invite);

    route(try-line-side);
    route(try-trunk-side);

    # Invalid destination
    sl_send_reply("404", "User Not Found");
    exit;
}

# Route towards line-side
route[line-side-invite]
{
    xlog("L_DBG","DEBUG -- route(line-side-invite) Routing to line-side");

    # If CFA is enabled, go that way
    if( $(avp(cfa)) )
    {
        xlog("L_DBG","DEBUG -- CFA = $(avp(cfa))");

        # CFA AVP is a full URI
        $ru = $(avp(cfa));
        # Note: we can't do NAT detection on a CFA
        route(update-media-proxy);   # Start MP if needed
        route(initial-forwarder);
        exit;
    }

    # Save the original username in case we need it.
    $var(a) = $rU;

    # Use the regular destination username
    # NumUser AVP only gives the username.
    $rU = $(avp(dst_subs));

    # Locate the username if available (REGISTERed).
    route(lookup);

    # This is going to one of our users, ring them.
    route(update-media-proxy);   # Start MP if needed
    route(initial-forwarder);
    exit;
}

route[pre-route-invite]
{
  # -- Provider-side (top)
  if (allow_trusted())
  {
      # A trusted device is a provider-side trunk, including a local gateway (S2S).
      $(avp(src_type)) = "PSTN";
  }
  # -- Customer-side
  else
  if($(avp(src_subs)))
  {
      $(avp(src_type)) = "ONNET";

      if( (! isflagset(16))
           && avp_db_load("$(avp(src_subs))","$(avp(user_recording))") )
      {
          xlog("L_DBG","DEBUG -- route(invite-handler): Recording at $(avp(user_recording))");
          setflag(16);
          $(avp(dest_domain)) = $(avp(user_recording));
      }
      if( avp_db_load("$(avp(src_subs))","$(avp(user_force_mp))") )
      {
          xlog("L_DBG","DEBUG -- route(invite-handler): Force MediaProxy for $(avp(src_subs))");
          setflag(7); # force MP for caller
          add_rr_param(";mp=yes");
      }

      avp_db_load("$(avp(src_subs))","$(avp(account))");

      xlog("L_DBG","DEBUG -- route(invite-handler): Customer device $(avp(src_subs)) with account $(avp(account)).");
  }
}


# Route $(avp(gwadv)) to its final destination
route[trunk-side-invite]
{
    xlog("L_DBG","DEBUG -- route(trunk-side-invite) Routing gwadv $(avp(gwadv))");

    # If we have a node-id, first try to locate a route specific to this node.
    # The AVP key is the route name followed by '/' then the node_id.
#IF_USE_NODE_ID $var(local_route) = $(avp(gwadv)) + '/${NODE_ID}';
#IF_USE_NODE_ID if( ! avp_db_load("$var(local_route)","$(avp(tgw))") )
#IF_USE_NODE_ID {

    # Find the generic target ip:port for this route
    if( ! avp_db_load("$(avp(gwadv))","$(avp(tgw))") )
    {
        return(-1);
    }

#IF_USE_NODE_ID }

    xlog("L_DBG","DEBUG -- route(trunk-side-invite) Location $(avp(tgw))");

    t_on_branch("1");
    return(1);
}

branch_route[1]
{
    xlog("L_DBG","DEBUG -- branch_route(forwarder) Processing $rm $ru");

    xlog("L_DBG","DEBUG -- branch_route(forwarder) Routing tgw $(avp(tgw))");

    # Modify the RURI to use the new target.
    $ru = "sip:" + $rU + "@" + $(avp(tgw));

    # Per-provider authentication
    avp_db_load("$(avp(tgw))","$(avp(uac_realm))"); # Must match the realm sent by the remote end
    avp_db_load("$(avp(tgw))","$(avp(uac_user))");
    avp_db_load("$(avp(tgw))","$(avp(uac_pass))");
}
<commit_msg>Removed extraneous branch_route[1]<commit_after># invite-router.cfg -- INVITE handler for a generic router
# Copyright (C) 2009  <NAME>
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program.  If not, see <http://www.gnu.org/licenses/>.

# -----------------------------------------------------------------
# INVITE Message Handler
# -----------------------------------------------------------------

route[invite-handler]
{
    xlog("L_DBG","DEBUG -- route(invite-handler) $ru -- INVITE Message Handler");

    sl_send_reply("100", "Trying");

    t_on_failure("1");
    t_on_reply("1");

    xlog("L_DBG","DEBUG -- route(invite-handler): From ip: $si - From URI: $fu");

    route(pre-route-invite);
    route(route-invite);
    route(mid-route-invite);

    route(try-line-side);
    route(try-trunk-side);

    # Invalid destination
    sl_send_reply("404", "User Not Found");
    exit;
}

# Route towards line-side
route[line-side-invite]
{
    xlog("L_DBG","DEBUG -- route(line-side-invite) Routing to line-side");

    # If CFA is enabled, go that way
    if( $(avp(cfa)) )
    {
        xlog("L_DBG","DEBUG -- CFA = $(avp(cfa))");

        # CFA AVP is a full URI
        $ru = $(avp(cfa));
        # Note: we can't do NAT detection on a CFA
        route(update-media-proxy);   # Start MP if needed
        route(initial-forwarder);
        exit;
    }

    # Save the original username in case we need it.
    $var(a) = $rU;

    # Use the regular destination username
    # NumUser AVP only gives the username.
    $rU = $(avp(dst_subs));

    # Locate the username if available (REGISTERed).
    route(lookup);

    # This is going to one of our users, ring them.
    route(update-media-proxy);   # Start MP if needed
    route(initial-forwarder);
    exit;
}

route[pre-route-invite]
{
  # -- Provider-side (top)
  if (allow_trusted())
  {
      # A trusted device is a provider-side trunk, including a local gateway (S2S).
      $(avp(src_type)) = "PSTN";
  }
  # -- Customer-side
  else
  if($(avp(src_subs)))
  {
      $(avp(src_type)) = "ONNET";

      if( (! isflagset(16))
           && avp_db_load("$(avp(src_subs))","$(avp(user_recording))") )
      {
          xlog("L_DBG","DEBUG -- route(invite-handler): Recording at $(avp(user_recording))");
          setflag(16);
          $(avp(dest_domain)) = $(avp(user_recording));
      }
      if( avp_db_load("$(avp(src_subs))","$(avp(user_force_mp))") )
      {
          xlog("L_DBG","DEBUG -- route(invite-handler): Force MediaProxy for $(avp(src_subs))");
          setflag(7); # force MP for caller
          add_rr_param(";mp=yes");
      }

      avp_db_load("$(avp(src_subs))","$(avp(account))");

      xlog("L_DBG","DEBUG -- route(invite-handler): Customer device $(avp(src_subs)) with account $(avp(account)).");
  }
}


# Route $(avp(gwadv)) to its final destination
route[trunk-side-invite]
{
    xlog("L_DBG","DEBUG -- route(trunk-side-invite) Routing gwadv $(avp(gwadv))");

    # If we have a node-id, first try to locate a route specific to this node.
    # The AVP key is the route name followed by '/' then the node_id.
#IF_USE_NODE_ID $var(local_route) = $(avp(gwadv)) + '/${NODE_ID}';
#IF_USE_NODE_ID if( ! avp_db_load("$var(local_route)","$(avp(tgw))") )
#IF_USE_NODE_ID {

    # Find the generic target ip:port for this route
    if( ! avp_db_load("$(avp(gwadv))","$(avp(tgw))") )
    {
        return(-1);
    }

#IF_USE_NODE_ID }

    xlog("L_DBG","DEBUG -- route(trunk-side-invite) Location $(avp(tgw))");

    t_on_branch("1");
    return(1);
}
{'fraction_non_alphanumeric': 0.18344155844155843, 'fraction_numerical': 0.005333951762523191, 'mean_word_length': 2.81468376824414, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1338729', 'n_tokens_mistral': 3010, 'n_tokens_neox': 2931, 'n_words': 761}