5 #include "multipartformdataparser_p.h" 15 qCWarning(CUTELYST_MULTIPART) <<
"Parsing sequential body is not supported" << body;
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) {
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"
int indexOf(QChar ch, int from, Qt::CaseSensitivity cs) const const
void append(const T &value)
QByteArray trimmed() const const
int indexIn(const QByteArray &ba, int from) const const
QString errorString() const const
bool isEmpty() const const
virtual bool isSequential() const const
Cutelyst Upload handles file upload request
int indexOf(char ch, int from) const const
QString fromUtf8(const char *str, int size)
virtual qint64 size() const const
QByteArray & prepend(char ch)
qint64 read(char *data, qint64 maxSize)
The Cutelyst namespace holds all public Cutelyst API.
QByteArray mid(int pos, int len) const const
QByteArray & append(char ch)
char toLatin1() const const
QByteArray left(int len) const const
const QChar at(int position) const const
QString fromLatin1(const char *str, int size)