From 3f8cd982e5a13d6b81d82360c4537d1c048be839 Mon Sep 17 00:00:00 2001 From: Max Lv Date: Tue, 24 Jan 2017 20:10:31 +0800 Subject: [PATCH] Drop MinGW32 support --- Changes | 6 +++ Makefile.am | 5 ++ README.md | 2 +- configure.ac | 56 ++------------------- debian/changelog | 6 +++ doc/Makefile.am | 2 + docker/alpine/Dockerfile | 2 +- rpm/genrpm.sh | 4 +- src/Makefile.am | 14 ++---- src/cache.c | 4 -- src/encrypt.c | 2 - src/encrypt.h | 13 ----- src/local.c | 37 -------------- src/manager.c | 20 -------- src/netutils.c | 5 -- src/netutils.h | 2 +- src/plugin.c | 43 ---------------- src/resolv.c | 8 --- src/resolv.h | 5 -- src/rule.c | 4 -- src/server.c | 27 ---------- src/tls.c | 5 -- src/tunnel.c | 22 -------- src/udprelay.c | 9 ---- src/utils.c | 11 ---- src/utils.h | 66 ++++-------------------- src/win32.c | 106 --------------------------------------- src/win32.h | 76 ---------------------------- 28 files changed, 42 insertions(+), 520 deletions(-) delete mode 100644 src/win32.c delete mode 100644 src/win32.h diff --git a/Changes b/Changes index 4c76a70e..2b5b77f5 100644 --- a/Changes +++ b/Changes @@ -1,3 +1,9 @@ +shadowsocks-libev (2.6.3-1) unstable; urgency=medium + + * Refine the project structure. + + -- Max Lv Tue, 24 Jan 2017 19:10:45 +0800 + shadowsocks-libev (2.6.2-1) unstable; urgency=medium * Refine SIP003 plugin support. diff --git a/Makefile.am b/Makefile.am index 82fd768e..4a25c0f2 100644 --- a/Makefile.am +++ b/Makefile.am @@ -8,3 +8,8 @@ ACLOCAL_AMFLAGS = -I m4 pkgconfiglibdir = $(libdir)/pkgconfig pkgconfiglib_DATA = shadowsocks-libev.pc + +EXTRA_DIST = acl Changes completions debian docker rpm README.md +EXTRA_DIST += libcork/include libipset/include +EXTRA_DIST += libipset/src/libipset/map/inspection-template.c.in +EXTRA_DIST += libipset/src/libipset/set/inspection-template.c.in diff --git a/README.md b/README.md index 1f027ad3..68fe4faa 100644 --- a/README.md +++ b/README.md @@ -9,7 +9,7 @@ It is a port of [Shadowsocks](https://github.com/shadowsocks/shadowsocks) created by [@clowwindy](https://github.com/clowwindy), and maintained by [@madeye](https://github.com/madeye) and [@linusyang](https://github.com/linusyang). -Current version: 2.6.2 | [Changelog](debian/changelog) +Current version: 2.6.3 | [Changelog](debian/changelog) Travis CI: [![Travis CI](https://travis-ci.org/shadowsocks/shadowsocks-libev.svg?branch=master)](https://travis-ci.org/shadowsocks/shadowsocks-libev) diff --git a/configure.ac b/configure.ac index 7db56a44..0669f978 100755 --- a/configure.ac +++ b/configure.ac @@ -2,7 +2,7 @@ dnl -*- Autoconf -*- dnl Process this file with autoconf to produce a configure script. AC_PREREQ([2.67]) -AC_INIT([shadowsocks-libev], [2.6.2], [max.c.lv@gmail.com]) +AC_INIT([shadowsocks-libev], [2.6.3], [max.c.lv@gmail.com]) AC_CONFIG_SRCDIR([src/encrypt.c]) AC_CONFIG_HEADERS([config.h]) AC_CONFIG_AUX_DIR(auto) @@ -76,19 +76,6 @@ AC_PROG_LIBTOOL AC_PROG_MAKE_SET AC_LANG_SOURCE -dnl Add library for mingw -case $host in - *-mingw*) - CFLAGS="$CFLAGS -mno-ms-bitfields" - LIBS="$LIBS -ladvapi32 -lgdi32 -lws2_32 -lcrypt32" - ;; - *-cygwin*) - CFLAGS="$CFLAGS -mno-ms-bitfields" - ;; - *) - ;; -esac - dnl Checks for TLS AX_TLS([:], [:]) @@ -135,15 +122,8 @@ case $host in os_support=linux AC_MSG_RESULT(Linux) ;; - *-mingw*) - dnl Add custom macros for libev - AC_DEFINE([FD_SETSIZE], [2048], [Reset max file descriptor size.]) - AC_DEFINE([EV_FD_TO_WIN32_HANDLE(fd)], [(fd)], [Override libev default fd conversion macro.]) - AC_DEFINE([EV_WIN32_HANDLE_TO_FD(handle)], [(handle)], [Override libev default handle conversion macro.]) - AC_DEFINE([EV_WIN32_CLOSE_FD(fd)], [closesocket(fd)], [Override libev default fd close macro.]) - - os_support=mingw - AC_MSG_RESULT(MinGW) + *-cygwin*) + CFLAGS="$CFLAGS -mno-ms-bitfields" ;; *) AC_MSG_RESULT(transparent proxy does not support for $host) @@ -188,7 +168,6 @@ if test x$has_stack_protector = xyes && test x$enable_ssp = xyes; then fi AM_CONDITIONAL(BUILD_REDIRECTOR, test "$os_support" = "linux") -AM_CONDITIONAL(BUILD_WINCOMPAT, test "$os_support" = "mingw") dnl Checks for header files. AC_CHECK_HEADERS([limits.h stdint.h inttypes.h arpa/inet.h fcntl.h langinfo.h locale.h netdb.h netinet/in.h stdlib.h string.h strings.h unistd.h sys/ioctl.h]) @@ -213,10 +192,6 @@ AC_CHECK_HEADERS([net/if.h], [], [], ]) case $host in - *-mingw*) - AC_DEFINE([CONNECT_IN_PROGRESS], [WSAEWOULDBLOCK], [errno for incomplete non-blocking connect(2)]) - AC_CHECK_HEADERS([windows.h winsock2.h ws2tcpip.h], [], [AC_MSG_ERROR([Missing MinGW headers])], []) - ;; *-linux*) AC_DEFINE([CONNECT_IN_PROGRESS], [EINPROGRESS], [errno for incomplete non-blocking connect(2)]) dnl Checks for netfilter headers @@ -270,31 +245,6 @@ AC_FUNC_SELECT_ARGTYPES AC_TYPE_SIGNAL AC_CHECK_FUNCS([memset select setresuid setreuid strerror getpwnam_r setrlimit]) -dnl Check for select() into ws2_32 for Msys/Mingw -if test "$ac_cv_func_select" != "yes"; then - AC_MSG_CHECKING([for select in ws2_32]) - AC_TRY_LINK([ -#ifdef HAVE_WINSOCK2_H -#ifndef WIN32_LEAN_AND_MEAN -#define WIN32_LEAN_AND_MEAN -#endif -#include -#endif - ],[ - select(0,(fd_set *)NULL,(fd_set *)NULL,(fd_set *)NULL,(struct timeval *)NULL); - ],[ - AC_MSG_RESULT([yes]) - HAVE_SELECT="1" - AC_DEFINE_UNQUOTED(HAVE_SELECT, 1, - [Define to 1 if you have the 'select' function.]) - HAVE_SYS_SELECT_H="1" - AC_DEFINE_UNQUOTED(HAVE_SYS_SELECT_H, 1, - [Define to 1 if you have the header file.]) - ],[ - AC_MSG_ERROR([no]) - ]) -fi - AC_CHECK_LIB(socket, connect) dnl Checks for library functions. diff --git a/debian/changelog b/debian/changelog index 4c76a70e..2b5b77f5 100644 --- a/debian/changelog +++ b/debian/changelog @@ -1,3 +1,9 @@ +shadowsocks-libev (2.6.3-1) unstable; urgency=medium + + * Refine the project structure. + + -- Max Lv Tue, 24 Jan 2017 19:10:45 +0800 + shadowsocks-libev (2.6.2-1) unstable; urgency=medium * Refine SIP003 plugin support. diff --git a/doc/Makefile.am b/doc/Makefile.am index 8c29d045..4159806d 100644 --- a/doc/Makefile.am +++ b/doc/Makefile.am @@ -60,3 +60,5 @@ html-local: $(MAN_HTML) doc_DATA = $(MAN_HTML) CLEANFILES = $(MAN_XML) $(man_MANS) $(MAN_HTML) + +EXTRA_DIST = *.asciidoc asciidoc.conf *.xsl diff --git a/docker/alpine/Dockerfile b/docker/alpine/Dockerfile index 8f8bf4d2..33ea515f 100644 --- a/docker/alpine/Dockerfile +++ b/docker/alpine/Dockerfile @@ -5,7 +5,7 @@ FROM alpine MAINTAINER kev -ARG SS_VER=2.6.2 +ARG SS_VER=2.6.3 ARG SS_URL=https://github.com/shadowsocks/shadowsocks-libev/archive/v$SS_VER.tar.gz ENV SERVER_ADDR 0.0.0.0 diff --git a/rpm/genrpm.sh b/rpm/genrpm.sh index 451f6c9a..b3b4882a 100755 --- a/rpm/genrpm.sh +++ b/rpm/genrpm.sh @@ -7,7 +7,7 @@ show_help() echo echo -e "Options:" echo -e " -h show this help." - echo -e " -v with argument version (2.6.2 by default)." + echo -e " -v with argument version (2.6.3 by default)." echo -e " -f with argument format (tar.xz by default) used by git archive." echo echo -e "Examples:" @@ -38,7 +38,7 @@ do esac done -: ${version:=2.6.2} +: ${version:=2.6.3} : ${format:=tar.gz} name="shadowsocks-libev" diff --git a/src/Makefile.am b/src/Makefile.am index 45f2f5c2..f890d978 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -11,10 +11,7 @@ SS_COMMON_LIBS = $(top_builddir)/libipset/libipset.la \ $(INET_NTOP_LIB) $(LIBPCRE_LIBS) SS_COMMON_LIBS += -lev -lsodium -lm -bin_PROGRAMS = ss-local ss-tunnel -if !BUILD_WINCOMPAT -bin_PROGRAMS += ss-server ss-manager -endif +bin_PROGRAMS = ss-local ss-tunnel ss-server ss-manager sni_src = http.c \ tls.c \ @@ -77,11 +74,6 @@ ss_tunnel_CFLAGS = $(AM_CFLAGS) -DMODULE_TUNNEL ss_server_CFLAGS = $(AM_CFLAGS) -DMODULE_REMOTE ss_manager_CFLAGS = $(AM_CFLAGS) -DMODULE_MANAGER -if BUILD_WINCOMPAT -ss_local_SOURCES += win32.c -ss_tunnel_SOURCES += win32.c -endif - if BUILD_REDIRECTOR bin_SCRIPTS = ss-nat bin_PROGRAMS += ss-redir @@ -107,3 +99,7 @@ libshadowsocks_libev_la_CFLAGS = $(ss_local_CFLAGS) -DLIB_ONLY libshadowsocks_libev_la_LDFLAGS = -version-info $(VERSION_INFO) libshadowsocks_libev_la_LIBADD = $(ss_local_LDADD) include_HEADERS = shadowsocks.h + +noinst_HEADERS = acl.h encrypt.h json.h netutils.h redir.h server.h tls.h uthash.h \ + cache.h http.h local.h plugin.h resolv.h tunnel.h utils.h \ + common.h jconf.h manager.h protocol.h rule.h socks5.h udprelay.h diff --git a/src/cache.c b/src/cache.c index c1a2995b..cb409131 100644 --- a/src/cache.c +++ b/src/cache.c @@ -31,10 +31,6 @@ #include "cache.h" #include "utils.h" -#ifdef __MINGW32__ -#include "win32.h" -#endif - /** Creates a new cache object * * @param dst diff --git a/src/encrypt.c b/src/encrypt.c index d1ac7795..53ac1651 100644 --- a/src/encrypt.c +++ b/src/encrypt.c @@ -69,9 +69,7 @@ #include -#ifndef __MINGW32__ #include -#endif #include "cache.h" #include "encrypt.h" diff --git a/src/encrypt.h b/src/encrypt.h index 836ed0fb..0a379161 100644 --- a/src/encrypt.h +++ b/src/encrypt.h @@ -23,20 +23,7 @@ #ifndef _ENCRYPT_H #define _ENCRYPT_H -#ifndef __MINGW32__ #include -#else - -#ifdef max -#undef max -#endif - -#ifdef min -#undef min -#endif - -#endif - #include #include #include diff --git a/src/local.c b/src/local.c index f9770e77..1f200cee 100644 --- a/src/local.c +++ b/src/local.c @@ -34,13 +34,11 @@ #include #include -#ifndef __MINGW32__ #include #include #include #include #include -#endif #ifdef LIB_ONLY #include @@ -56,10 +54,6 @@ #include #include -#ifdef __MINGW32__ -#include "win32.h" -#endif - #include "netutils.h" #include "utils.h" #include "socks5.h" @@ -109,10 +103,8 @@ static int fast_open = 0; static struct ev_signal sigint_watcher; static struct ev_signal sigterm_watcher; -#ifndef __MINGW32__ static struct ev_signal sigchld_watcher; static struct ev_signal sigusr1_watcher; -#endif #ifdef HAVE_SETRLIMIT #ifndef LIB_ONLY @@ -142,7 +134,6 @@ static server_t *new_server(int fd, int method); static struct cork_dllist connections; -#ifndef __MINGW32__ int setnonblocking(int fd) { @@ -152,7 +143,6 @@ setnonblocking(int fd) } return fcntl(fd, F_SETFL, flags | O_NONBLOCK); } -#endif int create_and_bind(const char *addr, const char *port) @@ -1129,22 +1119,18 @@ signal_cb(EV_P_ ev_signal *w, int revents) { if (revents & EV_SIGNAL) { switch (w->signum) { -#ifndef __MINGW32__ case SIGCHLD: if (!is_plugin_running()) LOGE("plugin service exit unexpectedly"); else return; case SIGUSR1: -#endif case SIGINT: case SIGTERM: ev_signal_stop(EV_DEFAULT, &sigint_watcher); ev_signal_stop(EV_DEFAULT, &sigterm_watcher); -#ifndef __MINGW32__ ev_signal_stop(EV_DEFAULT, &sigchld_watcher); ev_signal_stop(EV_DEFAULT, &sigusr1_watcher); -#endif keep_resolving = 0; ev_unloop(EV_A_ EVUNLOOP_ALL); } @@ -1473,13 +1459,9 @@ main(int argc, char **argv) } } -#ifdef __MINGW32__ - winsock_init(); -#else // ignore SIGPIPE signal(SIGPIPE, SIG_IGN); signal(SIGABRT, SIG_IGN); -#endif // Setup keys LOGI("initializing ciphers... %s", method); @@ -1517,11 +1499,8 @@ main(int argc, char **argv) ev_signal_init(&sigterm_watcher, signal_cb, SIGTERM); ev_signal_start(EV_DEFAULT, &sigint_watcher); ev_signal_start(EV_DEFAULT, &sigterm_watcher); - -#ifndef __MINGW32__ ev_signal_init(&sigchld_watcher, signal_cb, SIGCHLD); ev_signal_start(EV_DEFAULT, &sigchld_watcher); -#endif struct ev_loop *loop = EV_DEFAULT; @@ -1577,11 +1556,9 @@ main(int argc, char **argv) FATAL("failed to switch user"); } -#ifndef __MINGW32__ if (geteuid() == 0) { LOGI("running from root user"); } -#endif // Init connections cork_dllist_init(&connections); @@ -1611,10 +1588,6 @@ main(int argc, char **argv) free_udprelay(); } -#ifdef __MINGW32__ - winsock_cleanup(); -#endif - return 0; } @@ -1658,24 +1631,18 @@ start_ss_local_server(profile_t profile) local_addr = "127.0.0.1"; } -#ifdef __MINGW32__ - winsock_init(); -#else // ignore SIGPIPE signal(SIGPIPE, SIG_IGN); signal(SIGABRT, SIG_IGN); -#endif ev_signal_init(&sigint_watcher, signal_cb, SIGINT); ev_signal_init(&sigterm_watcher, signal_cb, SIGTERM); ev_signal_start(EV_DEFAULT, &sigint_watcher); ev_signal_start(EV_DEFAULT, &sigterm_watcher); -#ifndef __MINGW32__ ev_signal_init(&sigusr1_watcher, signal_cb, SIGUSR1); ev_signal_init(&sigchld_watcher, signal_cb, SIGCHLD); ev_signal_start(EV_DEFAULT, &sigusr1_watcher); ev_signal_start(EV_DEFAULT, &sigchld_watcher); -#endif // Setup keys LOGI("initializing ciphers... %s", method); @@ -1757,10 +1724,6 @@ start_ss_local_server(profile_t profile) ss_free(listen_ctx.remote_addr[0]); ss_free(remote_addr_tmp); -#ifdef __MINGW32__ - winsock_cleanup(); -#endif - // cannot reach here return 0; } diff --git a/src/manager.c b/src/manager.c index fcfba985..5672d2bd 100644 --- a/src/manager.c +++ b/src/manager.c @@ -39,7 +39,6 @@ #include #include -#ifndef __MINGW32__ #include #include #include @@ -49,14 +48,8 @@ #include #include #include -#endif - #include -#ifdef __MINGW32__ -#include "win32.h" -#endif - #if defined(HAVE_SYS_IOCTL_H) && defined(HAVE_NET_IF_H) && defined(__linux__) #include #include @@ -80,7 +73,6 @@ int working_dir_size = 0; static struct cork_hash_table *server_table; static struct cork_hash_table *sock_table; -#ifndef __MINGW32__ static int setnonblocking(int fd) { @@ -91,8 +83,6 @@ setnonblocking(int fd) return fcntl(fd, F_SETFL, flags | O_NONBLOCK); } -#endif - static void build_config(char *prefix, struct server *server) { @@ -1097,14 +1087,10 @@ main(int argc, char **argv) LOGI("onetime authentication enabled"); } -#ifdef __MINGW32__ - winsock_init(); -#else // ignore SIGPIPE signal(SIGPIPE, SIG_IGN); signal(SIGCHLD, SIG_IGN); signal(SIGABRT, SIG_IGN); -#endif struct ev_signal sigint_watcher; struct ev_signal sigterm_watcher; @@ -1147,11 +1133,9 @@ main(int argc, char **argv) FATAL("failed to switch user"); } -#ifndef __MINGW32__ if (geteuid() == 0) { LOGI("running from root user"); } -#endif struct passwd *pw = getpwuid(getuid()); const char *homedir = pw->pw_dir; @@ -1265,10 +1249,6 @@ main(int argc, char **argv) release_sock_lock(sock_lock); } -#ifdef __MINGW32__ - winsock_cleanup(); -#endif - ev_signal_stop(EV_DEFAULT, &sigint_watcher); ev_signal_stop(EV_DEFAULT, &sigterm_watcher); ss_free(working_dir); diff --git a/src/netutils.c b/src/netutils.c index 3fa1fa0d..68687c95 100644 --- a/src/netutils.c +++ b/src/netutils.c @@ -29,15 +29,10 @@ #include "config.h" #endif -#ifdef __MINGW32__ -#include "win32.h" -#define sleep(n) Sleep(1000 * (n)) -#else #include #include #include #include -#endif #if defined(HAVE_SYS_IOCTL_H) && defined(HAVE_NET_IF_H) && defined(__linux__) #include diff --git a/src/netutils.h b/src/netutils.h index 4efe4b94..82d1a78d 100644 --- a/src/netutils.h +++ b/src/netutils.h @@ -25,7 +25,7 @@ #if defined(__linux__) #include -#elif !defined(__MINGW32__) +#else #include #endif diff --git a/src/plugin.c b/src/plugin.c index 86df83e6..8fd892bb 100644 --- a/src/plugin.c +++ b/src/plugin.c @@ -24,8 +24,6 @@ #include "config.h" #endif -#ifndef __MINGW32__ - #include #include #include @@ -194,44 +192,3 @@ int is_plugin_running() } return 0; } - -#else - -#include "stdint.h" - -#include "utils.h" -#include "plugin.h" - -int -start_plugin(const char *plugin, - const char *plugin_opts, - const char *remote_host, - const char *remote_port, - const char *local_host, - const char *local_port) -{ - FATAL("Plugin is not supported on MinGW."); - return -1; -} - -uint16_t -get_local_port() -{ - FATAL("Plugin is not supported on MinGW."); - return 0; -} - -void -stop_plugin() -{ - FATAL("Plugin is not supported on MinGW."); -} - -int -is_plugin_running() -{ - FATAL("Plugin is not supported on MinGW."); - return 0; -} - -#endif diff --git a/src/resolv.c b/src/resolv.c index 7c694c05..bc3c7bc8 100644 --- a/src/resolv.c +++ b/src/resolv.c @@ -35,14 +35,10 @@ #include #include -#ifdef __MINGW32__ -#include "win32.h" -#else #include #include #include #include -#endif #include "resolv.h" #include "utils.h" @@ -120,12 +116,8 @@ resolv_init(struct ev_loop *loop, char **nameservers, int nameserver_num, int ip } } -#ifdef __MINGW32__ - setnonblocking(sockfd); -#else int flags = fcntl(sockfd, F_GETFL, 0); fcntl(sockfd, F_SETFL, flags | O_NONBLOCK); -#endif ev_io_init(&resolv_io_watcher, resolv_sock_cb, sockfd, EV_READ); resolv_io_watcher.data = ctx; diff --git a/src/resolv.h b/src/resolv.h index 05529223..80154620 100644 --- a/src/resolv.h +++ b/src/resolv.h @@ -31,12 +31,7 @@ #endif #include - -#ifdef __MINGW32__ -#include "win32.h" -#else #include -#endif struct ResolvQuery; diff --git a/src/rule.c b/src/rule.c index 8aae04ea..737013e6 100644 --- a/src/rule.c +++ b/src/rule.c @@ -32,10 +32,6 @@ #include #include -#ifdef __MINGW32__ -extern void ss_error(const char *s); -#endif - #include "rule.h" #include "utils.h" diff --git a/src/server.c b/src/server.c index 6e60b632..588fb469 100644 --- a/src/server.c +++ b/src/server.c @@ -36,22 +36,16 @@ #include #include -#ifndef __MINGW32__ #include #include #include #include #include #include -#endif #include #include -#ifdef __MINGW32__ -#include "win32.h" -#endif - #if defined(HAVE_SYS_IOCTL_H) && defined(HAVE_NET_IF_H) && defined(__linux__) #include #include @@ -372,7 +366,6 @@ setfastopen(int fd) return s; } -#ifndef __MINGW32__ int setnonblocking(int fd) { @@ -383,8 +376,6 @@ setnonblocking(int fd) return fcntl(fd, F_SETFL, flags | O_NONBLOCK); } -#endif - int create_and_bind(const char *host, const char *port, int mptcp) { @@ -1080,11 +1071,7 @@ server_timeout_cb(EV_P_ ev_timer *watcher, int revents) if (verbose) { size_t len = server->stage ? server->header_buf->len : server->buf->len; -#ifdef __MINGW32__ - LOGI("incomplete header: %u", len); -#else LOGI("incomplete header: %zu", len); -#endif } report_addr(server->fd, SUSPICIOUS); } @@ -1852,13 +1839,9 @@ main(int argc, char **argv) LOGI("TCP relay disabled"); } -#ifdef __MINGW32__ - winsock_init(); -#else // ignore SIGPIPE signal(SIGPIPE, SIG_IGN); signal(SIGABRT, SIG_IGN); -#endif ev_signal_init(&sigint_watcher, signal_cb, SIGINT); ev_signal_init(&sigterm_watcher, signal_cb, SIGTERM); @@ -1876,12 +1859,8 @@ main(int argc, char **argv) // setup udns if (nameserver_num == 0) { -#ifdef __MINGW32__ nameservers[nameserver_num++] = "8.8.8.8"; resolv_init(loop, nameservers, nameserver_num, ipv6first); -#else - resolv_init(loop, NULL, 0, ipv6first); -#endif } else { resolv_init(loop, nameservers, nameserver_num, ipv6first); } @@ -1983,11 +1962,9 @@ main(int argc, char **argv) FATAL("failed to switch user"); } -#ifndef __MINGW32__ if (geteuid() == 0) { LOGI("running from root user"); } -#endif // init block list init_block_list(); @@ -2035,9 +2012,5 @@ main(int argc, char **argv) resolv_shutdown(loop); -#ifdef __MINGW32__ - winsock_cleanup(); -#endif - return 0; } diff --git a/src/tls.c b/src/tls.c index 5c422160..0b2f4a4d 100644 --- a/src/tls.c +++ b/src/tls.c @@ -36,12 +36,7 @@ #include #include /* malloc() */ #include /* strncpy() */ - -#ifndef __MINGW32__ #include -#else -#include -#endif #include "tls.h" #include "protocol.h" diff --git a/src/tunnel.c b/src/tunnel.c index dbe59029..ca04c6e0 100644 --- a/src/tunnel.c +++ b/src/tunnel.c @@ -30,13 +30,11 @@ #include #include -#ifndef __MINGW32__ #include #include #include #include #include -#endif #ifdef HAVE_CONFIG_H #include "config.h" @@ -48,10 +46,6 @@ #define SET_INTERFACE #endif -#ifdef __MINGW32__ -#include "win32.h" -#endif - #include #include @@ -100,13 +94,10 @@ static int auth = 0; static int nofile = 0; #endif -#ifndef __MINGW32__ static struct ev_signal sigint_watcher; static struct ev_signal sigterm_watcher; static struct ev_signal sigchld_watcher; -#endif -#ifndef __MINGW32__ static int setnonblocking(int fd) { @@ -116,7 +107,6 @@ setnonblocking(int fd) } return fcntl(fd, F_SETFL, flags | O_NONBLOCK); } -#endif int create_and_bind(const char *addr, const char *port) @@ -715,7 +705,6 @@ accept_cb(EV_P_ ev_io *w, int revents) ev_timer_start(EV_A_ & remote->send_ctx->watcher); } -#ifndef __MINGW32__ static void signal_cb(EV_P_ ev_signal *w, int revents) { @@ -736,7 +725,6 @@ signal_cb(EV_P_ ev_signal *w, int revents) } } } -#endif int main(int argc, char **argv) @@ -1031,9 +1019,6 @@ main(int argc, char **argv) } } -#ifdef __MINGW32__ - winsock_init(); -#else // ignore SIGPIPE signal(SIGPIPE, SIG_IGN); signal(SIGABRT, SIG_IGN); @@ -1044,7 +1029,6 @@ main(int argc, char **argv) ev_signal_start(EV_DEFAULT, &sigint_watcher); ev_signal_start(EV_DEFAULT, &sigterm_watcher); ev_signal_start(EV_DEFAULT, &sigchld_watcher); -#endif // Setup keys LOGI("initializing ciphers... %s", method); @@ -1124,11 +1108,9 @@ main(int argc, char **argv) FATAL("failed to switch user"); } -#ifndef __MINGW32__ if (geteuid() == 0) { LOGI("running from root user"); } -#endif ev_run(loop, 0); @@ -1136,9 +1118,5 @@ main(int argc, char **argv) stop_plugin(); } -#ifdef __MINGW32__ - winsock_cleanup(); -#endif - return 0; } diff --git a/src/udprelay.c b/src/udprelay.c index 9246aa81..4a1a182a 100644 --- a/src/udprelay.c +++ b/src/udprelay.c @@ -30,13 +30,11 @@ #include #include -#ifndef __MINGW32__ #include #include #include #include #include -#endif #ifdef HAVE_CONFIG_H #include "config.h" @@ -48,10 +46,6 @@ #define SET_INTERFACE #endif -#ifdef __MINGW32__ -#include "win32.h" -#endif - #include #include @@ -108,7 +102,6 @@ static int buf_size = DEFAULT_PACKET_SIZE * 2; static int server_num = 0; static server_ctx_t *server_ctx_list[MAX_REMOTE_NUM] = { NULL }; -#ifndef __MINGW32__ static int setnonblocking(int fd) { @@ -119,8 +112,6 @@ setnonblocking(int fd) return fcntl(fd, F_SETFL, flags | O_NONBLOCK); } -#endif - #if defined(MODULE_REMOTE) && defined(SO_BROADCAST) static int set_broadcast(int socket_fd) diff --git a/src/utils.c b/src/utils.c index 12ef85be..b54be242 100644 --- a/src/utils.c +++ b/src/utils.c @@ -29,10 +29,8 @@ #include #include #include -#ifndef __MINGW32__ #include #include -#endif #include #include @@ -54,7 +52,6 @@ FILE *logfile; int use_syslog = 0; #endif -#ifndef __MINGW32__ void ERROR(const char *s) { @@ -62,8 +59,6 @@ ERROR(const char *s) LOGE("%s: %s", s, msg); } -#endif - int use_tty = 1; char * @@ -103,7 +98,6 @@ ss_isnumeric(const char *s) { int run_as(const char *user) { -#ifndef __MINGW32__ if (user[0]) { /* Convert user to a long integer if it is a non-negative number. * -1 means it is a user name. */ @@ -198,7 +192,6 @@ run_as(const char *user) #endif } -#endif // __MINGW32__ return 1; } @@ -357,12 +350,10 @@ usage() printf( " [--mptcp] Enable Multipath TCP on MPTCP Kernel.\n"); #endif -#ifndef __MINGW32__ printf( " [--plugin ] Enable SIP003 plugin. (Experimental)\n"); printf( " [--plugin-opts ] Set SIP003 plugin options. (Experimental)\n"); -#endif printf("\n"); printf( " [-v] Verbose mode.\n"); @@ -374,7 +365,6 @@ usage() void daemonize(const char *path) { -#ifndef __MINGW32__ /* Our process ID and Session ID */ pid_t pid, sid; @@ -419,7 +409,6 @@ daemonize(const char *path) close(STDIN_FILENO); close(STDOUT_FILENO); close(STDERR_FILENO); -#endif } #ifdef HAVE_SETRLIMIT diff --git a/src/utils.h b/src/utils.h index 0fb7f5a2..859fcb38 100644 --- a/src/utils.h +++ b/src/utils.h @@ -49,7 +49,6 @@ #ifdef ANDROID #include - #define USE_TTY() #define USE_SYSLOG(ident) #define LOGI(...) \ @@ -59,7 +58,7 @@ ((void)__android_log_print(ANDROID_LOG_ERROR, "shadowsocks", \ __VA_ARGS__)) -#else +#else // not ANDROID #define STR(x) # x #define TOSTR(x) STR(x) @@ -67,13 +66,9 @@ #ifdef LIB_ONLY extern FILE *logfile; - #define TIME_FORMAT "%Y-%m-%d %H:%M:%S" - #define USE_TTY() - #define USE_SYSLOG(ident) - #define USE_LOGFILE(ident) \ do { \ if (ident != NULL) { logfile = fopen(ident, "w+"); } } \ @@ -83,7 +78,6 @@ extern FILE *logfile; do { \ if (logfile != NULL) { fclose(logfile); } } \ while (0) - #define LOGI(format, ...) \ do { \ if (logfile != NULL) { \ @@ -94,7 +88,6 @@ extern FILE *logfile; fflush(logfile); } \ } \ while (0) - #define LOGE(format, ...) \ do { \ if (logfile != NULL) { \ @@ -107,47 +100,20 @@ extern FILE *logfile; } \ while (0) -#elif defined(_WIN32) - -#define TIME_FORMAT "%Y-%m-%d %H:%M:%S" - -#define USE_TTY() - -#define USE_SYSLOG(ident) - -#define LOGI(format, ...) \ - do { \ - time_t now = time(NULL); \ - char timestr[20]; \ - strftime(timestr, 20, TIME_FORMAT, localtime(&now)); \ - fprintf(stderr, " %s INFO: " format "\n", timestr, ## __VA_ARGS__); \ - fflush(stderr); } \ - while (0) - -#define LOGE(format, ...) \ - do { \ - time_t now = time(NULL); \ - char timestr[20]; \ - strftime(timestr, 20, TIME_FORMAT, localtime(&now)); \ - fprintf(stderr, " %s ERROR: " format "\n", timestr, ## __VA_ARGS__); \ - fflush(stderr); } \ - while (0) - -#else +#else // not LIB_ONLY #include - extern int use_tty; -#define USE_TTY() \ - do { \ - use_tty = isatty(STDERR_FILENO); \ - } while (0) \ - -#define HAS_SYSLOG extern int use_syslog; +#define HAS_SYSLOG #define TIME_FORMAT "%F %T" +#define USE_TTY() \ + do { \ + use_tty = isatty(STDERR_FILENO); \ + } while (0) + #define USE_SYSLOG(ident) \ do { \ use_syslog = 1; \ @@ -191,24 +157,12 @@ extern int use_syslog; } } \ while (0) -#endif -/* _WIN32 */ +#endif // if LIB_ONLY -#endif - -#ifdef __MINGW32__ - -#ifdef ERROR -#undef ERROR -#endif -#define ERROR(s) ss_error(s) - -#else +#endif // if ANDROID void ERROR(const char *s); -#endif - char *ss_itoa(int i); int ss_isnumeric(const char *s); int run_as(const char *user); diff --git a/src/win32.c b/src/win32.c deleted file mode 100644 index c293e948..00000000 --- a/src/win32.c +++ /dev/null @@ -1,106 +0,0 @@ -/* - * win32.c - Win32 port helpers - * - * Copyright (C) 2014, Linus Yang - * - * This file is part of the shadowsocks-libev. - * - * shadowsocks-libev is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 3 of the License, or - * (at your option) any later version. - * - * shadowsocks-libev 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 General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with shadowsocks-libev; see the file COPYING. If not, see - * . - */ - -#include "win32.h" -#include "utils.h" - -#ifdef setsockopt -#undef setsockopt -#endif - -void -winsock_init(void) -{ - WORD wVersionRequested; - WSADATA wsaData; - int ret; - wVersionRequested = MAKEWORD(1, 1); - ret = WSAStartup(wVersionRequested, &wsaData); - if (ret != 0) { - FATAL("Could not initialize winsock"); - } - if (LOBYTE(wsaData.wVersion) != 1 || HIBYTE(wsaData.wVersion) != 1) { - WSACleanup(); - FATAL("Could not find a usable version of winsock"); - } -} - -void -winsock_cleanup(void) -{ - WSACleanup(); -} - -void -ss_error(const char *s) -{ - LPVOID *msg = NULL; - FormatMessage( - FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS, - NULL, WSAGetLastError(), - MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), - (LPTSTR)&msg, 0, NULL); - if (msg != NULL) { - LOGE("%s: %s", s, (char *)msg); - LocalFree(msg); - } -} - -int -setnonblocking(int fd) -{ - u_long iMode = 1; - long int iResult; - iResult = ioctlsocket(fd, FIONBIO, &iMode); - if (iResult != NO_ERROR) { - LOGE("ioctlsocket failed with error: %ld\n", iResult); - } - return iResult; -} - -size_t -strnlen(const char *s, size_t maxlen) -{ - const char *end = memchr(s, 0, maxlen); - return end ? (size_t)(end - s) : maxlen; -} - -const char * -inet_ntop(int af, const void *src, char *dst, socklen_t size) -{ - struct sockaddr_storage ss; - unsigned long s = size; - ZeroMemory(&ss, sizeof(ss)); - ss.ss_family = af; - switch (af) { - case AF_INET: - ((struct sockaddr_in *)&ss)->sin_addr = *(struct in_addr *)src; - break; - case AF_INET6: - ((struct sockaddr_in6 *)&ss)->sin6_addr = *(struct in6_addr *)src; - break; - default: - return NULL; - } - return (WSAAddressToString((struct sockaddr *)&ss, sizeof(ss), NULL, dst, - &s) == 0) ? dst : NULL; -} diff --git a/src/win32.h b/src/win32.h deleted file mode 100644 index 5be7b868..00000000 --- a/src/win32.h +++ /dev/null @@ -1,76 +0,0 @@ -/* - * win32.h - Win32 port helpers - * - * Copyright (C) 2014, Linus Yang - * - * This file is part of the shadowsocks-libev. - * - * shadowsocks-libev is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 3 of the License, or - * (at your option) any later version. - * - * shadowsocks-libev 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 General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with shadowsocks-libev; see the file COPYING. If not, see - * . - */ - -#ifndef _WIN32_H -#define _WIN32_H - -#ifdef _WIN32_WINNT -#undef _WIN32_WINNT -#endif - -#define _WIN32_WINNT 0x0501 - -#include -#include - -#ifdef EWOULDBLOCK -#undef EWOULDBLOCK -#endif - -#ifdef errno -#undef errno -#endif - -#ifdef ERROR -#undef ERROR -#endif - -#ifndef AI_ALL -#define AI_ALL 0x00000100 -#endif - -#ifndef AI_ADDRCONFIG -#define AI_ADDRCONFIG 0x00000400 -#endif - -#ifndef AI_V4MAPPED -#define AI_V4MAPPED 0x00000800 -#endif - -#ifndef IPV6_V6ONLY -#define IPV6_V6ONLY 27 // Treat wildcard bind as AF_INET6-only. -#endif - -#define EWOULDBLOCK WSAEWOULDBLOCK -#define errno WSAGetLastError() -#define close(fd) closesocket(fd) -#define ERROR(s) ss_error(s) -#define setsockopt(a, b, c, d, e) setsockopt(a, b, c, (char *)(d), e) - -void winsock_init(void); -void winsock_cleanup(void); -void ss_error(const char *s); -size_t strnlen(const char *s, size_t maxlen); -int setnonblocking(int fd); -const char *inet_ntop(int af, const void *src, char *dst, socklen_t size); - -#endif