mirror of
https://codeberg.org/icewind/SMB.git
synced 2026-06-03 17:24:07 +02:00
factor out checking for next prompt
This commit is contained in:
parent
11023c007e
commit
2522f2f63f
1 changed files with 12 additions and 2 deletions
|
|
@ -15,6 +15,7 @@ use Icewind\SMB\Exception\NoLoginServerException;
|
|||
|
||||
class Connection extends RawConnection {
|
||||
const DELIMITER = 'smb:';
|
||||
const DELIMITER_LENGTH = 4;
|
||||
|
||||
/**
|
||||
* send input to smbclient
|
||||
|
|
@ -48,8 +49,7 @@ class Connection extends RawConnection {
|
|||
if ($line === false) {
|
||||
$this->unknownError($promptLine);
|
||||
}
|
||||
$length = mb_strlen(self::DELIMITER);
|
||||
while (mb_substr($line, 0, $length) !== self::DELIMITER && $line !== false) { //next prompt functions as delimiter
|
||||
while (!$this->isPrompt($line)) { //next prompt functions as delimiter
|
||||
if (is_callable($callback)) {
|
||||
$result = $callback($line);
|
||||
if ($result === false) { // allow the callback to close the connection for infinite running commands
|
||||
|
|
@ -63,6 +63,16 @@ class Connection extends RawConnection {
|
|||
return $output;
|
||||
}
|
||||
|
||||
/**
|
||||
* Check
|
||||
*
|
||||
* @param $line
|
||||
* @return bool
|
||||
*/
|
||||
private function isPrompt($line) {
|
||||
return mb_substr($line, 0, self::DELIMITER_LENGTH) === self::DELIMITER || $line === false;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $promptLine (optional) prompt line that might contain some info about the error
|
||||
* @throws ConnectException
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue