5 #include "multipartformdataparser_p.h"
15 qCWarning(CUTELYST_MULTIPART) <<
"Parsing sequential body is not supported" << body;
19 int start = contentType.
indexOf(u
"boundary=");
21 qCWarning(CUTELYST_MULTIPART) <<
"No boundary match" << contentType;
27 const int len = contentType.
length();
30 for (
int i = start, quotes = 0; i < len; ++i) {
31 const QChar ch = contentType.
at(i);
33 if ((quotes == 0 && i > start) || ++quotes == 2) {
36 }
else if (ch == u
';') {
44 qCWarning(CUTELYST_MULTIPART) <<
"Boundary match was empty" << contentType;
49 if (bufferSize < 1024) {
52 char *buffer =
new char[bufferSize];
54 ret = MultiPartFormDataParserPrivate::execute(buffer, bufferSize, body, boundary);
68 qint64 contentLength = body->
size();
70 int boundarySize = boundary.
size();
71 ParserState state = FindBoundary;
74 while (pos < contentLength) {
75 qint64 len = body->
read(buffer + bufferSkip, bufferSize - bufferSkip);
77 qCWarning(CUTELYST_MULTIPART) <<
"Error while reading POST body" << body->
errorString();
88 i += findBoundary(buffer + i, len - i, matcher, boundarySize, state);
92 if (buffer[i] !=
'\r') {
96 state = EndBoundaryLF;
99 if (buffer[i] !=
'\n') {
103 state = StartHeaders;
106 if (headerLine.
isEmpty() && buffer[i] ==
'\r') {
110 char *pch =
static_cast<char *
>(memchr(buffer + i,
'\r', len - i));
112 headerLine.
append(buffer + i, len - i);
115 headerLine.
append(buffer + i, pch - buffer - i);
117 state = FinishHeader;
122 if (buffer[i] ==
'\n') {
123 int dotdot = headerLine.
indexOf(
':');
127 state = StartHeaders;
134 if (buffer[i] ==
'\n') {
143 startOffset = pos - len + i;
146 i += findBoundary(buffer + i, len - i, matcher, boundarySize, state);
148 if (state == EndBoundaryCR) {
150 const qint64 endOffset = pos - len + i - boundarySize - 1;
151 auto upload =
new Upload(
new UploadPrivate(body, headers, startOffset, endOffset));
158 bufferSkip = boundarySize - 1;
159 memmove(buffer, buffer + len - bufferSkip, bufferSkip);
171 int MultiPartFormDataParserPrivate::findBoundary(
char *buffer,
int len,
const QByteArrayMatcher &matcher,
int boundarySize, MultiPartFormDataParserPrivate::ParserState &state)
173 int i = matcher.
indexIn(buffer, len);
177 state = EndBoundaryCR;
178 return i + boundarySize - 1;
183 #include "moc_multipartformdataparser_p.cpp"
Cutelyst Upload handles file upload request
The Cutelyst namespace holds all public Cutelyst API.
QByteArray & append(char ch)
int indexOf(char ch, int from) const const
bool isEmpty() const const
QByteArray left(int len) const const
QByteArray mid(int pos, int len) const const
QByteArray & prepend(char ch)
QByteArray trimmed() const const
int indexIn(const QByteArray &ba, int from) const const
char toLatin1() const const
QString errorString() const const
virtual bool isSequential() const const
qint64 read(char *data, qint64 maxSize)
virtual qint64 size() const const
QString fromLatin1(const char *str, int size)
QString fromUtf8(const char *str, int size)
QChar at(qsizetype n) const const
qsizetype indexOf(QChar c, qsizetype from, Qt::CaseSensitivity cs) const const
void append(const T &value)