From 6dae72dd78f436d7f69b1a763a9cdb30d2ccec45 Mon Sep 17 00:00:00 2001 From: temp Date: Thu, 1 May 2008 14:29:33 +0000 Subject: [PATCH] added a class prefix, refactored log-class, finished scopes for methods in xmlstream and xmpp git-svn-id: svn://netflint.net/xmpphp@29 ef36c318-a008-4979-b6e8-6b496270793b --- XMPPHP/Log.php | 101 ++++++++ xmlobj.php => XMPPHP/XMLObj.php | 60 ++++- xmlstream.php => XMPPHP/XMLStream.php | 346 ++++++++++++++++++++------ xmpp.php => XMPPHP/XMPP.php | 143 ++++++++--- cli_longrun_example.php | 10 +- logging.php | 60 ----- sendmessage_example.php | 10 +- 7 files changed, 543 insertions(+), 187 deletions(-) create mode 100644 XMPPHP/Log.php rename xmlobj.php => XMPPHP/XMLObj.php (71%) rename xmlstream.php => XMPPHP/XMLStream.php (58%) rename xmpp.php => XMPPHP/XMPP.php (64%) delete mode 100644 logging.php diff --git a/XMPPHP/Log.php b/XMPPHP/Log.php new file mode 100644 index 0000000..903d514 --- /dev/null +++ b/XMPPHP/Log.php @@ -0,0 +1,101 @@ +runlevel = (int)$runlevel; + $this->printout = (boolean)$printout; + } + + /** + * Add a message to the log data array + * If printout in this instance is set to true, directly output the message + * + * @param string $msg + * @param integer $runlevel + */ + public function log($msg, $runlevel = self::LEVEL_INFO) { + $time = time(); + $this->data[] = array($this->runlevel, $msg, $time); + if($this->printout and $runlevel <= $this->runlevel) { + $this->writeLine($msg, $runlevel, $time); + } + } + + /** + * Output the complete log. + * Log will be cleared if $clear = true + * + * @param boolean $clear + * @param integer $runlevel + */ + public function printout($clear = true, $runlevel = null) { + if($runlevel === null) { + $runlevel = $this->runlevel; + } + foreach($this->data as $data) { + if($runlevel <= $data[0]) { + $this->writeLine($data[1], $runlevel, $data[2]); + } + } + if($clear) { + $this->data = array(); + } + } + + protected function writeLine($msg, $runlevel, $time) { + //echo date('Y-m-d H:i:s', $time)." [".$this->names[$runlevel]."]: ".$msg."\n"; + echo $time." [".$this->names[$runlevel]."]: ".$msg."\n"; + } +} diff --git a/xmlobj.php b/XMPPHP/XMLObj.php similarity index 71% rename from xmlobj.php rename to XMPPHP/XMLObj.php index 691bf41..81a26e1 100644 --- a/xmlobj.php +++ b/XMPPHP/XMLObj.php @@ -19,11 +19,40 @@ along with XMPPHP; if not, write to the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */ -class XMLObj { +class XMPPHP_XMLObj { + /** + * Tag name + * + * @var string + */ public $name; + + /** + * Namespace + * + * @var string + */ public $ns; + + /** + * Attributes + * + * @var array + */ public $attrs = array(); + + /** + * Subs? + * + * @var array + */ public $subs = array(); + + /** + * Node data + * + * @var string + */ public $data = ''; /** @@ -45,6 +74,11 @@ class XMLObj { $this->data = $data; } + /** + * Dump this XML Object to output. + * + * @param integer $depth + */ public function printObj($depth = 0) { print str_repeat("\t", $depth) . $this->name . " " . $this->ns . ' ' . $this->data; print "\n"; @@ -53,6 +87,11 @@ class XMLObj { } } + /** + * Return this XML Object in xml notation + * + * @param string $str + */ public function toString($str = '') { $str .= "<{$this->name} xmlns='{$this->ns}' "; foreach($this->attrs as $key => $value) { @@ -70,16 +109,31 @@ class XMLObj { return $str; } + /** + * Has this XML Object the given sub? + * + * @param string $name + * @return boolean + */ public function hasSub($name) { foreach($this->subs as $sub) { if($sub->name == $name) return true; } - return False; + return false; } + /** + * Return a sub + * + * @param string $name + * @param string $attrs + * @param string $ns + */ public function sub($name, $attrs = null, $ns = null) { foreach($this->subs as $sub) { - if($sub->name == $name) return $sub; + if($sub->name == $name) { + return $sub; + } } } } diff --git a/xmlstream.php b/XMPPHP/XMLStream.php similarity index 58% rename from xmlstream.php rename to XMPPHP/XMLStream.php index 099116a..dd52483 100644 --- a/xmlstream.php +++ b/XMPPHP/XMLStream.php @@ -18,34 +18,110 @@ You should have received a copy of the GNU General Public License along with XMPPHP; if not, write to the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */ -require_once("xmlobj.php"); -require_once("logging.php"); -class XMLStream { - protected $socket; - protected $parser; - protected $buffer; - protected $xml_depth = 0; - protected $host; - protected $port; - protected $stream_start = ''; - protected $stream_end = ''; - public $disconnected = false; - protected $sent_disconnect = false; - protected $ns_map = array(); - protected $current_ns = array(); - protected $xmlobj = null; +require_once("XMLObj.php"); +require_once("Log.php"); + +class XMPPHP_XMLStream { + /** + * @var resource + */ + protected $socket; + /** + * @var resource + */ + protected $parser; + /** + * @var string + */ + protected $buffer; + /** + * @var integer + */ + protected $xml_depth = 0; + /** + * @var string + */ + protected $host; + /** + * @var integer + */ + protected $port; + /** + * @var string + */ + protected $stream_start = ''; + /** + * @var string + */ + protected $stream_end = ''; + /** + * @var boolean + */ + protected $disconnected = false; + /** + * @var boolean + */ + protected $sent_disconnect = false; + /** + * @var array + */ + protected $ns_map = array(); + /** + * @var array + */ + protected $current_ns = array(); + /** + * @var array + */ + protected $xmlobj = null; + /** + * @var array + */ protected $nshandlers = array(); + /** + * @var array + */ protected $idhandlers = array(); + /** + * @var array + */ protected $eventhandlers = array(); + /** + * @var integer + */ protected $lastid = 0; + /** + * @var string + */ protected $default_ns; + /** + * @var string + */ protected $until = ''; + /** + * @var array + */ protected $until_happened = false; + /** + * @var array + */ protected $until_payload = array(); + /** + * @var XMPPHP_Log + */ protected $log; + /** + * @var boolean + */ protected $reconnect = true; + /** + * @var boolean + */ protected $been_reset = false; + /** + * @var boolean + */ protected $is_server; /** @@ -53,36 +129,79 @@ class XMLStream { * * @param string $host * @param string $port - * @param boolean $log + * @param boolean $printlog * @param string $loglevel * @param boolean $is_server */ - public function __construct($host = null, $port = null, $log = false, $loglevel = null, $is_server = false) { + public function __construct($host = null, $port = null, $printlog = false, $loglevel = null, $is_server = false) { $this->reconnect = !$is_server; $this->is_server = $is_server; $this->host = $host; $this->port = $port; $this->setupParser(); - $this->log = new Logging($log, $loglevel); + $this->log = new XMPPHP_Log($printlog, $loglevel); } + /** + * Return the log instance + * + * @return XMPPHP_Log + */ + public function getLog() { + return $this->log; + } + + /** + * Get next ID + * + * @return integer + */ public function getId() { $this->lastid++; return $this->lastid; } + /** + * Add ID Handler + * + * @param integer $id + * @param string $pointer + * @param string $obj + */ public function addIdHandler($id, $pointer, $obj = null) { $this->idhandlers[$id] = array($pointer, $obj); } + /** + * Add Handler + * + * @param integer $id + * @param string $ns + * @param string $pointer + * @param string $obj + * @param integer $depth + */ public function addHandler($name, $ns, $pointer, $obj = null, $depth = 1) { $this->nshandlers[] = array($name,$ns,$pointer,$obj, $depth); } + /** + * Add Evemt Handler + * + * @param integer $id + * @param string $pointer + * @param string $obj + */ public function addEventHandler($name, $pointer, $obj) { $this->eventhanders[] = array($name, $pointer, $obj); } + /** + * Connect to XMPP Host + * + * @param boolean $persistent + * @param boolean $sendinit + */ public function connect($persistent = false, $sendinit = true) { $this->disconnected = false; $this->sent_disconnect = false; @@ -94,17 +213,49 @@ class XMLStream { $this->log->log("Connecting to tcp://{$this->host}:{$this->port}"); $this->socket = stream_socket_client("tcp://{$this->host}:{$this->port}", $conflag); if(!$this->socket) { - $this->log->log("Could not connect.", Logging::LOG_ERROR); + $this->log->log("Could not connect.", XMPPHP_Log::LEVEL_ERROR); $this->disconnected = true; } stream_set_blocking($this->socket, 1); if($sendinit) $this->send($this->stream_start); } - public function apply_socket($socket) { - $this->socket = $socket; - } + /** + * Reconnect XMPP Host + */ + public function doReconnect() { + if(!$this->is_server) { + $this->log->log("Reconnecting...", XMPPHP_Log::LEVEL_WARNING); + $this->connect(false, false); + $this->reset(); + } + } + /** + * Disconnect from XMPP Host + */ + public function disconnect() { + $this->reconnect = false; + $this->send($this->stream_end); + $this->sent_disconnect = true; + $this->processUntil('end_stream', 5); + $this->disconnected = true; + } + + /** + * Are we are disconnected? + * + * @return boolean + */ + public function isDisconnected() { + return $this->connected; + } + + /** + * Process + * + * @return string + */ public function process() { $updated = ''; while(!$this->disconnect) { @@ -122,26 +273,18 @@ class XMLStream { return false; } } - $this->log->log("RECV: $buff", Logging::LOG_VERBOSE); + $this->log->log("RECV: $buff", XMPPHP_Log::LEVEL_VERBOSE); xml_parse($this->parser, $buff, false); } } } - public function read() { - $buff = @fread($this->socket, 1024); - if(!$buff) { - if($this->reconnect) { - $this->doReconnect(); - } else { - fclose($this->socket); - return false; - } - } - $this->log->log("RECV: $buff", Logging::LOG_VERBOSE); - xml_parse($this->parser, $buff, false); - } - + /** + * Process until a timeout occurs + * + * @param integer $timeout + * @return string + */ public function processTime($timeout = -1) { $start = time(); $updated = ''; @@ -160,12 +303,19 @@ class XMLStream { return false; } } - $this->log->log("RECV: $buff", Logging::LOG_VERBOSE); + $this->log->log("RECV: $buff", XMPPHP_Log::LEVEL_VERBOSE); xml_parse($this->parser, $buff, false); } } } + /** + * Process until a specified event or a timeout occurs + * + * @param string|array $event + * @param integer $timeout + * @return string + */ public function processUntil($event, $timeout=-1) { $start = time(); if(!is_array($event)) $event = array($event); @@ -189,7 +339,7 @@ class XMLStream { return false; } } - $this->log->log("RECV: $buff", Logging::LOG_VERBOSE); + $this->log->log("RECV: $buff", XMPPHP_Log::LEVEL_VERBOSE); xml_parse($this->parser, $buff, false); } } @@ -202,7 +352,22 @@ class XMLStream { return $payload; } - public function startXML($parser, $name, $attr) { + /** + * Obsolete? + */ + protected function Xapply_socket($socket) { + $this->socket = $socket; + } + + /** + * XML start callback + * + * @see xml_set_element_handler + * + * @param resource $parser + * @param string $name + */ + protected function startXML($parser, $name, $attr) { if($this->been_reset) { $this->been_reset = false; $this->xml_depth = 0; @@ -228,14 +393,22 @@ class XMLStream { $ns = $this->ns_map[$name[0]]; $name = $name[1]; } - $obj = new XMLObj($name, $ns, $attr); + $obj = new XMPPHP_XMLObj($name, $ns, $attr); if($this->xml_depth > 1) $this->xmlobj[$this->xml_depth - 1]->subs[] = $obj; $this->xmlobj[$this->xml_depth] = $obj; } - public function endXML($parser, $name) { - #$this->log->log("Ending $name", Logging::LOG_DEBUG); + /** + * XML end callback + * + * @see xml_set_element_handler + * + * @param resource $parser + * @param string $name + */ + protected function endXML($parser, $name) { + #$this->log->log("Ending $name", XMPPHP_Log::LEVEL_DEBUG); #print "$name\n"; if($this->been_reset) { $this->been_reset = false; @@ -246,14 +419,14 @@ class XMLStream { #clean-up old objects $found = false; foreach($this->nshandlers as $handler) { - if($handler[4] != 1 and $this->xmlobj[2]->hassub($handler[0])) { + if($handler[4] != 1 and $this->xmlobj[2]->hasSub($handler[0])) { $searchxml = $this->xmlobj[2]->sub($handler[0]); } elseif(is_array($this->xmlobj) and array_key_exists(2, $this->xmlobj)) { $searchxml = $this->xmlobj[2]; } if($searchxml !== null and $searchxml->name == $handler[0] and ($searchxml->ns == $handler[1] or (!$handler[1] and $searchxml->ns == $this->default_ns))) { if($handler[3] === null) $handler[3] = $this; - $this->log->log("Calling {$handler[2]}", Logging::LOG_DEBUG); + $this->log->log("Calling {$handler[2]}", XMPPHP_Log::LEVEL_DEBUG); call_user_func(array($handler[3], $handler[2]), $this->xmlobj[2]); } } @@ -268,7 +441,7 @@ class XMLStream { } if(is_array($this->xmlobj)) { $this->xmlobj = array_slice($this->xmlobj, 0, 1); - if(isset($this->xmlobj[0]) && $this->xmlobj[0] instanceof XMLObj) { + if(isset($this->xmlobj[0]) && $this->xmlobj[0] instanceof XMPPHP_XMLObj) { $this->xmlobj[0]->subs = null; } } @@ -290,24 +463,26 @@ class XMLStream { } } - public function doReconnect() { - if(!$this->is_server) { - $this->log->log("Reconnecting...", Logging::LOG_WARNING); - $this->connect(false, false); - $this->reset(); - } - } + /** + * XML character callback + * @see xml_set_character_data_handler + * + * @param resource $parser + * @param string $data + */ + protected function charXML($parser, $data) { + if(array_key_exists($this->xml_depth, $this->xmlobj)) + $this->xmlobj[$this->xml_depth]->data .= $data; + } - public function disconnect() { - $this->reconnect = false; - $this->send($this->stream_end); - $this->sent_disconnect = true; - $this->processUntil('end_stream', 5); - $this->disconnected = true; - } - - public function event($name, $payload = null) { - $this->log->log("EVENT: $name", Logging::LOG_DEBUG); + /** + * Event? + * + * @param string $name + * @param string $payload + */ + protected function event($name, $payload = null) { + $this->log->log("EVENT: $name", XMPPHP_Log::LEVEL_DEBUG); foreach($this->eventhandlers as $handler) { if($name == $handler[0]) { if($handler[2] === null) $handler[2] = $this; @@ -324,18 +499,38 @@ class XMLStream { } } - public function charXML($parser, $data) { - if(array_key_exists($this->xml_depth, $this->xmlobj)) - $this->xmlobj[$this->xml_depth]->data .= $data; - } + /** + * Read from socket + */ + protected function read() { + $buff = @fread($this->socket, 1024); + if(!$buff) { + if($this->reconnect) { + $this->doReconnect(); + } else { + fclose($this->socket); + return false; + } + } + $this->log->log("RECV: $buff", XMPPHP_Log::LEVEL_VERBOSE); + xml_parse($this->parser, $buff, false); + } - public function send($msg) { + /** + * Send to socket + * + * @param string $msg + */ + protected function send($msg) { #socket_write($this->socket, $msg); - $this->log->log("SENT: $msg", Logging::LOG_VERBOSE); + $this->log->log("SENT: $msg", XMPPHP_Log::LEVEL_VERBOSE); @fwrite($this->socket, $msg); } - public function reset() { + /** + * Reset connection + */ + protected function reset() { $this->xml_depth = 0; unset($this->xmlobj); $this->xmlobj = array(); @@ -346,10 +541,13 @@ class XMLStream { $this->been_reset = true; } - public function setupParser() { + /** + * Setup the XML parser + */ + protected function setupParser() { $this->parser = xml_parser_create('UTF-8'); - xml_parser_set_option($this->parser,XML_OPTION_SKIP_WHITE,1); - xml_parser_set_option($this->parser,XML_OPTION_TARGET_ENCODING, "UTF-8"); + xml_parser_set_option($this->parser, XML_OPTION_SKIP_WHITE, 1); + xml_parser_set_option($this->parser, XML_OPTION_TARGET_ENCODING, 'UTF-8'); xml_set_object($this->parser, $this); xml_set_element_handler($this->parser, 'startXML', 'endXML'); xml_set_character_data_handler($this->parser, 'charXML'); diff --git a/xmpp.php b/XMPPHP/XMPP.php similarity index 64% rename from xmpp.php rename to XMPPHP/XMPP.php index 57d83a2..1ee9375 100644 --- a/xmpp.php +++ b/XMPPHP/XMPP.php @@ -18,9 +18,10 @@ You should have received a copy of the GNU General Public License along with XMPPHP; if not, write to the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */ -require_once("xmlstream.php"); -class XMPP extends XMLStream { +require_once("XMLStream.php"); + +class XMPPHP_XMPP extends XMPPHP_XMLStream { protected $server; protected $user; protected $password; @@ -42,24 +43,80 @@ class XMPP extends XMLStream { */ public function __construct($host, $port, $user, $password, $resource, $server = null, $printlog = false, $loglevel = null) { parent::__construct($host, $port, $printlog, $loglevel); - $this->user = $user; + + $this->user = $user; $this->password = $password; $this->resource = $resource; if(!$server) $server = $host; + $this->stream_start = ''; $this->stream_end = ''; $this->addHandler('features', 'http://etherx.jabber.org/streams', 'features_handler'); $this->addHandler('success', 'urn:ietf:params:xml:ns:xmpp-sasl', 'sasl_success_handler'); $this->addHandler('failure', 'urn:ietf:params:xml:ns:xmpp-sasl', 'sasl_failure_handler'); $this->addHandler('proceed', 'urn:ietf:params:xml:ns:xmpp-tls', 'tls_proceed_handler'); - $this->default_ns = 'jabber:client'; $this->addHandler('message', 'jabber:client', 'message_handler'); $this->addHandler('presence', 'jabber:client', 'presence_handler'); - $this->authed = false; + + $this->default_ns = 'jabber:client'; + $this->authed = false; $this->use_encryption = true; } - public function message_handler($xml) { + /** + * Send XMPP Message + * + * @param string $to + * @param string $body + * @param string $type + * @param string $subject + */ + public function message($to, $body, $type = 'chat', $subject = null) { + $to = htmlspecialchars($to); + $body = htmlspecialchars($body); + $subject = htmlspecialchars($subject); + + $out = ""; + if($subject) $out .= "$subject"; + $out .= "$body"; + + $this->send($out); + } + + /** + * Set Presence + * + * @param string $status + * @param string $show + * @param string $to + */ + public function presence($status = null, $show = 'available', $to = null) { + $type = ''; + $to = htmlspecialchars($to); + $status = htmlspecialchars($status); + if($show == 'unavailable') $type = 'unavailable'; + + $out = "send($out); + } + + /** + * Message handler + * + * @param string $xml + */ + public function message_handler($xml) { if(isset($xml->attrs['type'])) { $payload['type'] = $xml->attrs['type']; } else { @@ -67,52 +124,33 @@ class XMPP extends XMLStream { } $payload['from'] = $xml->attrs['from']; $payload['body'] = $xml->sub('body')->data; - $this->log->log("Message: {$xml->sub('body')->data}", Logging::LOG_DEBUG); + $this->log->log("Message: {$xml->sub('body')->data}", XMPPHP_Log::LEVEL_DEBUG); $this->event('message', $payload); } - public function message($to, $body, $type = 'chat', $subject = null) { - $to = htmlspecialchars($to); - $body = htmlspecialchars($body); - $subject = htmlspecialchars($subject); - $out = ""; - if($subject) $out .= "$subject"; - $out .= "$body"; - $this->send($out); - } - - public function presence($status = null, $show = 'available', $to = null) { - $type = ''; - $to = htmlspecialchars($to); - $status = htmlspecialchars($status); - if($show == 'unavailable') $type = 'unavailable'; - $out = "send($out); - } - + /** + * Presence handler + * + * @param string $xml + */ public function presence_handler($xml) { $payload['type'] = (isset($xml->attrs['type'])) ? $xml->attrs['type'] : 'available'; $payload['show'] = (isset($xml->sub('show')->data)) ? $xml->sub('show')->data : $payload['type']; $payload['from'] = $xml->attrs['from']; $payload['status'] = (isset($xml->sub('status')->data)) ? $xml->sub('status')->data : ''; - $this->log->log("Presence: {$payload['from']} [{$payload['show']}] {$payload['status']}", Logging::LOG_DEBUG); + $this->log->log("Presence: {$payload['from']} [{$payload['show']}] {$payload['status']}", XMPPHP_Log::LEVEL_DEBUG); $this->event('presence', $payload); } + /** + * Features handler + * + * @param string $xml + */ public function features_handler($xml) { - if($xml->hassub('starttls') and $this->use_encryption) { + if($xml->hasSub('starttls') and $this->use_encryption) { $this->send(""); - } elseif($xml->hassub('bind')) { + } elseif($xml->hasSub('bind')) { $id = $this->getId(); $this->addIdHandler($id, 'resource_bind_handler'); $this->send("{$this->resource}"); @@ -122,17 +160,32 @@ class XMPP extends XMLStream { } } + /** + * SASL success handler + * + * @param string $xml + */ public function sasl_success_handler($xml) { $this->log->log("Auth success!"); $this->authed = true; $this->reset(); } + /** + * SASL feature handler + * + * @param string $xml + */ public function sasl_failure_handler($xml) { - $this->log->log("Auth failed!", Logging::LOG_ERROR); + $this->log->log("Auth failed!", XMPPHP_Log::LEVEL_ERROR); $this->disconnect(); } + /** + * Resource bind handler + * + * @param string $xml + */ public function resource_bind_handler($xml) { if($xml->attrs['type'] == 'result') { $this->log->log("Bound to " . $xml->sub('bind')->sub('jid')->data); @@ -143,11 +196,21 @@ class XMPP extends XMLStream { $this->send(""); } + /** + * Session start handler + * + * @param string $xml + */ public function session_start_handler($xml) { $this->log->log("Session started"); $this->event('session_start'); } + /** + * TLS proceed handler + * + * @param string $xml + */ public function tls_proceed_handler($xml) { $this->log->log("Starting TLS encryption"); stream_socket_enable_crypto($this->socket, true, STREAM_CRYPTO_METHOD_SSLv23_CLIENT); diff --git a/cli_longrun_example.php b/cli_longrun_example.php index 2d035b3..d8bb158 100644 --- a/cli_longrun_example.php +++ b/cli_longrun_example.php @@ -3,10 +3,11 @@ // activate full error reporting error_reporting(E_ALL & E_STRICT); -include("xmpp.php"); -$conn = new XMPP('talk.google.com', 5222, 'user', 'password', 'xmpphp', 'gmail.com', $printlog=True, $loglevel=Logging::LOG_INFO); +include("XMPPHP/XMPP.php"); +//$conn = new XMPPHP_XMPP('talk.google.com', 5222, 'user', 'password', 'xmpphp', 'gmail.com', $printlog=true, $loglevel=Logging::LEVEL_INFO); +$conn = new XMPPHP_XMPP('jabber.wentz.it', 5222, 'dev', 'd3vd3v', 'xmpphp', 'jabber.wentz.it', $printlog=true, $loglevel=XMPPHP_Log::LEVEL_VERBOSE); $conn->connect(); -while(!$conn->disconnected) { +while(!$conn->isDisconnected()) { $payloads = $conn->processUntil(array('message', 'presence', 'end_stream', 'session_start')); foreach($payloads as $event) { $pl = $event[1]; @@ -25,10 +26,9 @@ while(!$conn->disconnected) { print "Presence: {$pl['from']} [{$pl['show']}] {$pl['status']}\n"; break; case 'session_start': + print "Session Start\n"; $conn->presence($status="Cheese!"); break; } } } - -?> diff --git a/logging.php b/logging.php deleted file mode 100644 index e7f4c71..0000000 --- a/logging.php +++ /dev/null @@ -1,60 +0,0 @@ -runlevel = $runlevel; - $this->printout = $printout; - } - - public function log($msg, $runlevel = null) { - if($runlevel === null) $runlevel = self::LOG_INFO; - $this->data[] = array($this->runlevel, $msg); - if($this->printout and $runlevel <= $this->runlevel) echo "{$this->names[$runlevel]}: $msg\n"; - } - - public function printout($clear = true, $runlevel = null) { - if($runlevel === null) $runlevel = $this->runlevel; - foreach($this->data as $data) { - if($runlevel <= $data[0]) echo "{$this->names[$runlevel]}: $data[1]\n"; - } - if($clear) $this->data = array(); - } -} diff --git a/sendmessage_example.php b/sendmessage_example.php index 7d3fe01..c1cfee0 100644 --- a/sendmessage_example.php +++ b/sendmessage_example.php @@ -3,12 +3,12 @@ // activate full error reporting error_reporting(E_ALL & E_STRICT); -include("xmpp.php"); -$conn = new XMPP('talk.google.com', 5222, 'username', 'password', 'xmpphp', 'gmail.com', $printlog=False, $loglevel=Logging::LOG_INFO); +include("XMPPHP/XMPP.php"); + +//$conn = new XMPP('talk.google.com', 5222, 'username', 'password', 'xmpphp', 'gmail.com', $printlog=false, $loglevel=Logging::LEVEL_INFO); +$conn = new XMPPHP_XMPP('jabber.wentz.it', 5222, 'dev', 'd3vd3v', 'xmpphp', 'jabber.wentz.it', $printlog=true, $loglevel=XMPPHP_Log::LEVEL_VERBOSE); $conn->connect(); $conn->processUntil('session_start'); $conn->presence(); -$conn->message('someguy@someserver.net', 'This is a test message!'); +$conn->message('stephan@jabber.wentz.it', 'This is a test message!'); $conn->disconnect(); - -?>