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.

154 lines
5.8 KiB

​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
  1. /*
  2. * libjingle
  3. * Copyright 2006, 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. // LibjinglePlus is a class that connects to Google Talk, creates
  28. // some common tasks, and emits signals when things change
  29. #ifndef LIBJINGLEPLUS_H__
  30. #define LIBJINGLEPLUS_H__
  31. #include "talk/base/basicdefs.h"
  32. #include "talk/app/rosteritem.h"
  33. #include "talk/app/message.h"
  34. #include "talk/app/status.h"
  35. #include "talk/xmpp/xmppengine.h"
  36. #include "talk/base/scoped_ptr.h"
  37. class LibjinglePlusWorker;
  38. class LibjinglePlusNotify {
  39. public:
  40. virtual ~LibjinglePlusNotify() {}
  41. /* Libjingle+ works on its own thread. It will call WakeupMainThread
  42. * when it has something to report. The main thread should then wake up,
  43. * and call DoCallbacks on the LibjinglePlus object.
  44. *
  45. * This function gets called from libjingle+'s worker thread. All other
  46. * methods in LibjinglePlusNotify get called from the thread you call
  47. * DoCallbacks() on.
  48. *
  49. * If running on Windows, libjingle+ will use Windows messages to generate
  50. * callbacks from the main thread, and you don't need to do anything here.
  51. */
  52. virtual void WakeupMainThread() = 0;
  53. /* Connection */
  54. /* Called when the connection state changes */
  55. virtual void OnStateChange(buzz::XmppEngine::State) = 0;
  56. /* Called when the socket closes */
  57. virtual void OnSocketClose(int error_code) = 0;
  58. /* Called when XMPP is being sent or received. Used for debugging */
  59. virtual void OnXmppOutput(const std::string &output) = 0;
  60. virtual void OnXmppInput(const std::string &input) = 0;
  61. /* Presence */
  62. /* Called when someone's Status is updated */
  63. virtual void OnStatusUpdate(const buzz::Status &status) = 0;
  64. /* Called when a status update results in an error */
  65. virtual void OnStatusError(const buzz::XmlElement &stanza) = 0;
  66. /* Called with an IQ return code */
  67. virtual void OnIqDone(bool success, const buzz::XmlElement &stanza) = 0;
  68. /* Message */
  69. /* Called when a message comes in. */
  70. virtual void OnMessage(const buzz::XmppMessage &message) = 0;
  71. /* Roster */
  72. /* Called when we start refreshing the roster */
  73. virtual void OnRosterRefreshStarted() = 0;
  74. /* Called when we have the entire roster */
  75. virtual void OnRosterRefreshFinished() = 0;
  76. /* Called when an item on the roster is created or updated */
  77. virtual void OnRosterItemUpdated(const buzz::RosterItem &ri) = 0;
  78. /* Called when an item on the roster is removed */
  79. virtual void OnRosterItemRemoved(const buzz::RosterItem &ri) = 0;
  80. /* Subscriptions */
  81. virtual void OnRosterSubscribe(const buzz::Jid &jid) = 0;
  82. virtual void OnRosterUnsubscribe(const buzz::Jid &jid) = 0;
  83. virtual void OnRosterSubscribed(const buzz::Jid &jid) = 0;
  84. virtual void OnRosterUnsubscribed(const buzz::Jid &jid) = 0;
  85. };
  86. class LibjinglePlus
  87. {
  88. public:
  89. /* Provide the constructor with your interface. */
  90. LibjinglePlus(LibjinglePlusNotify *notify);
  91. ~LibjinglePlus();
  92. /* Logs in and starts doing stuff
  93. *
  94. * If cookie_auth is true, password must be a Gaia SID. Otherwise,
  95. * it should be the user's password
  96. */
  97. void Login(const std::string &username, const std::string &password,
  98. const std::string &machine_address, bool is_test, bool cookie_auth);
  99. /* Set Presence */
  100. void SendPresence(const buzz::Status & s);
  101. void SendDirectedPresence(const buzz::Jid & j, const buzz::Status & s);
  102. void SendDirectedMUCPresence(const buzz::Jid & j, const buzz::Status & s,
  103. const std::string &user_nick, const std::string &api_capability,
  104. const std::string &api_message, const std::string &role);
  105. /* Send Message */
  106. void SendXmppMessage(const buzz::XmppMessage & m);
  107. /* Send IQ */
  108. void SendXmppIq(const buzz::Jid &to_jid, bool is_get,
  109. const buzz::XmlElement *iq_element);
  110. /* Set Roster */
  111. void UpdateRosterItem(const buzz::Jid & jid, const std::string & name,
  112. const std::vector<std::string> & groups, buzz::GrType grt);
  113. void RemoveRosterItem(const buzz::Jid &jid);
  114. /* Call this from the thread you want to receive callbacks on. Typically, this will be called
  115. * after your WakeupMainThread() notify function is called.
  116. *
  117. * On Windows, libjingle+ will trigger its callback from the Windows message loop, and
  118. * you needn't call this yourself.
  119. */
  120. void DoCallbacks();
  121. private:
  122. void LoginInternal(const std::string &jid, const std::string &password,
  123. const std::string &machine_address, bool is_test);
  124. LibjinglePlusWorker *worker_;
  125. };
  126. #endif // LIBJINGLE_PLUS_H__