[TASK] Fix line endings to LF only.

This commit is contained in:
Jan Philipp Timme 2013-09-05 11:55:43 +02:00
parent 4eaf0ede24
commit c5b045236e
5 changed files with 485 additions and 485 deletions

View File

@ -1,144 +1,144 @@
<?php <?php
/** /**
* ContentObject for IRC Protocol * ContentObject for IRC Protocol
* @author JPT * @author JPT
* @package Protocol * @package Protocol
*/ */
class Protocol_IrcProtocolContentObject extends Protocol_AbstractProtocolContentObject { class Protocol_IrcProtocolContentObject extends Protocol_AbstractProtocolContentObject {
/** /**
* @var string * @var string
*/ */
protected $sender; protected $sender;
/** /**
* @var string * @var string
*/ */
protected $command; protected $command;
/** /**
* @var string * @var string
*/ */
protected $params; protected $params;
/** /**
* Contains a user or the channel a command is addressed to. * Contains a user or the channel a command is addressed to.
* @var string * @var string
*/ */
protected $target; protected $target;
/** /**
* @var string * @var string
*/ */
protected $message; protected $message;
/** /**
* @var string * @var string
*/ */
protected $subject; protected $subject;
/** /**
* Sets sender. * Sets sender.
* @param string $sender * @param string $sender
* @return void * @return void
*/ */
public function setSender($sender) { public function setSender($sender) {
$this->sender = $sender; $this->sender = $sender;
} }
/** /**
* Gets sender. * Gets sender.
* @return string * @return string
*/ */
public function getSender() { public function getSender() {
return $this->sender; return $this->sender;
} }
/** /**
* Sets command. * Sets command.
* @param string $command * @param string $command
* @return void * @return void
*/ */
public function setCommand($command) { public function setCommand($command) {
$this->command = $command; $this->command = $command;
} }
/** /**
* Gets command. * Gets command.
* @return string * @return string
*/ */
public function getCommand() { public function getCommand() {
return $this->command; return $this->command;
} }
/** /**
* Sets params. * Sets params.
* @param string $params * @param string $params
* @return void * @return void
*/ */
public function setParams($params) { public function setParams($params) {
$this->params = $params; $this->params = $params;
} }
/** /**
* Gets params. * Gets params.
* @return string * @return string
*/ */
public function getParams() { public function getParams() {
return $this->params; return $this->params;
} }
/** /**
* Sets target. * Sets target.
* @param string $target * @param string $target
* @return void * @return void
*/ */
public function setTarget($target) { public function setTarget($target) {
$this->target = $target; $this->target = $target;
} }
/** /**
* Gets target. * Gets target.
* @return string * @return string
*/ */
public function getTarget() { public function getTarget() {
return $this->target; return $this->target;
} }
/** /**
* Sets message. * Sets message.
* @param string $message * @param string $message
* @return void * @return void
*/ */
public function setMessage($message) { public function setMessage($message) {
$this->message = $message; $this->message = $message;
} }
/** /**
* Gets message. * Gets message.
* @return string * @return string
*/ */
public function getMessage() { public function getMessage() {
return $this->message; return $this->message;
} }
/** /**
* Sets subject. * Sets subject.
* @param string $subject * @param string $subject
* @return void * @return void
*/ */
public function setSubject($subject) { public function setSubject($subject) {
$this->subject = $subject; $this->subject = $subject;
} }
/** /**
* Gets subject. * Gets subject.
* @return string * @return string
*/ */
public function getSubject() { public function getSubject() {
return $this->subject; return $this->subject;
} }
} }
?> ?>

View File

@ -1,211 +1,211 @@
<?php <?php
/** /**
* The ProtocolHandler for the IRC Protocol. * The ProtocolHandler for the IRC Protocol.
* @author JPT * @author JPT
* @package Protocol * @package Protocol
*/ */
class Protocol_IrcProtocolHandler extends Protocol_AbstractProtocolHandler { class Protocol_IrcProtocolHandler extends Protocol_AbstractProtocolHandler {
/** /**
* @var string * @var string
*/ */
protected $linebreak; protected $linebreak;
/** /**
* Is called by the constructor. * Is called by the constructor.
* Shall create the two buffers and set them up. * Shall create the two buffers and set them up.
* @return void * @return void
*/ */
protected function createBuffers() { protected function createBuffers() {
$this->linebreak = "\n"; $this->linebreak = "\n";
$this->bufferIncoming = new Misc_Buffer($this->linebreak); $this->bufferIncoming = new Misc_Buffer($this->linebreak);
$this->bufferOutgoing = new Misc_Buffer($this->linebreak); $this->bufferOutgoing = new Misc_Buffer($this->linebreak);
} }
/** /**
* Main worker function. It will be called in a loop. * Main worker function. It will be called in a loop.
* It does all the protocol-dependent parsing. * It does all the protocol-dependent parsing.
* The returned ContentObject will be passed to the client. * The returned ContentObject will be passed to the client.
* @return Protocol_IrcProtocolContentObject * @return Protocol_IrcProtocolContentObject
* @throws Exception_ProtocolHandlerException * @throws Exception_ProtocolHandlerException
* @throws Exception_GeneralException * @throws Exception_GeneralException
*/ */
public function work() { public function work() {
$data = $this->bufferIncoming->getNextLine(); $data = $this->bufferIncoming->getNextLine();
//create contentObject and set the raw data. //create contentObject and set the raw data.
$contentObject = new Protocol_IrcProtocolContentObject($data); $contentObject = new Protocol_IrcProtocolContentObject($data);
//trim whitespace //trim whitespace
$data = trim($data); $data = trim($data);
//no data? complain! //no data? complain!
if($data === "") throw new Exception_ProtocolHandlerException("No data to process! Where did it go?!", 1292082006); if($data === "") throw new Exception_ProtocolHandlerException("No data to process! Where did it go?!", 1292082006);
//get the guy who sent the message //get the guy who sent the message
$sender = ""; $sender = "";
if($data[0] === ":") { if($data[0] === ":") {
list($sender, $data) = explode(" ", $data, 2); list($sender, $data) = explode(" ", $data, 2);
//cut the colon //cut the colon
$sender = substr($sender, 1); $sender = substr($sender, 1);
$contentObject->setSender($sender); $contentObject->setSender($sender);
} }
//determine what command was sent //determine what command was sent
$command = ""; $command = "";
if(strpos($data, " ") !== FALSE) { if(strpos($data, " ") !== FALSE) {
list($command, $data) = explode(" ", $data, 2); list($command, $data) = explode(" ", $data, 2);
} else { } else {
$command = $data; $command = $data;
} }
$contentObject->setCommand($command); $contentObject->setCommand($command);
//we'll write these values into the contentObject later! //we'll write these values into the contentObject later!
//contains a user or the channel a command is addressed to. //contains a user or the channel a command is addressed to.
$target = NULL; $target = NULL;
//parameters of the command //parameters of the command
$params = NULL; $params = NULL;
//content or message //content or message
$message = NULL; $message = NULL;
//affected nickname(s) (e.g. by a KICK or MODE +b) //affected nickname(s) (e.g. by a KICK or MODE +b)
$subject = NULL; $subject = NULL;
//command-dependent parsing //command-dependent parsing
switch($command) { switch($command) {
case "PRIVMSG": case "PRIVMSG":
case "NOTICE": case "NOTICE":
list($target, $params) = explode(" ", $data, 2); list($target, $params) = explode(" ", $data, 2);
//cut the colon //cut the colon
$message = substr($params, 1); $message = substr($params, 1);
break; break;
case "INVITE": case "INVITE":
list($target, $params) = explode(" ", $data, 2); list($target, $params) = explode(" ", $data, 2);
//cut the colon //cut the colon
$params = substr($params, 1); $params = substr($params, 1);
break; break;
case "ERROR": case "ERROR":
case "QUIT": case "QUIT":
if(strpos($data, " :") !== FALSE) { if(strpos($data, " :") !== FALSE) {
list($params, $message) = explode(" :", $data); list($params, $message) = explode(" :", $data);
$message = substr($message, 1); $message = substr($message, 1);
} else { } else {
$params = $data; $params = $data;
} }
break; break;
case "PING": case "PING":
case "JOIN": case "JOIN":
//cut the colon //cut the colon
$params = substr($data, 1); $params = substr($data, 1);
break; break;
//channel, <comment> //channel, <comment>
case "PART": case "PART":
if(strpos($data, " :") !== FALSE) { if(strpos($data, " :") !== FALSE) {
list($params, $message) = explode(" :", $data); list($params, $message) = explode(" :", $data);
$message = substr($message, 1); $message = substr($message, 1);
} else { } else {
$params = $data; $params = $data;
} }
break; break;
case "NICK": case "NICK":
//cut the colon //cut the colon
$params = substr($data, 1); $params = substr($data, 1);
break; break;
//channel, user, <comment> //channel, user, <comment>
case "KICK": case "KICK":
$pieces = explode(" ", $data, 3); $pieces = explode(" ", $data, 3);
list($target, $subject, $data) = explode(" ", $data, 3); list($target, $subject, $data) = explode(" ", $data, 3);
//get comment for kick and cut the colon //get comment for kick and cut the colon
if(count($pieces === 3)) $message = substr($data, 1); if(count($pieces === 3)) $message = substr($data, 1);
unset($pieces); unset($pieces);
break; break;
//MOTD content //MOTD content
case "372": case "372":
list($target, $message) = explode(" :", $data); list($target, $message) = explode(" :", $data);
break; break;
//user, comment //user, comment
case "KILL": case "KILL":
case "MODE": case "MODE":
case "AWAY": case "AWAY":
case "001": case "001":
case "002": case "002":
case "003": case "003":
case "004": case "004":
case "005": case "005":
case "250": case "250":
case "251": case "251":
case "252": case "252":
case "253": case "253":
case "254": case "254":
case "255": case "255":
case "265": case "265":
case "266": case "266":
case "332": case "332":
case "333": case "333":
case "353": case "353":
//NAMES end //NAMES end
case "366": case "366":
//MOTD start //MOTD start
case "375": case "375":
//MOTD end //MOTD end
case "376": case "376":
//break; //break;
//tell when stuff is not implemented //tell when stuff is not implemented
default: default:
//echo "N.i.y.: " . $command . " [".$data."]\r\n"; //echo "N.i.y.: " . $command . " [".$data."]\r\n";
break; break;
} }
//we're done parsing, now write the stuff into the contentObject. //we're done parsing, now write the stuff into the contentObject.
$contentObject->setTarget($target); $contentObject->setTarget($target);
$contentObject->setParams($params); $contentObject->setParams($params);
$contentObject->setMessage($message); $contentObject->setMessage($message);
return $contentObject; return $contentObject;
} }
/** /**
* Returns whether there is work to be done. * Returns whether there is work to be done.
* Important in order to assure that a ContentObject is created and passed to the Client. * Important in order to assure that a ContentObject is created and passed to the Client.
* @return boolean * @return boolean
*/ */
public function canWork() { public function canWork() {
return $this->bufferIncoming->hasLines(); return $this->bufferIncoming->hasLines();
} }
/** /**
* Will put raw data into the outgoing buffer. * Will put raw data into the outgoing buffer.
* This function will be removed soon. * This function will be removed soon.
* The ProtocolHandler shall take care of this directly. * The ProtocolHandler shall take care of this directly.
* @param string $data * @param string $data
* @return void * @return void
*/ */
public function sendRaw($data) { public function sendRaw($data) {
$this->bufferOutgoing->addData($data . $this->linebreak); $this->bufferOutgoing->addData($data . $this->linebreak);
} }
/** /**
* Sends a pong. * Sends a pong.
* @param string $param * @param string $param
* @return void * @return void
*/ */
public function pong($param) { public function pong($param) {
$this->sendRaw("PONG :" . $param); $this->sendRaw("PONG :" . $param);
} }
} }
?> ?>

View File

@ -1,12 +1,12 @@
<?php <?php
/** /**
* This file bootstraps the SocketFramework by initializing the error_reporting to E_ALL * This file bootstraps the SocketFramework by initializing the error_reporting to E_ALL
* and initializing the ClassLoader. * and initializing the ClassLoader.
* @author jpt * @author jpt
*/ */
error_reporting(\E_ALL); error_reporting(\E_ALL);
require_once("Classes" . \DIRECTORY_SEPARATOR . "Core" . \DIRECTORY_SEPARATOR . "ClassLoader.php"); require_once("Classes" . \DIRECTORY_SEPARATOR . "Core" . \DIRECTORY_SEPARATOR . "ClassLoader.php");
$classLoader = new \JPT\SocketFramework\Core\ClassLoader(); $classLoader = new \JPT\SocketFramework\Core\ClassLoader();
$classLoader->initialize(); $classLoader->initialize();
?> ?>

View File

@ -1,74 +1,74 @@
<?php <?php
namespace JPT\SocketFramework\Client; namespace JPT\SocketFramework\Client;
/** /**
* Interface that includes the real must-have stuff. * Interface that includes the real must-have stuff.
* *
* @author jpt * @author jpt
* @interface * @interface
* @package Client * @package Client
*/ */
interface ClientDispatcherInterface { interface ClientDispatcherInterface {
/** /**
* Forwards incoming data to the ProtocolHandler * Forwards incoming data to the ProtocolHandler
* Let's the ProtocolHandler do all the work and forward its results to the Clients. * Let's the ProtocolHandler do all the work and forward its results to the Clients.
* Return resulting raw data. * Return resulting raw data.
* *
* @param string $rawData * @param string $rawData
* @return string * @return string
*/ */
public function processRawData($rawData); public function processRawData($rawData);
/** /**
* This function will load the given config. * This function will load the given config.
* *
* @param array $config * @param array $config
* @return void * @return void
*/ */
public function loadConfig($config); public function loadConfig($config);
/** /**
* Will reset the connectionStatus of the client. * Will reset the connectionStatus of the client.
* Implementation is optional and depends on the client. * Implementation is optional and depends on the client.
* Should be used to reset internal variables. * Should be used to reset internal variables.
* *
* @return void * @return void
*/ */
public function resetConnectionStatus(); public function resetConnectionStatus();
/** /**
* This function gets called every time, the connection is established. * This function gets called every time, the connection is established.
* This allows the client to send initial data. * This allows the client to send initial data.
* *
* @return void * @return void
*/ */
public function initializeConnection(); public function initializeConnection();
/** /**
* Sets the ID. * Sets the ID.
* *
* @param int $id * @param int $id
* @return void * @return void
*/ */
public function setID($id); public function setID($id);
/** /**
* Sets the group. * Sets the group.
* *
* @param string $group * @param string $group
* @return void * @return void
*/ */
public function setGroup($group); public function setGroup($group);
/** /**
* Injects ClientManager. * Injects ClientManager.
* *
* @param \JPT\SocketFramework\Client\ClientManager $clientManager * @param \JPT\SocketFramework\Client\ClientManager $clientManager
* @return void * @return void
* @throws \JPT\SocketFramework\Exception\WrongDatatypeException * @throws \JPT\SocketFramework\Exception\WrongDatatypeException
*/ */
public function injectClientManager($clientManager); public function injectClientManager($clientManager);
} }
?> ?>

View File

@ -1,49 +1,49 @@
<?php <?php
/** /**
* Parser for Clientside-IRC. * Parser for Clientside-IRC.
* @param string $msg * @param string $msg
* @return array * @return array
*/ */
function parse($msg){ function parse($msg){
//skip empty //skip empty
if(trim($msg) === "") return; if(trim($msg) === "") return;
$from = ""; $from = "";
if($msg[0] === ":") { if($msg[0] === ":") {
$piece = explode(" ", $msg, 2); $piece = explode(" ", $msg, 2);
list($from, $msg) = $piece; list($from, $msg) = $piece;
unset($piece); unset($piece);
//cut the colon //cut the colon
$from = substr($from, 1); $from = substr($from, 1);
} }
$command = ""; $command = "";
$piece = explode(" ", $msg, 2); $piece = explode(" ", $msg, 2);
list($command, $msg) = $piece; list($command, $msg) = $piece;
unset($piece); unset($piece);
return array("From" => $from, "Command" => $command, "Msg" => $msg); return array("From" => $from, "Command" => $command, "Msg" => $msg);
} }
$lines = array(); $lines = array();
$lines[] = ":kornbluth.freenode.net 376 JPT|test :End of /MOTD command."; $lines[] = ":kornbluth.freenode.net 376 JPT|test :End of /MOTD command.";
$lines[] = ":frigg!~frigg@freenode/utility-bot/frigg PRIVMSG JPT|test :VERSION"; $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[] = ":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[] = ":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[] = ":kornbluth.freenode.net NOTICE * :*** Found your hostname";
$lines[] = ":thomasbot!~thomasbot@unaffiliated/thomas/x-476237/bot/thomasbot PRIVMSG #botted :*pong*"; $lines[] = ":thomasbot!~thomasbot@unaffiliated/thomas/x-476237/bot/thomasbot PRIVMSG #botted :*pong*";
$lines[] = ":n|ki!~niki@star-sim.de MODE #botted -v JPT"; $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)"; $lines[] = "ERROR :Closing Link: dslb-088-070-011-158.pools.arcor-ip.net (Client Quit)";
foreach($lines AS $line) { foreach($lines AS $line) {
var_dump(parse($line)); var_dump(parse($line));
} }
echo "\r\n\r\n"; echo "\r\n\r\n";
?> ?>