-
Notifications
You must be signed in to change notification settings - Fork 15
/
utilfrequest.h
executable file
·166 lines (132 loc) · 5.2 KB
/
utilfrequest.h
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
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
/*
*
Copyright (C) 2017-2019 Fábio Bento (fabiobento512)
This program 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.
This program 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 this program. If not, see <http://www.gnu.org/licenses/>.
*
*/
#ifndef UTILFREQUEST_H
#define UTILFREQUEST_H
#include "util.h"
// PLog library (log library)
// https://github.com/SergiusTheBest/plog
#include <plog/Log.h>
#include <plog/Converters/NativeEOLConverter.h>
#include <pugixml/pugixml.hpp>
#include <cpp17optional/optional.hpp>
#include <cstdint>
#include <QComboBox>
#include <QDateTime>
#include <QMimeDatabase>
#include <QJsonDocument>
#include "Authentications/frequestauthentication.h"
#include "utilglobalvars.h"
namespace UtilFRequest{
struct HttpHeader{
QString name;
QString value;
};
// Update the vector bellow always that you update this enum
enum class RequestType{
GET_OPTION = 0,
POST_OPTION = 1,
PUT_OPTION = 2,
DELETE_OPTION = 3,
PATCH_OPTION = 4,
HEAD_OPTION = 5,
TRACE_OPTION = 6,
OPTIONS_OPTION = 7
};
const QVector<RequestType> possibleRequestTypes = {
UtilFRequest::RequestType::GET_OPTION,
UtilFRequest::RequestType::POST_OPTION,
UtilFRequest::RequestType::PUT_OPTION,
UtilFRequest::RequestType::DELETE_OPTION,
UtilFRequest::RequestType::PATCH_OPTION,
UtilFRequest::RequestType::HEAD_OPTION,
UtilFRequest::RequestType::TRACE_OPTION,
UtilFRequest::RequestType::OPTIONS_OPTION
};
enum class BodyType{
RAW = 0,
FORM_DATA = 1,
X_FORM_WWW_URLENCODED = 2
};
enum class FormKeyValueType{
TEXT = 0,
FILE = 1
};
enum class SerializationFormatType{
UNKNOWN = 0,
JSON = 1,
XML = 2
};
enum class IdentCharacter{
SPACE = 0,
TAB = 1
};
struct HttpFormKeyValueType{
QString key;
QString value;
FormKeyValueType type;
HttpFormKeyValueType(){}
HttpFormKeyValueType(const QString &key, const QString &value, const FormKeyValueType type){
this->key = key;
this->value = value;
this->type = type;
}
};
struct RequestInfo{
bool bOverridesMainUrl = false;
QString overrideMainUrl;
QString name;
QString path;
RequestType requestType = RequestType::GET_OPTION;
BodyType bodyType = BodyType::RAW;
QString body;
QVector<HttpFormKeyValueType> bodyForm;
QVector<HttpHeader> headers;
bool bDownloadResponseAsFile = false;
QString uuid;
unsigned long long int order = 0;
bool bDisableGlobalHeaders = true;
};
static QMimeDatabase mimeDatabase;
QString getDocumentsFolder();
bool requestTypeMayHaveBody(RequestType currentRequestType);
RequestType getRequestTypeByString(const QString ¤tRequestText);
QString getRequestTypeString(const RequestType currentRequestType);
FormKeyValueType getFormKeyTypeByString(const QString ¤tFormKeyValueString);
QString getFormKeyTypeString(const FormKeyValueType currentFormKeyValueType);
BodyType getBodyTypeByString(const QString ¤tBodyTypeText);
QString getBodyTypeString(const BodyType currentBodyType);
IdentCharacter getIdentCharacterByString(const QString ¤tIdentCharacterText);
QString getIdentCharacterString(const IdentCharacter currentIdentCharacter);
QString getDateTimeFormatForFilename(const QDateTime ¤tDateTime);
void addRequestFormBodyRow(QTableWidget * const myTable, const QString &key, const QString &value, const UtilFRequest::FormKeyValueType type);
// Return original content in case of error
QString getStringFormattedForSerializationType(const QString &content, const SerializationFormatType serializationType);
SerializationFormatType getSerializationFormatTypeForString(const QString &content);
// Simply ofuscation just to not store password string as plain text in project / configuration files
// (it does not protect the password, just obfuscates so can't be read directly)
// Applies a simple xor with the given salt
QByteArray simpleStringObfuscationDeobfuscation(const QString& ofuscationSalt, const QString &input);
// Replaces the textToReplace string with the actual username and password given (uses the FRequest Auth Placeholders for the replace)
QString replaceFRequestAuthenticationPlaceholders(const QString &textToReplace, const QString &username, const QString &password);
void setGlobalHeaderTableWidgetRow(QTableWidget *myTable, const int rowNumber);
void resetGlobalTableWidgetRow(QTableWidget *myTable, const int rowNumber);
bool isGlobalHeaderTableWidgetRow(QTableWidget *myTable, const int rowNumber);
// we can't use a static object for this because we will receive an error:
// "QWidget: Must construct a QApplication before a QWidget"
QBrush getTableWidgetRowDisabledBackStyle();
QBrush getTableWidgetRowDisabledTextStyle();
}
#endif // UTILFREQUEST_H