Added validate regexp and a few more comments

This commit is contained in:
Luke Fitzgerald 2010-06-16 00:04:59 +01:00
parent 27e8cfd360
commit d41298950b
2 changed files with 21 additions and 11 deletions

View File

@ -58,7 +58,7 @@ class MsnPlugin extends ImPlugin {
*
* @return string Name of service
*/
function getDisplayName() {
public function getDisplayName() {
return _m('MSN');
}
@ -68,7 +68,7 @@ class MsnPlugin extends ImPlugin {
* @param string $screenname screenname to normalize
* @return string an equivalent screenname in normalized form
*/
function normalize($screenname) {
public function normalize($screenname) {
$screenname = str_replace(" ","", $screenname);
return strtolower($screenname);
}
@ -78,7 +78,7 @@ class MsnPlugin extends ImPlugin {
*
* @return string Screenname
*/
function daemon_screenname() {
public function daemon_screenname() {
return $this->user;
}
@ -86,20 +86,21 @@ class MsnPlugin extends ImPlugin {
* Validate (ensure the validity of) a screenname
*
* @param string $screenname screenname to validate
*
* @return boolean
*/
function validate($screenname) {
//TODO Correct this for MSN screennames
//if(preg_match('/^[a-z]\w{2,15}$/i', $screenname)) {
return true;
public function validate($screenname) {
// RFC 2822 (simplified) regexp
if(preg_match('/[a-z0-9!#$%&\'*+\/=?^_`{|}~-]+(?:\.[a-z0-9!#$%&\'*+\/=?^_`{|}~-]+)*@(?:[a-z0-9](?:[a-z0-9-]*[a-z0-9])?\.)+[a-z0-9](?:[a-z0-9-]*[a-z0-9])?/i', $screenname)) {
return true;
} else {
return false;
}
}
/**
* Load related modules when needed
*
* @param string $cls Name of the class to be loaded
*
* @return boolean hook value; true means continue processing, false means stop.
*/
public function onAutoload($cls) {
@ -159,7 +160,7 @@ class MsnPlugin extends ImPlugin {
/**
* Initialize plugin
*
* @return void
* @return boolean
*/
public function initialize() {
if (!isset($this->user)) {
@ -175,7 +176,13 @@ class MsnPlugin extends ImPlugin {
return true;
}
function onPluginVersion(&$versions) {
/**
* Get plugin information
*
* @param array $versions array to insert information into
* @return void
*/
public function onPluginVersion(&$versions) {
$versions[] = array(
'name' => 'MSN',
'version' => STATUSNET_VERSION,

View File

@ -146,6 +146,7 @@ class MsnManager extends ImManager {
* Passes it back to the queuing system
*
* @param array $data Data
* @return void
*/
private function handle_msn_message($data) {
$this->plugin->enqueue_incoming_raw($data);
@ -156,6 +157,7 @@ class MsnManager extends ImManager {
* Called by callback to log failure during connect
*
* @param void $data Not used (there to keep callback happy)
* @return void
*/
function handle_connect_failed($data) {
common_log(LOG_NOTICE, 'MSN connect failed, retrying');
@ -165,6 +167,7 @@ class MsnManager extends ImManager {
* Called by callback to log reconnection
*
* @param void $data Not used (there to keep callback happy)
* @return void
*/
function handle_reconnect($data) {
common_log(LOG_NOTICE, 'MSN reconnecting');