<commit_before>/*
 * Copyright (C) 2013-2016 <NAME> <<EMAIL>>
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Library General Public
 * License as published by the Free Software Foundation; either
 * version 2 of the License, or (at your option) any later version.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
 * Library General Public License for more details.
 *
 * You should have received a copy of the GNU Library General Public License
 * along with this library; see the file COPYING.LIB. If not, write to
 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
 * Boston, MA 02110-1301, USA.
 */

#include "session_p.h"

#include "sessionstorefile.h"

#include <Cutelyst/Application>
#include <Cutelyst/Context>
#include <Cutelyst/Response>

#include <QUuid>
#include <QHostAddress>
#include <QLoggingCategory>
#include <QCoreApplication>

using namespace Cutelyst;

Q_LOGGING_CATEGORY(C_SESSION, "cutelyst.plugin.session")

#define SESSION_VALUES "__session_values"
#define SESSION_EXPIRES "__session_expires"
#define SESSION_TRIED_LOADING_EXPIRES "__session_tried_loading_expires"
#define SESSION_EXTENDED_EXPIRES "__session_extended_expires"
#define SESSION_UPDATED "__session_updated"
#define SESSION_ID "__session_id"
#define SESSION_TRIED_LOADING_ID "__session_tried_loading_id"
#define SESSION_DELETED_ID "__session_deleted_id"
#define SESSION_DELETE_REASON "__session_delete_reason"

static thread_local Session *m_instance = nullptr;

Session::Session(Cutelyst::Application *parent) : Plugin(parent)
  , d_ptr(new SessionPrivate(this))
{

}

Cutelyst::Session::~Session()
{
    delete d_ptr;
}

bool Session::setup(Application *app)
{
    Q_D(Session);
    d->sessionName = QCoreApplication::applicationName() + QLatin1String("_session");

    const QVariantMap config = app->config(QLatin1String("Session_Plugin")).toMap();
    d->sessionExpires = config.value(QLatin1String("expires"), 7200).toULongLong();
    d->expiryThreshold = config.value(QLatin1String("expiry_threshold"), 0).toULongLong();
    d->verifyAddress = config.value(QLatin1String("verify_address"), false).toBool();
    d->verifyUserAgent = config.value(QLatin1String("verify_user_agent"), false).toBool();

    connect(app, &Application::afterDispatch, this, &SessionPrivate::_q_saveSession);
    connect(app, &Application::postForked, this, &SessionPrivate::_q_postFork);

    if (!d->store) {<commit_msg>Fix SessionPlugin settings setup. (#31)<commit_after>/*
 * Copyright (C) 2013-2016 <NAME> <<EMAIL>>
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Library General Public
 * License as published by the Free Software Foundation; either
 * version 2 of the License, or (at your option) any later version.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
 * Library General Public License for more details.
 *
 * You should have received a copy of the GNU Library General Public License
 * along with this library; see the file COPYING.LIB. If not, write to
 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
 * Boston, MA 02110-1301, USA.
 */

#include "session_p.h"

#include "sessionstorefile.h"

#include <Cutelyst/Application>
#include <Cutelyst/Context>
#include <Cutelyst/Response>
#include <Cutelyst/Engine>

#include <QUuid>
#include <QHostAddress>
#include <QLoggingCategory>
#include <QCoreApplication>

using namespace Cutelyst;

Q_LOGGING_CATEGORY(C_SESSION, "cutelyst.plugin.session")

#define SESSION_VALUES "__session_values"
#define SESSION_EXPIRES "__session_expires"
#define SESSION_TRIED_LOADING_EXPIRES "__session_tried_loading_expires"
#define SESSION_EXTENDED_EXPIRES "__session_extended_expires"
#define SESSION_UPDATED "__session_updated"
#define SESSION_ID "__session_id"
#define SESSION_TRIED_LOADING_ID "__session_tried_loading_id"
#define SESSION_DELETED_ID "__session_deleted_id"
#define SESSION_DELETE_REASON "__session_delete_reason"

static thread_local Session *m_instance = nullptr;

Session::Session(Cutelyst::Application *parent) : Plugin(parent)
  , d_ptr(new SessionPrivate(this))
{

}

Cutelyst::Session::~Session()
{
    delete d_ptr;
}

bool Session::setup(Application *app)
{
    Q_D(Session);
    d->sessionName = QCoreApplication::applicationName() + QLatin1String("_session");

    const QVariantMap config = app->engine()->config(QLatin1String("Cutelyst_Session_Plugin"));
    d->sessionExpires = config.value(QLatin1String("expires"), 7200).toULongLong();
    d->expiryThreshold = config.value(QLatin1String("expiry_threshold"), 0).toULongLong();
    d->verifyAddress = config.value(QLatin1String("verify_address"), false).toBool();
    d->verifyUserAgent = config.value(QLatin1String("verify_user_agent"), false).toBool();

    connect(app, &Application::afterDispatch, this, &SessionPrivate::_q_saveSession);
    connect(app, &Application::postForked, this, &SessionPrivate::_q_postFork);

    if (!d->store) {
{'fraction_non_alphanumeric': 0.10612321562734786, 'fraction_numerical': 0.012021036814425245, 'mean_word_length': 6.147651006711409, 'pattern_counts': {'":': 0, '<': 24, '<?xml version=': 0, '>': 39, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, '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': '803665', 'n_tokens_mistral': 1677, 'n_tokens_neox': 1639, 'n_words': 450}