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.

119 lines
3.4 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. #include <iostream>
  28. #include <string>
  29. #include "talk/base/thread.h"
  30. #include "talk/libjingle-plus/libjingleplus.h"
  31. #include "talk/libjingle-plus/testutil/libjingleplus_test_notifier.h"
  32. #if defined(_MSC_VER) && (_MSC_VER < 1400)
  33. void __cdecl std::_Throw(const std::exception &) {}
  34. std::_Prhand std::_Raise_handler =0;
  35. #endif
  36. void SetConsoleEcho(bool on) {
  37. #ifdef WIN32
  38. HANDLE hIn = GetStdHandle(STD_INPUT_HANDLE);
  39. if ((hIn == INVALID_HANDLE_VALUE) || (hIn == NULL))
  40. return;
  41. DWORD mode;
  42. if (!GetConsoleMode(hIn, &mode))
  43. return;
  44. if (on) {
  45. mode = mode | ENABLE_ECHO_INPUT;
  46. } else {
  47. mode = mode & ~ENABLE_ECHO_INPUT;
  48. }
  49. SetConsoleMode(hIn, mode);
  50. #else
  51. if (on)
  52. system("stty echo");
  53. else
  54. system("stty -echo");
  55. #endif
  56. }
  57. int main (int argc, char **argv)
  58. {
  59. std::string username;
  60. std::string password;
  61. bool gaia = false;
  62. for (int i = 1; i < argc; i++) {
  63. if (!strcmp(argv[i], "-gaia"))
  64. gaia = true;
  65. }
  66. std::cout << "Username: ";
  67. std::cin >> username;
  68. std::cout << (gaia ? "Gaia cookie: " : "Password: ");
  69. SetConsoleEcho(false);
  70. std::cin >> password;
  71. SetConsoleEcho(true);
  72. // Create a LibjinglePlus object and give it the notifier interface
  73. LibjinglePlus ljp(new Notifier);
  74. // Login
  75. ljp.Login(username, password, "talk.google.com", false, gaia);
  76. buzz::Status s;
  77. s.set_available(true);
  78. s.set_show(buzz::Status::SHOW_ONLINE);
  79. s.set_status("I'm online.");
  80. buzz::XmppMessage m;
  81. m.set_to(buzz::Jid(username + "@gmail.com"));
  82. m.set_body("What's up?");
  83. // Typically, you would wait for WakeupMainThread to be called, and then call
  84. // DoCallbacks. Because I have nothing else to do on the main thread, I'm just going
  85. // to do a few things after 10 seconds and then poll every 2ms.
  86. Sleep(10000);
  87. // ljp.DoCallbacks();
  88. ljp.SendPresence(s);
  89. ljp.SendXmppMessage(m);
  90. #ifdef WIN32
  91. MSG msg;
  92. while (GetMessage(&msg, NULL, 0, 0)) {
  93. DispatchMessage(&msg);
  94. }
  95. #else
  96. for (;;) {
  97. ljp.DoCallbacks();
  98. Sleep(2);
  99. }
  100. #endif
  101. }