1bda3441225e0607b5ced8b538123fd7c7a417910chrismair/* 2bda3441225e0607b5ced8b538123fd7c7a417910chrismair * Copyright 2009 the original author or authors. 3bda3441225e0607b5ced8b538123fd7c7a417910chrismair * 4bda3441225e0607b5ced8b538123fd7c7a417910chrismair * Licensed under the Apache License, Version 2.0 (the "License"); 5bda3441225e0607b5ced8b538123fd7c7a417910chrismair * you may not use this file except in compliance with the License. 6bda3441225e0607b5ced8b538123fd7c7a417910chrismair * You may obtain a copy of the License at 7bda3441225e0607b5ced8b538123fd7c7a417910chrismair * 8bda3441225e0607b5ced8b538123fd7c7a417910chrismair * http://www.apache.org/licenses/LICENSE-2.0 9bda3441225e0607b5ced8b538123fd7c7a417910chrismair * 10bda3441225e0607b5ced8b538123fd7c7a417910chrismair * Unless required by applicable law or agreed to in writing, software 11bda3441225e0607b5ced8b538123fd7c7a417910chrismair * distributed under the License is distributed on an "AS IS" BASIS, 12bda3441225e0607b5ced8b538123fd7c7a417910chrismair * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13bda3441225e0607b5ced8b538123fd7c7a417910chrismair * See the License for the specific language governing permissions and 14bda3441225e0607b5ced8b538123fd7c7a417910chrismair * limitations under the License. 15bda3441225e0607b5ced8b538123fd7c7a417910chrismair */ 16bda3441225e0607b5ced8b538123fd7c7a417910chrismairpackage org.mockftpserver.fake.command; 17bda3441225e0607b5ced8b538123fd7c7a417910chrismair 18bda3441225e0607b5ced8b538123fd7c7a417910chrismairimport org.mockftpserver.core.command.Command; 19bda3441225e0607b5ced8b538123fd7c7a417910chrismairimport org.mockftpserver.core.command.ReplyCodes; 20bda3441225e0607b5ced8b538123fd7c7a417910chrismairimport org.mockftpserver.core.session.Session; 21bda3441225e0607b5ced8b538123fd7c7a417910chrismairimport org.mockftpserver.core.util.HostAndPort; 22bda3441225e0607b5ced8b538123fd7c7a417910chrismairimport org.mockftpserver.core.util.PortParser; 23bda3441225e0607b5ced8b538123fd7c7a417910chrismair 24bda3441225e0607b5ced8b538123fd7c7a417910chrismair/** 25bda3441225e0607b5ced8b538123fd7c7a417910chrismair * CommandHandler for the EPRT command. Handler logic: 26bda3441225e0607b5ced8b538123fd7c7a417910chrismair * <ol> 27bda3441225e0607b5ced8b538123fd7c7a417910chrismair * <li>Parse the client network address (InetAddress) and port number from the (single) 28bda3441225e0607b5ced8b538123fd7c7a417910chrismair * parameter string of the form: "EPRT<space><d><net-prt><d><net-addr><d><tcp-port><d>". 29bda3441225e0607b5ced8b538123fd7c7a417910chrismair * The client network address can be in IPv4 format (e.g., "132.235.1.2") or 30bda3441225e0607b5ced8b538123fd7c7a417910chrismair * IPv6 format (e.g., "1080::8:800:200C:417A") 31bda3441225e0607b5ced8b538123fd7c7a417910chrismair * <li>Send back a reply of 200</li> 32bda3441225e0607b5ced8b538123fd7c7a417910chrismair * </ol> 33bda3441225e0607b5ced8b538123fd7c7a417910chrismair * See RFC2428 for more information. 34bda3441225e0607b5ced8b538123fd7c7a417910chrismair * 35bda3441225e0607b5ced8b538123fd7c7a417910chrismair * @author Chris Mair 36bda3441225e0607b5ced8b538123fd7c7a417910chrismair * @version $Revision$ - $Date$ 37bda3441225e0607b5ced8b538123fd7c7a417910chrismair */ 38bda3441225e0607b5ced8b538123fd7c7a417910chrismairpublic class EprtCommandHandler extends AbstractFakeCommandHandler { 39bda3441225e0607b5ced8b538123fd7c7a417910chrismair 40bda3441225e0607b5ced8b538123fd7c7a417910chrismair protected void handle(Command command, Session session) { 41bda3441225e0607b5ced8b538123fd7c7a417910chrismair String parameter = command.getRequiredParameter(0); 42bda3441225e0607b5ced8b538123fd7c7a417910chrismair HostAndPort client = PortParser.parseExtendedAddressHostAndPort(parameter); 43bda3441225e0607b5ced8b538123fd7c7a417910chrismair LOG.debug("host=" + client.host + " port=" + client.port); 44bda3441225e0607b5ced8b538123fd7c7a417910chrismair session.setClientDataHost(client.host); 45bda3441225e0607b5ced8b538123fd7c7a417910chrismair session.setClientDataPort(client.port); 46bda3441225e0607b5ced8b538123fd7c7a417910chrismair sendReply(session, ReplyCodes.EPRT_OK, "eprt"); 47bda3441225e0607b5ced8b538123fd7c7a417910chrismair } 48bda3441225e0607b5ced8b538123fd7c7a417910chrismair 49bda3441225e0607b5ced8b538123fd7c7a417910chrismair}