From caeaf4b5201fd72e958cbedc5a2a88c859cfd0d9 Mon Sep 17 00:00:00 2001 From: multiOTP Date: Fri, 21 Oct 2022 18:28:27 +0200 Subject: [PATCH] 2.0.1.0 Full support of upper and lower case response, also for handling authentication --- README.md | 7 ++-- pjlink.class.php | 107 ++++++++++++++++++++++++----------------------- test.class.php | 2 +- 3 files changed, 59 insertions(+), 57 deletions(-) diff --git a/README.md b/README.md index 63378ca..b261cf4 100644 --- a/README.md +++ b/README.md @@ -13,16 +13,17 @@ PJLink Class2 specifications are available here: PJLink test software is available gere: http://pjlink.jbmia.or.jp/english/data_cl2/PJLink_5-2.zip -(c) 2017-2019 SysCo systemes de communication sa +(c) 2017-2022 SysCo systemes de communication sa http://developer.sysco.ch/php/ -Current build: 2.0.0.2 (2019-03-13) +Current build: 2.0.1.0 (2022-10-21) No external file is needed (no PEAR, no PECL, no cURL). # Change Log ``` +2022-10-21 2.0.1.0 SysCo/al Full support of upper and lower case response, also for handling authentication 2019-03-13 2.0.0.2 tomatow Lower case response are now accepted 2017-09-05 2.0.0.0 SysCo/al First public Class2 support 2017-04-24 1.0.0.1 SysCo/al First public version @@ -32,7 +33,7 @@ No external file is needed (no PEAR, no PECL, no cURL). # Licence - Copyright (c) 2017-2019 SysCo systemes de communication sa + Copyright (c) 2017-2022 SysCo systemes de communication sa SysCo (tm) is a trademark of SysCo systemes de communication sa (http://www.sysco.ch/) All rights reserved. diff --git a/pjlink.class.php b/pjlink.class.php index 7524bc4..25f52fd 100644 --- a/pjlink.class.php +++ b/pjlink.class.php @@ -26,8 +26,8 @@ * PHP 5.3.0 or higher is supported. * * @author Andre Liechti, SysCo systemes de communication sa, - * @version 2.0.0.2 - * @date 2019-03-13 + * @version 2.0.1.0 + * @date 2022-10-21 * @since 2017-04-23 * @copyright (c) 2017-2019 SysCo systemes de communication sa * @copyright GNU Lesser General Public License @@ -36,7 +36,7 @@ * * LICENCE * - * Copyright (c) 2017-2019 SysCo systemes de communication sa + * Copyright (c) 2017-2022 SysCo systemes de communication sa * SysCo (tm) is a trademark of SysCo systemes de communication sa * (http://www.sysco.ch/) * All rights reserved. @@ -170,7 +170,8 @@ * * Change Log * - * 2019-03-13 2.0.0.2 tomatow Lower case response are now accepted + * 2022-10-21 2.0.1.0 SysCo/al Full support of upper and lower case response, also for handling authentication + * 2019-03-13 2.0.0.2 tomatow Lower case response are now accepted * 2017-09-05 2.0.0.0 SysCo/al First public Class2 support * 2017-04-24 1.0.0.1 SysCo/al First public version * 2017-04-23 1.0.0.0 SysCo/al Initial implementation @@ -308,13 +309,13 @@ private function open( stream_set_timeout($this->socket, $this->timeout, 0); - $response = strtoupper($this->getResponse()); + $response = $this->getResponse(); - if (FALSE !== strpos($response, "PJLINK 0")) { + if (FALSE !== stripos($response, "PJLINK 0")) { $this->prefix_hash = ""; return true; - } elseif (FALSE !== strpos($response, "PJLINK 1")) { - $auth_random = trim(substr($response, strpos($response, "PJLINK 1") + 9)); + } elseif (FALSE !== stripos($response, "PJLINK 1")) { + $auth_random = trim(substr($response, stripos($response, "PJLINK 1") + 9)); $this->prefix_hash = md5($auth_random . $this->password); return true; } else { @@ -348,13 +349,13 @@ private function sendCommand( $response = $this->getResponse(); - if (FALSE !== strpos($response, "PJLINK ERRA")) { + if (FALSE !== stripos($response, "PJLINK ERRA")) { $this->error = "Authentication failed"; $this->error_number = PJLINK_AUTH_ERROR; return false; - } elseif (FALSE !== strpos($response, PJLINK_PREFIX)) { - $result = trim(substr($response, strpos($response, "=") + 1)); - if (0 === strpos($result, "ERR")) { + } elseif (FALSE !== stripos($response, PJLINK_PREFIX)) { + $result = trim(substr($response, stripos($response, "=") + 1)); + if (0 === stripos($result, "ERR")) { $this->response_text = $result; return false; } else { @@ -424,12 +425,12 @@ public function powerOn( if ($this->open($host, $password, $timeout, $port)) { $result = $this->sendCommand($command); if (false !== $result) { - switch ($result) { + switch (strtoupper($result)) { default: $this->response_text = $result; } } else { - switch ($result) { + switch (strtoupper($result)) { case 'ERR2': $this->response_text = "out-of-parameter"; break; @@ -460,12 +461,12 @@ public function powerOff( if ($this->open($host, $password, $timeout, $port)) { $result = $this->sendCommand($command); if (false !== $result) { - switch ($result) { + switch (strtoupper($result)) { default: $this->response_text = $result; } } else { - switch ($result) { + switch (strtoupper($result)) { case 'ERR2': $this->response_text = "out-of-parameter"; break; @@ -496,7 +497,7 @@ public function getPowerState( if ($this->open($host, $password, $timeout, $port)) { $result = $this->sendCommand($command); if (false !== $result) { - switch ($result) { + switch (strtoupper($result)) { case '0': $this->response_text = "off"; break; @@ -513,7 +514,7 @@ public function getPowerState( $this->response_text = $result; } } else { - switch ($result) { + switch (strtoupper($result)) { case 'ERR3': $this->response_text = "unavailable"; break; @@ -542,12 +543,12 @@ public function setInput( if ($this->open($host, $password, $timeout, $port)) { $result = $this->sendCommand($command); if (false !== $result) { - switch ($result) { + switch (strtoupper($result)) { default: $this->response_text = $result; } } else { - switch ($result) { + switch (strtoupper($result)) { case 'ERR2': $this->response_text = "nonexistent"; break; @@ -578,12 +579,12 @@ public function getInput( if ($this->open($host, $password, $timeout, $port)) { $result = $this->sendCommand($command); if (false !== $result) { - switch ($result) { + switch (strtoupper($result)) { default: $this->response_text = $result; } } else { - switch ($result) { + switch (strtoupper($result)) { case 'ERR3': $this->response_text = "unavailable"; break; @@ -612,12 +613,12 @@ private function muteVideoAudio( if ($this->open($host, $password, $timeout, $port)) { $result = $this->sendCommand($command); if (false !== $result) { - switch ($result) { + switch (strtoupper($result)) { default: $this->response_text = $result; } } else { - switch ($result) { + switch (strtoupper($result)) { case 'ERR2': $this->response_text = "out-of-parameter"; break; @@ -708,7 +709,7 @@ public function getMuteState( if ($this->open($host, $password, $timeout, $port)) { $result = $this->sendCommand($command); if (false !== $result) { - switch ($result) { + switch (strtoupper($result)) { case '11': $this->response_text = "video-mute-on"; break; @@ -725,7 +726,7 @@ public function getMuteState( $this->response_text = $result; } } else { - switch ($result) { + switch (strtoupper($result)) { case 'ERR3': $this->response_text = "unavailable"; break; @@ -773,7 +774,7 @@ public function getErrorState( $this->response_text.= ($this->response_text != "" ? ", " : "") . "OTHER: " . ((substr($result, 5, 1) == "1") ? "WARNING" : "ERROR"); } } else { - switch ($result) { + switch (strtoupper($result)) { case 'ERR3': $this->response_text = "unavailable"; break; @@ -818,7 +819,7 @@ public function getLampState( } $this->response_text = $result_text; } else { - switch ($result) { + switch (strtoupper($result)) { case 'ERR1': $this->response_text = "no-lamp"; break; @@ -849,12 +850,12 @@ public function getInputList( if ($this->open($host, $password, $timeout, $port)) { $result = $this->sendCommand($command); if (false !== $result) { - switch ($result) { + switch (strtoupper($result)) { default: $this->response_text = $result; } } else { - switch ($result) { + switch (strtoupper($result)) { case 'ERR2': $this->response_text = "out-of-parameter"; break; @@ -887,7 +888,7 @@ public function getName( if (false !== $result) { $this->response_text = $result; } else { - switch ($result) { + switch (strtoupper($result)) { case 'ERR3': $this->response_text = "unavailable"; break; @@ -916,7 +917,7 @@ public function getManufactureName( if (false !== $result) { $this->response_text = $result; } else { - switch ($result) { + switch (strtoupper($result)) { case 'ERR3': $this->response_text = "unavailable"; break; @@ -946,7 +947,7 @@ public function getProductName( if (false !== $result) { $this->response_text = $result; } else { - switch ($result) { + switch (strtoupper($result)) { case 'ERR3': $this->response_text = "unavailable"; break; @@ -976,7 +977,7 @@ public function getOtherInfo( if (false !== $result) { $this->response_text = $result; } else { - switch ($result) { + switch (strtoupper($result)) { case 'ERR3': $this->response_text = "unavailable"; break; @@ -1009,7 +1010,7 @@ public function getClass( $this->setClassLevel(intval($result)); } } else { - switch ($result) { + switch (strtoupper($result)) { case 'ERR3': $this->response_text = "unavailable"; break; @@ -1039,7 +1040,7 @@ public function getSerialNumber( if (false !== $result) { $this->response_text = $result; } else { - switch ($result) { + switch (strtoupper($result)) { case 'ERR3': $this->response_text = "unavailable"; break; @@ -1069,7 +1070,7 @@ public function getSoftwareVersion( if (false !== $result) { $this->response_text = $result; } else { - switch ($result) { + switch (strtoupper($result)) { case 'ERR3': $this->response_text = "unavailable"; break; @@ -1100,7 +1101,7 @@ public function getInputTerminalName( if (false !== $result) { $this->response_text = $result; } else { - switch ($result) { + switch (strtoupper($result)) { case 'ERR2': $this->response_text = "out-of-parameter"; break; @@ -1133,7 +1134,7 @@ public function getInputResolution( if (false !== $result) { $this->response_text = $result; } else { - switch ($result) { + switch (strtoupper($result)) { case '-': $this->response_text = "no-signal"; break; @@ -1169,7 +1170,7 @@ public function getRecommendedResolution( if (false !== $result) { $this->response_text = $result; } else { - switch ($result) { + switch (strtoupper($result)) { case 'ERR3': $this->response_text = "unavailable"; break; @@ -1199,7 +1200,7 @@ public function getFilterUsage( if (false !== $result) { $this->response_text = $result; } else { - switch ($result) { + switch (strtoupper($result)) { case 'ERR1': $this->response_text = "no-filter"; break; @@ -1232,7 +1233,7 @@ public function getLampReplacementModel( if (false !== $result) { $this->response_text = $result; } else { - switch ($result) { + switch (strtoupper($result)) { case '': $this->response_text = "no-replacement-model-number"; break; @@ -1265,7 +1266,7 @@ public function getFilterReplacementModel( if (false !== $result) { $this->response_text = $result; } else { - switch ($result) { + switch (strtoupper($result)) { case '': $this->response_text = "no-replacement-model-number"; break; @@ -1297,12 +1298,12 @@ public function setSpeakerVolume( if ($this->open($host, $password, $timeout, $port)) { $result = $this->sendCommand($command); if (false !== $result) { - switch ($result) { + switch (strtoupper($result)) { default: $this->response_text = $result; } } else { - switch ($result) { + switch (strtoupper($result)) { case 'ERR1': $this->response_text = "no-speaker"; break; @@ -1337,12 +1338,12 @@ public function setMicrophoneVolume( if ($this->open($host, $password, $timeout, $port)) { $result = $this->sendCommand($command); if (false !== $result) { - switch ($result) { + switch (strtoupper($result)) { default: $this->response_text = $result; } } else { - switch ($result) { + switch (strtoupper($result)) { case 'ERR1': $this->response_text = "no-microphone"; break; @@ -1376,12 +1377,12 @@ public function freezeOn( if ($this->open($host, $password, $timeout, $port)) { $result = $this->sendCommand($command); if (false !== $result) { - switch ($result) { + switch (strtoupper($result)) { default: $this->response_text = $result; } } else { - switch ($result) { + switch (strtoupper($result)) { case 'ERR1': $this->response_text = "not-supported"; break; @@ -1415,12 +1416,12 @@ public function freezeOff( if ($this->open($host, $password, $timeout, $port)) { $result = $this->sendCommand($command); if (false !== $result) { - switch ($result) { + switch (strtoupper($result)) { default: $this->response_text = $result; } } else { - switch ($result) { + switch (strtoupper($result)) { case 'ERR1': $this->response_text = "not-supported"; break; @@ -1454,7 +1455,7 @@ public function getFreezeState( if ($this->open($host, $password, $timeout, $port)) { $result = $this->sendCommand($command); if (false !== $result) { - switch ($result) { + switch (strtoupper($result)) { case '0': $this->response_text = "unfreezed"; break; @@ -1465,7 +1466,7 @@ public function getFreezeState( $this->response_text = $result; } } else { - switch ($result) { + switch (strtoupper($result)) { case 'ERR1': $this->response_text = "not-supported"; break; diff --git a/test.class.php b/test.class.php index f0c2323..7262d08 100644 --- a/test.class.php +++ b/test.class.php @@ -6,7 +6,7 @@ require_once('pjlink.class.php'); $host = "127.0.0.1"; - $password = "JBMIAProjectorLink": + $password = "JBMIAProjectorLink"; $wait = 10; $input = 22;