<commit_before>#include "Session.hh"

#include "../net/HttpConnection.hh"
#include "../net/HttpRequest.hh"
#include <tr064/trace.hh>

#include "../Tr064Exception.hh"

#include <pugixml/pugixml.hpp>

#include <sstream>
#include <iostream>

using namespace tr064::soap;


//------------------------------------------------------------------------------

pugi::xml_node
Session::execute_action(
      const Service::Ptr& service, 
      const ServiceAction::Ptr& action) 
{

  LOG_TRACE("Going to execute Service: " + service->name() + 
            " with action: " + action->name());

  HttpConnection http_conn(_host, _port);

  pugi::xml_document doc;
  // iterate as long as it is not authenticated
  do 
  {
    // reset xml docuemnt.
    doc.reset();

    auto body_str = get_body(service, action);
    std::stringstream ss;
    //ss << headers
       //<< body;

    std::stringbuf headers_buf;
    std::ostream headers(&headers_buf);
    auto header_str = get_headers(service, action, body_str.size()+4);
    headers << header_str;

    std::stringbuf body_buf;
    std::ostream body(&body_buf);
    body << body_str;

    LOG_DEBUG("Current request: " << std::endl << header_str << body_str);

    HttpRequest req(headers, body);
    auto response = http_conn.sync(&req);
    //return "";

    std::ostringstream r_oss;
    r_oss << (response->body());
    std::string r_s = r_oss.str();

    doc.load(r_s.c_str());

    // used for debug
    std::stringstream d_ss; doc.save(d_ss); LOG_DEBUG(d_ss.str());

    const auto& envelope_node = doc.child("s:Envelope");
    if ( envelope_node.empty() )
    {
      throw tr064::Tr064Exception(
          "Received response does not contain an envelope_node, "
          "unable to proceed, received: \n" + r_s);
    }

    _auth.handle_auth_response(envelope_node);

    delete response;

  } while ( !_auth.is_authenticated() );

  // the xml doc should be filled at this point
  auto body_node = doc.child("s:Envelope").child("s:Body");
  if ( body_node.empty() )
  {
    std::cerr << "Received body node is empty." << std::endl;
  }
  return body_node;
}
<commit_msg>Handle no_auth on HttpRepsonses<commit_after>#include "Session.hh"

#include "../net/HttpConnection.hh"
#include "../net/HttpRequest.hh"
#include <tr064/trace.hh>

#include "../Tr064Exception.hh"

#include <pugixml/pugixml.hpp>

#include <sstream>
#include <iostream>

using namespace tr064::soap;


//------------------------------------------------------------------------------

pugi::xml_node
Session::execute_action(
      const Service::Ptr& service, 
      const ServiceAction::Ptr& action) 
{

  LOG_TRACE("Going to execute Service: " + service->name() + 
            " with action: " + action->name());

  HttpConnection http_conn(_host, _port);

  pugi::xml_document doc;
  // iterate as long as it is not authenticated
  do 
  {
    // reset xml docuemnt.
    doc.reset();

    auto body_str = get_body(service, action);
    std::stringstream ss;
    //ss << headers
       //<< body;

    std::stringbuf headers_buf;
    std::ostream headers(&headers_buf);
    auto header_str = get_headers(service, action, body_str.size()+4);
    headers << header_str;

    std::stringbuf body_buf;
    std::ostream body(&body_buf);
    body << body_str;

    LOG_DEBUG("Current request: " << std::endl << header_str << body_str);

    HttpRequest req(headers, body);
    auto response = http_conn.sync(&req);
    //return "";

    std::ostringstream r_oss;
    r_oss << (response->body());
    std::string r_s = r_oss.str();

    doc.load(r_s.c_str());

    // used for debug
    std::stringstream d_ss; doc.save(d_ss); LOG_DEBUG(d_ss.str());

    const auto& envelope_node = doc.child("s:Envelope");
    if ( envelope_node.empty() )
    {
      throw tr064::Tr064Exception(
          "Received response does not contain an envelope_node, "
          "unable to proceed, received: \n" + r_s);
    }

    if ( !_no_auth )
      _auth.handle_auth_response(envelope_node);

    delete response;

  } while ( !_auth.is_authenticated() && !_no_auth );

  // the xml doc should be filled at this point
  auto body_node = doc.child("s:Envelope").child("s:Body");
  if ( body_node.empty() )
  {
    std::cerr << "Received body node is empty." << std::endl;
  }
  return body_node;
}

{'fraction_non_alphanumeric': 0.17885421518397765, 'fraction_numerical': 0.007452258965999069, 'mean_word_length': 2.774165202108963, 'pattern_counts': {'":': 0, '<': 51, '<?xml version=': 0, '>': 17, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 12}, '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': '5029551', 'n_tokens_mistral': 1448, 'n_tokens_neox': 1379, 'n_words': 316}