Skip to content

Commit

Permalink
Removed Windows code bits from source
Browse files Browse the repository at this point in the history
  • Loading branch information
danielniccoli committed Sep 19, 2014
1 parent 3d727b9 commit ab5e066
Show file tree
Hide file tree
Showing 31 changed files with 33 additions and 725 deletions.
5 changes: 0 additions & 5 deletions Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -54,10 +54,6 @@ http-cherokee.xml.pre
XMLS = \
$(XMLS_PRE:.xml.pre=.xml)


WINDOWS_PORT_FILES = \
config.h.win32

CLEANFILES = \
$(XMLS) \
$(CONFS) \
Expand Down Expand Up @@ -86,7 +82,6 @@ $(XMLS_PRE) \
$(CONFS_PRE) \
$(CONSTANTS_PRE) \
$(man_MANS) \
$(WINDOWS_PORT_FILES) \
$(COMPILATION_TESTS)

all-local: $(CONSTANTS) $(CONFS) $(XMLS) add_user_group
Expand Down
3 changes: 1 addition & 2 deletions admin/consts.py
Original file line number Diff line number Diff line change
Expand Up @@ -137,8 +137,7 @@
('kqueue', 'kqueue() - BSD, OS X'),
('ports', 'Solaris ports - >= 10'),
('poll', 'poll()'),
('select', 'select()'),
('win32', 'Win32')
('select', 'select()')
]

REDIR_SHOW = [
Expand Down
35 changes: 12 additions & 23 deletions cherokee/common-internal.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,29 +28,22 @@
#include <config.h>
#include <constants.h>

#ifdef _WIN32
# include "unix4win32.h"
# include "win32_misc.h"
#endif

#include "common.h"
#include "threading.h"
#include "error_log.h"

#ifndef _WIN32
# if defined HAVE_ENDIAN_H
# include <endian.h>
# elif defined HAVE_MACHINE_ENDIAN_H
# include <machine/endian.h>
# elif defined HAVE_SYS_ENDIAN_H
# include <sys/endian.h>
# elif defined HAVE_SYS_MACHINE_H
# include <sys/machine.h>
# elif defined HAVE_SYS_ISA_DEFS_H
# include <sys/isa_defs.h>
# else
# error "Can not include endian.h"
# endif
#if defined HAVE_ENDIAN_H
# include <endian.h>
#elif defined HAVE_MACHINE_ENDIAN_H
# include <machine/endian.h>
#elif defined HAVE_SYS_ENDIAN_H
# include <sys/endian.h>
#elif defined HAVE_SYS_MACHINE_H
# include <sys/machine.h>
#elif defined HAVE_SYS_ISA_DEFS_H
# include <sys/isa_defs.h>
#else
# error "Can not include endian.h"
#endif

#include <stdio.h>
Expand Down Expand Up @@ -162,11 +155,7 @@
#endif


#ifdef _WIN32
# define SOCK_ERRNO() WSAGetLastError()
#else
# define SOCK_ERRNO() errno
#endif


/* IMPORTANT:
Expand Down
8 changes: 0 additions & 8 deletions cherokee/connection.c
Original file line number Diff line number Diff line change
Expand Up @@ -2217,14 +2217,6 @@ cherokee_connection_get_request (cherokee_connection_t *conn)
goto error;
}

#ifdef _WIN32
/* Prevent back-slashes in the request on Windows
*/
TRACE (ENTRIES, "Win32 req before: %s\n", conn->request.buf);
cherokee_buffer_swap_chars (&conn->request, '\\', '/');
TRACE (ENTRIES, "Win32 req after: %s\n", conn->request.buf);
#endif

/* Short the path. It transforms the request:
* /dir1/dir2/../file in /dir1/file
*/
Expand Down
2 changes: 0 additions & 2 deletions cherokee/fdpoll-protected.h
Original file line number Diff line number Diff line change
Expand Up @@ -42,14 +42,12 @@ ret_t fdpoll_kqueue_get_fdlimits (cuint_t *sys_fd_limit, cuint_t *fd_limit);
ret_t fdpoll_port_get_fdlimits (cuint_t *sys_fd_limit, cuint_t *fd_limit);
ret_t fdpoll_poll_get_fdlimits (cuint_t *sys_fd_limit, cuint_t *fd_limit);
ret_t fdpoll_select_get_fdlimits (cuint_t *sys_fd_limit, cuint_t *fd_limit);
ret_t fdpoll_win32_get_fdlimits (cuint_t *sys_fd_limit, cuint_t *fd_limit);

ret_t fdpoll_epoll_new (cherokee_fdpoll_t **fdp, int sys_fd_limit, int fd_limit);
ret_t fdpoll_kqueue_new (cherokee_fdpoll_t **fdp, int sys_fd_limit, int fd_limit);
ret_t fdpoll_port_new (cherokee_fdpoll_t **fdp, int sys_fd_limit, int fd_limit);
ret_t fdpoll_poll_new (cherokee_fdpoll_t **fdp, int sys_fd_limit, int fd_limit);
ret_t fdpoll_select_new (cherokee_fdpoll_t **fdp, int sys_fd_limit, int fd_limit);
ret_t fdpoll_win32_new (cherokee_fdpoll_t **fdp, int sys_fd_limit, int fd_limit);


struct cherokee_fdpoll {
Expand Down
188 changes: 0 additions & 188 deletions cherokee/handler_cgi.c
Original file line number Diff line number Diff line change
Expand Up @@ -60,13 +60,8 @@

#define ENTRIES "handler,cgi"

#ifdef _WIN32
# define fork_and_execute_cgi(c) fork_and_execute_cgi_win32(c)
static ret_t fork_and_execute_cgi_win32 (cherokee_handler_cgi_t *cgi);
#else
# define fork_and_execute_cgi(c) fork_and_execute_cgi_unix(c)
static ret_t fork_and_execute_cgi_unix (cherokee_handler_cgi_t *cgi);
#endif

#define set_env(cgi,k,v,vl) cherokee_handler_cgi_add_env_pair(cgi, k, sizeof(k)-1, v, vl)

Expand Down Expand Up @@ -148,19 +143,11 @@ cherokee_handler_cgi_new (cherokee_handler_t **hdl, void *cnt, cherokee_module_p
*/
n->pipeInput = -1;
n->pipeOutput = -1;

#ifdef _WIN32
n->process = NULL;
n->thread = NULL;

cherokee_buffer_init (&n->envp);
#else
n->pid = -1;
n->envp_last = 0;

for (i=0; i<ENV_VAR_NUM; i++)
n->envp[i] = NULL;
#endif

/* Return the object
*/
Expand All @@ -176,8 +163,6 @@ do_reap (void)
int status;
int child_count = 0;

#ifndef _WIN32

/* Reap defunct children until there aren't any more.
*/
for (child_count = 0; ; ++child_count) {
Expand All @@ -195,7 +180,6 @@ do_reap (void)
break;
}
}
#endif

return child_count;
}
Expand Down Expand Up @@ -224,7 +208,6 @@ cherokee_handler_cgi_free (cherokee_handler_cgi_t *cgi)

/* Kill the CGI
*/
#ifndef _WIN32
if (cgi->pid > 0) {
pid_t pid;
cint_t tries = 2;
Expand All @@ -250,27 +233,13 @@ cherokee_handler_cgi_free (cherokee_handler_cgi_t *cgi)
break;
}
}
#else
if (cgi->process) {
WaitForSingleObject (cgi->process, INFINITE);
CloseHandle (cgi->process);
}

if (cgi->thread) {
CloseHandle (cgi->thread);
}
#endif

/* Free the environment variables
*/
#ifdef _WIN32
cherokee_buffer_mrproper (&cgi->envp);
#else
for (i=0; i<cgi->envp_last; i++) {
free (cgi->envp[i]);
cgi->envp[i] = NULL;
}
#endif

/* For some reason, we have seen that the SIGCHLD signal does not call to
* our handler in a server with a lot of requests, so the wait() call,
Expand Down Expand Up @@ -318,10 +287,6 @@ cherokee_handler_cgi_add_env_pair (cherokee_handler_cgi_base_t *cgi_base,
{
cherokee_handler_cgi_t *cgi = HDL_CGI(cgi_base);

#ifdef _WIN32
cherokee_buffer_add_va (&cgi->envp, "%s=%s", name, content);
cherokee_buffer_add (&cgi->envp, "\0", 1);
#else
char *entry;

/* Build the new envp entry
Expand Down Expand Up @@ -350,7 +315,6 @@ cherokee_handler_cgi_add_env_pair (cherokee_handler_cgi_base_t *cgi_base,
if (cgi->envp_last >= ENV_VAR_NUM) {
SHOULDNT_HAPPEN;
}
#endif
}

static ret_t
Expand Down Expand Up @@ -482,12 +446,6 @@ cherokee_handler_cgi_read_post (cherokee_handler_cgi_t *cgi)
}


/*******************************
* UNIX: Linux, Solaris, etc.. *
*******************************/

#ifndef _WIN32

static ret_t
_fd_set_properties (int fd, int add_flags, int remove_flags)
{
Expand Down Expand Up @@ -727,152 +685,6 @@ fork_and_execute_cgi_unix (cherokee_handler_cgi_t *cgi)
}



#else



/*******************************
* WINDOWS *
*******************************/

static ret_t
fork_and_execute_cgi_win32 (cherokee_handler_cgi_t *cgi)
{
int re;
PROCESS_INFORMATION pi;
STARTUPINFO si;
char *cmd;
cherokee_buffer_t cmd_line = CHEROKEE_BUF_INIT;
cherokee_buffer_t exec_dir = CHEROKEE_BUF_INIT;
cherokee_connection_t *conn = HANDLER_CONN(cgi);

SECURITY_ATTRIBUTES saSecAtr;
HANDLE hProc;
HANDLE hChildStdinRd = INVALID_HANDLE_VALUE;
HANDLE hChildStdinWr = INVALID_HANDLE_VALUE;
HANDLE hChildStdoutRd = INVALID_HANDLE_VALUE;
HANDLE hChildStdoutWr = INVALID_HANDLE_VALUE;

/* Create the environment for the process
*/
add_environment (cgi, conn);
cherokee_buffer_add (&cgi->envp, "\0", 1);

/* Command line
*/
cmd = HDL_CGI_BASE(cgi)->executable.buf;
cherokee_buffer_add (&cmd_line, cmd, strlen(cmd));
// cherokee_buffer_add_va (&cmd_line, " \"%s\"", HDL_CGI_BASE(cgi)->param.buf);

/* Execution directory
*/
if (! cherokee_buffer_is_empty (&conn->effective_directory)) {
cherokee_buffer_add_buffer (&exec_dir, &conn->effective_directory);
} else {
char *file = strrchr (cmd, '/');
char *end = HDL_CGI_BASE(cgi)->executable.buf + HDL_CGI_BASE(cgi)->executable.len;

cherokee_buffer_add (&exec_dir, cmd,
HDL_CGI_BASE(cgi)->executable.len - (end - file));
}

/* Set the bInheritHandle flag so pipe handles are inherited.
*/
memset(&saSecAtr, 0, sizeof(SECURITY_ATTRIBUTES));
saSecAtr.nLength = sizeof(SECURITY_ATTRIBUTES);
saSecAtr.lpSecurityDescriptor = NULL;
saSecAtr.bInheritHandle = TRUE;

/* Create the pipes
*/
hProc = GetCurrentProcess();

re = CreatePipe (&hChildStdoutRd, &hChildStdoutWr, &saSecAtr, 0);
if (!re) return ret_error;

re = CreatePipe (&hChildStdinRd, &hChildStdinWr, &saSecAtr, 0);
if (!re) return ret_error;

/* Make them inheritable
*/
re = DuplicateHandle (hProc, hChildStdoutRd,
hProc, &hChildStdoutRd,
0, TRUE,
DUPLICATE_CLOSE_SOURCE | DUPLICATE_SAME_ACCESS);
if (!re) return ret_error;

re = DuplicateHandle (hProc, hChildStdinWr,
hProc, &hChildStdinWr,
0, TRUE,
DUPLICATE_CLOSE_SOURCE | DUPLICATE_SAME_ACCESS);
if (!re) return ret_error;


/* Starting information
*/
ZeroMemory (&si, sizeof(STARTUPINFO));
si.cb = sizeof(STARTUPINFO);
si.hStdOutput = hChildStdoutWr;
si.hStdError = hChildStdoutWr;
si.hStdInput = hChildStdinRd;
si.dwFlags |= STARTF_USESTDHANDLES;

TRACE (ENTRIES, "exec %s dir %s\n", cmd_line.buf, exec_dir.buf);

/* Launch the child process
*/
re = CreateProcess (cmd, /* ApplicationName */
cmd_line.buf, /* Command line */
NULL, /* Process handle not inheritable */
NULL, /* Thread handle not inheritable */
TRUE, /* Handle inheritance */
0, /* Creation flags */
cgi->envp.buf, /* Use parent's environment block */
exec_dir.buf, /* Use parent's starting directory */
&si, /* Pointer to STARTUPINFO structure */
&pi); /* Pointer to PROCESS_INFORMATION structure */

CloseHandle (hChildStdinRd);
CloseHandle (hChildStdoutWr);

if (!re) {
LOG_ERROR (CHEROKEE_ERROR_HANDLER_CGI_CREATEPROCESS, GetLastError());

CloseHandle (pi.hProcess);
CloseHandle (pi.hThread);

conn->error_code = http_internal_error;
return ret_error;
}

cherokee_buffer_mrproper (&cmd_line);
cherokee_buffer_mrproper (&exec_dir);

cgi->thread = pi.hThread;
cgi->process = pi.hProcess;

/* Wait for the CGI process to be ready
*/
WaitForInputIdle (pi.hProcess, INFINITE);

/* Extract the file descriptors
*/
cgi->pipeInput = _open_osfhandle((LONG)hChildStdoutRd, O_BINARY|_O_RDONLY);

if (! conn->post.len <= 0) {
CloseHandle (hChildStdinWr);
} else {
cgi->pipeOutput = _open_osfhandle((LONG)hChildStdinWr, O_BINARY|_O_WRONLY);
}

TRACE (ENTRIES, "In fd %d, Out fd %d\n", cgi->pipeInput, cgi->pipeOutput);

return ret_ok;
}

#endif

static ret_t
fork_and_execute_cgi_via_spawner(cherokee_handler_cgi_t *cgi)
{
Expand Down
Loading

0 comments on commit ab5e066

Please sign in to comment.