-
Notifications
You must be signed in to change notification settings - Fork 0
/
parsedrequest.cpp
83 lines (71 loc) · 2.62 KB
/
parsedrequest.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
/**
* This file is part of PasswordSender.
*
* PasswordSender is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
* PasswordSender 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 General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with PasswordSender. If not, see <https://www.gnu.org/licenses/>.
*
* Copyright 2020 Wiebe Cazemier <[email protected]>
*/
#include "parsedrequest.h"
#include "algorithm"
#include <iostream>
#include <sys/random.h>
ParsedRequest::ParsedRequest(QFCgiRequest *parent) : QObject(parent)
{
this->fcgiRequest = parent;
for(const QString &s : parent->getParams())
{
this->params[s] = parent->getParam(s);
}
/* There's a difference between Apache's fcgi params and Nginx's. Apache passes, for instance:
*
* SCRIPT_URL = /passwordsender/upload?querystringarg=1 (although we don't use query strings.
* SCRIPT_URI = https://passwords.mydomain.nl/passwordsender/upload?querystringarg=1
* HTTP_HOST = passwords.mydomain.nl
* [nothing for request method?]
*
* Nginx passes (I think, I didn't test):
*
* REQUEST_URI = /passwordsender/upload?querystringarg=1
* SERVER_NAME = passwords.mydomain.nl
* REQUEST_METHOD = GET/POST/PUT/DELETE?
*
* TODO: detect which ones and unify.
*
* Anyway, we store the important ones in variables, because I want easy access.
*/
this->scriptURL = this->params["SCRIPT_URL"];
this->httpHost = this->params["HTTP_HOST"];
ranBuf = new char[RAN_BUF_SIZE];
if (getrandom(ranBuf, RAN_BUF_SIZE, 0) != RAN_BUF_SIZE)
throw std::runtime_error("Not enough random entroy?");
iv = QByteArray(ranBuf, RAN_BUF_SIZE);
if (getrandom(ranBuf, RAN_BUF_SIZE, 0) != RAN_BUF_SIZE)
throw std::runtime_error("Not enough random entroy?");
cipherKey = QByteArray(ranBuf, RAN_BUF_SIZE);
}
ParsedRequest::~ParsedRequest()
{
delete[] ranBuf;
}
void ParsedRequest::addFile(UploadedFile &uploaded_file)
{
this->files.push_back(std::move(uploaded_file));
}
void ParsedRequest::addField(const FormField &formField)
{
this->formFields[formField.name] = formField;
}
void ParsedRequest::requestDone(quint32 code)
{
this->fcgiRequest->endRequest(code);
}