src/transaction.cc
/**
 * @name    appendRequestBody
 * @brief   Adds request body to be inspected.
 *
 * With this method it is possible to feed ModSecurity with data for
 * inspection regarding the request body. There are two possibilities here:
 * 
 * 1 - Adds the buffer in a row;
 * 2 - Adds it in chunks;
 *
 * A third option should be developed which is share your application buffer.
 * In any case, remember that the utilization of this function may reduce your
 * server throughput, as this buffer creations is computationally expensive.
 *
 * @note While feeding ModSecurity remember to keep checking if there is an
 *       intervention, Sec Language has the capability to set the maximum
 *       inspection size which may be reached, and the decision on what to do
 *       in this case is upon the rules.
 *
 * @returns If the operation was successful or not.
 * @retval true Operation was successful.
 * @retval false Operation failed.
 *
 */
@name    appendRequestBody
@brief   Adds request body to be inspected.

With this method it is possible to feed ModSecurity with data for
inspection regarding the request body. There are two possibilities here.

Adds the buffer in a row;
2 - Adds it in chunks.

A third option should be developed which is share your application buffer.
In any case, remember that the utilization of this function may reduce your
server throughput, as this buffer creations is computationally expensive.

@note While feeding ModSecurity remember to keep checking if there is an
intervention, Sec Language has the capability to set the maximum
inspection size which may be reached, and the decision on what to do
in this case is upon the rules.

@returns If the operation was successful or not.
@retval true Operation was successful.
@retval false Operation failed.
@name appendRequestBody @brief Adds request body to be inspected . With this method it is possible to feed ModSecurity with data for inspection regarding the request body . There are two possibilities here . Adds the buffer in a row ; 2 - Adds it in chunks . A third option should be developed which is share your application buffer . In any case remember that the utilization of this function may reduce your server throughput as this buffer creations is computationally expensive . @note While feeding ModSecurity remember to keep checking if there is an intervention Sec Language has the capability to set the maximum inspection size which may be reached and the decision on what to do in this case is upon the rules . @returns If the operation was successful or not . @retval true Operation was successful . @retval false Operation failed .
int Transaction::requestBodyFromFile(const char *path) {
    std::ifstream request_body(path);
    std::string str;
    if (request_body.is_open() == false) {
#ifndef NO_LOGS
        debug(3, "Failed to open request body at: " + std::string(path));
#endif
        return false;
    }
    request_body.seekg(0, std::ios::end);
    str.reserve(request_body.tellg());
    request_body.seekg(0, std::ios::beg);
    str.assign((std::istreambuf_iterator<char>(request_body)),
            std::istreambuf_iterator<char>());
    const char *buf = str.c_str();
    int len = request_body.tellg();
#ifndef NO_LOGS
    debug(9, "Adding request body: " + std::to_string(len) + " bytes. " \
        "Limit set to: "
        + std::to_string(this->m_rules->m_requestBodyLimit.m_value));
#endif
    return appendRequestBody(reinterpret_cast<const unsigned char*>(buf), len);
}
int Transaction :: requestBodyFromFile ( const char * path ) { std :: ifstream request_body ( path ) ; std :: string str ; if ( request_body . is_open ( ) == false ) { #ifndef NO_LOGS debug ( 3 , " " + std :: string ( path ) ) ; #endif return false ; } request_body . seekg ( 0 , std :: ios :: end ) ; str . reserve ( request_body . tellg ( ) ) ; request_body . seekg ( 0 , std :: ios :: beg ) ; str . assign ( ( std :: istreambuf_iterator < char > ( request_body ) ) , std :: istreambuf_iterator < char > ( ) ) ; const char * buf = str . c_str ( ) ; int len = request_body . tellg ( ) ; #ifndef NO_LOGS debug ( 9 , " " + std :: to_string ( len ) + " " " " + std :: to_string ( this -> m_rules -> m_requestBodyLimit . m_value ) ) ; #endif return appendRequestBody ( reinterpret_cast < const unsigned char * > ( buf ) , len ) ; }
@name    appendRequestBody
 @brief   Adds request body to be inspected.
@name appendRequestBody @brief Adds request body to be inspected .