1 | <?php |
||
24 | class Parser { |
||
25 | const MSG_NOT_FOUND = 'Error opening local file '; |
||
26 | |||
27 | /** |
||
28 | * @var \Icewind\SMB\TimeZoneProvider |
||
29 | */ |
||
30 | protected $timeZoneProvider; |
||
31 | |||
32 | // todo replace with static once <5.6 support is dropped |
||
33 | // see error.h |
||
34 | const EXCEPTION_MAP = [ |
||
35 | ErrorCodes::LogonFailure => AuthenticationException::class, |
||
36 | ErrorCodes::PathNotFound => NotFoundException::class, |
||
37 | ErrorCodes::ObjectNotFound => NotFoundException::class, |
||
38 | ErrorCodes::NoSuchFile => NotFoundException::class, |
||
39 | ErrorCodes::NameCollision => AlreadyExistsException::class, |
||
40 | ErrorCodes::AccessDenied => AccessDeniedException::class, |
||
41 | ErrorCodes::DirectoryNotEmpty => NotEmptyException::class, |
||
42 | ErrorCodes::FileIsADirectory => InvalidTypeException::class, |
||
43 | ErrorCodes::NotADirectory => InvalidTypeException::class, |
||
44 | ErrorCodes::SharingViolation => FileInUseException::class, |
||
45 | ErrorCodes::InvalidParameter => InvalidParameterException::class |
||
46 | ]; |
||
47 | |||
48 | /** |
||
49 | * @param TimeZoneProvider $timeZoneProvider |
||
50 | */ |
||
51 | 825 | public function __construct(TimeZoneProvider $timeZoneProvider) { |
|
54 | |||
55 | 60 | private function getErrorCode($line) { |
|
64 | |||
65 | 60 | public function checkForError($output, $path) { |
|
78 | |||
79 | /** |
||
80 | * check if the first line holds a connection failure |
||
81 | * |
||
82 | * @param $line |
||
83 | * @throws AuthenticationException |
||
84 | * @throws InvalidHostException |
||
85 | * @throws NoLoginServerException |
||
86 | * @throws AccessDeniedException |
||
87 | */ |
||
88 | 777 | public function checkConnectionError($line) { |
|
89 | 777 | $line = rtrim($line, ')'); |
|
90 | 777 | if (substr($line, -23) === ErrorCodes::LogonFailure) { |
|
91 | 3 | throw new AuthenticationException('Invalid login'); |
|
92 | } |
||
93 | 774 | if (substr($line, -26) === ErrorCodes::BadHostName) { |
|
94 | throw new InvalidHostException('Invalid hostname'); |
||
95 | } |
||
96 | 774 | if (substr($line, -22) === ErrorCodes::Unsuccessful) { |
|
97 | 9 | throw new InvalidHostException('Connection unsuccessful'); |
|
98 | } |
||
99 | 768 | if (substr($line, -28) === ErrorCodes::ConnectionRefused) { |
|
100 | throw new InvalidHostException('Connection refused'); |
||
101 | } |
||
102 | 768 | if (substr($line, -26) === ErrorCodes::NoLogonServers) { |
|
103 | throw new NoLoginServerException('No login server'); |
||
104 | } |
||
105 | 768 | if (substr($line, -23) === ErrorCodes::AccessDenied) { |
|
106 | throw new AccessDeniedException('Access denied'); |
||
107 | } |
||
108 | 768 | } |
|
109 | |||
110 | 324 | public function parseMode($mode) { |
|
127 | |||
128 | 81 | public function parseStat($output) { |
|
145 | |||
146 | 754 | public function parseDir($output, $basePath) { |
|
164 | |||
165 | 6 | public function parseListShares($output) { |
|
181 | } |
||
182 |