Torc
0.1
Main Page
Related Pages
Namespaces
Classes
Files
File List
File Members
torc
http
torchtmldynamiccontent.cpp
Go to the documentation of this file.
1
/* Class TorcHTMLStaticContent
2
*
3
* This file is part of the Torc project.
4
*
5
* Copyright (C) Mark Kendall 2013-18
6
*
7
* This program is free software; you can redistribute it and/or modify
8
* it under the terms of the GNU General Public License as published by
9
* the Free Software Foundation; either version 2 of the License, or
10
* (at your option) any later version.
11
*
12
* This program is distributed in the hope that it will be useful,
13
* but WITHOUT ANY WARRANTY; without even the implied warranty of
14
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15
* GNU General Public License for more details.
16
*
17
* You should have received a copy of the GNU General Public License
18
* along with this program; if not, write to the Free Software
19
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
20
* USA.
21
*/
22
23
// Qt
24
#include <QDir>
25
26
// Torc
27
#include "
torclogging.h
"
28
#include "
torclocaldefs.h
"
29
#include "
torcdirectories.h
"
30
#include "
torchttprequest.h
"
31
#include "
torchtmldynamiccontent.h
"
32
37
TorcHTMLDynamicContent::TorcHTMLDynamicContent
()
38
:
TorcHTTPHandler
(
TORC_CONTENT_DIR
, QStringLiteral(
"dynamic"
)),
39
m_pathToContent(
GetTorcConfigDir
())
40
{
41
m_recursive
=
true
;
42
43
// Create the content directory if needed
44
// TorcLocalContext should already have created the config directory
45
if
(m_pathToContent.endsWith(
'/'
))
46
m_pathToContent.chop(1);
47
QString configdir =
GetTorcContentDir
();
48
49
QDir dir(configdir);
50
if
(!dir.exists())
51
if
(!dir.mkpath(configdir))
52
LOG
(VB_GENERAL, LOG_ERR, QStringLiteral(
"Failed to create content directory ('%1')"
).arg(configdir));
53
}
54
55
void
TorcHTMLDynamicContent::ProcessHTTPRequest
(
const
QString &PeerAddress,
int
PeerPort,
const
QString &LocalAddress,
int
LocalPort,
TorcHTTPRequest
&Request)
56
{
57
(void)PeerAddress;
58
(void)PeerPort;
59
(void)LocalAddress;
60
(void)LocalPort;
61
62
// handle options request
63
if
(Request.
GetHTTPRequestType
() ==
HTTPOptions
)
64
{
65
HandleOptions
(Request,
HTTPHead
|
HTTPGet
|
HTTPOptions
);
66
return
;
67
}
68
69
// restrict access to config file - require authentication
70
if
(Request.
GetUrl
().trimmed().endsWith(
TORC_CONFIG_FILE
))
71
{
72
if
(!
TorcHTTPHandler::MethodIsAuthorised
(Request,
HTTPAuth
))
73
return
;
74
}
75
76
// get the requested file subpath
77
HandleFile
(Request, m_pathToContent + Request.
GetUrl
(),
HTTPCacheNone
);
78
}
TorcHTTPRequest
A class to encapsulate an incoming HTTP request.
Definition:
torchttprequest.h:112
TorcHTTPRequest::GetHTTPRequestType
HTTPRequestType GetHTTPRequestType(void) const
Definition:
torchttprequest.cpp:271
TorcHTMLDynamicContent::TorcHTMLDynamicContent
TorcHTMLDynamicContent()
Definition:
torchtmldynamiccontent.cpp:37
torchtmldynamiccontent.h
TorcHTTPHandler
Base HTTP response handler class.
Definition:
torchttphandler.h:13
TORC_CONTENT_DIR
#define TORC_CONTENT_DIR
Definition:
torclocaldefs.h:19
HTTPHead
Definition:
torchttprequest.h:26
torchttprequest.h
torclogging.h
TorcHTTPHandler::m_recursive
bool m_recursive
Definition:
torchttphandler.h:32
torclocaldefs.h
TorcHTTPHandler::HandleOptions
static void HandleOptions(TorcHTTPRequest &Request, int Allowed)
Definition:
torchttphandler.cpp:102
TorcHTTPHandler::HandleFile
static void HandleFile(TorcHTTPRequest &Request, const QString &Filename, int Cache)
Definition:
torchttphandler.cpp:111
TorcHTMLDynamicContent::ProcessHTTPRequest
void ProcessHTTPRequest(const QString &PeerAddress, int PeerPort, const QString &LocalAddress, int LocalPort, TorcHTTPRequest &Request) override
Definition:
torchtmldynamiccontent.cpp:55
HTTPOptions
Definition:
torchttprequest.h:31
TORC_CONFIG_FILE
#define TORC_CONFIG_FILE
Definition:
torclocaldefs.h:18
GetTorcContentDir
QString GetTorcContentDir(void)
brief Return the path to generated content
Definition:
torcdirectories.cpp:104
HTTPAuth
Definition:
torchttprequest.h:33
HTTPCacheNone
Definition:
torchttprequest.h:95
LOG
#define LOG(_MASK_, _LEVEL_, _STRING_)
Definition:
torclogging.h:20
TorcHTTPHandler::MethodIsAuthorised
static bool MethodIsAuthorised(TorcHTTPRequest &Request, int Allowed)
Check the current request is authorised and set the authentication header if not. ...
Definition:
torchttphandler.cpp:92
torcdirectories.h
TorcHTTPRequest::GetUrl
QString GetUrl(void) const
Definition:
torchttprequest.cpp:281
HTTPGet
Definition:
torchttprequest.h:27
GetTorcConfigDir
QString GetTorcConfigDir(void)
Return the path to the application configuration directory.
Definition:
torcdirectories.cpp:83
Generated on Sat Jan 5 2019 21:54:03 for Torc by
1.8.11