mirror of
https://github.com/scm-manager/scm-manager.git
synced 2026-04-01 09:50:16 +02:00
rebuild cgi stack
This commit is contained in:
@@ -118,12 +118,14 @@ public class IOUtil
|
||||
*
|
||||
* @param reader
|
||||
* @param writer
|
||||
* @param bufferSize
|
||||
*
|
||||
* @throws IOException
|
||||
*/
|
||||
public static void copy(Reader reader, Writer writer) throws IOException
|
||||
public static void copy(Reader reader, Writer writer, int bufferSize)
|
||||
throws IOException
|
||||
{
|
||||
char[] buffer = new char[0xFFFF];
|
||||
char[] buffer = new char[bufferSize];
|
||||
|
||||
for (int len; (len = reader.read(buffer)) != -1; )
|
||||
{
|
||||
@@ -131,6 +133,20 @@ public class IOUtil
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Method description
|
||||
*
|
||||
*
|
||||
* @param reader
|
||||
* @param writer
|
||||
*
|
||||
* @throws IOException
|
||||
*/
|
||||
public static void copy(Reader reader, Writer writer) throws IOException
|
||||
{
|
||||
copy(reader, writer, 0xFFFF);
|
||||
}
|
||||
|
||||
/**
|
||||
* Method description
|
||||
*
|
||||
@@ -142,12 +158,30 @@ public class IOUtil
|
||||
*/
|
||||
public static void copy(InputStream in, OutputStream out) throws IOException
|
||||
{
|
||||
byte[] buffer = new byte[0xFFFF];
|
||||
copy(in, out, 0xFFFF);
|
||||
}
|
||||
|
||||
/**
|
||||
* Method description
|
||||
*
|
||||
*
|
||||
* @param in
|
||||
* @param out
|
||||
* @param bufferSize
|
||||
*
|
||||
* @throws IOException
|
||||
*/
|
||||
public static void copy(InputStream in, OutputStream out, int bufferSize)
|
||||
throws IOException
|
||||
{
|
||||
byte[] buffer = new byte[bufferSize];
|
||||
|
||||
for (int len; (len = in.read(buffer)) != -1; )
|
||||
{
|
||||
out.write(buffer, 0, len);
|
||||
}
|
||||
|
||||
out.flush();
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -0,0 +1,158 @@
|
||||
/**
|
||||
* Copyright (c) 2010, Sebastian Sdorra
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright notice,
|
||||
* this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright notice,
|
||||
* this list of conditions and the following disclaimer in the documentation
|
||||
* and/or other materials provided with the distribution.
|
||||
* 3. Neither the name of SCM-Manager; nor the names of its
|
||||
* contributors may be used to endorse or promote products derived from this
|
||||
* software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
||||
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
* DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE FOR ANY
|
||||
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
|
||||
* ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
* http://bitbucket.org/sdorra/scm-manager
|
||||
*
|
||||
*/
|
||||
|
||||
|
||||
|
||||
package sonia.scm.web.cgi;
|
||||
|
||||
//~--- JDK imports ------------------------------------------------------------
|
||||
|
||||
import java.io.File;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Sebastian Sdorra
|
||||
*/
|
||||
public abstract class AbstractCGIExecutor implements CGIExecutor
|
||||
{
|
||||
|
||||
/**
|
||||
* Method description
|
||||
*
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
@Override
|
||||
public int getBufferSize()
|
||||
{
|
||||
return bufferSize;
|
||||
}
|
||||
|
||||
/**
|
||||
* Method description
|
||||
*
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
@Override
|
||||
public EnvList getEnvironment()
|
||||
{
|
||||
return environment;
|
||||
}
|
||||
|
||||
/**
|
||||
* Method description
|
||||
*
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
@Override
|
||||
public String getInterpreter()
|
||||
{
|
||||
return interpreter;
|
||||
}
|
||||
|
||||
/**
|
||||
* Method description
|
||||
*
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
@Override
|
||||
public File getWorkDirectory()
|
||||
{
|
||||
return workDirectory;
|
||||
}
|
||||
|
||||
//~--- set methods ----------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Method description
|
||||
*
|
||||
*
|
||||
* @param bufferSize
|
||||
*/
|
||||
@Override
|
||||
public void setBufferSize(int bufferSize)
|
||||
{
|
||||
this.bufferSize = bufferSize;
|
||||
}
|
||||
|
||||
/**
|
||||
* Method description
|
||||
*
|
||||
*
|
||||
* @param environment
|
||||
*/
|
||||
@Override
|
||||
public void setEnvironment(EnvList environment)
|
||||
{
|
||||
this.environment = environment;
|
||||
}
|
||||
|
||||
/**
|
||||
* Method description
|
||||
*
|
||||
*
|
||||
* @param interpreter
|
||||
*/
|
||||
@Override
|
||||
public void setInterpreter(String interpreter)
|
||||
{
|
||||
this.interpreter = interpreter;
|
||||
}
|
||||
|
||||
/**
|
||||
* Method description
|
||||
*
|
||||
*
|
||||
* @param workDirectory
|
||||
*/
|
||||
@Override
|
||||
public void setWorkDirectory(File workDirectory)
|
||||
{
|
||||
this.workDirectory = workDirectory;
|
||||
}
|
||||
|
||||
//~--- fields ---------------------------------------------------------------
|
||||
|
||||
/** Field description */
|
||||
protected int bufferSize;
|
||||
|
||||
/** Field description */
|
||||
protected EnvList environment;
|
||||
|
||||
/** Field description */
|
||||
protected String interpreter;
|
||||
|
||||
/** Field description */
|
||||
protected File workDirectory;
|
||||
}
|
||||
@@ -53,7 +53,9 @@ import javax.servlet.http.HttpServletResponse;
|
||||
/**
|
||||
*
|
||||
* @author Sebastian Sdorra
|
||||
* @deprecated use {@link CGIExecutorFactory}
|
||||
*/
|
||||
@Deprecated
|
||||
public abstract class AbstractCGIServlet extends HttpServlet
|
||||
{
|
||||
|
||||
|
||||
202
scm-core/src/main/java/sonia/scm/web/cgi/CGIExecutor.java
Normal file
202
scm-core/src/main/java/sonia/scm/web/cgi/CGIExecutor.java
Normal file
@@ -0,0 +1,202 @@
|
||||
/**
|
||||
* Copyright (c) 2010, Sebastian Sdorra
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright notice,
|
||||
* this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright notice,
|
||||
* this list of conditions and the following disclaimer in the documentation
|
||||
* and/or other materials provided with the distribution.
|
||||
* 3. Neither the name of SCM-Manager; nor the names of its
|
||||
* contributors may be used to endorse or promote products derived from this
|
||||
* software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
||||
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
* DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE FOR ANY
|
||||
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
|
||||
* ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
* http://bitbucket.org/sdorra/scm-manager
|
||||
*
|
||||
*/
|
||||
|
||||
|
||||
|
||||
package sonia.scm.web.cgi;
|
||||
|
||||
//~--- JDK imports ------------------------------------------------------------
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
|
||||
import javax.servlet.ServletException;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Sebastian Sdorra
|
||||
*/
|
||||
public interface CGIExecutor
|
||||
{
|
||||
|
||||
/** Field description */
|
||||
public static final String ENV_AUTH_TYPE = "AUTH_TYPE";
|
||||
|
||||
/** Field description */
|
||||
public static final String ENV_CONTENT_LENGTH = "CONTENT_LENGTH";
|
||||
|
||||
/** Field description */
|
||||
public static final String ENV_CONTENT_TYPE = "CONTENT_TYPE";
|
||||
|
||||
/** Field description */
|
||||
public static final String ENV_GATEWAY_INTERFACE = "GATEWAY_INTERFACE";
|
||||
|
||||
/** Field description */
|
||||
public static final String ENV_HTTPS = "HTTPS";
|
||||
|
||||
/** Field description */
|
||||
public static final String ENV_HTTPS_VALUE_OFF = "OFF";
|
||||
|
||||
/** Field description */
|
||||
public static final String ENV_HTTPS_VALUE_ON = "ON";
|
||||
|
||||
/** Field description */
|
||||
public static final String ENV_HTTP_HEADER_PREFIX = "HTTP_";
|
||||
|
||||
/** Field description */
|
||||
public static final String ENV_PATH_INFO = "PATH_INFO";
|
||||
|
||||
/** Field description */
|
||||
public static final String ENV_PATH_TRANSLATED = "PATH_TRANSLATED";
|
||||
|
||||
/** Field description */
|
||||
public static final String ENV_QUERY_STRING = "QUERY_STRING";
|
||||
|
||||
/** Field description */
|
||||
public static final String ENV_REMOTE_ADDR = "REMOTE_ADDR";
|
||||
|
||||
/** Field description */
|
||||
public static final String ENV_REMOTE_HOST = "REMOTE_HOST";
|
||||
|
||||
/** Field description */
|
||||
public static final String ENV_REMOTE_USER = "REMOTE_USER";
|
||||
|
||||
/** Field description */
|
||||
public static final String ENV_REQUEST_METHOD = "REQUEST_METHOD";
|
||||
|
||||
/** Field description */
|
||||
public static final String ENV_SCRIPT_FILENAME = "SCRIPT_FILENAME";
|
||||
|
||||
/** Field description */
|
||||
public static final String ENV_SCRIPT_NAME = "SCRIPT_NAME";
|
||||
|
||||
/** Field description */
|
||||
public static final String ENV_SERVER_NAME = "SERVER_NAME";
|
||||
|
||||
/** Field description */
|
||||
public static final String ENV_SERVER_PORT = "SERVER_PORT";
|
||||
|
||||
/** Field description */
|
||||
public static final String ENV_SERVER_PROTOCOL = "SERVER_PROTOCOL";
|
||||
|
||||
/** Field description */
|
||||
public static final String ENV_SERVER_SOFTWARE = "SERVER_SOFTWARE";
|
||||
|
||||
/** Field description */
|
||||
public static final String RESPONSE_HEADER_HTTP_PREFIX = "HTTP";
|
||||
|
||||
/** Field description */
|
||||
public static final String RESPONSE_HEADER_LOCATION = "Location";
|
||||
|
||||
/** Field description */
|
||||
public static final String RESPONSE_HEADER_STATUS = "Status";
|
||||
|
||||
//~--- methods --------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Method description
|
||||
*
|
||||
*
|
||||
* @param cmd
|
||||
*
|
||||
* @throws IOException
|
||||
* @throws ServletException
|
||||
*/
|
||||
public void execute(String cmd) throws IOException, ServletException;
|
||||
|
||||
//~--- get methods ----------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Method description
|
||||
*
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
public int getBufferSize();
|
||||
|
||||
/**
|
||||
* Method description
|
||||
*
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
public EnvList getEnvironment();
|
||||
|
||||
/**
|
||||
* Method description
|
||||
*
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
public String getInterpreter();
|
||||
|
||||
/**
|
||||
* Method description
|
||||
*
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
public File getWorkDirectory();
|
||||
|
||||
//~--- set methods ----------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Method description
|
||||
*
|
||||
*
|
||||
* @param bufferSize
|
||||
*/
|
||||
public void setBufferSize(int bufferSize);
|
||||
|
||||
/**
|
||||
* Method description
|
||||
*
|
||||
*
|
||||
* @param environment
|
||||
*/
|
||||
public void setEnvironment(EnvList environment);
|
||||
|
||||
/**
|
||||
* Method description
|
||||
*
|
||||
*
|
||||
* @param interpreter
|
||||
*/
|
||||
public void setInterpreter(String interpreter);
|
||||
|
||||
/**
|
||||
* Method description
|
||||
*
|
||||
*
|
||||
* @param workDirectory
|
||||
*/
|
||||
public void setWorkDirectory(File workDirectory);
|
||||
}
|
||||
@@ -0,0 +1,69 @@
|
||||
/**
|
||||
* Copyright (c) 2010, Sebastian Sdorra
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright notice,
|
||||
* this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright notice,
|
||||
* this list of conditions and the following disclaimer in the documentation
|
||||
* and/or other materials provided with the distribution.
|
||||
* 3. Neither the name of SCM-Manager; nor the names of its
|
||||
* contributors may be used to endorse or promote products derived from this
|
||||
* software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
||||
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
* DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE FOR ANY
|
||||
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
|
||||
* ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
* http://bitbucket.org/sdorra/scm-manager
|
||||
*
|
||||
*/
|
||||
|
||||
|
||||
|
||||
package sonia.scm.web.cgi;
|
||||
|
||||
//~--- non-JDK imports --------------------------------------------------------
|
||||
|
||||
import sonia.scm.config.ScmConfiguration;
|
||||
|
||||
//~--- JDK imports ------------------------------------------------------------
|
||||
|
||||
import javax.servlet.ServletContext;
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Sebastian Sdorra
|
||||
*/
|
||||
public interface CGIExecutorFactory
|
||||
{
|
||||
|
||||
/**
|
||||
* Method description
|
||||
*
|
||||
*
|
||||
*
|
||||
* @param configuration
|
||||
* @param context
|
||||
* @param request
|
||||
* @param response
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
public CGIExecutor createExecutor(ScmConfiguration configuration,
|
||||
ServletContext context,
|
||||
HttpServletRequest request,
|
||||
HttpServletResponse response);
|
||||
}
|
||||
@@ -59,8 +59,9 @@ import javax.servlet.http.HttpServletResponse;
|
||||
* Based on org.eclipse.jetty.servlets.CGI
|
||||
*
|
||||
* @author Sebastian Sdorra
|
||||
*
|
||||
* @deprecated use {@link CGIExecutorFactory}
|
||||
*/
|
||||
@Deprecated
|
||||
public class CGIRunner
|
||||
{
|
||||
|
||||
@@ -335,11 +336,7 @@ public class CGIRunner
|
||||
}
|
||||
finally
|
||||
{
|
||||
if (os != null)
|
||||
{
|
||||
IOUtil.close(os);
|
||||
}
|
||||
|
||||
IOUtil.close(os);
|
||||
os = null;
|
||||
p.destroy();
|
||||
|
||||
|
||||
Reference in New Issue
Block a user