/* * Copyright (C) 2014-2016 CZ.NIC * * This program 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. * * This program 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 this program. If not, see . * * In addition, as a special exception, the copyright holders give * permission to link the code of portions of this program with the * OpenSSL library under certain conditions as described in each * individual source file, and distribute linked combinations including * the two. */ #ifndef _XML_LAYER_H_ #define _XML_LAYER_H_ #include #include #include #include "src/net/isds_session.h" #include "src/net/net_layer.h" #include "src/messages.h" #include "src/accounts.h" #include "src/files.h" #include "src/net/db_wrapper.h" /* * Class XmlLayer realizes XML layer over netmanager. * Creates SOAP envelopes of services and parse SOAP responses. * Class is initialised and used in the IsdsWrapper class (isds_wrapper.h) * Requires class DbWrapper (db_wrapper.h) for storing of response data to db. * Requires class NetLayer (net_layer.h) for sending of POST/GET requests. */ class XmlLayer : public QObject { Q_OBJECT public: XmlLayer(QObject *parent = 0); ~XmlLayer(void); /*! * @brief Connect to databox on ISDS server. * * @param[in] ctx - account isds context structure. * @return true if success. */ bool isdsConnectToDatabox(IsdsContext &ctx); /*! * @brief Verify connection to ISDS is alive and server is responding. * * @param[in] ctx - account isds context structure. * @return true if success. */ bool isdsPingServer(IsdsContext &ctx); /*! * @brief Get password expiration info from server. * * @param[in] ctx - account isds context structure. * @return true if success. */ bool isdsGetPasswordExpiration(IsdsContext &ctx); /*! * @brief Get info about databox owner and his box. * * @param[in] ctx - account isds context structure. * @return true if success. */ bool isdsGetOwnerInfoFromLogin(IsdsContext &ctx); /*! * @brief Get user info. * * @param[in] ctx - account isds context structure. * @return true if success. */ bool isdsGetUserInfoFromLogin(IsdsContext &ctx); /*! * @brief Get list of incoming (addressed to you) messages. * * @param[in] ctx - account isds context structure. * @param[in] only90Days - true = download messages without data sejf * false = all messages include also data sejf. * @param[out] msgIds - message id list. * @return true if success. */ bool isdsGetReceivedMessageList(IsdsContext &ctx, bool only90Days, QList &msgIds); /*! * @brief Get list of outcoming (addressed from you) messages. * * @param[in] ctx - account isds context structure. * @param[in] only90Days - true = download messages without data sejf * false = all messages include also data sejf. * @param[out] msgIds - message id list. * @return true if success. */ bool isdsGetSentMessageList(IsdsContext &ctx, bool only90Days, QList &msgIds); /*! * @brief Get complete received message by ID without cms and timestamp. * * @param[in] ctx - account isds context structure. * @param[in] msgID - message ID. * @return true if success. */ bool isdsGetCompleteMsgWithoutCms(IsdsContext &ctx, qint64 msgID); /*! * @brief Get complete sent message by ID with cms and timestamp. * * @param[in] ctx - account isds context structure. * @param[in] msgID - message ID. * @return true if success. */ bool isdsGetCompleteSentMsgWithCms(IsdsContext &ctx, qint64 msgID); /*! * @brief Get message delivery info without cms and timestamp. * * @param[in] ctx - account isds context structure. * @param[in] msgID - message ID. * @return true if success. */ bool isdsGetMsgDeliveryInfoWithoutCms(IsdsContext &ctx, qint64 msgID); /*! * @brief Get message author. * * @param[in] ctx - account isds context structure. * @param[in] msgID - message ID. * @return true if success. */ bool isdsGetMsgAuthorInfo(IsdsContext &ctx, qint64 msgID); /*! * @brief Mark message as downloaded on ISDS. * * @param[in] ctx isds context structure. * @param[in] msgID message ID. */ bool isdsMarkMsgAsDownloaded(IsdsContext &ctx, qint64 msgID); /*! * @brief Change password in ISDS. * * @param[in] ctx isds context structure. * @param[in] newPwd new password. */ bool isdsChangePassword(IsdsContext &ctx, const QString &newPwd); /*! * @brief Send SMS for OTP login method. * * @param[in] ctx - account isds context structure. * @return true if success. */ bool isdsSendSMS(IsdsContext &ctx); /*! * @brief Logout OTP account from ISDS. * * @param[in] ctx - account isds context structure. * @return true if success. */ bool isdsLogoutOtp(IsdsContext &ctx); /*! * @brief Parse completeMessageParse XML. * * @param[in] xml - xml Data for parsing. * @param[out] msg - envelope message structure. * @param[out] fileList - list of files structure. * @return true if success. */ bool completeMessageParse(QXmlStreamReader &xml, Messages::Message &msg, QList &fileList); private: /*! * @brief Create xml envelope. * * @param[in] xmlBodyContent - content body. * @return Xml string with envelope. */ QString createEnvelope(const QString &xmlBodyContent); /*! * @brief Get aproximatle file size from length of base64 string. * * @param[in] userName - account username. * @return true if success. */ QString getFileSizeFromBase64(int fileLen); /*! * @brief Get icon filename from extension of attachmnet filename. * * @param[in] fileName - filename with ext. * @return true icon filename. */ QString getFileIconFromFileName(QString fileName); /*! * @brief Parse dmStatus from XML response. * * @param[in] xmlData - xml Data for parsing. * @param[out] txt - error description if something failed. * @return true if login success. */ bool parseDmStatusFromXml(const QByteArray &xmlData, QString &txt); /*! * @brief Parse dbStatus from XML response. * * @param[in] xmlData - xml Data for parsing. * @param[out] txt - error description if something failed. * @return true if login success. */ bool parseDbStatusFromXml(const QByteArray &xmlData, QString &txt); /*! * @brief Parse loginResponse XML. * * @param[in] xmlData - xml Data for parsing. * @param[out] txt - error description if something failed. * @return true if login success. */ bool parseLoginResponse(const QByteArray &xmlData, QString &txt); /*! * @brief Parse getListOfMessagesResponse XML. * * @param[in] messageType - message type (sent/received). * @param[in] xmlData - xml Data for parsing. * @param[out] txt - error description if something failed. * @return true if success. */ bool parseGetListOfMessagesResponse(enum MessageDb::MessageType messageType, const QByteArray &xmlData, QList &messages, QString &txt); /*! * @brief Parse messageDownloadResponse XML. * * @param[in] xml - xml Data for parsing. * @param[out] msg - envelope message structure. * @param[out] fileList - list of files structure. * @param[out] txt - error description if something failed. * @return true if success. */ bool parseMessageDownloadResponse(const QByteArray &xmlData, Messages::Message &msg, QList &fileList, QString &txt); /*! * @brief Parse SignedSendMessageDownloadResponse XML. * * @param[in] xml - xml Data for parsing. * @param[out] msg - envelope message structure. * @param[out] fileList - list of files structure. * @param[out] txt - error description if something failed. * @return true if success. */ bool parseSignedSentMessageDownloadResponse(const QByteArray &xmlData, Messages::Message &msg, QList &fileList, QString &txt); /*! * @brief Parse getOwnerInfoFromLogin XML. * * @param[in] content - xml Data for parsing. * @param[out] accountInfo - account info structures. * @param[out] txt - error description if something failed. * @return true if success. */ bool parseGetOwnerInfoFromLogin(const QByteArray &xmlData, DbWrapper::AccountInfo &accountInfo, QString &txt); /*! * @brief Parse getOwnerInfoFromLogin XML. * * @param[in] content - xml Data for parsing. * @param[out] userInfo - user info structure. * @param[out] txt - error description if something failed. * @return true if success. */ bool parseGetUserInfoFromLogin(const QByteArray &xmlData, DbWrapper::UserInfo &userInfo, QString &txt); /*! * @brief Parse getPasswordInfo XML. * * @param[in] content - xml Data for parsing. * @param[out] expirDate - expiration date of password. * @param[out] txt - error description if something failed. * @return true if success. */ bool parseGetPasswordInfo(const QByteArray &xmlData, QString &expirDate, QString &txt); /*! * @brief Parse msgEnvelopeParse XML. * * @param[in] xml - xml Data for parsing. * @param[in] messageType - message type. * @return Message envelope structure. */ Messages::Message msgEnvelopeParse(QXmlStreamReader &xml, enum MessageDb::MessageType messageType); /*! * @brief Parse parse file XML. * * @param[in] xml - xml Data for parsing. * @param[in] msgId - message id. * @param[in] downloadDate - datetime when complete message was downloaded. * @return File structure. */ Files::File parseFile(QXmlStreamReader &xml, const qint64 msgId, const QString &downloadDate); /*! * @brief Parse dbOwnerInfoParse XML. * * @param[in] xml - xml Data for parsing. * @param[out] accountInfo - account info structures. * @return true if success. */ bool dbOwnerInfoParse(QXmlStreamReader &xml, DbWrapper::AccountInfo &accountInfo); /*! * @brief Parse dbUserInfoParse XML. * * @param[in] xml - xml Data for parsing. * @param[out] userInfo - user info structure. * @param[out] txt - error description if something failed. * @return true if success. */ bool dbUserInfoParse(QXmlStreamReader &xml, DbWrapper::UserInfo &userInfo); /*! * @brief Parse dbUserInfoParse XML. * * @param[in] xmlData - xml Data for parsing. * @param[out] userType - author type string. * @param[out] authorName - author name string. * @param[out] txt - error description if something failed. * @return true if success. */ bool parseGetAuthorInfo(const QByteArray &xmlData, QString &userType, QString &authorName, QString &txt); /*! * @brief Parse msgDeliveryInfo XML. * * @param[in] xmlData - xml Data for parsing. * @param[out] eventList - list of message events. * @param[out] txt - error description if something failed. * @return true if success. */ bool parseGetMsgDeliveryInfoResponse(const QByteArray &xmlData, QList &eventList, QString &txt); /*! * @brief Parse event from XML. * * @param[in] xml - xml Data for parsing. * @return Event structure. */ Messages::Event parseEvent(QXmlStreamReader &xml); /*! * @brief Instance of NetLayer class (net_layer.h). * * Object NetLayer realizes POST/GET requests and net management. */ NetLayer m_netLayer; /*! * @brief Instance of DbWrapper class (db_wrapper.h). * * Object DbWrapper stores response data to database. */ DbWrapper m_dbWrapper; }; #endif /* _XML_LAYER_H_ */