connected()) die('Trying to use Connector communication while disconnected. This is not possible.'); } public function __construct() { $this->ip = new IP(); $this->ip->timeout = 8; } public function __destruct() { $this->ip->disconnect(); } public function connect($host) { return $this->ip->connect($host, 2089); } public function disconnect() { $this->ip->disconnect(); } public function send(ConnectorPacket $packet) { $this->assertConnected(); $this->ip->send($packet->packet()); } public function read() { $data = $this->ip->readeol(CONNECTOR_ETX); if ($data == "") return null; return ConnectorPacket::decode($data); } public function connected() { return $this->ip->connected(); } public function sessionized() { return $this->ip->connected() && $this->session != ""; } public function authorized() { return $this->ip->connected() && $this->sessionized() && $this->authorized; } public function stat() { $this->send(new ConnectorPacket('STAT')); if (($packet = $this->read()) == null) die("Connector: STAT did not receive a reply"); return $packet; } public function req_s() { $this->send(new ConnectorPacket('REQ-S')); if (($packet = $this->read()) == null) die("Connector: REQ-S did not receive a reply"); if ($packet->errno == 0) $this->session = $packet->get('000'); return $packet; } public function end() { $this->send(new ConnectorPacket('END', array( FLD_SESSION => $this->session ))); if (($packet = $this->read()) == null) die("Connector: END did not receive a reply"); $this->session = ""; return $packet; } public function auth($anknr, $password) { $this->send(new ConnectorPacket('AUTH', array( FLD_SESSION => $this->session, FLD_ANKNR => $anknr, FLD_PASSWORD => $password ))); if (($packet = $this->read()) == null) die("Connector: AUTH did not receive a reply"); $this->authorized = $packet->success(); return $packet; } public function signon($value) { $this->send(new ConnectorPacket('AUTH', array( FLD_SESSION => $this->session, FLD_SIGNON => $value ))); if (($packet = $this->read()) == null) die("Connector: AUTH did not receive a reply"); $this->authorized = $packet->success(); return $packet; } public function info($id = "") { $packet = new ConnectorPacket('INFO', array( FLD_SESSION => $this->session )); if ($id != "") $packet->add(FLD_ID, $id); $this->send($packet); if (($packet = $this->read()) == null) die("Connector: INFO did not receive a reply"); return $packet; } public function info_data($id = "") { $packet = new ConnectorPacket('INFO-DATA', array( FLD_SESSION => $this->session )); if ($id != "") $packet->add(FLD_ID, $id); $this->send($packet); if (($packet = $this->read()) == null) die("Connector: INFO-DATA did not receive a reply"); return $packet; } public function int_call($number) { $this->send(new ConnectorPacket('INT-CALL', array( FLD_SESSION => $this->session, FLD_INT_TARGET => $number ))); if (($packet = $this->read()) == null) die("Connector: INT-CALL did not receive a reply"); return $packet; } }