xml_layer.h 11.9 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186
/*
 * 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 <http://www.gnu.org/licenses/>.
 *
 * 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 <QObject>
#include <QXmlReader>
#include <QXmlStreamReader>

#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<qint64> &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<qint64> &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);

187 188 189 190 191 192 193 194 195 196 197
	/*!
	 * @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<Files::File> &fileList);

198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258
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.
	 */
259
	bool parseGetListOfMessagesResponse(enum MessageDb::MessageType messageType,
260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327
	    const QByteArray &xmlData, QList<Messages::Message> &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<Files::File> &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<Files::File> &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,
328
	    enum MessageDb::MessageType messageType);
329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408

	/*!
	 * @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<Messages::Event> &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_ */