Skip to content
Snippets Groups Projects
Commit 97edd298 authored by Langella Olivier's avatar Langella Olivier
Browse files

mimeparser for mascot

parent 1ec7aea3
No related branches found
No related tags found
No related merge requests found
/**
* \file /input/mascot/mimeparser.cpp
* \date 17/2/2018
* \author Olivier Langella
* \brief basic mime multipart parser
*/
/*******************************************************************************
* Copyright (c) 2018 Olivier Langella <olivier.langella@u-psud.fr>.
*
* This file is part of XTPcpp.
*
* XTPcpp 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.
*
* XTPcpp 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 XTPcpp. If not, see <http://www.gnu.org/licenses/>.
*
* Contributors:
* Olivier Langella <olivier.langella@u-psud.fr> - initial API and implementation
******************************************************************************/
#include "mimeparser.h"
#include <QRegExp>
MimeParser::MimeParser(QIODevice * p_inputstream) {
_p_inputstream = p_inputstream;
}
bool MimeParser::open() {
_p_inputstream->open(QIODevice::ReadOnly);
_real_in = new QTextStream(_p_inputstream);
}
bool MimeParser::close() {
if (_real_in !=nullptr) {
delete _real_in;
_real_in =nullptr;
}
if (_p_inputstream !=nullptr) {
_p_inputstream->close();
delete _p_inputstream;
_p_inputstream =nullptr;
}
}
bool MimeParser::goToFirstFile() {
/*
MIME-Version: 1.0 (Generated by Mascot version 1.0)
Content-Type: multipart/mixed; boundary=gc0p4Jq0M2Yt08jU534c0p
--gc0p4Jq0M2Yt08jU534c0p
Content-Type: application/x-Mascot; name="parameters"
*/
QRegExp regexp_boundary("^Content-Type:\\smultipart/mixed;\\sboundary=(.*)$");
while(!_real_in->atEnd()) {
QString line = _real_in->readLine();
if (regexp_boundary.exactMatch(line)) {
QStringList boundary_list = regexp_boundary.capturedTexts();
_boundary = boundary_list[1];
break;
}
}
}
bool MimeParser::goToNextFile() {
}
const QString & MimeParser::getCurrentFileName() {
return _current_file_name;
}
QTextStream & MimeParser::getCurrentTextStream() {
}
/**
* \file /input/mascot/mimeparser.h
* \date 17/2/2018
* \author Olivier Langella
* \brief basic mime multipart parser
*/
/*******************************************************************************
* Copyright (c) 2018 Olivier Langella <olivier.langella@u-psud.fr>.
*
* This file is part of XTPcpp.
*
* XTPcpp 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.
*
* XTPcpp 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 XTPcpp. If not, see <http://www.gnu.org/licenses/>.
*
* Contributors:
* Olivier Langella <olivier.langella@u-psud.fr> - initial API and implementation
******************************************************************************/
#ifndef MIMEPARSER_H
#define MIMEPARSER_H
#include <QIODevice>
#include <QTextStream>
class MimeParser
{
public:
MimeParser(QIODevice * p_inputstream);
bool open();
bool close();
bool goToFirstFile();
bool goToNextFile();
const QString & getCurrentFileName();
QTextStream & getCurrentTextStream();
private:
QString _current_file_name;
QIODevice * _p_inputstream = nullptr;
QTextStream * _real_in = nullptr;
QString _boundary;
};
#endif // MIMEPARSER_H
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment