aimmanager.php 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  1. <?php
  2. /*
  3. * StatusNet - the distributed open-source microblogging tool
  4. * Copyright (C) 2008, 2009, StatusNet, Inc.
  5. *
  6. * This program is free software: you can redistribute it and/or modify
  7. * it under the terms of the GNU Affero General Public License as published by
  8. * the Free Software Foundation, either version 3 of the License, or
  9. * (at your option) any later version.
  10. *
  11. * This program is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. * GNU Affero General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU Affero General Public License
  17. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  18. */
  19. if (!defined('STATUSNET') && !defined('LACONICA')) { exit(1); }
  20. /**
  21. * AIM background connection manager for AIM-using queue handlers,
  22. * allowing them to send outgoing messages on the right connection.
  23. *
  24. * Input is handled during socket select loop, keepalive pings during idle.
  25. * Any incoming messages will be handled.
  26. *
  27. * In a multi-site queuedaemon.php run, one connection will be instantiated
  28. * for each site being handled by the current process that has XMPP enabled.
  29. */
  30. class AimManager extends ImManager
  31. {
  32. public $conn = null;
  33. /**
  34. * Initialize connection to server.
  35. * @return boolean true on success
  36. */
  37. public function start($master)
  38. {
  39. if(parent::start($master))
  40. {
  41. $this->connect();
  42. return true;
  43. }else{
  44. return false;
  45. }
  46. }
  47. public function getSockets()
  48. {
  49. $this->connect();
  50. if($this->conn){
  51. return array($this->conn->myConnection);
  52. }else{
  53. return array();
  54. }
  55. }
  56. /**
  57. * Process AIM events that have come in over the wire.
  58. * @param resource $socket
  59. */
  60. public function handleInput($socket)
  61. {
  62. common_log(LOG_DEBUG, "Servicing the AIM queue.");
  63. $this->stats('aim_process');
  64. $this->conn->receive();
  65. }
  66. function connect()
  67. {
  68. if (!$this->conn) {
  69. $this->conn=new Aim($this->plugin->user,$this->plugin->password,4);
  70. $this->conn->registerHandler("IMIn",array($this,"handle_aim_message"));
  71. $this->conn->myServer="toc.oscar.aol.com";
  72. $this->conn->signon();
  73. // @todo i18n FIXME: Update translator documentation, please.
  74. // TRANS: No idea what the use case for this message is.
  75. $this->conn->setProfile(_m('Send me a message to post a notice'),false);
  76. }
  77. return $this->conn;
  78. }
  79. function handle_aim_message($data)
  80. {
  81. $this->plugin->enqueueIncomingRaw($data);
  82. return true;
  83. }
  84. function send_raw_message($data)
  85. {
  86. $this->connect();
  87. if (!$this->conn) {
  88. return false;
  89. }
  90. $this->conn->sflapSend($data[0],$data[1],$data[2],$data[3]);
  91. return true;
  92. }
  93. }