QXmppIbbIq.cpp 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176
  1. /*
  2. * Copyright (C) 2008-2012 The QXmpp developers
  3. *
  4. * Authors:
  5. * Manjeet Dahiya
  6. * Jeremy Lainé
  7. *
  8. * Source:
  9. * http://code.google.com/p/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. #include <QDomElement>
  25. #include <QXmlStreamWriter>
  26. #include "QXmppConstants.h"
  27. #include "QXmppIbbIq.h"
  28. QXmppIbbOpenIq::QXmppIbbOpenIq() : QXmppIq(QXmppIq::Set), m_block_size(1024)
  29. {
  30. }
  31. long QXmppIbbOpenIq::blockSize() const
  32. {
  33. return m_block_size;
  34. }
  35. void QXmppIbbOpenIq::setBlockSize( long block_size )
  36. {
  37. m_block_size = block_size;
  38. }
  39. QString QXmppIbbOpenIq::sid() const
  40. {
  41. return m_sid;
  42. }
  43. void QXmppIbbOpenIq::setSid( const QString &sid )
  44. {
  45. m_sid = sid;
  46. }
  47. /// \cond
  48. bool QXmppIbbOpenIq::isIbbOpenIq(const QDomElement &element)
  49. {
  50. QDomElement openElement = element.firstChildElement("open");
  51. return openElement.namespaceURI() == ns_ibb;
  52. }
  53. void QXmppIbbOpenIq::parseElementFromChild(const QDomElement &element)
  54. {
  55. QDomElement openElement = element.firstChildElement("open");
  56. m_sid = openElement.attribute( "sid" );
  57. m_block_size = openElement.attribute( "block-size" ).toLong();
  58. }
  59. void QXmppIbbOpenIq::toXmlElementFromChild(QXmlStreamWriter *writer) const
  60. {
  61. writer->writeStartElement("open");
  62. writer->writeAttribute( "xmlns",ns_ibb);
  63. writer->writeAttribute( "sid",m_sid);
  64. writer->writeAttribute( "block-size",QString::number(m_block_size) );
  65. writer->writeEndElement();
  66. }
  67. /// \endcond
  68. QXmppIbbCloseIq::QXmppIbbCloseIq() : QXmppIq(QXmppIq::Set)
  69. {
  70. }
  71. QString QXmppIbbCloseIq::sid() const
  72. {
  73. return m_sid;
  74. }
  75. void QXmppIbbCloseIq::setSid( const QString &sid )
  76. {
  77. m_sid = sid;
  78. }
  79. /// \cond
  80. bool QXmppIbbCloseIq::isIbbCloseIq(const QDomElement &element)
  81. {
  82. QDomElement openElement = element.firstChildElement("close");
  83. return openElement.namespaceURI() == ns_ibb;
  84. }
  85. void QXmppIbbCloseIq::parseElementFromChild(const QDomElement &element)
  86. {
  87. QDomElement openElement = element.firstChildElement("close");
  88. m_sid = openElement.attribute( "sid" );
  89. }
  90. void QXmppIbbCloseIq::toXmlElementFromChild(QXmlStreamWriter *writer) const
  91. {
  92. writer->writeStartElement("close");
  93. writer->writeAttribute( "xmlns",ns_ibb);
  94. writer->writeAttribute( "sid",m_sid);
  95. writer->writeEndElement();
  96. }
  97. /// \endcond
  98. QXmppIbbDataIq::QXmppIbbDataIq() : QXmppIq( QXmppIq::Set ), m_seq(0)
  99. {
  100. }
  101. quint16 QXmppIbbDataIq::sequence() const
  102. {
  103. return m_seq;
  104. }
  105. void QXmppIbbDataIq::setSequence( quint16 seq )
  106. {
  107. m_seq = seq;
  108. }
  109. QString QXmppIbbDataIq::sid() const
  110. {
  111. return m_sid;
  112. }
  113. void QXmppIbbDataIq::setSid( const QString &sid )
  114. {
  115. m_sid = sid;
  116. }
  117. QByteArray QXmppIbbDataIq::payload() const
  118. {
  119. return m_payload;
  120. }
  121. void QXmppIbbDataIq::setPayload( const QByteArray &data )
  122. {
  123. m_payload = data;
  124. }
  125. /// \cond
  126. bool QXmppIbbDataIq::isIbbDataIq(const QDomElement &element)
  127. {
  128. QDomElement dataElement = element.firstChildElement("data");
  129. return dataElement.namespaceURI() == ns_ibb;
  130. }
  131. void QXmppIbbDataIq::parseElementFromChild(const QDomElement &element)
  132. {
  133. QDomElement dataElement = element.firstChildElement("data");
  134. m_sid = dataElement.attribute( "sid" );
  135. m_seq = dataElement.attribute( "seq" ).toLong();
  136. m_payload = QByteArray::fromBase64( dataElement.text().toLatin1() );
  137. }
  138. void QXmppIbbDataIq::toXmlElementFromChild(QXmlStreamWriter *writer) const
  139. {
  140. writer->writeStartElement("data");
  141. writer->writeAttribute( "xmlns",ns_ibb);
  142. writer->writeAttribute( "sid",m_sid);
  143. writer->writeAttribute( "seq",QString::number(m_seq) );
  144. writer->writeCharacters( m_payload.toBase64() );
  145. writer->writeEndElement();
  146. }
  147. /// \endcond