コード例 #1
0
ファイル: simservs_test.cpp プロジェクト: AiprNick/sprout
void expect_cb_rule(const ss_cb_rule& expected, const simservs::CBRule& actual)
{
  EXPECT_EQ(expected.conditions, actual.conditions());
  EXPECT_EQ(expected.allow_call, actual.allow_call());
}
コード例 #2
0
ファイル: callservices.cpp プロジェクト: triendeau/sprout
// Determine if an arbitary rule's conditions apply to a call.
//
// @return true if the rule should be applied (i.e. the conditions hold)
bool CallServices::CallServiceBase::check_cb_rule(const simservs::CBRule& rule, pjsip_msg* msg)
{
  bool rule_matches = true;
  int conditions = rule.conditions();
  LOG_DEBUG("Testing call against conditions (0x%X)", conditions);

  if (conditions & simservs::Rule::CONDITION_ROAMING)
  {
    // Clearwater doesn't support roaming calls yet, this never applies
    LOG_DEBUG("Roaming condition fails");
    rule_matches = false;
  }
  if (conditions & simservs::Rule::CONDITION_INTERNATIONAL)
  {
    // Detect international calls, this requires the request URI to be a TEL URI or a SIP URI with a 'phone'
    // parameter set.  Then we need to look at the country code to determine if we're going international.
    std::string dialed_number;
    pjsip_uri *uri = msg->line.req.uri;
    if (PJSIP_URI_SCHEME_IS_TEL(uri))
    {
      LOG_DEBUG("TEL: Number dialed");
      pj_str_t* tel_number = &((pjsip_tel_uri *)uri)->number;
      dialed_number.assign(pj_strbuf(tel_number), pj_strlen(tel_number));
    }
    else if (PJSIP_URI_SCHEME_IS_SIP(uri))
    {
      LOG_DEBUG("SIP/SIPS: Number dialed");
      pjsip_sip_uri *sip_uri = (pjsip_sip_uri *)uri;

      // According to 3GPP TS 24.611 v11.2.0, only SIP UIRs with user=phone may be treated as international
      // unfortunately neither X-Lite nor Accession ever set this parameter.  Therefore we will look at any SIP username
      // as a potential international number.
      //
      // To restore the specced behaviour, uncomment the below:
      //
      // if (pj_stricmp2(&sip_uri->user_param, "phone") == 0)
      {
        pj_str_t *sip_number = &sip_uri->user;
        dialed_number.assign(pj_strbuf(sip_number), pj_strlen(sip_number));
      }
    }

    // If we have no number or it starts with our country code or doesn't start with '+', '00' or '011' it's
    // non-international.
    if (dialed_number == "")
    {
      LOG_DEBUG("SIP username requested, international number detection not possible");
      rule_matches = false;
    }
    else if (!(boost::starts_with(dialed_number, "+") ||
               boost::starts_with(dialed_number, "00") ||
               boost::starts_with(dialed_number, "011")) ||
             boost::starts_with(dialed_number, "+" + _country_code) ||
             boost::starts_with(dialed_number, "00" + _country_code) ||
             boost::starts_with(dialed_number, "011" + _country_code))
    {
      LOG_DEBUG("International condition fails, dialed number is '%s'", dialed_number.c_str());
      rule_matches = false;
    }
  }
  if (conditions & simservs::Rule::CONDITION_INTERNATIONAL_EXHC)
  {
    // Clearwater does not support roaming calls yet, this never applies
    LOG_DEBUG("International Excluding Home Country rule fails");
    rule_matches = false;
  }

  return rule_matches;
}