]> git.mxchange.org Git - quix0rs-gnu-social.git/blob - plugins/Msn/msnmanager.php
Initial commit of msn-plugin work
[quix0rs-gnu-social.git] / plugins / Msn / msnmanager.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 MsnManager 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 $this->conn->getSockets();
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 MSN queue.");
69         $this->stats('msn_process');
70         $this->conn->receive();
71     }
72
73     function connect()
74     {
75         if (!$this->conn) {
76             $this->conn=new MSN(array(
77                                       'user' => $this->plugin->user,
78                                       'password' => $this->plugin->password,
79                                       'alias' => $this->plugin->nickname,
80                                       'psm' => 'Send me a message to post a notice',
81                                       'debug' => true
82                                 )
83                         );
84             $this->conn->registerHandler("IMIn", array($this, 'handle_msn_message'));
85             $this->conn->signon();
86         }
87         return $this->conn;
88     }
89
90     function handle_msn_message($data)
91     {
92         $this->plugin->enqueue_incoming_raw($data);
93         return true;
94     }
95
96     function send_raw_message($data)
97     {
98         $this->connect();
99         if (!$this->conn) {
100             return false;
101         }
102         $this->conn->sflapSend($data[0],$data[1],$data[2],$data[3]);
103         return true;
104     }
105 }