<commit_before>/*
 * ModSecurity, http://www.modsecurity.org/
 * Copyright (c) 2015 Trustwave Holdings, Inc. (http://www.trustwave.com/)
 *
 * You may not use this file except in compliance with
 * the License.  You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * If any of the files related to licensing are missing or if you have any
 * other questions related to licensing please contact Trustwave Holdings, Inc.
 * directly using the email address <EMAIL>.
 *
 */

#include "src/audit_log_writer_serial.h"

#include <mutex>

#include "src/audit_log.h"

namespace ModSecurity {

static std::mutex serialLoggingMutex;


AuditLogWriterSerial::~AuditLogWriterSerial() {
    log.close();
}


void AuditLogWriterSerial::generateBoundary(std::string *boundary) {
    static const char alphanum[] =
        "0123456789"
        "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
        "abcdefghijklmnopqrstuvwxyz";

    for (int i = 0; i < SERIAL_AUDIT_LOG_BOUNDARY_LENGTH; ++i) {
        boundary->append(1, alphanum[rand() % (sizeof(alphanum) - 1)]);
    }
}


bool AuditLogWriterSerial::init() {
    log.open(m_audit->m_path1, std::fstream::out | std::fstream::app);
    return true;
}


bool AuditLogWriterSerial::write(Assay *assay, int parts) {
    std::string boundary;

    generateBoundary(&boundary);

    serialLoggingMutex.lock();
    log << assay->toOldAuditLogFormat(parts, "-" + boundary + "--");
    serialLoggingMutex.unlock();
    return true;
}


}  // namespace ModSecurity<commit_msg>Disables c++11 mutex, until we have a better approach<commit_after>/*
 * ModSecurity, http://www.modsecurity.org/
 * Copyright (c) 2015 Trustwave Holdings, Inc. (http://www.trustwave.com/)
 *
 * You may not use this file except in compliance with
 * the License.  You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * If any of the files related to licensing are missing or if you have any
 * other questions related to licensing please contact Trustwave Holdings, Inc.
 * directly using the email address <EMAIL>.
 *
 */

#include "src/audit_log_writer_serial.h"

// #include <mutex>

#include "src/audit_log.h"

namespace ModSecurity {

// static std::mutex serialLoggingMutex;


AuditLogWriterSerial::~AuditLogWriterSerial() {
    log.close();
}


void AuditLogWriterSerial::generateBoundary(std::string *boundary) {
    static const char alphanum[] =
        "0123456789"
        "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
        "abcdefghijklmnopqrstuvwxyz";

    for (int i = 0; i < SERIAL_AUDIT_LOG_BOUNDARY_LENGTH; ++i) {
        boundary->append(1, alphanum[rand() % (sizeof(alphanum) - 1)]);
    }
}


bool AuditLogWriterSerial::init() {
    log.open(m_audit->m_path1, std::fstream::out | std::fstream::app);
    return true;
}


bool AuditLogWriterSerial::write(Assay *assay, int parts) {
    std::string boundary;

    generateBoundary(&boundary);

    // serialLoggingMutex.lock();
    log << assay->toOldAuditLogFormat(parts, "-" + boundary + "--");
    // serialLoggingMutex.unlock();
    return true;
}


}  // namespace ModSecurity
{'fraction_non_alphanumeric': 0.12773487773487774, 'fraction_numerical': 0.013513513513513514, 'mean_word_length': 3.7757296466973886, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 13, 'https://': 0, 'lorem ipsum': 0, 'www.': 6, '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': '5192274', 'n_tokens_mistral': 1073, 'n_tokens_neox': 1011, 'n_words': 249}