mirror of
https://github.com/shadowsocks/shadowsocks-libev.git
synced 2026-10-28 11:43:50 +00:00
@@ -52,6 +52,10 @@
|
||||
/* Do some BSD (4.3 code base or newer)specific autodetection. */
|
||||
#include <libcork/config/bsd.h>
|
||||
|
||||
#elif defined(__MINGW32__)
|
||||
/* Do some mingw32 autodetection. */
|
||||
#include <libcork/config/mingw32.h>
|
||||
|
||||
#endif /* platforms */
|
||||
|
||||
|
||||
|
||||
@@ -0,0 +1,52 @@
|
||||
/* -*- coding: utf-8 -*-
|
||||
* ----------------------------------------------------------------------
|
||||
* Copyright © 2011, RedJack, LLC.
|
||||
* All rights reserved.
|
||||
*
|
||||
* Please see the COPYING file in this distribution for license
|
||||
* details.
|
||||
* ----------------------------------------------------------------------
|
||||
*/
|
||||
|
||||
#ifndef LIBCORK_CONFIG_MINGW32_H
|
||||
#define LIBCORK_CONFIG_MINGW32_H
|
||||
|
||||
#include <io.h>
|
||||
|
||||
/*-----------------------------------------------------------------------
|
||||
* Endianness
|
||||
*/
|
||||
|
||||
/* Assume MinGW32 only works on x86 platform */
|
||||
|
||||
#define CORK_CONFIG_IS_BIG_ENDIAN 0
|
||||
#define CORK_CONFIG_IS_LITTLE_ENDIAN 1
|
||||
|
||||
#define CORK_HAVE_REALLOCF 0
|
||||
#define CORK_HAVE_PTHREADS 1
|
||||
|
||||
/*
|
||||
* File io stuff. Odd that this is not defined by MinGW.
|
||||
* Maybe there is an M$ish way to do it.
|
||||
*/
|
||||
#define F_SETFL 4
|
||||
#define O_NONBLOCK 0x4000 /* non blocking I/O (POSIX style) */
|
||||
|
||||
#define F_GETFD 1
|
||||
#define F_SETFD 2
|
||||
#define FD_CLOEXEC 0x1
|
||||
|
||||
#define WNOHANG 1
|
||||
|
||||
/*
|
||||
* simple adaptors
|
||||
*/
|
||||
|
||||
static inline int mingw_mkdir(const char *path, int mode)
|
||||
{
|
||||
return mkdir(path);
|
||||
}
|
||||
#define mkdir mingw_mkdir
|
||||
|
||||
|
||||
#endif /* LIBCORK_CONFIG_MINGW32_H */
|
||||
@@ -12,8 +12,10 @@
|
||||
#include <errno.h>
|
||||
#include <fcntl.h>
|
||||
#include <signal.h>
|
||||
#ifndef __MINGW32__
|
||||
#include <sys/select.h>
|
||||
#include <sys/wait.h>
|
||||
#endif
|
||||
#include <unistd.h>
|
||||
|
||||
#include "libcork/core.h"
|
||||
@@ -506,7 +508,7 @@ cork_subprocess_is_finished(struct cork_subprocess *self)
|
||||
&& cork_read_pipe_is_finished(&self->stderr_pipe);
|
||||
}
|
||||
|
||||
#if defined(__APPLE__)
|
||||
#if defined(__APPLE__) || defined(__MINGW32__)
|
||||
#include <pthread.h>
|
||||
#define THREAD_YIELD pthread_yield_np
|
||||
#elif defined(__linux__) || defined(BSD)
|
||||
|
||||
@@ -1,12 +1,38 @@
|
||||
/*
|
||||
* acl.c - Manage the ACL (Access Control List)
|
||||
*
|
||||
* Copyright (C) 2013 - 2014, Max Lv <max.c.lv@gmail.com>
|
||||
*
|
||||
* 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 pdnsd; see the file COPYING. If not, see
|
||||
* <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include <ipset/ipset.h>
|
||||
#include <libcork/ds.h>
|
||||
|
||||
#include "utils.h"
|
||||
|
||||
static struct ip_set set;
|
||||
static struct ip_set acl_ip_set;
|
||||
static struct cork_string_array acl_domain_array;
|
||||
|
||||
static void parse_addr_cidr(const char *str, char **host, int *cidr)
|
||||
{
|
||||
int ret = -1, n = 0;
|
||||
char *pch;
|
||||
|
||||
pch = strchr(str, '/');
|
||||
while (pch != NULL)
|
||||
{
|
||||
@@ -35,8 +61,12 @@ static void parse_addr_cidr(const char *str, char **host, int *cidr)
|
||||
|
||||
int init_acl(const char *path)
|
||||
{
|
||||
// initialize ipset
|
||||
ipset_init_library();
|
||||
ipset_init(&set);
|
||||
ipset_init(&acl_ip_set);
|
||||
|
||||
// initialize array
|
||||
cork_string_array_init(&acl_domain_array);
|
||||
|
||||
FILE *f = fopen(path, "r");
|
||||
if (f == NULL) FATAL("Invalid acl path.");
|
||||
@@ -46,16 +76,33 @@ int init_acl(const char *path)
|
||||
{
|
||||
if (fgets(line, 256, f))
|
||||
{
|
||||
// Trim the newline
|
||||
int len = strlen(line);
|
||||
if (len > 0 && line[len - 1] == '\n')
|
||||
{
|
||||
line[len - 1] = '\0';
|
||||
}
|
||||
|
||||
char *host = NULL;
|
||||
int cidr;
|
||||
parse_addr_cidr(line, &host, &cidr);
|
||||
struct cork_ipv4 addr;
|
||||
int err = cork_ipv4_init(&addr, host);
|
||||
if (err) continue;
|
||||
if (cidr >= 0)
|
||||
ipset_ipv4_add_network(&set, &addr, cidr);
|
||||
|
||||
if (cidr == -1)
|
||||
{
|
||||
cork_string_array_append(&acl_domain_array, host);
|
||||
}
|
||||
else
|
||||
ipset_ipv4_add(&set, &addr);
|
||||
{
|
||||
struct cork_ipv4 addr;
|
||||
int err = cork_ipv4_init(&addr, host);
|
||||
if (!err)
|
||||
{
|
||||
if (cidr >= 0)
|
||||
ipset_ipv4_add_network(&acl_ip_set, &addr, cidr);
|
||||
else
|
||||
ipset_ipv4_add(&acl_ip_set, &addr);
|
||||
}
|
||||
}
|
||||
|
||||
if (host != NULL) free(host);
|
||||
}
|
||||
@@ -68,15 +115,43 @@ int init_acl(const char *path)
|
||||
|
||||
void free_acl(void)
|
||||
{
|
||||
ipset_done(&set);
|
||||
ipset_done(&acl_ip_set);
|
||||
}
|
||||
|
||||
int acl_is_bypass(const char* host)
|
||||
int acl_contains_domain(const char* domain)
|
||||
{
|
||||
const char **list = acl_domain_array.items;
|
||||
const int size = acl_domain_array.size;
|
||||
const int domain_len = strlen(domain);
|
||||
|
||||
for (int i = 0; i < size; i++)
|
||||
{
|
||||
const char *acl_domain = list[i];
|
||||
const int acl_domain_len = strlen(acl_domain);
|
||||
if (acl_domain_len > domain_len) continue;
|
||||
int match = true;
|
||||
for (int offset = 1; offset <= acl_domain_len; offset++)
|
||||
{
|
||||
if (domain[domain_len - offset] != acl_domain[acl_domain_len - offset])
|
||||
{
|
||||
match = false;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (match) return 1;
|
||||
}
|
||||
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int acl_contains_ip(const char* host)
|
||||
{
|
||||
struct cork_ipv4 addr;
|
||||
int err = cork_ipv4_init(&addr, host);
|
||||
if (err) return 0;
|
||||
|
||||
struct cork_ip ip;
|
||||
cork_ip_from_ipv4(&ip, &addr);
|
||||
return ipset_contains_ip(&set, &ip);
|
||||
return ipset_contains_ip(&acl_ip_set, &ip);
|
||||
}
|
||||
|
||||
@@ -1,8 +1,32 @@
|
||||
/*
|
||||
* acl.h - Define the ACL interface
|
||||
*
|
||||
* Copyright (C) 2013 - 2014, Max Lv <max.c.lv@gmail.com>
|
||||
*
|
||||
* 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 pdnsd; see the file COPYING. If not, see
|
||||
* <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#ifndef _ACL_H
|
||||
#define _ACL_H
|
||||
|
||||
int init_acl(const char *path);
|
||||
void free_acl(void);
|
||||
int acl_is_bypass(const char* host);
|
||||
|
||||
int acl_contains_ip(const char* ip);
|
||||
int acl_contains_domain(const char* domain);
|
||||
|
||||
#endif // _ACL_H
|
||||
|
||||
+22
@@ -1,3 +1,25 @@
|
||||
/*
|
||||
* cache.c - Manage the connection cache for UDPRELAY
|
||||
*
|
||||
* Copyright (C) 2013 - 2014, Max Lv <max.c.lv@gmail.com>
|
||||
*
|
||||
* 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 pdnsd; see the file COPYING. If not, see
|
||||
* <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
/*
|
||||
* Original Author: Oliver Lorenz (ol), olli@olorenz.org, https://olorenz.org
|
||||
* License: This is licensed under the same terms as uthash itself
|
||||
|
||||
+22
@@ -1,3 +1,25 @@
|
||||
/*
|
||||
* cache.c - Define the cache manager interface
|
||||
*
|
||||
* Copyright (C) 2013 - 2014, Max Lv <max.c.lv@gmail.com>
|
||||
*
|
||||
* 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 pdnsd; see the file COPYING. If not, see
|
||||
* <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
/*
|
||||
* Original Author: Oliver Lorenz (ol), olli@olorenz.org, https://olorenz.org
|
||||
* License: This is licensed under the same terms as uthash itself
|
||||
|
||||
@@ -1,3 +1,25 @@
|
||||
/*
|
||||
* encrypt.c - Manage the global encryptor
|
||||
*
|
||||
* Copyright (C) 2013 - 2014, Max Lv <max.c.lv@gmail.com>
|
||||
*
|
||||
* 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 pdnsd; see the file COPYING. If not, see
|
||||
* <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#ifdef HAVE_CONFIG_H
|
||||
#include "config.h"
|
||||
#endif
|
||||
|
||||
@@ -1,3 +1,25 @@
|
||||
/*
|
||||
* encrypt.h - Define the enryptor's interface
|
||||
*
|
||||
* Copyright (C) 2013 - 2014, Max Lv <max.c.lv@gmail.com>
|
||||
*
|
||||
* 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 pdnsd; see the file COPYING. If not, see
|
||||
* <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#ifndef _ENCRYPT_H
|
||||
#define _ENCRYPT_H
|
||||
|
||||
|
||||
+22
-1
@@ -1,3 +1,24 @@
|
||||
/*
|
||||
* include.h - Provide global definitions
|
||||
*
|
||||
* Copyright (C) 2013 - 2014, Max Lv <max.c.lv@gmail.com>
|
||||
*
|
||||
* 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 pdnsd; see the file COPYING. If not, see
|
||||
* <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#ifndef _INCLUDE_H
|
||||
#define _INCLUDE_H
|
||||
|
||||
@@ -8,7 +29,7 @@
|
||||
#ifndef TCP_FASTOPEN
|
||||
#define TCP_FASTOPEN 23
|
||||
#endif
|
||||
|
||||
|
||||
/* conditional define for MSG_FASTOPEN */
|
||||
#ifndef MSG_FASTOPEN
|
||||
#define MSG_FASTOPEN 0x20000000
|
||||
|
||||
+21
@@ -1,3 +1,24 @@
|
||||
/*
|
||||
* jconf.c - Parse the JSON format config file
|
||||
*
|
||||
* Copyright (C) 2013 - 2014, Max Lv <max.c.lv@gmail.com>
|
||||
*
|
||||
* 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 pdnsd; see the file COPYING. If not, see
|
||||
* <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
#include <unistd.h>
|
||||
|
||||
+21
@@ -1,3 +1,24 @@
|
||||
/*
|
||||
* server.c - Define the config data structure
|
||||
*
|
||||
* Copyright (C) 2013 - 2014, Max Lv <max.c.lv@gmail.com>
|
||||
*
|
||||
* 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 pdnsd; see the file COPYING. If not, see
|
||||
* <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#ifndef _JCONF_H
|
||||
#define _JCONF_H
|
||||
|
||||
|
||||
+106
-107
@@ -1,4 +1,3 @@
|
||||
|
||||
/* vim: set et ts=3 sw=3 sts=3 ft=c:
|
||||
*
|
||||
* Copyright (C) 2012, 2013, 2014 James McLaughlin et al. All rights reserved.
|
||||
@@ -120,151 +119,151 @@ typedef struct _json_value
|
||||
} * values;
|
||||
|
||||
#if defined(__cplusplus) && __cplusplus >= 201103L
|
||||
decltype(values) begin () const
|
||||
{
|
||||
return values;
|
||||
}
|
||||
decltype(values) end () const
|
||||
{
|
||||
return values + length;
|
||||
}
|
||||
decltype(values) begin () const
|
||||
{
|
||||
return values;
|
||||
}
|
||||
decltype(values) end () const
|
||||
{
|
||||
return values + length;
|
||||
}
|
||||
#endif
|
||||
|
||||
} object;
|
||||
} object;
|
||||
|
||||
struct
|
||||
{
|
||||
unsigned int length;
|
||||
struct _json_value ** values;
|
||||
struct
|
||||
{
|
||||
unsigned int length;
|
||||
struct _json_value ** values;
|
||||
|
||||
#if defined(__cplusplus) && __cplusplus >= 201103L
|
||||
decltype(values) begin () const
|
||||
{
|
||||
return values;
|
||||
}
|
||||
decltype(values) end () const
|
||||
{
|
||||
return values + length;
|
||||
}
|
||||
decltype(values) begin () const
|
||||
{
|
||||
return values;
|
||||
}
|
||||
decltype(values) end () const
|
||||
{
|
||||
return values + length;
|
||||
}
|
||||
#endif
|
||||
|
||||
} array;
|
||||
} array;
|
||||
|
||||
} u;
|
||||
} u;
|
||||
|
||||
union
|
||||
{
|
||||
struct _json_value * next_alloc;
|
||||
void * object_mem;
|
||||
union
|
||||
{
|
||||
struct _json_value * next_alloc;
|
||||
void * object_mem;
|
||||
|
||||
} _reserved;
|
||||
} _reserved;
|
||||
|
||||
|
||||
/* Some C++ operator sugar */
|
||||
/* Some C++ operator sugar */
|
||||
|
||||
#ifdef __cplusplus
|
||||
|
||||
public:
|
||||
public:
|
||||
|
||||
inline _json_value ()
|
||||
inline _json_value ()
|
||||
{
|
||||
memset (this, 0, sizeof (_json_value));
|
||||
}
|
||||
|
||||
inline const struct _json_value &operator [] (int index) const
|
||||
{
|
||||
if (type != json_array || index < 0
|
||||
|| ((unsigned int) index) >= u.array.length)
|
||||
{
|
||||
memset (this, 0, sizeof (_json_value));
|
||||
}
|
||||
|
||||
inline const struct _json_value &operator [] (int index) const
|
||||
{
|
||||
if (type != json_array || index < 0
|
||||
|| ((unsigned int) index) >= u.array.length)
|
||||
{
|
||||
return json_value_none;
|
||||
}
|
||||
|
||||
return *u.array.values [index];
|
||||
}
|
||||
|
||||
inline const struct _json_value &operator [] (const char * index) const
|
||||
{
|
||||
if (type != json_object)
|
||||
return json_value_none;
|
||||
|
||||
for (unsigned int i = 0; i < u.object.length; ++ i)
|
||||
if (!strcmp (u.object.values [i].name, index))
|
||||
return *u.object.values [i].value;
|
||||
|
||||
return json_value_none;
|
||||
}
|
||||
|
||||
inline operator const char * () const
|
||||
return *u.array.values [index];
|
||||
}
|
||||
|
||||
inline const struct _json_value &operator [] (const char * index) const
|
||||
{
|
||||
if (type != json_object)
|
||||
return json_value_none;
|
||||
|
||||
for (unsigned int i = 0; i < u.object.length; ++ i)
|
||||
if (!strcmp (u.object.values [i].name, index))
|
||||
return *u.object.values [i].value;
|
||||
|
||||
return json_value_none;
|
||||
}
|
||||
|
||||
inline operator const char * () const
|
||||
{
|
||||
switch (type)
|
||||
{
|
||||
switch (type)
|
||||
{
|
||||
case json_string:
|
||||
return u.string.ptr;
|
||||
case json_string:
|
||||
return u.string.ptr;
|
||||
|
||||
default:
|
||||
return "";
|
||||
};
|
||||
}
|
||||
default:
|
||||
return "";
|
||||
};
|
||||
}
|
||||
|
||||
inline operator json_int_t () const
|
||||
inline operator json_int_t () const
|
||||
{
|
||||
switch (type)
|
||||
{
|
||||
switch (type)
|
||||
{
|
||||
case json_integer:
|
||||
return u.integer;
|
||||
case json_integer:
|
||||
return u.integer;
|
||||
|
||||
case json_double:
|
||||
return (json_int_t) u.dbl;
|
||||
case json_double:
|
||||
return (json_int_t) u.dbl;
|
||||
|
||||
default:
|
||||
return 0;
|
||||
};
|
||||
}
|
||||
default:
|
||||
return 0;
|
||||
};
|
||||
}
|
||||
|
||||
inline operator bool () const
|
||||
inline operator bool () const
|
||||
{
|
||||
if (type != json_boolean)
|
||||
return false;
|
||||
|
||||
return u.boolean != 0;
|
||||
}
|
||||
|
||||
inline operator double () const
|
||||
{
|
||||
switch (type)
|
||||
{
|
||||
if (type != json_boolean)
|
||||
return false;
|
||||
case json_integer:
|
||||
return (double) u.integer;
|
||||
|
||||
return u.boolean != 0;
|
||||
}
|
||||
case json_double:
|
||||
return u.dbl;
|
||||
|
||||
inline operator double () const
|
||||
{
|
||||
switch (type)
|
||||
{
|
||||
case json_integer:
|
||||
return (double) u.integer;
|
||||
|
||||
case json_double:
|
||||
return u.dbl;
|
||||
|
||||
default:
|
||||
return 0;
|
||||
};
|
||||
}
|
||||
default:
|
||||
return 0;
|
||||
};
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
} json_value;
|
||||
} json_value;
|
||||
|
||||
json_value * json_parse (const json_char * json,
|
||||
size_t length);
|
||||
json_value * json_parse (const json_char * json,
|
||||
size_t length);
|
||||
|
||||
#define json_error_max 128
|
||||
json_value * json_parse_ex (json_settings * settings,
|
||||
const json_char * json,
|
||||
size_t length,
|
||||
char * error);
|
||||
json_value * json_parse_ex (json_settings * settings,
|
||||
const json_char * json,
|
||||
size_t length,
|
||||
char * error);
|
||||
|
||||
void json_value_free (json_value *);
|
||||
void json_value_free (json_value *);
|
||||
|
||||
|
||||
/* Not usually necessary, unless you used a custom mem_alloc and now want to
|
||||
* use a custom mem_free.
|
||||
*/
|
||||
void json_value_free_ex (json_settings * settings,
|
||||
json_value *);
|
||||
/* Not usually necessary, unless you used a custom mem_alloc and now want to
|
||||
* use a custom mem_free.
|
||||
*/
|
||||
void json_value_free_ex (json_settings * settings,
|
||||
json_value *);
|
||||
|
||||
|
||||
#ifdef __cplusplus
|
||||
|
||||
+24
-4
@@ -1,3 +1,25 @@
|
||||
/*
|
||||
* local.c - Setup a socks5 proxy through remote shadowsocks server
|
||||
*
|
||||
* Copyright (C) 2013 - 2014, Max Lv <max.c.lv@gmail.com>
|
||||
*
|
||||
* 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 pdnsd; see the file COPYING. If not, see
|
||||
* <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include <sys/stat.h>
|
||||
#include <sys/types.h>
|
||||
#include <fcntl.h>
|
||||
@@ -361,7 +383,6 @@ static void server_recv_cb (EV_P_ ev_io *w, int revents)
|
||||
host, INET_ADDRSTRLEN);
|
||||
sprintf(port, "%d", p);
|
||||
}
|
||||
|
||||
}
|
||||
else if (request->atyp == 3)
|
||||
{
|
||||
@@ -378,7 +399,6 @@ static void server_recv_cb (EV_P_ ev_io *w, int revents)
|
||||
host[name_len] = '\0';
|
||||
sprintf(port, "%d", p);
|
||||
}
|
||||
|
||||
}
|
||||
else if (request->atyp == 4)
|
||||
{
|
||||
@@ -394,7 +414,6 @@ static void server_recv_cb (EV_P_ ev_io *w, int revents)
|
||||
host, INET6_ADDRSTRLEN);
|
||||
sprintf(port, "%d", p);
|
||||
}
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -413,7 +432,8 @@ static void server_recv_cb (EV_P_ ev_io *w, int revents)
|
||||
LOGD("connect to %s:%s", host, port);
|
||||
}
|
||||
|
||||
if (acl_is_bypass(host))
|
||||
if ((request->atyp == 1 && acl_contains_ip(host))
|
||||
|| (request->atyp = 3 && acl_contains_domain(host)))
|
||||
{
|
||||
remote = connect_to_remote(server->listener, host, port);
|
||||
remote->direct = 1;
|
||||
|
||||
+22
@@ -1,3 +1,25 @@
|
||||
/*
|
||||
* local.h - Define the clinet's buffers and callbacks
|
||||
*
|
||||
* Copyright (C) 2013 - 2014, Max Lv <max.c.lv@gmail.com>
|
||||
*
|
||||
* 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 pdnsd; see the file COPYING. If not, see
|
||||
* <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#ifndef _LOCAL_H
|
||||
#define _LOCAL_H
|
||||
|
||||
|
||||
+23
@@ -1,3 +1,26 @@
|
||||
/*
|
||||
* redir.c - Provide a transparent TCP proxy through remote shadowsocks
|
||||
* server
|
||||
*
|
||||
* Copyright (C) 2013 - 2014, Max Lv <max.c.lv@gmail.com>
|
||||
*
|
||||
* 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 pdnsd; see the file COPYING. If not, see
|
||||
* <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include <sys/stat.h>
|
||||
#include <sys/types.h>
|
||||
#include <arpa/inet.h>
|
||||
|
||||
+22
@@ -1,3 +1,25 @@
|
||||
/*
|
||||
* redir.h - Define the redirector's buffers and callbacks
|
||||
*
|
||||
* Copyright (C) 2013 - 2014, Max Lv <max.c.lv@gmail.com>
|
||||
*
|
||||
* 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 pdnsd; see the file COPYING. If not, see
|
||||
* <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#ifndef _LOCAL_H
|
||||
#define _LOCAL_H
|
||||
|
||||
|
||||
@@ -1,3 +1,25 @@
|
||||
/*
|
||||
* server.c - Provide shadowsocks service
|
||||
*
|
||||
* Copyright (C) 2013 - 2014, Max Lv <max.c.lv@gmail.com>
|
||||
*
|
||||
* 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 pdnsd; see the file COPYING. If not, see
|
||||
* <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include <sys/stat.h>
|
||||
#include <sys/types.h>
|
||||
#include <arpa/inet.h>
|
||||
|
||||
@@ -1,3 +1,25 @@
|
||||
/*
|
||||
* server.h - Define shadowsocks server's buffers and callbacks
|
||||
*
|
||||
* Copyright (C) 2013 - 2014, Max Lv <max.c.lv@gmail.com>
|
||||
*
|
||||
* 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 pdnsd; see the file COPYING. If not, see
|
||||
* <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#ifndef _SERVER_H
|
||||
#define _SERVER_H
|
||||
|
||||
|
||||
@@ -1,3 +1,25 @@
|
||||
/*
|
||||
* socks5.h - Define SOCKS5's header
|
||||
*
|
||||
* Copyright (C) 2013, clowwindy <clowwindy42@gmail.com>
|
||||
*
|
||||
* 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 pdnsd; see the file COPYING. If not, see
|
||||
* <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#ifndef _SOCKS5_H
|
||||
#define _SOCKS5_H
|
||||
|
||||
|
||||
@@ -1,3 +1,25 @@
|
||||
/*
|
||||
* tunnel.c - Setup a local port forwarding through remote shadowsocks server
|
||||
*
|
||||
* Copyright (C) 2013 - 2014, Max Lv <max.c.lv@gmail.com>
|
||||
*
|
||||
* 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 pdnsd; see the file COPYING. If not, see
|
||||
* <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include <sys/stat.h>
|
||||
#include <sys/types.h>
|
||||
#include <fcntl.h>
|
||||
|
||||
+24
-2
@@ -1,5 +1,27 @@
|
||||
#ifndef _LOCAL_H
|
||||
#define _LOCAL_H
|
||||
/*
|
||||
* tunnel.h - Define tunnel's buffers and callbacks
|
||||
*
|
||||
* Copyright (C) 2013 - 2014, Max Lv <max.c.lv@gmail.com>
|
||||
*
|
||||
* 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 pdnsd; see the file COPYING. If not, see
|
||||
* <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#ifndef _TUNNEL_H
|
||||
#define _TUNNEL_H
|
||||
|
||||
#include <ev.h>
|
||||
#include "encrypt.h"
|
||||
|
||||
@@ -1,3 +1,25 @@
|
||||
/*
|
||||
* udprelay.c - Setup UDP relay for both client and server
|
||||
*
|
||||
* Copyright (C) 2013 - 2014, Max Lv <max.c.lv@gmail.com>
|
||||
*
|
||||
* 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 pdnsd; see the file COPYING. If not, see
|
||||
* <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include <sys/stat.h>
|
||||
#include <sys/types.h>
|
||||
#include <fcntl.h>
|
||||
|
||||
@@ -1,3 +1,25 @@
|
||||
/*
|
||||
* udprelay.h - Define UDP relay's buffers and callbacks
|
||||
*
|
||||
* Copyright (C) 2013 - 2014, Max Lv <max.c.lv@gmail.com>
|
||||
*
|
||||
* 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 pdnsd; see the file COPYING. If not, see
|
||||
* <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#ifndef _UDPRELAY_H
|
||||
#define _UDPRELAY_H
|
||||
|
||||
|
||||
+22
@@ -1,3 +1,25 @@
|
||||
/*
|
||||
* utils.c - Misc utilities
|
||||
*
|
||||
* Copyright (C) 2013 - 2014, Max Lv <max.c.lv@gmail.com>
|
||||
*
|
||||
* 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 pdnsd; see the file COPYING. If not, see
|
||||
* <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <unistd.h>
|
||||
#include <string.h>
|
||||
|
||||
+22
@@ -1,3 +1,25 @@
|
||||
/*
|
||||
* utils.h - Misc utilities
|
||||
*
|
||||
* Copyright (C) 2013 - 2014, Max Lv <max.c.lv@gmail.com>
|
||||
*
|
||||
* 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 pdnsd; see the file COPYING. If not, see
|
||||
* <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#ifndef _UTILS_H
|
||||
#define _UTILS_H
|
||||
|
||||
|
||||
+22
@@ -1,3 +1,25 @@
|
||||
/*
|
||||
* win32.c - Win32 port helpers
|
||||
*
|
||||
* Copyright (C) 2014, Linus Yang <linusyang@gmail.com>
|
||||
*
|
||||
* 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 pdnsd; see the file COPYING. If not, see
|
||||
* <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include "win32.h"
|
||||
|
||||
#ifdef setsockopt
|
||||
|
||||
+22
@@ -1,3 +1,25 @@
|
||||
/*
|
||||
* win32.c - Win32 port helpers
|
||||
*
|
||||
* Copyright (C) 2014, Linus Yang <linusyang@gmail.com>
|
||||
*
|
||||
* 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 pdnsd; see the file COPYING. If not, see
|
||||
* <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#ifndef _WIN32_H
|
||||
#define _WIN32_H
|
||||
|
||||
|
||||
Reference in New Issue
Block a user