Skip to content

Commit

Permalink
Clean up
Browse files Browse the repository at this point in the history
  • Loading branch information
madeye committed Sep 9, 2016
1 parent 96dda0e commit b28638a
Show file tree
Hide file tree
Showing 23 changed files with 603 additions and 366 deletions.
2 changes: 1 addition & 1 deletion .uncrustify.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -896,7 +896,7 @@ nl_class_brace = ignore # ignore/add/remove/force
nl_class_init_args = ignore # ignore/add/remove/force

# Add or remove newline between return type and function name in a function definition
nl_func_type_name = remove # ignore/add/remove/force
nl_func_type_name = force # ignore/add/remove/force

# Add or remove newline between return type and function name inside a class {}
# Uses nl_func_type_name or nl_func_proto_type_name if set to ignore.
Expand Down
59 changes: 35 additions & 24 deletions src/acl.c
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,8 @@ static struct cork_dllist white_list_rules;

static int acl_mode = BLACK_LIST;

static void parse_addr_cidr(const char *str, char *host, int *cidr)
static void
parse_addr_cidr(const char *str, char *host, int *cidr)
{
int ret = -1, n = 0;
char *pch;
Expand All @@ -59,27 +60,31 @@ static void parse_addr_cidr(const char *str, char *host, int *cidr)
}
}

char *trimwhitespace(char *str)
char *
trimwhitespace(char *str)
{
char *end;
char *end;

// Trim leading space
while(isspace(*str)) str++;
// Trim leading space
while (isspace(*str))
str++;

if(*str == 0) // All spaces?
return str;
if (*str == 0) // All spaces?
return str;

// Trim trailing space
end = str + strlen(str) - 1;
while(end > str && isspace(*end)) end--;
// Trim trailing space
end = str + strlen(str) - 1;
while (end > str && isspace(*end))
end--;

// Write new null terminator
*(end+1) = 0;
// Write new null terminator
*(end + 1) = 0;

return str;
return str;
}

int init_acl(const char *path)
int
init_acl(const char *path)
{
// initialize ipset
ipset_init_library();
Expand Down Expand Up @@ -123,23 +128,23 @@ int init_acl(const char *path)
}

if (strcmp(line, "[black_list]") == 0
|| strcmp(line, "[bypass_list]") == 0) {
|| strcmp(line, "[bypass_list]") == 0) {
list_ipv4 = &black_list_ipv4;
list_ipv6 = &black_list_ipv6;
rules = &black_list_rules;
continue;
} else if (strcmp(line, "[white_list]") == 0
|| strcmp(line, "[proxy_list]") == 0) {
|| strcmp(line, "[proxy_list]") == 0) {
list_ipv4 = &white_list_ipv4;
list_ipv6 = &white_list_ipv6;
rules = &white_list_rules;
continue;
} else if (strcmp(line, "[reject_all]") == 0
|| strcmp(line, "[bypass_all]") == 0) {
|| strcmp(line, "[bypass_all]") == 0) {
acl_mode = WHITE_LIST;
continue;
} else if (strcmp(line, "[accept_all]") == 0
|| strcmp(line, "[proxy_all]") == 0) {
|| strcmp(line, "[proxy_all]") == 0) {
acl_mode = BLACK_LIST;
continue;
}
Expand Down Expand Up @@ -177,7 +182,8 @@ int init_acl(const char *path)
return 0;
}

void free_rules(struct cork_dllist *rules)
void
free_rules(struct cork_dllist *rules)
{
struct cork_dllist_item *iter;
while ((iter = cork_dllist_head(rules)) != NULL) {
Expand All @@ -186,7 +192,8 @@ void free_rules(struct cork_dllist *rules)
}
}

void free_acl(void)
void
free_acl(void)
{
ipset_done(&black_list_ipv4);
ipset_done(&black_list_ipv6);
Expand All @@ -197,7 +204,8 @@ void free_acl(void)
free_rules(&white_list_rules);
}

int get_acl_mode(void)
int
get_acl_mode(void)
{
return acl_mode;
}
Expand All @@ -207,7 +215,8 @@ int get_acl_mode(void)
* Return 1, if match black list.
* Return -1, if match white list.
*/
int acl_match_host(const char *host)
int
acl_match_host(const char *host)
{
struct cork_ip addr;
int ret = 0;
Expand Down Expand Up @@ -237,7 +246,8 @@ int acl_match_host(const char *host)
return ret;
}

int acl_add_ip(const char *ip)
int
acl_add_ip(const char *ip)
{
struct cork_ip addr;
int err = cork_ip_init(&addr, ip);
Expand All @@ -254,7 +264,8 @@ int acl_add_ip(const char *ip)
return 0;
}

int acl_remove_ip(const char *ip)
int
acl_remove_ip(const char *ip)
{
struct cork_ip addr;
int err = cork_ip_init(&addr, ip);
Expand Down
6 changes: 4 additions & 2 deletions src/android.c
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,8 @@

extern char *prefix;

int protect_socket(int fd)
int
protect_socket(int fd)
{
int sock;
struct sockaddr_un addr;
Expand Down Expand Up @@ -96,7 +97,8 @@ int protect_socket(int fd)
return ret;
}

int send_traffic_stat(uint64_t tx, uint64_t rx)
int
send_traffic_stat(uint64_t tx, uint64_t rx)
{
int sock;
struct sockaddr_un addr;
Expand Down
20 changes: 13 additions & 7 deletions src/cache.c
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,9 @@
*
* @return EINVAL if dst is NULL, ENOMEM if malloc fails, 0 otherwise
*/
int cache_create(struct cache **dst, const size_t capacity,
void (*free_cb)(void *element))
int
cache_create(struct cache **dst, const size_t capacity,
void (*free_cb)(void *element))
{
struct cache *new = NULL;

Expand Down Expand Up @@ -75,7 +76,8 @@ int cache_create(struct cache **dst, const size_t capacity,
*
* @return EINVAL if cache is NULL, 0 otherwise
*/
int cache_delete(struct cache *cache, int keep_data)
int
cache_delete(struct cache *cache, int keep_data)
{
struct cache_entry *entry, *tmp;

Expand Down Expand Up @@ -115,7 +117,8 @@ int cache_delete(struct cache *cache, int keep_data)
*
* @return EINVAL if cache is NULL, 0 otherwise
*/
int cache_remove(struct cache *cache, char *key, size_t key_len)
int
cache_remove(struct cache *cache, char *key, size_t key_len)
{
struct cache_entry *tmp;

Expand Down Expand Up @@ -161,7 +164,8 @@ int cache_remove(struct cache *cache, char *key, size_t key_len)
*
* @return EINVAL if cache is NULL, 0 otherwise
*/
int cache_lookup(struct cache *cache, char *key, size_t key_len, void *result)
int
cache_lookup(struct cache *cache, char *key, size_t key_len, void *result)
{
struct cache_entry *tmp = NULL;
char **dirty_hack = result;
Expand All @@ -182,7 +186,8 @@ int cache_lookup(struct cache *cache, char *key, size_t key_len, void *result)
return 0;
}

int cache_key_exist(struct cache *cache, char *key, size_t key_len)
int
cache_key_exist(struct cache *cache, char *key, size_t key_len)
{
struct cache_entry *tmp = NULL;

Expand Down Expand Up @@ -218,7 +223,8 @@ int cache_key_exist(struct cache *cache, char *key, size_t key_len)
*
* @return EINVAL if cache is NULL, ENOMEM if malloc fails, 0 otherwise
*/
int cache_insert(struct cache *cache, char *key, size_t key_len, void *data)
int
cache_insert(struct cache *cache, char *key, size_t key_len, void *data)
{
struct cache_entry *entry = NULL;
struct cache_entry *tmp_entry = NULL;
Expand Down
Loading

0 comments on commit b28638a

Please sign in to comment.