qBittorrent
types.h
Go to the documentation of this file.
1 /*
2  * Bittorrent Client using Qt and libtorrent.
3  * Copyright (C) 2018 Mike Tzou (Chocobo1)
4  * Copyright (C) 2014 Vladimir Golovnev <[email protected]>
5  *
6  * This program is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU General Public License
8  * as published by the Free Software Foundation; either version 2
9  * of the License, or (at your option) any later version.
10  *
11  * This program is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with this program; if not, write to the Free Software
18  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
19  *
20  * In addition, as a special exception, the copyright holders give permission to
21  * link this program with the OpenSSL project's "OpenSSL" library (or with
22  * modified versions of it that use the same license as the "OpenSSL" library),
23  * and distribute the linked executables. You must obey the GNU General Public
24  * License in all respects for all of the code used other than "OpenSSL". If you
25  * modify file(s), you may extend this exception to your version of the file(s),
26  * but you are not obligated to do so. If you do not wish to do so, delete this
27  * exception statement from your version.
28  */
29 
30 #pragma once
31 
32 #include <QHostAddress>
33 #include <QString>
34 #include <QVector>
35 
36 namespace Http
37 {
38  inline const char METHOD_GET[] = "GET";
39  inline const char METHOD_POST[] = "POST";
40 
41  inline const char HEADER_CACHE_CONTROL[] = "cache-control";
42  inline const char HEADER_CONNECTION[] = "connection";
43  inline const char HEADER_CONTENT_DISPOSITION[] = "content-disposition";
44  inline const char HEADER_CONTENT_ENCODING[] = "content-encoding";
45  inline const char HEADER_CONTENT_LENGTH[] = "content-length";
46  inline const char HEADER_CONTENT_SECURITY_POLICY[] = "content-security-policy";
47  inline const char HEADER_CONTENT_TYPE[] = "content-type";
48  inline const char HEADER_DATE[] = "date";
49  inline const char HEADER_HOST[] = "host";
50  inline const char HEADER_ORIGIN[] = "origin";
51  inline const char HEADER_REFERER[] = "referer";
52  inline const char HEADER_REFERRER_POLICY[] = "referrer-policy";
53  inline const char HEADER_SET_COOKIE[] = "set-cookie";
54  inline const char HEADER_X_CONTENT_TYPE_OPTIONS[] = "x-content-type-options";
55  inline const char HEADER_X_FORWARDED_FOR[] = "x-forwarded-for";
56  inline const char HEADER_X_FORWARDED_HOST[] = "x-forwarded-host";
57  inline const char HEADER_X_FRAME_OPTIONS[] = "x-frame-options";
58  inline const char HEADER_X_XSS_PROTECTION[] = "x-xss-protection";
59 
60  inline const char HEADER_REQUEST_METHOD_GET[] = "GET";
61  inline const char HEADER_REQUEST_METHOD_HEAD[] = "HEAD";
62  inline const char HEADER_REQUEST_METHOD_POST[] = "POST";
63 
64  inline const char CONTENT_TYPE_HTML[] = "text/html";
65  inline const char CONTENT_TYPE_CSS[] = "text/css";
66  inline const char CONTENT_TYPE_TXT[] = "text/plain; charset=UTF-8";
67  inline const char CONTENT_TYPE_JS[] = "application/javascript";
68  inline const char CONTENT_TYPE_JSON[] = "application/json";
69  inline const char CONTENT_TYPE_GIF[] = "image/gif";
70  inline const char CONTENT_TYPE_PNG[] = "image/png";
71  inline const char CONTENT_TYPE_FORM_ENCODED[] = "application/x-www-form-urlencoded";
72  inline const char CONTENT_TYPE_FORM_DATA[] = "multipart/form-data";
73 
74  // portability: "\r\n" doesn't guarantee mapping to the correct symbol
75  inline const char CRLF[] = {0x0D, 0x0A, '\0'};
76 
77  struct Environment
78  {
79  QHostAddress localAddress;
80  quint16 localPort;
81 
82  QHostAddress clientAddress;
83  quint16 clientPort;
84  };
85 
86  struct UploadedFile
87  {
88  QString filename;
89  QString type; // MIME type
90  QByteArray data;
91  };
92 
93  struct Header
94  {
95  QString name;
96  QString value;
97  };
98 
99  using HeaderMap = QMap<QString, QString>; // <Header name, Header value>
100 
101  struct Request
102  {
103  QString version;
104  QString method;
105  QString path;
107  QHash<QString, QByteArray> query;
108  QHash<QString, QString> posts;
109  QVector<UploadedFile> files;
110  };
111 
113  {
114  uint code;
115  QString text;
116  };
117 
118  struct Response
119  {
122  QByteArray content;
123 
124  Response(uint code = 200, const QString &text = QLatin1String("OK"))
125  : status {code, text}
126  {
127  }
128  };
129 }
Definition: tracker.h:46
const char CONTENT_TYPE_PNG[]
Definition: types.h:70
const char CONTENT_TYPE_HTML[]
Definition: types.h:64
const char CRLF[]
Definition: types.h:75
const char HEADER_REQUEST_METHOD_GET[]
Definition: types.h:60
const char HEADER_CONTENT_TYPE[]
Definition: types.h:47
const char CONTENT_TYPE_FORM_ENCODED[]
Definition: types.h:71
const char HEADER_X_FRAME_OPTIONS[]
Definition: types.h:57
const char METHOD_GET[]
Definition: types.h:38
const char HEADER_REFERRER_POLICY[]
Definition: types.h:52
const char HEADER_ORIGIN[]
Definition: types.h:50
const char HEADER_CONNECTION[]
Definition: types.h:42
const char CONTENT_TYPE_JS[]
Definition: types.h:67
const char HEADER_REQUEST_METHOD_POST[]
Definition: types.h:62
const char HEADER_CONTENT_ENCODING[]
Definition: types.h:44
const char HEADER_X_XSS_PROTECTION[]
Definition: types.h:58
const char CONTENT_TYPE_JSON[]
Definition: types.h:68
const char METHOD_POST[]
Definition: types.h:39
const char HEADER_X_CONTENT_TYPE_OPTIONS[]
Definition: types.h:54
const char CONTENT_TYPE_GIF[]
Definition: types.h:69
const char HEADER_X_FORWARDED_FOR[]
Definition: types.h:55
const char HEADER_CONTENT_LENGTH[]
Definition: types.h:45
const char HEADER_CONTENT_SECURITY_POLICY[]
Definition: types.h:46
const char HEADER_CONTENT_DISPOSITION[]
Definition: types.h:43
const char CONTENT_TYPE_CSS[]
Definition: types.h:65
const char HEADER_DATE[]
Definition: types.h:48
const char HEADER_REFERER[]
Definition: types.h:51
const char HEADER_X_FORWARDED_HOST[]
Definition: types.h:56
const char HEADER_REQUEST_METHOD_HEAD[]
Definition: types.h:61
const char CONTENT_TYPE_FORM_DATA[]
Definition: types.h:72
QMap< QString, QString > HeaderMap
Definition: types.h:99
const char HEADER_CACHE_CONTROL[]
Definition: types.h:41
const char HEADER_SET_COOKIE[]
Definition: types.h:53
const char CONTENT_TYPE_TXT[]
Definition: types.h:66
const char HEADER_HOST[]
Definition: types.h:49
QHostAddress localAddress
Definition: types.h:79
QHostAddress clientAddress
Definition: types.h:82
quint16 clientPort
Definition: types.h:83
quint16 localPort
Definition: types.h:80
QString name
Definition: types.h:95
QString value
Definition: types.h:96
QVector< UploadedFile > files
Definition: types.h:109
QString version
Definition: types.h:103
QString path
Definition: types.h:105
HeaderMap headers
Definition: types.h:106
QHash< QString, QString > posts
Definition: types.h:108
QHash< QString, QByteArray > query
Definition: types.h:107
QString method
Definition: types.h:104
HeaderMap headers
Definition: types.h:121
QByteArray content
Definition: types.h:122
Response(uint code=200, const QString &text=QLatin1String("OK"))
Definition: types.h:124
ResponseStatus status
Definition: types.h:120
QString filename
Definition: types.h:88
QString type
Definition: types.h:89
QByteArray data
Definition: types.h:90