package net.sourceforge.guacamole.net.basic.crud.connections;

/*
 *  Guacamole - Clientless Remote Desktop
 *  Copyright (C) 2010  Michael Jumper
 *
 *  This program is free software: you can redistribute it and/or modify
 *  it under the terms of the GNU Affero General Public License as published by
 *  the Free Software Foundation, either version 3 of the License, or
 *  (at your option) any later version.
 *
 *  This program is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *  GNU Affero General Public License for more details.
 *
 *  You should have received a copy of the GNU Affero General Public License
 *  along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */

import java.io.IOException;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import net.sourceforge.guacamole.net.auth.UserContext;
import net.sourceforge.guacamole.net.basic.AuthenticatingHttpServlet;

/**
 * Simple HttpServlet which handles connection creation.
 *
 * @author Michael Jumper
 */
public class Create extends AuthenticatingHttpServlet {

    @Override
    protected void authenticatedService(
            UserContext context,
            HttpServletRequest request, HttpServletResponse response)
    throws IOException, ServletException {

        /* FIXME: STUB */
        
    }

}


@@ -845,32 +845,62 @@
 io.IOException;%0A
+import java.util.Enumeration;%0A
 import javax.ser
@@ -1015,16 +1015,176 @@
 sponse;%0A
+import net.sourceforge.guacamole.GuacamoleException;%0Aimport net.sourceforge.guacamole.net.auth.Connection;%0Aimport net.sourceforge.guacamole.net.auth.Directory;%0A
 import n
@@ -1299,16 +1299,82 @@
 Servlet;
+%0Aimport net.sourceforge.guacamole.protocol.GuacamoleConfiguration;
 %0A%0A/**%0A *
@@ -1514,24 +1514,230 @@
 pServlet %7B%0A%0A
+    /**%0A     * Prefix given to a parameter name when that parameter is a protocol-%0A     * specific parameter meant for the configuration.%0A     */%0A    public static final String PARAMETER_PREFIX = %22_%22;%0A    %0A
     @Overrid
@@ -1939,24 +1939,1499 @@
    /
-* FIXME: STUB */
+/ Get ID and protocol%0A        String identifier = request.getParameter(%22id%22);%0A        String protocol = request.getParameter(%22protocol%22);%0A        %0A        try %7B%0A%0A            // Attempt to get connection directory%0A            Directory%3CString, Connection%3E directory =%0A                    context.getConnectionDirectory();%0A%0A            // Create config%0A            GuacamoleConfiguration config = new GuacamoleConfiguration();%0A            config.setProtocol(protocol);%0A%0A            // Load parameters into config%0A            Enumeration%3CString%3E params = request.getParameterNames();%0A            while (params.hasMoreElements()) %7B%0A%0A                // If parameter starts with prefix, load corresponding parameter%0A                // value into config%0A                String param = params.nextElement();%0A                if (param.startsWith(PARAMETER_PREFIX))%0A                    config.setParameter(%0A                        param.substring(PARAMETER_PREFIX.length()),%0A                        request.getParameter(param));%0A                %0A            %7D%0A            %0A            // Create connection skeleton%0A            Connection connection = new DummyConnection();%0A            connection.setIdentifier(identifier);%0A            connection.setConfiguration(config);%0A            %0A            // Add connection%0A            directory.add(connection);%0A            %0A        %7D%0A        catch (GuacamoleException e) %7B%0A            throw new ServletException(%22Unable to create connection.%22, e);%0A        %7D
 %0A   

Implement connection creation.