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