Changeset View
Changeset View
Standalone View
Standalone View
src/postfiledata.cpp
Show All 20 Lines | 1 | /* | |||
---|---|---|---|---|---|
21 | 21 | | |||
22 | You should have received a copy of the GNU Lesser General Public | 22 | You should have received a copy of the GNU Lesser General Public | ||
23 | License along with this library. If not, see <http://www.gnu.org/licenses/>. | 23 | License along with this library. If not, see <http://www.gnu.org/licenses/>. | ||
24 | 24 | | |||
25 | */ | 25 | */ | ||
26 | 26 | | |||
27 | #include "postfiledata.h" | 27 | #include "postfiledata.h" | ||
28 | 28 | | |||
29 | #include <QRandomGenerator> | ||||
29 | #include <QDebug> | 30 | #include <QDebug> | ||
30 | #include <QDateTime> | 31 | #include <QDateTime> | ||
31 | 32 | | |||
32 | namespace Attica | 33 | namespace Attica | ||
33 | { | 34 | { | ||
34 | class PostFileDataPrivate | 35 | class PostFileDataPrivate | ||
35 | { | 36 | { | ||
36 | public: | 37 | public: | ||
37 | QByteArray buffer; | 38 | QByteArray buffer; | ||
38 | QByteArray boundary; | 39 | QByteArray boundary; | ||
39 | QUrl url; | 40 | QUrl url; | ||
40 | bool finished; | 41 | bool finished; | ||
41 | 42 | | |||
42 | PostFileDataPrivate() | 43 | PostFileDataPrivate() | ||
43 | : finished(false) | 44 | : finished(false) | ||
44 | { | 45 | { | ||
45 | } | 46 | } | ||
46 | }; | 47 | }; | ||
47 | 48 | | |||
48 | PostFileData::PostFileData(const QUrl &url) | 49 | PostFileData::PostFileData(const QUrl &url) | ||
49 | : d(new PostFileDataPrivate) | 50 | : d(new PostFileDataPrivate) | ||
50 | { | 51 | { | ||
51 | d->url = url; | 52 | d->url = url; | ||
52 | qsrand(QTime::currentTime().secsTo(QTime(0, 0, 0))); | | |||
53 | d->boundary = "----------" + randomString(42 + 13).toLatin1(); | 53 | d->boundary = "----------" + randomString(42 + 13).toLatin1(); | ||
54 | } | 54 | } | ||
55 | 55 | | |||
56 | PostFileData::~PostFileData() | 56 | PostFileData::~PostFileData() | ||
57 | { | 57 | { | ||
58 | delete d; | 58 | delete d; | ||
59 | } | 59 | } | ||
60 | 60 | | |||
61 | QString PostFileData::randomString(int length) | 61 | QString PostFileData::randomString(int length) | ||
62 | { | 62 | { | ||
63 | if (length <= 0) { | 63 | if (length <= 0) { | ||
64 | return QString(); | 64 | return QString(); | ||
65 | } | 65 | } | ||
66 | 66 | | |||
67 | QString str; str.resize(length); | 67 | QString str; str.resize(length); | ||
68 | int i = 0; | 68 | int i = 0; | ||
69 | auto *generator = QRandomGenerator::global(); | ||||
69 | while (length--) { | 70 | while (length--) { | ||
70 | int r = qrand() % 62; | 71 | int r = generator->bounded(62); | ||
71 | r += 48; | 72 | r += 48; | ||
72 | if (r > 57) { | 73 | if (r > 57) { | ||
73 | r += 7; | 74 | r += 7; | ||
74 | } | 75 | } | ||
75 | if (r > 90) { | 76 | if (r > 90) { | ||
76 | r += 6; | 77 | r += 6; | ||
77 | } | 78 | } | ||
78 | str[i++] = char(r); | 79 | str[i++] = char(r); | ||
▲ Show 20 Lines • Show All 73 Lines • Show Last 20 Lines |