Exemplo n.º 1
0
HTTPCode HSSConnection::get_registration_data(const std::string& public_user_identity,
                                              std::string& regstate,
                                              std::map<std::string, Ifcs >& ifcs_map,
                                              std::vector<std::string>& associated_uris,
                                              std::deque<std::string>& ccfs,
                                              std::deque<std::string>& ecfs,
                                              SAS::TrailId trail)
{
  Utils::StopWatch stopWatch;
  stopWatch.start();

  SAS::Event event(trail, SASEvent::HTTP_HOMESTEAD_GET_REG, 0);
  event.add_var_param(public_user_identity);
  SAS::report_event(event);

  std::string path = "/impu/" + Utils::url_escape(public_user_identity) + "/reg-data";

  LOG_DEBUG("Making Homestead request for %s", path.c_str());
  rapidxml::xml_document<>* root_underlying_ptr = NULL;
  HTTPCode http_code = get_xml_object(path, root_underlying_ptr, trail);

  // Needs to be a shared pointer - multiple Ifcs objects will need a reference
  // to it, so we want to delete the underlying document when they all go out
  // of scope.
  std::shared_ptr<rapidxml::xml_document<> > root (root_underlying_ptr);
  unsigned long latency_us = 0;

  // Only accumulate the latency if we haven't already applied a
  // penalty
  if ((http_code != HTTP_SERVER_UNAVAILABLE) &&
      (http_code != HTTP_GATEWAY_TIMEOUT)    &&
      (stopWatch.read(latency_us)))
  {
    _latency_stat.accumulate(latency_us);
    _subscription_latency_stat.accumulate(latency_us);
  }

  if (http_code != HTTP_OK)
  {
    // If get_xml_object has returned a HTTP error code, we have either not found
    // the subscriber on the HSS or been unable to communicate with
    // the HSS successfully. In either case we should fail.
    LOG_ERROR("Could not get subscriber data from HSS");
    return http_code;
  }

  // Return whether the XML was successfully decoded. The XML can be decoded and
  // not return any IFCs (when the subscriber isn't registered), so a successful
  // response shouldn't be taken as a guarantee of IFCs.
  std::vector<std::string> unused_aliases;
  return decode_homestead_xml(public_user_identity,
                              root,
                              regstate,
                              ifcs_map,
                              associated_uris,
                              unused_aliases,
                              ccfs,
                              ecfs,
                              true) ? HTTP_OK : HTTP_SERVER_ERROR;
}
Exemplo n.º 2
0
HTTPCode HSSConnection::update_registration_state(const std::string& public_user_identity,
                                                  const std::string& private_user_identity,
                                                  const std::string& type,
                                                  std::string& regstate,
                                                  std::map<std::string, Ifcs >& ifcs_map,
                                                  std::vector<std::string>& associated_uris,
                                                  std::deque<std::string>& ccfs,
                                                  std::deque<std::string>& ecfs,
                                                  SAS::TrailId trail)
{
  Utils::StopWatch stopWatch;
  stopWatch.start();

  SAS::Event event(trail, SASEvent::HTTP_HOMESTEAD_CHECK_STATE, 0);
  event.add_var_param(public_user_identity);
  event.add_var_param(private_user_identity);
  event.add_var_param(type);
  SAS::report_event(event);

  std::string path = "/impu/" + Utils::url_escape(public_user_identity) + "/reg-data";
  if (!private_user_identity.empty())
  {
    path += "?private_id=" + Utils::url_escape(private_user_identity);
  }

  LOG_DEBUG("Making Homestead request for %s", path.c_str());
  // Needs to be a shared pointer - multiple Ifcs objects will need a reference
  // to it, so we want to delete the underlying document when they all go out
  // of scope.

  rapidxml::xml_document<>* root_underlying_ptr = NULL;
  HTTPCode http_code = put_for_xml_object(path, "{\"reqtype\": \""+type+"\"}", root_underlying_ptr, trail);
  std::shared_ptr<rapidxml::xml_document<> > root (root_underlying_ptr);

  unsigned long latency_us = 0;

  // Only accumulate the latency if we haven't already applied a
  // penalty
  if ((http_code != HTTP_SERVER_UNAVAILABLE) &&
      (http_code != HTTP_GATEWAY_TIMEOUT)    &&
      (stopWatch.read(latency_us)))
  {
    _latency_stat.accumulate(latency_us);
    _subscription_latency_stat.accumulate(latency_us);
  }

  if (http_code != HTTP_OK)
  {
    // If get_xml_object has returned a HTTP error code, we have either not found
    // the subscriber on the HSS or been unable to communicate with
    // the HSS successfully. In either case we should fail.
    LOG_ERROR("Could not get subscriber data from HSS");
    return http_code;
  }

  return decode_homestead_xml(root, regstate, ifcs_map, associated_uris, ccfs, ecfs, false) ? HTTP_OK : HTTP_SERVER_ERROR;
}