diff --git a/src/input/mascot/mimeparser.cpp b/src/input/mascot/mimeparser.cpp new file mode 100644 index 0000000000000000000000000000000000000000..634959866e41d4115c4c0348fa806f07684f5e46 --- /dev/null +++ b/src/input/mascot/mimeparser.cpp @@ -0,0 +1,80 @@ +/** + * \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() { +} diff --git a/src/input/mascot/mimeparser.h b/src/input/mascot/mimeparser.h new file mode 100644 index 0000000000000000000000000000000000000000..641d418bd04f92c4fbb757645264a6312672dc76 --- /dev/null +++ b/src/input/mascot/mimeparser.h @@ -0,0 +1,54 @@ +/** + * \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