All pastes #548312 Raw Edit

Someone

public php v1 · immutable
·published 2007-06-07 18:12 UTC
rendered paste body
<?php    require_once "bencode.php";    class Intermission {        private $daemon_version;        private $sock;        private $version = array("version" => array("min" => 1, "max" => 2));        public function __construct($daemon_socket) {            $this->sock = socket_create(AF_UNIX, SOCK_STREAM, 0);            socket_connect($this->sock, $daemon_socket);            $this->daemon_version = $this->sock_write($this->version);        }        private function parse($data) {            if ($data[1]) {                return $data[1];            } else {                return $data[0];            }        }        public function sock_close() {            socket_close($this->sock);        }        private function sock_read() {            return bdecode(socket_read($this->sock, hexdec(socket_read($this->sock, 8))));        }        public function sock_write($data, $response = true, $parsed = false) {            $data = bencode($data);            socket_write($this->sock, sprintf("%08X", strlen($data)) . $data);            if ($response) {                if ($parsed) {                    return $this->parse($this->sock_read());                } else {                    return $this->sock_read();                }            }        }        public function helper_get_info_all($type = array("id")) {            return $this->sock_write(array("get-info-all", $type, 0), true, true);        }        public function helper_get_status($id, $type = array("id")) {            if (!is_array($id)) {                if (!is_int($id)) {                    $id = array((int)$id);                } else {                    $id = array($id);                }            }            $response = $this->sock_write(array("get-status", array("id" => $id, "type" => $type), 0), true, true);            return $response[0];        }    }?>