From c5b045236e619fb0b6c49337c18865eeff742b6c Mon Sep 17 00:00:00 2001 From: Jan Philipp Timme Date: Thu, 5 Sep 2013 11:55:43 +0200 Subject: [PATCH] [TASK] Fix line endings to LF only. --- .../Protocol/IrcProtocolContentObject.php | 286 ++++++------ .../Classes/Protocol/IrcProtocolHandler.php | 420 +++++++++--------- SocketFramework/Bootstrap.php | 22 +- .../Client/ClientDispatcherInterface.php | 146 +++--- Testcode/Misc/IrcParser.php | 96 ++-- 5 files changed, 485 insertions(+), 485 deletions(-) diff --git a/IrcClient/Classes/Protocol/IrcProtocolContentObject.php b/IrcClient/Classes/Protocol/IrcProtocolContentObject.php index dbcd844..ea935ab 100644 --- a/IrcClient/Classes/Protocol/IrcProtocolContentObject.php +++ b/IrcClient/Classes/Protocol/IrcProtocolContentObject.php @@ -1,144 +1,144 @@ -sender = $sender; - } - - /** - * Gets sender. - * @return string - */ - public function getSender() { - return $this->sender; - } - - /** - * Sets command. - * @param string $command - * @return void - */ - public function setCommand($command) { - $this->command = $command; - } - - /** - * Gets command. - * @return string - */ - public function getCommand() { - return $this->command; - } - - /** - * Sets params. - * @param string $params - * @return void - */ - public function setParams($params) { - $this->params = $params; - } - - /** - * Gets params. - * @return string - */ - public function getParams() { - return $this->params; - } - - /** - * Sets target. - * @param string $target - * @return void - */ - public function setTarget($target) { - $this->target = $target; - } - - /** - * Gets target. - * @return string - */ - public function getTarget() { - return $this->target; - } - - /** - * Sets message. - * @param string $message - * @return void - */ - public function setMessage($message) { - $this->message = $message; - } - - /** - * Gets message. - * @return string - */ - public function getMessage() { - return $this->message; - } - - /** - * Sets subject. - * @param string $subject - * @return void - */ - public function setSubject($subject) { - $this->subject = $subject; - } - - /** - * Gets subject. - * @return string - */ - public function getSubject() { - return $this->subject; - } - -} +sender = $sender; + } + + /** + * Gets sender. + * @return string + */ + public function getSender() { + return $this->sender; + } + + /** + * Sets command. + * @param string $command + * @return void + */ + public function setCommand($command) { + $this->command = $command; + } + + /** + * Gets command. + * @return string + */ + public function getCommand() { + return $this->command; + } + + /** + * Sets params. + * @param string $params + * @return void + */ + public function setParams($params) { + $this->params = $params; + } + + /** + * Gets params. + * @return string + */ + public function getParams() { + return $this->params; + } + + /** + * Sets target. + * @param string $target + * @return void + */ + public function setTarget($target) { + $this->target = $target; + } + + /** + * Gets target. + * @return string + */ + public function getTarget() { + return $this->target; + } + + /** + * Sets message. + * @param string $message + * @return void + */ + public function setMessage($message) { + $this->message = $message; + } + + /** + * Gets message. + * @return string + */ + public function getMessage() { + return $this->message; + } + + /** + * Sets subject. + * @param string $subject + * @return void + */ + public function setSubject($subject) { + $this->subject = $subject; + } + + /** + * Gets subject. + * @return string + */ + public function getSubject() { + return $this->subject; + } + +} ?> \ No newline at end of file diff --git a/IrcClient/Classes/Protocol/IrcProtocolHandler.php b/IrcClient/Classes/Protocol/IrcProtocolHandler.php index 780dfd4..0868bb4 100644 --- a/IrcClient/Classes/Protocol/IrcProtocolHandler.php +++ b/IrcClient/Classes/Protocol/IrcProtocolHandler.php @@ -1,211 +1,211 @@ -linebreak = "\n"; - $this->bufferIncoming = new Misc_Buffer($this->linebreak); - $this->bufferOutgoing = new Misc_Buffer($this->linebreak); - } - - /** - * Main worker function. It will be called in a loop. - * It does all the protocol-dependent parsing. - * The returned ContentObject will be passed to the client. - * @return Protocol_IrcProtocolContentObject - * @throws Exception_ProtocolHandlerException - * @throws Exception_GeneralException - */ - public function work() { - $data = $this->bufferIncoming->getNextLine(); - //create contentObject and set the raw data. - $contentObject = new Protocol_IrcProtocolContentObject($data); - - //trim whitespace - $data = trim($data); - - //no data? complain! - if($data === "") throw new Exception_ProtocolHandlerException("No data to process! Where did it go?!", 1292082006); - - //get the guy who sent the message - $sender = ""; - if($data[0] === ":") { - list($sender, $data) = explode(" ", $data, 2); - //cut the colon - $sender = substr($sender, 1); - $contentObject->setSender($sender); - } - - //determine what command was sent - $command = ""; - if(strpos($data, " ") !== FALSE) { - list($command, $data) = explode(" ", $data, 2); - } else { - $command = $data; - } - $contentObject->setCommand($command); - - //we'll write these values into the contentObject later! - //contains a user or the channel a command is addressed to. - $target = NULL; - //parameters of the command - $params = NULL; - //content or message - $message = NULL; - //affected nickname(s) (e.g. by a KICK or MODE +b) - $subject = NULL; - - //command-dependent parsing - switch($command) { - - case "PRIVMSG": - case "NOTICE": - list($target, $params) = explode(" ", $data, 2); - //cut the colon - $message = substr($params, 1); - break; - - case "INVITE": - list($target, $params) = explode(" ", $data, 2); - //cut the colon - $params = substr($params, 1); - break; - - case "ERROR": - case "QUIT": - if(strpos($data, " :") !== FALSE) { - list($params, $message) = explode(" :", $data); - $message = substr($message, 1); - } else { - $params = $data; - } - break; - - case "PING": - case "JOIN": - //cut the colon - $params = substr($data, 1); - break; - - //channel, - case "PART": - if(strpos($data, " :") !== FALSE) { - list($params, $message) = explode(" :", $data); - $message = substr($message, 1); - } else { - $params = $data; - } - break; - - case "NICK": - //cut the colon - $params = substr($data, 1); - break; - - //channel, user, - case "KICK": - $pieces = explode(" ", $data, 3); - list($target, $subject, $data) = explode(" ", $data, 3); - //get comment for kick and cut the colon - if(count($pieces === 3)) $message = substr($data, 1); - unset($pieces); - break; - - //MOTD content - case "372": - list($target, $message) = explode(" :", $data); - break; - - //user, comment - case "KILL": - case "MODE": - - - case "AWAY": - - case "001": - case "002": - case "003": - case "004": - case "005": - - case "250": - case "251": - case "252": - case "253": - case "254": - case "255": - case "265": - case "266": - - case "332": - case "333": - case "353": - //NAMES end - case "366": - - //MOTD start - case "375": - //MOTD end - case "376": - - //break; - //tell when stuff is not implemented - default: - //echo "N.i.y.: " . $command . " [".$data."]\r\n"; - break; - } - - //we're done parsing, now write the stuff into the contentObject. - $contentObject->setTarget($target); - $contentObject->setParams($params); - $contentObject->setMessage($message); - - return $contentObject; - } - - /** - * Returns whether there is work to be done. - * Important in order to assure that a ContentObject is created and passed to the Client. - * @return boolean - */ - public function canWork() { - return $this->bufferIncoming->hasLines(); - } - - /** - * Will put raw data into the outgoing buffer. - * This function will be removed soon. - * The ProtocolHandler shall take care of this directly. - * @param string $data - * @return void - */ - public function sendRaw($data) { - $this->bufferOutgoing->addData($data . $this->linebreak); - } - - /** - * Sends a pong. - * @param string $param - * @return void - */ - public function pong($param) { - $this->sendRaw("PONG :" . $param); - } - -} +linebreak = "\n"; + $this->bufferIncoming = new Misc_Buffer($this->linebreak); + $this->bufferOutgoing = new Misc_Buffer($this->linebreak); + } + + /** + * Main worker function. It will be called in a loop. + * It does all the protocol-dependent parsing. + * The returned ContentObject will be passed to the client. + * @return Protocol_IrcProtocolContentObject + * @throws Exception_ProtocolHandlerException + * @throws Exception_GeneralException + */ + public function work() { + $data = $this->bufferIncoming->getNextLine(); + //create contentObject and set the raw data. + $contentObject = new Protocol_IrcProtocolContentObject($data); + + //trim whitespace + $data = trim($data); + + //no data? complain! + if($data === "") throw new Exception_ProtocolHandlerException("No data to process! Where did it go?!", 1292082006); + + //get the guy who sent the message + $sender = ""; + if($data[0] === ":") { + list($sender, $data) = explode(" ", $data, 2); + //cut the colon + $sender = substr($sender, 1); + $contentObject->setSender($sender); + } + + //determine what command was sent + $command = ""; + if(strpos($data, " ") !== FALSE) { + list($command, $data) = explode(" ", $data, 2); + } else { + $command = $data; + } + $contentObject->setCommand($command); + + //we'll write these values into the contentObject later! + //contains a user or the channel a command is addressed to. + $target = NULL; + //parameters of the command + $params = NULL; + //content or message + $message = NULL; + //affected nickname(s) (e.g. by a KICK or MODE +b) + $subject = NULL; + + //command-dependent parsing + switch($command) { + + case "PRIVMSG": + case "NOTICE": + list($target, $params) = explode(" ", $data, 2); + //cut the colon + $message = substr($params, 1); + break; + + case "INVITE": + list($target, $params) = explode(" ", $data, 2); + //cut the colon + $params = substr($params, 1); + break; + + case "ERROR": + case "QUIT": + if(strpos($data, " :") !== FALSE) { + list($params, $message) = explode(" :", $data); + $message = substr($message, 1); + } else { + $params = $data; + } + break; + + case "PING": + case "JOIN": + //cut the colon + $params = substr($data, 1); + break; + + //channel, + case "PART": + if(strpos($data, " :") !== FALSE) { + list($params, $message) = explode(" :", $data); + $message = substr($message, 1); + } else { + $params = $data; + } + break; + + case "NICK": + //cut the colon + $params = substr($data, 1); + break; + + //channel, user, + case "KICK": + $pieces = explode(" ", $data, 3); + list($target, $subject, $data) = explode(" ", $data, 3); + //get comment for kick and cut the colon + if(count($pieces === 3)) $message = substr($data, 1); + unset($pieces); + break; + + //MOTD content + case "372": + list($target, $message) = explode(" :", $data); + break; + + //user, comment + case "KILL": + case "MODE": + + + case "AWAY": + + case "001": + case "002": + case "003": + case "004": + case "005": + + case "250": + case "251": + case "252": + case "253": + case "254": + case "255": + case "265": + case "266": + + case "332": + case "333": + case "353": + //NAMES end + case "366": + + //MOTD start + case "375": + //MOTD end + case "376": + + //break; + //tell when stuff is not implemented + default: + //echo "N.i.y.: " . $command . " [".$data."]\r\n"; + break; + } + + //we're done parsing, now write the stuff into the contentObject. + $contentObject->setTarget($target); + $contentObject->setParams($params); + $contentObject->setMessage($message); + + return $contentObject; + } + + /** + * Returns whether there is work to be done. + * Important in order to assure that a ContentObject is created and passed to the Client. + * @return boolean + */ + public function canWork() { + return $this->bufferIncoming->hasLines(); + } + + /** + * Will put raw data into the outgoing buffer. + * This function will be removed soon. + * The ProtocolHandler shall take care of this directly. + * @param string $data + * @return void + */ + public function sendRaw($data) { + $this->bufferOutgoing->addData($data . $this->linebreak); + } + + /** + * Sends a pong. + * @param string $param + * @return void + */ + public function pong($param) { + $this->sendRaw("PONG :" . $param); + } + +} ?> \ No newline at end of file diff --git a/SocketFramework/Bootstrap.php b/SocketFramework/Bootstrap.php index a0ea807..fdc05f5 100644 --- a/SocketFramework/Bootstrap.php +++ b/SocketFramework/Bootstrap.php @@ -1,12 +1,12 @@ -initialize(); +initialize(); ?> \ No newline at end of file diff --git a/SocketFramework/Classes/Client/ClientDispatcherInterface.php b/SocketFramework/Classes/Client/ClientDispatcherInterface.php index 7ae7919..b89359f 100644 --- a/SocketFramework/Classes/Client/ClientDispatcherInterface.php +++ b/SocketFramework/Classes/Client/ClientDispatcherInterface.php @@ -1,74 +1,74 @@ - \ No newline at end of file diff --git a/Testcode/Misc/IrcParser.php b/Testcode/Misc/IrcParser.php index f2af15e..549de64 100644 --- a/Testcode/Misc/IrcParser.php +++ b/Testcode/Misc/IrcParser.php @@ -1,49 +1,49 @@ - $from, "Command" => $command, "Msg" => $msg); -} - -$lines = array(); -$lines[] = ":kornbluth.freenode.net 376 JPT|test :End of /MOTD command."; -$lines[] = ":frigg!~frigg@freenode/utility-bot/frigg PRIVMSG JPT|test :VERSION"; -$lines[] = ":kornbluth.freenode.net 333 JPT|test #botted rotw!~rotw@p5B133ADF.dip.t-dialin.net 1291741910"; -$lines[] = ":ChanServ!ChanServ@services. NOTICE JPT|test :[#botted] Für Statistiken siehe !stats. Wenn du nicht in diesen Auftauchen willst, wende dich bitte an samohT"; -$lines[] = ":kornbluth.freenode.net NOTICE * :*** Found your hostname"; -$lines[] = ":thomasbot!~thomasbot@unaffiliated/thomas/x-476237/bot/thomasbot PRIVMSG #botted :*pong*"; -$lines[] = ":n|ki!~niki@star-sim.de MODE #botted -v JPT"; -$lines[] = "ERROR :Closing Link: dslb-088-070-011-158.pools.arcor-ip.net (Client Quit)"; - - -foreach($lines AS $line) { - var_dump(parse($line)); -} - -echo "\r\n\r\n"; + $from, "Command" => $command, "Msg" => $msg); +} + +$lines = array(); +$lines[] = ":kornbluth.freenode.net 376 JPT|test :End of /MOTD command."; +$lines[] = ":frigg!~frigg@freenode/utility-bot/frigg PRIVMSG JPT|test :VERSION"; +$lines[] = ":kornbluth.freenode.net 333 JPT|test #botted rotw!~rotw@p5B133ADF.dip.t-dialin.net 1291741910"; +$lines[] = ":ChanServ!ChanServ@services. NOTICE JPT|test :[#botted] Für Statistiken siehe !stats. Wenn du nicht in diesen Auftauchen willst, wende dich bitte an samohT"; +$lines[] = ":kornbluth.freenode.net NOTICE * :*** Found your hostname"; +$lines[] = ":thomasbot!~thomasbot@unaffiliated/thomas/x-476237/bot/thomasbot PRIVMSG #botted :*pong*"; +$lines[] = ":n|ki!~niki@star-sim.de MODE #botted -v JPT"; +$lines[] = "ERROR :Closing Link: dslb-088-070-011-158.pools.arcor-ip.net (Client Quit)"; + + +foreach($lines AS $line) { + var_dump(parse($line)); +} + +echo "\r\n\r\n"; ?> \ No newline at end of file