QXmpp  Version:1.3.2
QXmppUtils.h
1 /*
2  * Copyright (C) 2008-2020 The QXmpp developers
3  *
4  * Authors:
5  * Manjeet Dahiya
6  * Jeremy LainĂ©
7  *
8  * Source:
9  * https://github.com/qxmpp-project/qxmpp
10  *
11  * This file is a part of QXmpp library.
12  *
13  * This library is free software; you can redistribute it and/or
14  * modify it under the terms of the GNU Lesser General Public
15  * License as published by the Free Software Foundation; either
16  * version 2.1 of the License, or (at your option) any later version.
17  *
18  * This library is distributed in the hope that it will be useful,
19  * but WITHOUT ANY WARRANTY; without even the implied warranty of
20  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
21  * Lesser General Public License for more details.
22  *
23  */
24 
25 #ifndef QXMPPUTILS_H
26 #define QXMPPUTILS_H
27 
28 // forward declarations of QXmlStream* classes will not work on Mac, we need to
29 // include the whole header.
30 // See http://lists.trolltech.com/qt-interest/2008-07/thread00798-0.html
31 // for an explanation.
32 #include "QXmppGlobal.h"
33 
34 #include <QXmlStreamWriter>
35 
36 class QByteArray;
37 class QDateTime;
38 class QDomElement;
39 class QString;
40 class QStringList;
41 
44 class QXMPP_EXPORT QXmppUtils
45 {
46 public:
47  // XEP-0082: XMPP Date and Time Profiles
48  static QDateTime datetimeFromString(const QString& str);
49  static QString datetimeToString(const QDateTime& dt);
50  static int timezoneOffsetFromString(const QString& str);
51  static QString timezoneOffsetToString(int secs);
52 
53  static QString jidToDomain(const QString& jid);
54  static QString jidToResource(const QString& jid);
55  static QString jidToUser(const QString& jid);
56  static QString jidToBareJid(const QString& jid);
57 
58  static quint32 generateCrc32(const QByteArray& input);
59  static QByteArray generateHmacMd5(const QByteArray& key, const QByteArray& text);
60  static QByteArray generateHmacSha1(const QByteArray& key, const QByteArray& text);
61  static int generateRandomInteger(int N);
62  static QByteArray generateRandomBytes(int length);
63  static QString generateStanzaUuid();
64  static QString generateStanzaHash(int length = 36);
65 };
66 
67 void helperToXmlAddAttribute(QXmlStreamWriter* stream, const QString& name,
68  const QString& value);
69 void helperToXmlAddTextElement(QXmlStreamWriter* stream, const QString& name,
70  const QString& value);
71 
72 #endif // QXMPPUTILS_H
QXmppUtils
The QXmppUtils class contains static utility functions.
Definition: QXmppUtils.h:44