You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

124 lines
4.2 KiB

​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
  1. /*
  2. * libjingle
  3. * Copyright 2004--2005, Google Inc.
  4. *
  5. * Redistribution and use in source and binary forms, with or without
  6. * modification, are permitted provided that the following conditions are met:
  7. *
  8. * 1. Redistributions of source code must retain the above copyright notice,
  9. * this list of conditions and the following disclaimer.
  10. * 2. Redistributions in binary form must reproduce the above copyright notice,
  11. * this list of conditions and the following disclaimer in the documentation
  12. * and/or other materials provided with the distribution.
  13. * 3. The name of the author may not be used to endorse or promote products
  14. * derived from this software without specific prior written permission.
  15. *
  16. * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
  17. * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
  18. * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO
  19. * EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
  20. * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
  21. * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
  22. * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
  23. * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
  24. * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
  25. * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  26. */
  27. #include "talk/xmpp/constants.h"
  28. #include "talk/examples/call/mucinviterecvtask.h"
  29. namespace buzz {
  30. const char* types[] = {
  31. "unknown",
  32. "audio",
  33. "video",
  34. };
  35. const char* statuses[] = {
  36. "unknown",
  37. "sendrecv",
  38. "sendonly",
  39. "recvonly",
  40. "inactive",
  41. };
  42. const char*
  43. AvailableMediaEntry::TypeAsString(type_t type) {
  44. // The values of the constants have been chosen such that this is correct.
  45. return types[type];
  46. }
  47. const char*
  48. AvailableMediaEntry::StatusAsString(status_t status) {
  49. // The values of the constants have been chosen such that this is correct.
  50. return statuses[status];
  51. }
  52. int bodytext_to_array_pos(const XmlElement* elem, const char* array[],
  53. int len, int defval = -1) {
  54. if (elem) {
  55. const std::string& body(elem->BodyText());
  56. for (int i = 0; i < len; ++i) {
  57. if (body == array[i]) {
  58. // Found it.
  59. return i;
  60. }
  61. }
  62. }
  63. // If we get here, it's not any value in the array.
  64. return defval;
  65. }
  66. bool
  67. MucInviteRecvTask::HandleStanza(const XmlElement* stanza) {
  68. // Figuring out that we want to handle this is a lot of the work of
  69. // actually handling it, so we handle it right here instead of queueing it.
  70. const XmlElement* xstanza;
  71. const XmlElement* invite;
  72. if (stanza->Name() != QN_MESSAGE) return false;
  73. xstanza = stanza->FirstNamed(QN_MUC_USER_X);
  74. if (!xstanza) return false;
  75. invite = xstanza->FirstNamed(QN_MUC_USER_INVITE);
  76. if (!invite) return false;
  77. // Else it's an invite and we definitely want to handle it. Parse the
  78. // available-media, if any.
  79. std::vector<AvailableMediaEntry> v;
  80. const XmlElement* avail =
  81. invite->FirstNamed(QN_GOOGLE_MUC_USER_AVAILABLE_MEDIA);
  82. if (avail) {
  83. for (const XmlElement* entry = avail->FirstNamed(QN_GOOGLE_MUC_USER_ENTRY);
  84. entry;
  85. entry = entry->NextNamed(QN_GOOGLE_MUC_USER_ENTRY)) {
  86. AvailableMediaEntry tmp;
  87. // In the interest of debugging, we accept as much valid-looking data
  88. // as we can.
  89. tmp.label = atoi(entry->Attr(QN_LABEL).c_str());
  90. tmp.type = static_cast<AvailableMediaEntry::type_t>(
  91. bodytext_to_array_pos(
  92. entry->FirstNamed(QN_GOOGLE_MUC_USER_TYPE),
  93. types,
  94. sizeof(types)/sizeof(const char*),
  95. AvailableMediaEntry::TYPE_UNKNOWN));
  96. tmp.status = static_cast<AvailableMediaEntry::status_t>(
  97. bodytext_to_array_pos(
  98. entry->FirstNamed(QN_GOOGLE_MUC_USER_STATUS),
  99. statuses,
  100. sizeof(statuses)/sizeof(const char*),
  101. AvailableMediaEntry::STATUS_UNKNOWN));
  102. v.push_back(tmp);
  103. }
  104. }
  105. SignalInviteReceived(Jid(invite->Attr(QN_FROM)), Jid(stanza->Attr(QN_FROM)),
  106. v);
  107. return true;
  108. }
  109. int
  110. MucInviteRecvTask::ProcessStart() {
  111. // We never queue anything so we are always blocked.
  112. return STATE_BLOCKED;
  113. }
  114. }