QXmppJingleIq.h 8.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331
  1. /*
  2. * Copyright (C) 2008-2012 The QXmpp developers
  3. *
  4. * Author:
  5. * Jeremy Lainé
  6. *
  7. * Source:
  8. * http://code.google.com/p/qxmpp
  9. *
  10. * This file is a part of QXmpp library.
  11. *
  12. * This library is free software; you can redistribute it and/or
  13. * modify it under the terms of the GNU Lesser General Public
  14. * License as published by the Free Software Foundation; either
  15. * version 2.1 of the License, or (at your option) any later version.
  16. *
  17. * This library is distributed in the hope that it will be useful,
  18. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  19. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  20. * Lesser General Public License for more details.
  21. *
  22. */
  23. #ifndef QXMPPJINGLEIQ_H
  24. #define QXMPPJINGLEIQ_H
  25. #include <QHostAddress>
  26. #include "QXmppIq.h"
  27. /// \brief The QXmppJinglePayloadType class represents a payload type
  28. /// as specified by XEP-0167: Jingle RTP Sessions and RFC 5245.
  29. ///
  30. class QXMPP_EXPORT QXmppJinglePayloadType
  31. {
  32. public:
  33. QXmppJinglePayloadType();
  34. unsigned char channels() const;
  35. void setChannels(unsigned char channels);
  36. unsigned int clockrate() const;
  37. void setClockrate(unsigned int clockrate);
  38. unsigned char id() const;
  39. void setId(unsigned char id);
  40. unsigned int maxptime() const;
  41. void setMaxptime(unsigned int maxptime);
  42. QString name() const;
  43. void setName(const QString &name);
  44. QMap<QString, QString> parameters() const;
  45. void setParameters(const QMap<QString, QString> &parameters);
  46. unsigned int ptime() const;
  47. void setPtime(unsigned int ptime);
  48. /// \cond
  49. void parse(const QDomElement &element);
  50. void toXml(QXmlStreamWriter *writer) const;
  51. /// \endcond
  52. bool operator==(const QXmppJinglePayloadType &other) const;
  53. private:
  54. unsigned char m_channels;
  55. unsigned int m_clockrate;
  56. unsigned char m_id;
  57. unsigned int m_maxptime;
  58. QString m_name;
  59. QMap<QString, QString> m_parameters;
  60. unsigned int m_ptime;
  61. };
  62. /// \brief The QXmppJingleCandidate class represents a transport candidate
  63. /// as specified by XEP-0176: Jingle ICE-UDP Transport Method.
  64. ///
  65. class QXMPP_EXPORT QXmppJingleCandidate
  66. {
  67. public:
  68. /// This enum is used to describe a candidate's type.
  69. enum Type
  70. {
  71. HostType, ///< Host candidate, a local address/port.
  72. PeerReflexiveType, ///< Peer-reflexive candidate,
  73. ///< the address/port as seen from the peer.
  74. ServerReflexiveType, ///< Server-reflexive candidate,
  75. ///< the address/port as seen by the STUN server
  76. RelayedType, ///< Relayed candidate, a candidate from
  77. ///< a TURN relay.
  78. };
  79. QXmppJingleCandidate();
  80. int component() const;
  81. void setComponent(int component);
  82. int foundation() const;
  83. void setFoundation(int foundation);
  84. QHostAddress host() const;
  85. void setHost(const QHostAddress &host);
  86. QString id() const;
  87. void setId(const QString &id);
  88. int network() const;
  89. void setNetwork(int network);
  90. quint16 port() const;
  91. void setPort(quint16 port);
  92. int priority() const;
  93. void setPriority(int priority);
  94. QString protocol() const;
  95. void setProtocol(const QString &protocol);
  96. QXmppJingleCandidate::Type type() const;
  97. void setType(QXmppJingleCandidate::Type);
  98. bool isNull() const;
  99. /// \cond
  100. void parse(const QDomElement &element);
  101. void toXml(QXmlStreamWriter *writer) const;
  102. static QXmppJingleCandidate::Type typeFromString(const QString &typeStr, bool *ok = 0);
  103. static QString typeToString(QXmppJingleCandidate::Type type);
  104. /// \endcond
  105. private:
  106. int m_component;
  107. int m_foundation;
  108. int m_generation;
  109. QHostAddress m_host;
  110. QString m_id;
  111. int m_network;
  112. quint16 m_port;
  113. QString m_protocol;
  114. int m_priority;
  115. QXmppJingleCandidate::Type m_type;
  116. };
  117. /// \brief The QXmppJingleIq class represents an IQ used for initiating media
  118. /// sessions as specified by XEP-0166: Jingle.
  119. ///
  120. /// \ingroup Stanzas
  121. class QXMPP_EXPORT QXmppJingleIq : public QXmppIq
  122. {
  123. public:
  124. /// This enum is used to describe a Jingle action.
  125. enum Action {
  126. ContentAccept,
  127. ContentAdd,
  128. ContentModify,
  129. ContentReject,
  130. ContentRemove,
  131. DescriptionInfo,
  132. SecurityInfo,
  133. SessionAccept,
  134. SessionInfo,
  135. SessionInitiate,
  136. SessionTerminate,
  137. TransportAccept,
  138. TransportInfo,
  139. TransportReject,
  140. TransportReplace,
  141. };
  142. /// \internal
  143. ///
  144. /// The QXmppJingleIq::Content class represents the "content" element of a
  145. /// QXmppJingleIq.
  146. class QXMPP_EXPORT Content
  147. {
  148. public:
  149. Content();
  150. QString creator() const;
  151. void setCreator(const QString &creator);
  152. QString name() const;
  153. void setName(const QString &name);
  154. QString senders() const;
  155. void setSenders(const QString &senders);
  156. // XEP-0167: Jingle RTP Sessions
  157. QString descriptionMedia() const;
  158. void setDescriptionMedia(const QString &media);
  159. void addPayloadType(const QXmppJinglePayloadType &payload);
  160. QList<QXmppJinglePayloadType> payloadTypes() const;
  161. void setPayloadTypes(const QList<QXmppJinglePayloadType> &payloadTypes);
  162. void addTransportCandidate(const QXmppJingleCandidate &candidate);
  163. QList<QXmppJingleCandidate> transportCandidates() const;
  164. QString transportUser() const;
  165. void setTransportUser(const QString &user);
  166. QString transportPassword() const;
  167. void setTransportPassword(const QString &password);
  168. /// \cond
  169. void parse(const QDomElement &element);
  170. void toXml(QXmlStreamWriter *writer) const;
  171. /// \endcond
  172. private:
  173. QString m_creator;
  174. QString m_disposition;
  175. QString m_name;
  176. QString m_senders;
  177. QString m_descriptionMedia;
  178. QString m_descriptionType;
  179. QString m_transportType;
  180. QString m_transportUser;
  181. QString m_transportPassword;
  182. QList<QXmppJinglePayloadType> m_payloadTypes;
  183. QList<QXmppJingleCandidate> m_transportCandidates;
  184. };
  185. /// \internal
  186. ///
  187. /// The QXmppJingleIq::Reason class represents the "reason" element of a
  188. /// QXmppJingleIq.
  189. class QXMPP_EXPORT Reason
  190. {
  191. public:
  192. enum Type {
  193. None,
  194. AlternativeSession,
  195. Busy,
  196. Cancel,
  197. ConnectivityError,
  198. Decline,
  199. Expired,
  200. FailedApplication,
  201. FailedTransport,
  202. GeneralError,
  203. Gone,
  204. IncompatibleParameters,
  205. MediaError,
  206. SecurityError,
  207. Success,
  208. Timeout,
  209. UnsupportedApplications,
  210. UnsupportedTransports,
  211. };
  212. Reason();
  213. QString text() const;
  214. void setText(const QString &text);
  215. Type type() const;
  216. void setType(Type type);
  217. /// \cond
  218. void parse(const QDomElement &element);
  219. void toXml(QXmlStreamWriter *writer) const;
  220. /// \endcond
  221. private:
  222. QString m_text;
  223. Type m_type;
  224. };
  225. QXmppJingleIq();
  226. Action action() const;
  227. void setAction(Action action);
  228. QString initiator() const;
  229. void setInitiator(const QString &initiator);
  230. QString responder() const;
  231. void setResponder(const QString &responder);
  232. QString sid() const;
  233. void setSid(const QString &sid);
  234. /// Returns a reference to the IQ's content element.
  235. Content& content() { return m_content; };
  236. /// Returns a const reference to the IQ's content element.
  237. const Content& content() const { return m_content; };
  238. /// Returns a reference to the IQ's reason element.
  239. Reason& reason() { return m_reason; };
  240. /// Returns a const reference to the IQ's reason element.
  241. const Reason& reason() const { return m_reason; };
  242. // XEP-0167: Jingle RTP Sessions
  243. bool ringing() const;
  244. void setRinging(bool ringing);
  245. /// \cond
  246. static bool isJingleIq(const QDomElement &element);
  247. /// \endcond
  248. protected:
  249. /// \cond
  250. void parseElementFromChild(const QDomElement &element);
  251. void toXmlElementFromChild(QXmlStreamWriter *writer) const;
  252. /// \endcond
  253. private:
  254. Action m_action;
  255. QString m_initiator;
  256. QString m_responder;
  257. QString m_sid;
  258. Content m_content;
  259. Reason m_reason;
  260. bool m_ringing;
  261. };
  262. #endif