QXmpp  Version: 1.4.0
QXmppUtils.h
1 /*
2  * Copyright (C) 2008-2021 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 
43 class QXMPP_EXPORT QXmppUtils
44 {
45 public:
46  // XEP-0082: XMPP Date and Time Profiles
47  static QDateTime datetimeFromString(const QString& str);
48  static QString datetimeToString(const QDateTime& dt);
49  static int timezoneOffsetFromString(const QString& str);
50  static QString timezoneOffsetToString(int secs);
51 
52  static QString jidToDomain(const QString& jid);
53  static QString jidToResource(const QString& jid);
54  static QString jidToUser(const QString& jid);
55  static QString jidToBareJid(const QString& jid);
56 
57  static quint32 generateCrc32(const QByteArray& input);
58  static QByteArray generateHmacMd5(const QByteArray& key, const QByteArray& text);
59  static QByteArray generateHmacSha1(const QByteArray& key, const QByteArray& text);
60  static int generateRandomInteger(int N);
61  static QByteArray generateRandomBytes(int length);
62  static QString generateStanzaUuid();
63  static QString generateStanzaHash(int length = 36);
64 };
65 
66 void helperToXmlAddAttribute(QXmlStreamWriter* stream, const QString& name,
67  const QString& value);
68 void helperToXmlAddTextElement(QXmlStreamWriter* stream, const QString& name,
69  const QString& value);
70 
71 #endif // QXMPPUTILS_H
The QXmppUtils class contains static utility functions.
Definition: QXmppUtils.h:43