<commit_before>/*
 * Copyright (C) 2004-2015 ZNC, see the NOTICE file for details.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * 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
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

#ifndef NOWEBMODULES_H
#define NOWEBMODULES_H

#include <no/noglobal.h>
#include <no/notemplate.h>
#include <no/nohttpsocket.h>
#include <no/noutils.h>
#include <no/nocachemap.h>

class NoAuthBase;
class NoUser;
class NoWebSock;
class NoModule;
class NoWebSubPage;

typedef std::shared_ptr<NoWebSubPage> TWebSubPage;
typedef std::vector<TWebSubPage> VWebSubPages;

class NO_EXPORT NoWebSession
{
public:
    NoWebSession(const NoString& sId, const NoString& sIP);
    ~NoWebSession();

    NoWebSession(const NoWebSession&) = delete;
    NoWebSession& operator=(const NoWebSession&) = delete;

    const NoString& GetId() const { return m_sId; }
    const NoString& GetIP() const { return m_sIP; }
    NoUser* GetUser() const { return m_pUser; }
    time_t GetLastActive() const { return m_tmLastActive; }
    bool IsLoggedIn() const { return m_pUser != nullptr; }
    bool IsAdmin() const;
    void UpdateLastActive();

    NoUser* SetUser(NoUser* p)
    {
        m_pUser = p;
        return m_pUser;
    }

    void ClearMessageLoops();
    void FillMessageLoops(NoTemplate& Tmpl);
    size_t AddError(const NoString& sMessage);
    size_t AddSuccess(const NoString& sMessage);

private:
    NoString m_sId;
    NoString m_sIP;
    NoUser* m_pUser;
    NoStringVector m_vsErrorMsgs;
    NoStringVector m_vsSuccessMsgs;
    time_t m_tmLastActive;
};


class NO_EXPORT NoWebSubPage
{
public:
    NoWebSubPage(const NoString& sName, const NoString& sTitle = "", uint uFlags = 0)
        : m_uFlags(uFlags), m_sName(sName), m_sTitle(sTitle), m_vParams()
    {
    }

    NoWebSubPage(const NoString& sName, const NoString& sTitle, const NoStringPairVector& vParams, uint uFlags = 0)
        : m_uFlags(uFlags), m_sName(sName), m_sTitle(sTitle), m_vParams(vParams)
    {
    }

    virtual ~NoWebSubPage() {}

    enum { Admin = 1 };

    void SetName(const NoString& s) { m_sName = s; }
    void SetTitle(const NoString& s) { m_sTitle = s; }
    void AddParam(const NoString& sName, const NoString& sValue) { m_vParams.push_back(make_pair(sName, sValue)); }

    bool RequiresAdmin() const { return m_uFlags & Admin; }

    const NoString& GetName() const { return m_sName; }
    const NoString& GetTitle() const { return m_sTitle; }
    const NoStringPairVector& GetParams() const { return m_vParams; }

private:
    uint m_uFlags;
    NoString m_sName;
    NoString m_sTitle;
    NoStringPairVector m_vParams;
};

class NO_EXPORT NoWebSock : public NoHttpSocket
{
public:
    enum PageRequest {
        NotFound, // print 404 and Close()
        Print, // print page contents and Close()
        Deferred, // async processing, Close() will be called from a different place
        Done // all stuff has been done
    };<commit_msg>NoWebSubPage: remove virtual dtor<commit_after>/*
 * Copyright (C) 2004-2015 ZNC, see the NOTICE file for details.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * 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
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

#ifndef NOWEBMODULES_H
#define NOWEBMODULES_H

#include <no/noglobal.h>
#include <no/notemplate.h>
#include <no/nohttpsocket.h>
#include <no/noutils.h>
#include <no/nocachemap.h>

class NoAuthBase;
class NoUser;
class NoWebSock;
class NoModule;
class NoWebSubPage;

typedef std::shared_ptr<NoWebSubPage> TWebSubPage;
typedef std::vector<TWebSubPage> VWebSubPages;

class NO_EXPORT NoWebSession
{
public:
    NoWebSession(const NoString& sId, const NoString& sIP);
    ~NoWebSession();

    NoWebSession(const NoWebSession&) = delete;
    NoWebSession& operator=(const NoWebSession&) = delete;

    const NoString& GetId() const { return m_sId; }
    const NoString& GetIP() const { return m_sIP; }
    NoUser* GetUser() const { return m_pUser; }
    time_t GetLastActive() const { return m_tmLastActive; }
    bool IsLoggedIn() const { return m_pUser != nullptr; }
    bool IsAdmin() const;
    void UpdateLastActive();

    NoUser* SetUser(NoUser* p)
    {
        m_pUser = p;
        return m_pUser;
    }

    void ClearMessageLoops();
    void FillMessageLoops(NoTemplate& Tmpl);
    size_t AddError(const NoString& sMessage);
    size_t AddSuccess(const NoString& sMessage);

private:
    NoString m_sId;
    NoString m_sIP;
    NoUser* m_pUser;
    NoStringVector m_vsErrorMsgs;
    NoStringVector m_vsSuccessMsgs;
    time_t m_tmLastActive;
};


class NO_EXPORT NoWebSubPage
{
public:
    NoWebSubPage(const NoString& sName, const NoString& sTitle = "", uint uFlags = 0)
        : m_uFlags(uFlags), m_sName(sName), m_sTitle(sTitle), m_vParams()
    {
    }

    NoWebSubPage(const NoString& sName, const NoString& sTitle, const NoStringPairVector& vParams, uint uFlags = 0)
        : m_uFlags(uFlags), m_sName(sName), m_sTitle(sTitle), m_vParams(vParams)
    {
    }

    enum { Admin = 1 };

    void SetName(const NoString& s) { m_sName = s; }
    void SetTitle(const NoString& s) { m_sTitle = s; }
    void AddParam(const NoString& sName, const NoString& sValue) { m_vParams.push_back(make_pair(sName, sValue)); }

    bool RequiresAdmin() const { return m_uFlags & Admin; }

    const NoString& GetName() const { return m_sName; }
    const NoString& GetTitle() const { return m_sTitle; }
    const NoStringPairVector& GetParams() const { return m_vParams; }

private:
    uint m_uFlags;
    NoString m_sName;
    NoString m_sTitle;
    NoStringPairVector m_vParams;
};

class NO_EXPORT NoWebSock : public NoHttpSocket
{
public:
    enum PageRequest {
        NotFound, // print 404 and Close()
        Print, // print page contents and Close()
        Deferred, // async processing, Close() will be called from a different place
        Done // all stuff has been done
    };
{'fraction_non_alphanumeric': 0.09608540925266904, 'fraction_numerical': 0.005338078291814947, 'mean_word_length': 3.697075208913649, 'pattern_counts': {'":': 0, '<': 17, '<?xml version=': 0, '>': 17, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, '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': '6057277', 'n_tokens_mistral': 2262, 'n_tokens_neox': 2200, 'n_words': 663}