forked from apache/mina-sshd
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
apacheGH-275: Improve SFTP status message parsing
Introduce a message record for SSH_FXP_STATUS to centralize parsing it from a buffer. Treat the error message and the language tag as optional because these fields exist only since SFTP v3, and apparently there are SFTP v3 servers that don't send it. Bug: apache#275
- Loading branch information
Showing
7 changed files
with
207 additions
and
71 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
71 changes: 71 additions & 0 deletions
71
sshd-sftp/src/main/java/org/apache/sshd/sftp/client/impl/SftpStatus.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
/* | ||
* Licensed to the Apache Software Foundation (ASF) under one | ||
* or more contributor license agreements. See the NOTICE file | ||
* distributed with this work for additional information | ||
* regarding copyright ownership. The ASF licenses this file | ||
* to you under the Apache License, Version 2.0 (the | ||
* "License"); you may not use this file except in compliance | ||
* with the License. You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, | ||
* software distributed under the License is distributed on an | ||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
* KIND, either express or implied. See the License for the | ||
* specific language governing permissions and limitations | ||
* under the License. | ||
*/ | ||
package org.apache.sshd.sftp.client.impl; | ||
|
||
import org.apache.sshd.common.util.buffer.Buffer; | ||
import org.apache.sshd.sftp.common.SftpConstants; | ||
|
||
/** | ||
* A representation of a SSH_FXP_STATUS record. | ||
*/ | ||
public final class SftpStatus { | ||
|
||
private final int statusCode; | ||
|
||
private final String language; | ||
|
||
private final String message; | ||
|
||
private SftpStatus(int statusCode, String message, String language) { | ||
this.statusCode = statusCode; | ||
this.message = message; | ||
this.language = language; | ||
} | ||
|
||
public int getStatusCode() { | ||
return statusCode; | ||
} | ||
|
||
public String getLanguage() { | ||
return language; | ||
} | ||
|
||
public String getMessage() { | ||
return message; | ||
} | ||
|
||
public boolean isOk() { | ||
return statusCode == SftpConstants.SSH_FX_OK; | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
return "SSH_FXP_STATUS[" + SftpConstants.getStatusName(statusCode) + " ,language=" + language + " ,message=" + message | ||
+ ']'; | ||
} | ||
|
||
public static SftpStatus parse(Buffer buffer) { | ||
int code = buffer.getInt(); | ||
// Treat the message and language tag as optional. These fields did not exist in SFTP v0-2, and there are | ||
// apparently SFTP v3 servers that sometimes send SSH_FXP_STATUS without them. | ||
String message = buffer.available() > 0 ? buffer.getString() : null; | ||
String language = buffer.available() > 0 ? buffer.getString() : null; | ||
return new SftpStatus(code, message, language); | ||
} | ||
} |
Oops, something went wrong.