]> git.mxchange.org Git - quix0rs-gnu-social.git/blob - plugins/Aim/aimmanager.php
Merge branch '0.9.x' into 1.0.x
[quix0rs-gnu-social.git] / plugins / Aim / aimmanager.php
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
20 if (!defined('STATUSNET') && !defined('LACONICA')) { exit(1); }
21
22 /**
23  * AIM background connection manager for AIM-using queue handlers,
24  * allowing them to send outgoing messages on the right connection.
25  *
26  * Input is handled during socket select loop, keepalive pings during idle.
27  * Any incoming messages will be handled.
28  *
29  * In a multi-site queuedaemon.php run, one connection will be instantiated
30  * for each site being handled by the current process that has XMPP enabled.
31  */
32
33 class AimManager extends ImManager
34 {
35
36     public $conn = null;
37     /**
38      * Initialize connection to server.
39      * @return boolean true on success
40      */
41     public function start($master)
42     {
43         if(parent::start($master))
44         {
45             $this->connect();
46             return true;
47         }else{
48             return false;
49         }
50     }
51
52     public function getSockets()
53     {
54         $this->connect();
55         if($this->conn){
56             return array($this->conn->myConnection);
57         }else{
58             return array();
59         }
60     }
61
62     /**
63      * Process AIM events that have come in over the wire.
64      * @param resource $socket
65      */
66     public function handleInput($socket)
67     {
68         common_log(LOG_DEBUG, "Servicing the AIM queue.");
69         $this->stats('aim_process');
70         $this->conn->receive();
71     }
72
73     function connect()
74     {
75         if (!$this->conn) {
76             $this->conn=new Aim($this->plugin->user,$this->plugin->password,4);
77             $this->conn->registerHandler("IMIn",array($this,"handle_aim_message"));
78             $this->conn->myServer="toc.oscar.aol.com";
79             $this->conn->signon();
80             $this->conn->setProfile(_m('Send me a message to post a notice'),false);
81         }
82         return $this->conn;
83     }
84
85     function handle_aim_message($data)
86     {
87         $this->plugin->enqueueIncomingRaw($data);
88         return true;
89     }
90
91     function send_raw_message($data)
92     {
93         $this->connect();
94         if (!$this->conn) {
95             return false;
96         }
97         $this->conn->sflapSend($data[0],$data[1],$data[2],$data[3]);
98         return true;
99     }
100 }