~vanhoof/+junk/znc

« back to all changes in this revision

Viewing changes to .pc/02-inc-port-in-cookie.diff/WebModules.h

  • Committer: Bazaar Package Importer
  • Author(s): Patrick Matthäi
  • Date: 2011-02-06 17:41:38 UTC
  • mfrom: (21.1.2 experimental)
  • Revision ID: james.westby@ubuntu.com-20110206174138-ush4l5mkr4wg738n
Tags: 0.096-2
* Merge 0.092-3~bpo50+1 changelog.
* Upload to unstable.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/*
2
 
 * Copyright (C) 2004-2009  See the AUTHORS file for details.
3
 
 *
4
 
 * This program is free software; you can redistribute it and/or modify it
5
 
 * under the terms of the GNU General Public License version 2 as published
6
 
 * by the Free Software Foundation.
7
 
 */
8
 
 
9
 
#ifndef _WEBMODULES_H
10
 
#define _WEBMODULES_H
11
 
 
12
 
#include "Client.h"
13
 
#include "Template.h"
14
 
#include "HTTPSock.h"
15
 
#include "FileUtils.h"
16
 
 
17
 
class CWebSock;
18
 
class CModule;
19
 
class CWebSubPage;
20
 
 
21
 
typedef CSmartPtr<CWebSubPage> TWebSubPage;
22
 
typedef vector<TWebSubPage> VWebSubPages;
23
 
 
24
 
class CZNCTagHandler : public CTemplateTagHandler {
25
 
public:
26
 
        CZNCTagHandler(CWebSock& pWebSock);
27
 
        virtual ~CZNCTagHandler() {}
28
 
 
29
 
        virtual bool HandleTag(CTemplate& Tmpl, const CString& sName, const CString& sArgs, CString& sOutput);
30
 
private:
31
 
        CWebSock& m_WebSock;
32
 
};
33
 
 
34
 
 
35
 
class CWebSession {
36
 
public:
37
 
        CWebSession(const CString& sId);
38
 
        virtual ~CWebSession() {}
39
 
 
40
 
        const CString& GetId() const { return m_sId; }
41
 
        CUser* GetUser() const { return m_pUser; }
42
 
        bool IsLoggedIn() const { return m_pUser != NULL; }
43
 
        bool IsAdmin() const;
44
 
 
45
 
        CUser* SetUser(CUser* p) { m_pUser = p; return m_pUser; }
46
 
 
47
 
        void ClearMessageLoops();
48
 
        void FillMessageLoops(CTemplate& Tmpl);
49
 
        size_t AddError(const CString& sMessage);
50
 
        size_t AddSuccess(const CString& sMessage);
51
 
private:
52
 
        CString         m_sId;
53
 
        CUser*          m_pUser;
54
 
        VCString        m_vsErrorMsgs;
55
 
        VCString        m_vsSuccessMsgs;
56
 
};
57
 
 
58
 
 
59
 
class CWebSubPage {
60
 
public:
61
 
        CWebSubPage(const CString& sName, const CString& sTitle = "", unsigned int uFlags = 0) : m_sName(sName), m_sTitle(sTitle) {
62
 
                m_uFlags = uFlags;
63
 
        }
64
 
 
65
 
        CWebSubPage(const CString& sName, const CString& sTitle, const VPair& vParams, unsigned int uFlags = 0) : m_sName(sName), m_sTitle(sTitle), m_vParams(vParams) {
66
 
                m_uFlags = uFlags;
67
 
        }
68
 
 
69
 
        virtual ~CWebSubPage() {}
70
 
 
71
 
        enum {
72
 
                F_ADMIN = 1
73
 
        };
74
 
 
75
 
        void SetName(const CString& s) { m_sName = s; }
76
 
        void SetTitle(const CString& s) { m_sTitle = s; }
77
 
        void AddParam(const CString& sName, const CString& sValue) { m_vParams.push_back(make_pair(sName, sValue)); }
78
 
 
79
 
        bool RequiresAdmin() const { return m_uFlags & F_ADMIN; }
80
 
 
81
 
        const CString& GetName() const { return m_sName; }
82
 
        const CString& GetTitle() const { return m_sTitle; }
83
 
        const VPair& GetParams() const { return m_vParams; }
84
 
private:
85
 
        unsigned int    m_uFlags;
86
 
        CString         m_sName;
87
 
        CString         m_sTitle;
88
 
        VPair           m_vParams;
89
 
};
90
 
 
91
 
class CWebAuth : public CAuthBase {
92
 
public:
93
 
        CWebAuth(CWebSock* pWebSock, const CString& sUsername, const CString& sPassword);
94
 
        virtual ~CWebAuth() {}
95
 
 
96
 
        void SetWebSock(CWebSock* pWebSock) { m_pWebSock = pWebSock; }
97
 
        void AcceptedLogin(CUser& User);
98
 
        void RefusedLogin(const CString& sReason);
99
 
        void Invalidate();
100
 
private:
101
 
protected:
102
 
        CWebSock*   m_pWebSock;
103
 
};
104
 
 
105
 
class CWebSessionMap : public TCacheMap<CString, CSmartPtr<CWebSession> > {
106
 
        public:
107
 
                CWebSessionMap(unsigned int uTTL = 5000) : TCacheMap<CString, CSmartPtr<CWebSession> >(uTTL) {}
108
 
                void FinishUserSessions(const CUser& User);
109
 
};
110
 
 
111
 
class CWebSock : public CHTTPSock {
112
 
public:
113
 
        enum EPageReqResult {
114
 
                PAGE_NOTFOUND, // print 404 and Close()
115
 
                PAGE_PRINT,    // print page contents and Close()
116
 
                PAGE_DEFERRED, // async processing, Close() will be called from a different place
117
 
                PAGE_DONE      // all stuff has been done
118
 
        };
119
 
 
120
 
        CWebSock(CModule* pModule);
121
 
        CWebSock(CModule* pModule, const CString& sHostname, unsigned short uPort, int iTimeout = 60);
122
 
        virtual ~CWebSock();
123
 
 
124
 
        virtual bool ForceLogin();
125
 
        virtual bool OnLogin(const CString& sUser, const CString& sPass);
126
 
        virtual void OnPageRequest(const CString& sURI);
127
 
 
128
 
        void ParsePath();   // This parses the path portion of the url into some member vars
129
 
        CModule* ResolveModule();
130
 
 
131
 
        //virtual bool PrintFile(const CString& sFileName, CString sContentType = "");
132
 
        EPageReqResult PrintTemplate(const CString& sPageName, CString& sPageRet, CModule* pModule = NULL);
133
 
        EPageReqResult PrintStaticFile(const CString& sPath, CString& sPageRet, CModule* pModule = NULL);
134
 
 
135
 
        bool AddModLoop(const CString& sLoopName, CModule& Module);
136
 
        void SetPaths(CModule* pModule, bool bIsTemplate = false);
137
 
        void SetVars();
138
 
 
139
 
        void FillErrorPage(CString& sPageRet, const CString& sError) {
140
 
                m_Template["Action"] = "error";
141
 
                m_Template["Title"] = "Error";
142
 
                m_Template["Error"] = sError;
143
 
 
144
 
                PrintTemplate("error", sPageRet);
145
 
        }
146
 
 
147
 
        void PrintErrorPage(const CString& sMessage);
148
 
 
149
 
        CSmartPtr<CWebSession> GetSession();
150
 
        CString GetCSRFCheck();
151
 
 
152
 
        virtual Csock* GetSockObj(const CString& sHost, unsigned short uPort);
153
 
        CString GetSkinPath(const CString& sSkinName) const;
154
 
        CModule* GetModule() const { return (CModule*) m_pModule; }
155
 
        size_t GetAvailSkins(vector<CFile>& vRet);
156
 
        CString GetSkinName();
157
 
 
158
 
        CString GetRequestCookie(const CString& sKey) const;
159
 
        bool SendCookie(const CString& sKey, const CString& sValue);
160
 
 
161
 
        static void FinishUserSessions(const CUser& User) {
162
 
                m_mspSessions.FinishUserSessions(User);
163
 
        }
164
 
 
165
 
private:
166
 
        EPageReqResult OnPageRequestInternal(const CString& sURI, CString& sPageRet);
167
 
 
168
 
        bool                    m_bPathsSet;
169
 
        CTemplate               m_Template;
170
 
        CSmartPtr<CAuthBase>    m_spAuth;
171
 
        CString                 m_sForceUser;   // Gets filled by ResolveModule()
172
 
        CString                 m_sModName;     // Gets filled by ResolveModule()
173
 
        CString                 m_sPath;        // Gets filled by ResolveModule()
174
 
        CString                 m_sPage;        // Gets filled by ResolveModule()
175
 
        CSmartPtr<CWebSession>  m_spSession;
176
 
 
177
 
        static CWebSessionMap   m_mspSessions;
178
 
};
179
 
 
180
 
#endif // !_WEBMODULES_H