summaryrefslogtreecommitdiff
path: root/shared
diff options
context:
space:
mode:
Diffstat (limited to 'shared')
-rw-r--r--shared/ansi-colors.h14
-rw-r--r--shared/config-parser.c66
-rw-r--r--shared/config-parser.h8
-rw-r--r--shared/debug.h97
-rw-r--r--shared/external.h3
-rw-r--r--shared/list.h202
-rw-r--r--shared/mc-protocol.c71
-rw-r--r--shared/mc-protocol.h1
-rw-r--r--shared/rcon-protocol.c35
-rw-r--r--shared/rcon-protocol.h5
-rw-r--r--shared/server-config-options.h40
-rw-r--r--shared/utils.c56
-rw-r--r--shared/utils.h30
13 files changed, 312 insertions, 316 deletions
diff --git a/shared/ansi-colors.h b/shared/ansi-colors.h
index ba89c46..8294f2d 100644
--- a/shared/ansi-colors.h
+++ b/shared/ansi-colors.h
@@ -1,12 +1,12 @@
#ifndef fooansicolorshfoo
#define fooansicolorshfoo
-#define ANSI_RED "\x1B[0;31m"
-#define ANSI_GREEN "\x1B[0;32m"
-#define ANSI_YELLOW "\x1B[0;33m"
-#define ANSI_BLUE "\x1B[0;34m"
-#define ANSI_MAGENTA "\x1B[0;35m"
-#define ANSI_GREY "\x1B[0;38;5;245m"
-#define ANSI_NORMAL "\x1B[0m"
+#define ANSI_RED "\x1B[0;31m"
+#define ANSI_GREEN "\x1B[0;32m"
+#define ANSI_YELLOW "\x1B[0;33m"
+#define ANSI_BLUE "\x1B[0;34m"
+#define ANSI_MAGENTA "\x1B[0;35m"
+#define ANSI_GREY "\x1B[0;38;5;245m"
+#define ANSI_NORMAL "\x1B[0m"
#endif
diff --git a/shared/config-parser.c b/shared/config-parser.c
index 386d5a2..13b26e1 100644
--- a/shared/config-parser.c
+++ b/shared/config-parser.c
@@ -13,8 +13,7 @@
#include "config-parser.h"
#include "config.h"
-static void
-eat_whitespace_and_comments(char **pos)
+static void eat_whitespace_and_comments(char **pos)
{
assert_return(pos && *pos);
@@ -30,8 +29,7 @@ eat_whitespace_and_comments(char **pos)
}
}
-static char *
-get_line(char **pos)
+static char *get_line(char **pos)
{
char *begin, *end;
@@ -63,9 +61,8 @@ get_line(char **pos)
return begin;
}
-static bool
-dnslookup(const char *name, uint16_t port, struct cfg_value *rvalue,
- unsigned *naddrs, bool async)
+static bool dnslookup(const char *name, uint16_t port, struct cfg_value *rvalue,
+ unsigned *naddrs, bool async)
{
struct sockaddr_in *in4;
struct sockaddr_in6 *in6;
@@ -77,7 +74,9 @@ dnslookup(const char *name, uint16_t port, struct cfg_value *rvalue,
bool rv = false;
int r;
- assert_return(!empty_str(name) && strlen(name) < sizeof(dns->name) && port > 0 && rvalue, false);
+ assert_return(!empty_str(name) && strlen(name) < sizeof(dns->name) &&
+ port > 0 && rvalue,
+ false);
if (async) {
rvalue->type = CFG_VAL_TYPE_ASYNC_ADDRS;
@@ -94,7 +93,7 @@ dnslookup(const char *name, uint16_t port, struct cfg_value *rvalue,
debug(DBG_DNS, "doing sync DNS lookup of %s", name);
}
- sprintf(dns->name, "%s", name);
+ sprintf(dns->name, "%s", name);
sprintf(dns->port, "%" PRIu16, port);
dns->req.ai_family = AF_UNSPEC;
@@ -114,7 +113,8 @@ dnslookup(const char *name, uint16_t port, struct cfg_value *rvalue,
r = getaddrinfo_a(mode, gcbs, ARRAY_SIZE(gcbs), &dns->sev);
if (r != 0) {
- error("getaddrinfo(%s:%" PRIu16 "): %s", name, port, gai_strerror(r));
+ error("getaddrinfo(%s:%" PRIu16 "): %s", name, port,
+ gai_strerror(r));
goto out;
}
@@ -136,7 +136,8 @@ dnslookup(const char *name, uint16_t port, struct cfg_value *rvalue,
switch (ai->ai_family) {
case AF_INET:
in4 = (struct sockaddr_in *)ai->ai_addr;
- saddr_set_ipv4(saddr, in4->sin_addr.s_addr, in4->sin_port);
+ saddr_set_ipv4(saddr, in4->sin_addr.s_addr,
+ in4->sin_port);
debug(DBG_CFG, "addrstr: %s", saddr->addrstr);
list_add(&saddr->list, &rvalue->saddrs);
(*naddrs)++;
@@ -165,8 +166,7 @@ out:
return rv;
}
-bool
-strtosockaddrs(const char *str, struct cfg_value *rvalue, bool async)
+bool strtosockaddrs(const char *str, struct cfg_value *rvalue, bool async)
{
struct saddr *saddr;
uint16_t port;
@@ -235,7 +235,8 @@ strtosockaddrs(const char *str, struct cfg_value *rvalue, bool async)
} else if ((tmp = strchr(str, ':'))) {
/* IPv4, a.b.c.d:p or IPv4/6 hostname:p */
- debug(DBG_CFG, "attempting to parse IPv4 addr or hostname (%s)", str);
+ debug(DBG_CFG, "attempting to parse IPv4 addr or hostname (%s)",
+ str);
*tmp = '\0';
tmp++;
@@ -247,15 +248,18 @@ strtosockaddrs(const char *str, struct cfg_value *rvalue, bool async)
goto error;
if (inet_pton(AF_INET, str, &saddr->in4.sin_addr) > 0) {
- debug(DBG_CFG, "got an IPv4:port (%s:%" PRIu16 ")", str, port);
- saddr_set_ipv4(saddr, saddr->in4.sin_addr.s_addr, htons(port));
+ debug(DBG_CFG, "got an IPv4:port (%s:%" PRIu16 ")", str,
+ port);
+ saddr_set_ipv4(saddr, saddr->in4.sin_addr.s_addr,
+ htons(port));
list_add(&saddr->list, list);
naddrs++;
goto success;
- }
+ }
xfree(saddr);
- debug(DBG_CFG, "maybe got a hostname:port (%s:%" PRIu16 ")", str, port);
+ debug(DBG_CFG, "maybe got a hostname:port (%s:%" PRIu16 ")",
+ str, port);
if (!dnslookup(str, port, rvalue, &naddrs, async))
goto error;
@@ -318,16 +322,16 @@ error:
}
/* Returns true if there's data left to parse in buf */
-bool
-config_parse_line(const char *filename, char **buf,
- struct cfg_key_value_map *kvmap, int *rkey,
- const char **rkeyname, struct cfg_value *rvalue,
- bool async_dns)
+bool config_parse_line(const char *filename, char **buf,
+ struct cfg_key_value_map *kvmap, int *rkey,
+ const char **rkeyname, struct cfg_value *rvalue,
+ bool async_dns)
{
char *line, *tmp, *key;
int i;
- assert_return(buf && *buf && kvmap && rkey && rkeyname && rvalue, false);
+ assert_return(buf && *buf && kvmap && rkey && rkeyname && rvalue,
+ false);
line = get_line(buf);
if (!line)
@@ -370,7 +374,6 @@ config_parse_line(const char *filename, char **buf,
continue;
switch (kvmap[i].value_type) {
-
case CFG_VAL_TYPE_STRING:
rvalue->type = CFG_VAL_TYPE_STRING;
rvalue->str = tmp;
@@ -425,7 +428,8 @@ config_parse_line(const char *filename, char **buf,
if (strcaseeq(tmp, "yes") || strcaseeq(tmp, "true")) {
rvalue->type = CFG_VAL_TYPE_BOOL;
rvalue->boolean = true;
- } else if (strcaseeq(tmp, "no") || strcaseeq(tmp, "false")) {
+ } else if (strcaseeq(tmp, "no") ||
+ strcaseeq(tmp, "false")) {
rvalue->type = CFG_VAL_TYPE_BOOL;
rvalue->boolean = false;
} else {
@@ -454,7 +458,8 @@ config_parse_line(const char *filename, char **buf,
}
error:
- /* FIXME: the line is already mangled here, a line number would be nice */
+ /* FIXME: the line is already mangled here, a line number would be nice
+ */
error("%s: invalid config line: %s", filename, line);
rvalue->type = CFG_VAL_TYPE_INVALID;
*rkey = 0;
@@ -462,8 +467,7 @@ error:
return true;
}
-bool
-config_parse_header(const char *title, char **buf)
+bool config_parse_header(const char *title, char **buf)
{
char *line;
@@ -481,8 +485,7 @@ config_parse_header(const char *title, char **buf)
return false;
}
-bool
-is_valid_server_config_filename(struct dirent *dent, const char *filename)
+bool is_valid_server_config_filename(struct dirent *dent, const char *filename)
{
const char *suffix;
@@ -512,4 +515,3 @@ is_valid_server_config_filename(struct dirent *dent, const char *filename)
return true;
}
-
diff --git a/shared/config-parser.h b/shared/config-parser.h
index 7c5703e..771ece1 100644
--- a/shared/config-parser.h
+++ b/shared/config-parser.h
@@ -18,7 +18,7 @@ enum cfg_value_type {
struct dns_async;
-typedef void (dns_cb_t)(struct dns_async *);
+typedef void(dns_cb_t)(struct dns_async *);
struct dns_async {
char name[FQDN_STR_LEN + 1];
@@ -51,9 +51,9 @@ struct cfg_value {
bool strtosockaddrs(const char *str, struct cfg_value *rvalue, bool async);
bool config_parse_line(const char *filename, char **buf,
- struct cfg_key_value_map *kvmap,
- int *rkey, const char **rkeyname,
- struct cfg_value *rvalue, bool async_dns);
+ struct cfg_key_value_map *kvmap, int *rkey,
+ const char **rkeyname, struct cfg_value *rvalue,
+ bool async_dns);
bool config_parse_header(const char *title, char **buf);
diff --git a/shared/debug.h b/shared/debug.h
index 6f1a054..2b1eba0 100644
--- a/shared/debug.h
+++ b/shared/debug.h
@@ -2,6 +2,7 @@
#define foodebughfoo
/* FIXME: Should these be shared? */
+/* clang-format off */
enum debug_lvl {
DBG_ERROR = (0x1 << 1),
DBG_INFO = (0x1 << 2),
@@ -21,70 +22,70 @@ enum debug_lvl {
DBG_DNS = (0x1 << 16),
DBG_TIMER = (0x1 << 17),
};
+/* clang-format on */
-static inline bool
-debug_enabled(enum debug_lvl lvl)
+static inline bool debug_enabled(enum debug_lvl lvl)
{
return !!(lvl & debug_mask);
}
-#define __ifdebug(lvl, fmt, ...) \
- do { \
- if (debug_enabled((lvl))) \
- __debug((lvl), fmt "\n"__VA_OPT__(,) __VA_ARGS__); \
+#define __ifdebug(lvl, fmt, ...) \
+ do { \
+ if (debug_enabled((lvl))) \
+ __debug((lvl), fmt "\n"__VA_OPT__(, )__VA_ARGS__); \
} while (0)
-#define debug(lvl, fmt, ...) __ifdebug((lvl), "%s:%s:%i: " fmt, \
- __FILE__, __func__, __LINE__ \
- __VA_OPT__(,) __VA_ARGS__)
-#define verbose(fmt, ...) __ifdebug(DBG_VERBOSE, fmt, __VA_ARGS__)
-#define info(fmt, ...) __ifdebug(DBG_INFO, fmt, __VA_ARGS__)
-#define error(fmt, ...) __ifdebug(DBG_ERROR, "%s:%s:%i: " fmt, \
- __FILE__, __func__, __LINE__ \
- __VA_OPT__(,) __VA_ARGS__)
+#define debug(lvl, fmt, ...) \
+ __ifdebug((lvl), "%s:%s:%i: " fmt, __FILE__, __func__, \
+ __LINE__ __VA_OPT__(, ) __VA_ARGS__)
+#define verbose(fmt, ...) __ifdebug(DBG_VERBOSE, fmt, __VA_ARGS__)
+#define info(fmt, ...) __ifdebug(DBG_INFO, fmt, __VA_ARGS__)
+#define error(fmt, ...) \
+ __ifdebug(DBG_ERROR, "%s:%s:%i: " fmt, __FILE__, __func__, \
+ __LINE__ __VA_OPT__(, ) __VA_ARGS__)
-#define die(fmt, ...) \
- __die("%s:%s:%i: " fmt "\n", \
- __FILE__, __func__, __LINE__ \
- __VA_OPT__(,) __VA_ARGS__)
+#define die(fmt, ...) \
+ __die("%s:%s:%i: " fmt "\n", __FILE__, __func__, \
+ __LINE__ __VA_OPT__(, ) __VA_ARGS__)
-#define assert_log(expr, msg) \
- ((expr) ? \
- (true) : \
- (__debug(DBG_ERROR, "%s:%s:%i: assertion \"" msg "\" failed\n", \
- __FILE__, __func__, __LINE__), false))
+#define assert_log(expr, msg) \
+ ((expr) ? (true) : \
+ (__debug(DBG_ERROR, \
+ "%s:%s:%i: assertion \"" msg "\" failed\n", \
+ __FILE__, __func__, __LINE__), \
+ false))
-#define assert_return(expr, ...) \
- do { \
- if (!assert_log(expr, #expr)) \
- return __VA_ARGS__; \
+#define assert_return(expr, ...) \
+ do { \
+ if (!assert_log(expr, #expr)) \
+ return __VA_ARGS__; \
} while (0)
-#define assert_return_silent(expr, ...) \
- do { \
- if (!(expr)) \
- return __VA_ARGS__; \
+#define assert_return_silent(expr, ...) \
+ do { \
+ if (!(expr)) \
+ return __VA_ARGS__; \
} while (0)
-#define assert_die(expr, msg) \
- do { \
- if (!assert_log(expr, #expr)) \
- die(msg); \
+#define assert_die(expr, msg) \
+ do { \
+ if (!assert_log(expr, #expr)) \
+ die(msg); \
} while (0)
-#define assert_task_alive_or(lvl, t, cmd) \
-do { \
- if (!(t)) { \
- error("invalid task"); \
- cmd; \
- } \
- \
- if ((t)->dead) { \
- debug((lvl), "task dead"); \
- cmd; \
- } \
-} while(0)
+#define assert_task_alive_or(lvl, t, cmd) \
+ do { \
+ if (!(t)) { \
+ error("invalid task"); \
+ cmd; \
+ } \
+ \
+ if ((t)->dead) { \
+ debug((lvl), "task dead"); \
+ cmd; \
+ } \
+ } while (0)
-#define assert_task_alive(lvl, t) assert_task_alive_or((lvl), (t), return)
+#define assert_task_alive(lvl, t) assert_task_alive_or((lvl), (t), return )
#endif
diff --git a/shared/external.h b/shared/external.h
index beba93a..738e460 100644
--- a/shared/external.h
+++ b/shared/external.h
@@ -9,7 +9,8 @@ void *__zmalloc(const char *fn, int line, size_t s) _malloc_ _alloc_(3);
char *__xstrdup(const char *fn, int line, const char *s) _malloc_;
#define xstrndup(s, n) __xstrndup(__func__, __LINE__, s, n)
-char *__xstrndup(const char *fn, int line, const char *s, size_t n) _malloc_ _alloc_(4);
+char *__xstrndup(const char *fn, int line, const char *s, size_t n) _malloc_
+ _alloc_(4);
#define xfree(s) __xfree(__func__, __LINE__, s)
void __xfree(const char *fn, int line, void *ptr);
diff --git a/shared/list.h b/shared/list.h
index fcd005a..25f4219 100644
--- a/shared/list.h
+++ b/shared/list.h
@@ -17,15 +17,17 @@ struct list_head {
};
#define WRITE_ONCE(a, b) ((a) = (b))
-#define READ_ONCE(a) (a)
-#define LIST_POISON1 ((void *) 0x100)
-#define LIST_POISON2 ((void *) 0x122)
+#define READ_ONCE(a) (a)
+#define LIST_POISON1 ((void *)0x100)
+#define LIST_POISON2 ((void *)0x122)
-#define offsetof(TYPE, MEMBER) ((size_t) &((TYPE *)0)->MEMBER)
+#define offsetof(TYPE, MEMBER) ((size_t) & ((TYPE *)0)->MEMBER)
-#define container_of(ptr, type, member) __extension__ ({ \
- const typeof( ((type *)0)->member ) *__mptr = (ptr); \
- (type *)( (char *)__mptr - offsetof(type,member) );})
+#define container_of(ptr, type, member) \
+ __extension__({ \
+ const typeof(((type *)0)->member) *__mptr = (ptr); \
+ (type *)((char *)__mptr - offsetof(type, member)); \
+ })
/* End of added stuff */
@@ -39,10 +41,12 @@ struct list_head {
* using the generic single-entry routines.
*/
-#define LIST_HEAD_INIT(name) { &(name), &(name) }
+#define LIST_HEAD_INIT(name) \
+ { \
+ &(name), &(name) \
+ }
-#define LIST_HEAD(name) \
- struct list_head name = LIST_HEAD_INIT(name)
+#define LIST_HEAD(name) struct list_head name = LIST_HEAD_INIT(name)
/**
* INIT_LIST_HEAD - Initialize a list_head structure
@@ -58,14 +62,13 @@ static inline void INIT_LIST_HEAD(struct list_head *list)
}
#ifdef CONFIG_DEBUG_LIST
-extern bool __list_add_valid(struct list_head *new,
- struct list_head *prev,
- struct list_head *next);
+extern bool __list_add_valid(struct list_head *new, struct list_head *prev,
+ struct list_head *next);
extern bool __list_del_entry_valid(struct list_head *entry);
#else
static inline bool __list_add_valid(_unused_ struct list_head *new,
- _unused_ struct list_head *prev,
- _unused_ struct list_head *next)
+ _unused_ struct list_head *prev,
+ _unused_ struct list_head *next)
{
return true;
}
@@ -81,8 +84,7 @@ static inline bool __list_del_entry_valid(_unused_ struct list_head *entry)
* This is only for internal list manipulation where we know
* the prev/next entries already!
*/
-static inline void __list_add(struct list_head *new,
- struct list_head *prev,
+static inline void __list_add(struct list_head *new, struct list_head *prev,
struct list_head *next)
{
if (!__list_add_valid(new, prev, next))
@@ -107,7 +109,6 @@ static inline void list_add(struct list_head *new, struct list_head *head)
__list_add(new, head, head->next);
}
-
/**
* list_add_tail - add a new entry
* @new: new entry to be added
@@ -128,7 +129,7 @@ static inline void list_add_tail(struct list_head *new, struct list_head *head)
* This is only for internal list manipulation where we know
* the prev/next entries already!
*/
-static inline void __list_del(struct list_head * prev, struct list_head * next)
+static inline void __list_del(struct list_head *prev, struct list_head *next)
{
next->prev = prev;
WRITE_ONCE(prev->next, next);
@@ -176,8 +177,7 @@ static inline void list_del(struct list_head *entry)
*
* If @old was empty, it will be overwritten.
*/
-static inline void list_replace(struct list_head *old,
- struct list_head *new)
+static inline void list_replace(struct list_head *old, struct list_head *new)
{
new->next = old->next;
new->next->prev = new;
@@ -204,8 +204,7 @@ static inline void list_replace_init(struct list_head *old,
* @entry1: the location to place entry2
* @entry2: the location to place entry1
*/
-static inline void list_swap(struct list_head *entry1,
- struct list_head *entry2)
+static inline void list_swap(struct list_head *entry1, struct list_head *entry2)
{
struct list_head *pos = entry2->prev;
@@ -278,7 +277,7 @@ static inline void list_bulk_move_tail(struct list_head *head,
* @head: the head of the list
*/
static inline int list_is_first(const struct list_head *list,
- const struct list_head *head)
+ const struct list_head *head)
{
return list->prev == head;
}
@@ -289,7 +288,7 @@ static inline int list_is_first(const struct list_head *list,
* @head: the head of the list
*/
static inline int list_is_last(const struct list_head *list,
- const struct list_head *head)
+ const struct list_head *head)
{
return list->next == head;
}
@@ -364,7 +363,8 @@ static inline int list_is_singular(const struct list_head *head)
}
static inline void __list_cut_position(struct list_head *list,
- struct list_head *head, struct list_head *entry)
+ struct list_head *head,
+ struct list_head *entry)
{
struct list_head *new_first = entry->next;
list->next = head->next;
@@ -390,12 +390,12 @@ static inline void __list_cut_position(struct list_head *list,
*
*/
static inline void list_cut_position(struct list_head *list,
- struct list_head *head, struct list_head *entry)
+ struct list_head *head,
+ struct list_head *entry)
{
if (list_empty(head))
return;
- if (list_is_singular(head) &&
- (head->next != entry && head != entry))
+ if (list_is_singular(head) && (head->next != entry && head != entry))
return;
if (entry == head)
INIT_LIST_HEAD(list);
@@ -434,8 +434,7 @@ static inline void list_cut_before(struct list_head *list,
}
static inline void __list_splice(const struct list_head *list,
- struct list_head *prev,
- struct list_head *next)
+ struct list_head *prev, struct list_head *next)
{
struct list_head *first = list->next;
struct list_head *last = list->prev;
@@ -453,7 +452,7 @@ static inline void __list_splice(const struct list_head *list,
* @head: the place to add it in the first list.
*/
static inline void list_splice(const struct list_head *list,
- struct list_head *head)
+ struct list_head *head)
{
if (!list_empty(list))
__list_splice(list, head, head->next);
@@ -465,7 +464,7 @@ static inline void list_splice(const struct list_head *list,
* @head: the place to add it in the first list.
*/
static inline void list_splice_tail(struct list_head *list,
- struct list_head *head)
+ struct list_head *head)
{
if (!list_empty(list))
__list_splice(list, head->prev, head);
@@ -510,8 +509,7 @@ static inline void list_splice_tail_init(struct list_head *list,
* @type: the type of the struct this is embedded in.
* @member: the name of the list_head within the struct.
*/
-#define list_entry(ptr, type, member) \
- container_of(ptr, type, member)
+#define list_entry(ptr, type, member) container_of(ptr, type, member)
/**
* list_first_entry - get the first element from a list
@@ -521,7 +519,7 @@ static inline void list_splice_tail_init(struct list_head *list,
*
* Note, that list is expected to be not empty.
*/
-#define list_first_entry(ptr, type, member) \
+#define list_first_entry(ptr, type, member) \
list_entry((ptr)->next, type, member)
/**
@@ -532,8 +530,7 @@ static inline void list_splice_tail_init(struct list_head *list,
*
* Note, that list is expected to be not empty.
*/
-#define list_last_entry(ptr, type, member) \
- list_entry((ptr)->prev, type, member)
+#define list_last_entry(ptr, type, member) list_entry((ptr)->prev, type, member)
/**
* list_first_entry_or_null - get the first element from a list
@@ -543,18 +540,19 @@ static inline void list_splice_tail_init(struct list_head *list,
*
* Note that if the list is empty, it returns NULL.
*/
-#define list_first_entry_or_null(ptr, type, member) ({ \
- struct list_head *head__ = (ptr); \
- struct list_head *pos__ = READ_ONCE(head__->next); \
- pos__ != head__ ? list_entry(pos__, type, member) : NULL; \
-})
+#define list_first_entry_or_null(ptr, type, member) \
+ ({ \
+ struct list_head *head__ = (ptr); \
+ struct list_head *pos__ = READ_ONCE(head__->next); \
+ pos__ != head__ ? list_entry(pos__, type, member) : NULL; \
+ })
/**
* list_next_entry - get the next element in list
* @pos: the type * to cursor
* @member: the name of the list_head within the struct.
*/
-#define list_next_entry(pos, member) \
+#define list_next_entry(pos, member) \
list_entry((pos)->member.next, typeof(*(pos)), member)
/**
@@ -562,7 +560,7 @@ static inline void list_splice_tail_init(struct list_head *list,
* @pos: the type * to cursor
* @member: the name of the list_head within the struct.
*/
-#define list_prev_entry(pos, member) \
+#define list_prev_entry(pos, member) \
list_entry((pos)->member.prev, typeof(*(pos)), member)
/**
@@ -570,7 +568,7 @@ static inline void list_splice_tail_init(struct list_head *list,
* @pos: the &struct list_head to use as a loop cursor.
* @head: the head for your list.
*/
-#define list_for_each(pos, head) \
+#define list_for_each(pos, head) \
for (pos = (head)->next; pos != (head); pos = pos->next)
/**
@@ -580,7 +578,7 @@ static inline void list_splice_tail_init(struct list_head *list,
*
* Continue to iterate over a list, continuing after the current position.
*/
-#define list_for_each_continue(pos, head) \
+#define list_for_each_continue(pos, head) \
for (pos = pos->next; pos != (head); pos = pos->next)
/**
@@ -588,7 +586,7 @@ static inline void list_splice_tail_init(struct list_head *list,
* @pos: the &struct list_head to use as a loop cursor.
* @head: the head for your list.
*/
-#define list_for_each_prev(pos, head) \
+#define list_for_each_prev(pos, head) \
for (pos = (head)->prev; pos != (head); pos = pos->prev)
/**
@@ -597,19 +595,19 @@ static inline void list_splice_tail_init(struct list_head *list,
* @n: another &struct list_head to use as temporary storage
* @head: the head for your list.
*/
-#define list_for_each_safe(pos, n, head) \
- for (pos = (head)->next, n = pos->next; pos != (head); \
- pos = n, n = pos->next)
+#define list_for_each_safe(pos, n, head) \
+ for (pos = (head)->next, n = pos->next; pos != (head); \
+ pos = n, n = pos->next)
/**
- * list_for_each_prev_safe - iterate over a list backwards safe against removal of list entry
+ * list_for_each_prev_safe - iterate over a list backwards safe against removal
+ * of list entry
* @pos: the &struct list_head to use as a loop cursor.
* @n: another &struct list_head to use as temporary storage
* @head: the head for your list.
*/
-#define list_for_each_prev_safe(pos, n, head) \
- for (pos = (head)->prev, n = pos->prev; \
- pos != (head); \
+#define list_for_each_prev_safe(pos, n, head) \
+ for (pos = (head)->prev, n = pos->prev; pos != (head); \
pos = n, n = pos->prev)
/**
@@ -618,10 +616,9 @@ static inline void list_splice_tail_init(struct list_head *list,
* @head: the head for your list.
* @member: the name of the list_head within the struct.
*/
-#define list_for_each_entry(pos, head, member) \
- for (pos = list_first_entry(head, typeof(*pos), member); \
- &pos->member != (head); \
- pos = list_next_entry(pos, member))
+#define list_for_each_entry(pos, head, member) \
+ for (pos = list_first_entry(head, typeof(*pos), member); \
+ &pos->member != (head); pos = list_next_entry(pos, member))
/**
* list_for_each_entry_reverse - iterate backwards over list of given type.
@@ -629,21 +626,22 @@ static inline void list_splice_tail_init(struct list_head *list,
* @head: the head for your list.
* @member: the name of the list_head within the struct.
*/
-#define list_for_each_entry_reverse(pos, head, member) \
- for (pos = list_last_entry(head, typeof(*pos), member); \
- &pos->member != (head); \
- pos = list_prev_entry(pos, member))
+#define list_for_each_entry_reverse(pos, head, member) \
+ for (pos = list_last_entry(head, typeof(*pos), member); \
+ &pos->member != (head); pos = list_prev_entry(pos, member))
/**
- * list_prepare_entry - prepare a pos entry for use in list_for_each_entry_continue()
+ * list_prepare_entry - prepare a pos entry for use in
+ * list_for_each_entry_continue()
* @pos: the type * to use as a start point
* @head: the head of the list
* @member: the name of the list_head within the struct.
*
- * Prepares a pos entry for use as a start point in list_for_each_entry_continue().
+ * Prepares a pos entry for use as a start point in
+ * list_for_each_entry_continue().
*/
-#define list_prepare_entry(pos, head, member) \
- ((pos) ? : list_entry(head, typeof(*pos), member))
+#define list_prepare_entry(pos, head, member) \
+ ((pos) ?: list_entry(head, typeof(*pos), member))
/**
* list_for_each_entry_continue - continue iteration over list of given type
@@ -654,9 +652,8 @@ static inline void list_splice_tail_init(struct list_head *list,
* Continue to iterate over list of given type, continuing after
* the current position.
*/
-#define list_for_each_entry_continue(pos, head, member) \
- for (pos = list_next_entry(pos, member); \
- &pos->member != (head); \
+#define list_for_each_entry_continue(pos, head, member) \
+ for (pos = list_next_entry(pos, member); &pos->member != (head); \
pos = list_next_entry(pos, member))
/**
@@ -668,22 +665,21 @@ static inline void list_splice_tail_init(struct list_head *list,
* Start to iterate over list of given type backwards, continuing after
* the current position.
*/
-#define list_for_each_entry_continue_reverse(pos, head, member) \
- for (pos = list_prev_entry(pos, member); \
- &pos->member != (head); \
+#define list_for_each_entry_continue_reverse(pos, head, member) \
+ for (pos = list_prev_entry(pos, member); &pos->member != (head); \
pos = list_prev_entry(pos, member))
/**
- * list_for_each_entry_from - iterate over list of given type from the current point
+ * list_for_each_entry_from - iterate over list of given type from the current
+ * point
* @pos: the type * to use as a loop cursor.
* @head: the head for your list.
* @member: the name of the list_head within the struct.
*
* Iterate over list of given type, continuing from current position.
*/
-#define list_for_each_entry_from(pos, head, member) \
- for (; &pos->member != (head); \
- pos = list_next_entry(pos, member))
+#define list_for_each_entry_from(pos, head, member) \
+ for (; &pos->member != (head); pos = list_next_entry(pos, member))
/**
* list_for_each_entry_from_reverse - iterate backwards over list of given type
@@ -694,25 +690,25 @@ static inline void list_splice_tail_init(struct list_head *list,
*
* Iterate backwards over list of given type, continuing from current position.
*/
-#define list_for_each_entry_from_reverse(pos, head, member) \
- for (; &pos->member != (head); \
- pos = list_prev_entry(pos, member))
+#define list_for_each_entry_from_reverse(pos, head, member) \
+ for (; &pos->member != (head); pos = list_prev_entry(pos, member))
/**
- * list_for_each_entry_safe - iterate over list of given type safe against removal of list entry
+ * list_for_each_entry_safe - iterate over list of given type safe against
+ * removal of list entry
* @pos: the type * to use as a loop cursor.
* @n: another type * to use as temporary storage
* @head: the head for your list.
* @member: the name of the list_head within the struct.
*/
-#define list_for_each_entry_safe(pos, n, head, member) \
- for (pos = list_first_entry(head, typeof(*pos), member), \
- n = list_next_entry(pos, member); \
- &pos->member != (head); \
- pos = n, n = list_next_entry(n, member))
+#define list_for_each_entry_safe(pos, n, head, member) \
+ for (pos = list_first_entry(head, typeof(*pos), member), \
+ n = list_next_entry(pos, member); \
+ &pos->member != (head); pos = n, n = list_next_entry(n, member))
/**
- * list_for_each_entry_safe_continue - continue list iteration safe against removal
+ * list_for_each_entry_safe_continue - continue list iteration safe against
+ * removal
* @pos: the type * to use as a loop cursor.
* @n: another type * to use as temporary storage
* @head: the head for your list.
@@ -721,14 +717,14 @@ static inline void list_splice_tail_init(struct list_head *list,
* Iterate over list of given type, continuing after current point,
* safe against removal of list entry.
*/
-#define list_for_each_entry_safe_continue(pos, n, head, member) \
- for (pos = list_next_entry(pos, member), \
- n = list_next_entry(pos, member); \
- &pos->member != (head); \
- pos = n, n = list_next_entry(n, member))
+#define list_for_each_entry_safe_continue(pos, n, head, member) \
+ for (pos = list_next_entry(pos, member), \
+ n = list_next_entry(pos, member); \
+ &pos->member != (head); pos = n, n = list_next_entry(n, member))
/**
- * list_for_each_entry_safe_from - iterate over list from current point safe against removal
+ * list_for_each_entry_safe_from - iterate over list from current point safe
+ * against removal
* @pos: the type * to use as a loop cursor.
* @n: another type * to use as temporary storage
* @head: the head for your list.
@@ -737,13 +733,13 @@ static inline void list_splice_tail_init(struct list_head *list,
* Iterate over list of given type from current point, safe against
* removal of list entry.
*/
-#define list_for_each_entry_safe_from(pos, n, head, member) \
- for (n = list_next_entry(pos, member); \
- &pos->member != (head); \
+#define list_for_each_entry_safe_from(pos, n, head, member) \
+ for (n = list_next_entry(pos, member); &pos->member != (head); \
pos = n, n = list_next_entry(n, member))
/**
- * list_for_each_entry_safe_reverse - iterate backwards over list safe against removal
+ * list_for_each_entry_safe_reverse - iterate backwards over list safe against
+ * removal
* @pos: the type * to use as a loop cursor.
* @n: another type * to use as temporary storage
* @head: the head for your list.
@@ -752,11 +748,10 @@ static inline void list_splice_tail_init(struct list_head *list,
* Iterate backwards over list of given type, safe against removal
* of list entry.
*/
-#define list_for_each_entry_safe_reverse(pos, n, head, member) \
- for (pos = list_last_entry(head, typeof(*pos), member), \
- n = list_prev_entry(pos, member); \
- &pos->member != (head); \
- pos = n, n = list_prev_entry(n, member))
+#define list_for_each_entry_safe_reverse(pos, n, head, member) \
+ for (pos = list_last_entry(head, typeof(*pos), member), \
+ n = list_prev_entry(pos, member); \
+ &pos->member != (head); pos = n, n = list_prev_entry(n, member))
/**
* list_safe_reset_next - reset a stale list_for_each_entry_safe loop
@@ -770,7 +765,6 @@ static inline void list_splice_tail_init(struct list_head *list,
* and list_safe_reset_next is called after re-taking the lock and before
* completing the current iteration of the loop body.
*/
-#define list_safe_reset_next(pos, n, member) \
- n = list_next_entry(pos, member)
+#define list_safe_reset_next(pos, n, member) n = list_next_entry(pos, member)
#endif
diff --git a/shared/mc-protocol.c b/shared/mc-protocol.c
index afc9b38..03a2dcd 100644
--- a/shared/mc-protocol.c
+++ b/shared/mc-protocol.c
@@ -4,15 +4,14 @@
#include "utils.h"
-#define MC_HELO 0x00
-#define MC_NEXT_STATE_STATUS 0x01
-#define MC_GET_STATUS 0x00
-#define MC_VARINT_MAX_BYTES 5
-#define MC_STATUS_REPLY 0x00
-#define MC_UNDEFINED_VERSION -1
-
-static inline unsigned
-write_byte(char **pos, char byte)
+#define MC_HELO 0x00
+#define MC_NEXT_STATE_STATUS 0x01
+#define MC_GET_STATUS 0x00
+#define MC_VARINT_MAX_BYTES 5
+#define MC_STATUS_REPLY 0x00
+#define MC_UNDEFINED_VERSION -1
+
+static inline unsigned write_byte(char **pos, char byte)
{
if (pos && *pos) {
**pos = byte;
@@ -20,8 +19,7 @@ write_byte(char **pos, char byte)
}
return 1;
}
-static inline unsigned
-write_varint(char **pos, int32_t v)
+static inline unsigned write_varint(char **pos, int32_t v)
{
uint32_t u = (uint32_t)v;
unsigned rv = 0;
@@ -40,8 +38,7 @@ write_varint(char **pos, int32_t v)
return rv;
}
-static inline unsigned
-write_bytes(char **pos, const char *bytes, size_t n)
+static inline unsigned write_bytes(char **pos, const char *bytes, size_t n)
{
if (pos && *pos) {
memcpy(*pos, bytes, n);
@@ -51,8 +48,7 @@ write_bytes(char **pos, const char *bytes, size_t n)
return n;
}
-static inline unsigned
-write_str(char **pos, const char *str, size_t len)
+static inline unsigned write_str(char **pos, const char *str, size_t len)
{
unsigned rv;
@@ -68,8 +64,7 @@ write_str(char **pos, const char *str, size_t len)
* 0 = need more bytes
* < 0 = error
*/
-static inline int
-read_varint(const char **from, size_t *remain, int32_t *res)
+static inline int read_varint(const char **from, size_t *remain, int32_t *res)
{
unsigned consumed;
uint32_t val = 0;
@@ -103,8 +98,7 @@ read_varint(const char **from, size_t *remain, int32_t *res)
* 0 = need more bytes
* < 0 = error
*/
-int
-mc_is_handshake_complete(const char *buf, size_t len)
+int mc_is_handshake_complete(const char *buf, size_t len)
{
int32_t mclen;
int r;
@@ -123,21 +117,21 @@ mc_is_handshake_complete(const char *buf, size_t len)
}
if (mclen < len) {
- debug(DBG_IDLE, "short MC message - len: %" PRIi32 ", remain: %zu",
- mclen, len);
+ debug(DBG_IDLE,
+ "short MC message - len: %" PRIi32 ", remain: %zu", mclen,
+ len);
return 0;
- }
+ }
debug(DBG_IDLE, "Complete message");
return 1;
}
-#define PLAYERS_NEEDLE "\"players\""
-#define MAX_NEEDLE "\"max\""
-#define ONLINE_NEEDLE "\"online\""
-static bool
-mc_get_player_count(const char *buf, size_t remain,
- unsigned *ronline, unsigned *rmax)
+#define PLAYERS_NEEDLE "\"players\""
+#define MAX_NEEDLE "\"max\""
+#define ONLINE_NEEDLE "\"online\""
+static bool mc_get_player_count(const char *buf, size_t remain,
+ unsigned *ronline, unsigned *rmax)
{
/*
* Example JSON (line breaks added):
@@ -182,9 +176,8 @@ error:
return false;
}
-bool
-mc_protocol_parse_status_reply(const char *buf, size_t len,
- unsigned *online, unsigned *max)
+bool mc_protocol_parse_status_reply(const char *buf, size_t len,
+ unsigned *online, unsigned *max)
{
const char *from = buf;
size_t remain = len;
@@ -201,8 +194,8 @@ mc_protocol_parse_status_reply(const char *buf, size_t len,
return false;
}
- debug(DBG_IDLE, "MC message - len: %" PRIi32 ", remain: %zu",
- mclen, remain);
+ debug(DBG_IDLE, "MC message - len: %" PRIi32 ", remain: %zu", mclen,
+ remain);
if (*from != MC_STATUS_REPLY) {
error("unknown server reply (0x%02hhx)", *from);
@@ -218,8 +211,8 @@ mc_protocol_parse_status_reply(const char *buf, size_t len,
return false;
}
- debug(DBG_IDLE, "MC - json len: %" PRIi32 ", remain: %zu",
- jsonlen, remain);
+ debug(DBG_IDLE, "MC - json len: %" PRIi32 ", remain: %zu", jsonlen,
+ remain);
if (jsonlen < remain) {
error("invalid JSON length");
@@ -232,9 +225,8 @@ mc_protocol_parse_status_reply(const char *buf, size_t len,
return false;
}
-bool
-mc_protocol_create_status_request(char *buf, size_t len, size_t *rlen,
- struct saddr *saddr)
+bool mc_protocol_create_status_request(char *buf, size_t len, size_t *rlen,
+ struct saddr *saddr)
{
uint16_t port;
char hostname[INET6_ADDRSTRLEN];
@@ -248,7 +240,7 @@ mc_protocol_create_status_request(char *buf, size_t len, size_t *rlen,
hostlen = strlen(hostname);
/* First, a handshake, calculate body length... */
- bodylen = write_byte(NULL, MC_HELO);
+ bodylen = write_byte(NULL, MC_HELO);
bodylen += write_varint(NULL, MC_UNDEFINED_VERSION);
bodylen += write_str(NULL, hostname, hostlen);
bodylen += write_byte(NULL, (port >> 8) & 0xff);
@@ -279,4 +271,3 @@ mc_protocol_create_status_request(char *buf, size_t len, size_t *rlen,
*rlen = packetlen;
return true;
}
-
diff --git a/shared/mc-protocol.h b/shared/mc-protocol.h
index 8ecc02a..8e62aeb 100644
--- a/shared/mc-protocol.h
+++ b/shared/mc-protocol.h
@@ -10,4 +10,3 @@ bool mc_protocol_create_status_request(char *buf, size_t len, size_t *rlen,
struct saddr *saddr);
#endif
-
diff --git a/shared/rcon-protocol.c b/shared/rcon-protocol.c
index 0ea1245..0cf73fc 100644
--- a/shared/rcon-protocol.c
+++ b/shared/rcon-protocol.c
@@ -5,8 +5,7 @@
#include "rcon-protocol.h"
-static int32_t
-read_int(const char **pos, size_t *len)
+static int32_t read_int(const char **pos, size_t *len)
{
uint32_t val;
const char *p;
@@ -18,8 +17,8 @@ read_int(const char **pos, size_t *len)
return 0;
p = *pos;
- val = ((uint8_t)p[0] << 0);
- val += ((uint8_t)p[1] << 8);
+ val = ((uint8_t)p[0] << 0);
+ val += ((uint8_t)p[1] << 8);
val += ((uint8_t)p[2] << 16);
val += ((uint8_t)p[3] << 24);
@@ -30,8 +29,7 @@ read_int(const char **pos, size_t *len)
return (int32_t)val;
}
-static void
-write_int(char **pos, size_t *len, int32_t orig)
+static void write_int(char **pos, size_t *len, int32_t orig)
{
uint32_t val = (uint32_t)orig;
char *p;
@@ -40,8 +38,8 @@ write_int(char **pos, size_t *len, int32_t orig)
return;
p = *pos;
- p[0] = (val >> 0) & 0xff;
- p[1] = (val >> 8) & 0xff;
+ p[0] = (val >> 0) & 0xff;
+ p[1] = (val >> 8) & 0xff;
p[2] = (val >> 16) & 0xff;
p[3] = (val >> 24) & 0xff;
@@ -50,8 +48,7 @@ write_int(char **pos, size_t *len, int32_t orig)
*len += RCON_INT_LEN;
}
-static void
-write_str(char **pos, size_t *len, const char *str, size_t slen)
+static void write_str(char **pos, size_t *len, const char *str, size_t slen)
{
if (!pos || !*pos || !str || *str == '\0' || slen < 1)
return;
@@ -62,8 +59,7 @@ write_str(char **pos, size_t *len, const char *str, size_t slen)
*len += slen;
}
-static void
-write_end(char **pos, size_t *len)
+static void write_end(char **pos, size_t *len)
{
char *p;
@@ -79,9 +75,9 @@ write_end(char **pos, size_t *len)
*len += RCON_END_LEN;
}
-bool
-rcon_protocol_create_packet(char *buf, size_t len, size_t *rlen, int32_t reqid,
- enum rcon_packet_type type, const char *msg)
+bool rcon_protocol_create_packet(char *buf, size_t len, size_t *rlen,
+ int32_t reqid, enum rcon_packet_type type,
+ const char *msg)
{
size_t plen, msglen;
char *pos;
@@ -115,8 +111,7 @@ rcon_protocol_create_packet(char *buf, size_t len, size_t *rlen, int32_t reqid,
* 0 = packet not complete
* > 0 = packet complete (length)
*/
-int32_t
-rcon_protocol_packet_complete(const char *buf, size_t len)
+int32_t rcon_protocol_packet_complete(const char *buf, size_t len)
{
const char *pos;
int32_t plen;
@@ -140,9 +135,9 @@ rcon_protocol_packet_complete(const char *buf, size_t len)
return plen;
}
-bool
-rcon_protocol_read_packet(const char *buf, size_t len, int32_t *id, int32_t *type,
- const char **rmsg, const char **error)
+bool rcon_protocol_read_packet(const char *buf, size_t len, int32_t *id,
+ int32_t *type, const char **rmsg,
+ const char **error)
{
const char *pos;
int32_t plen;
diff --git a/shared/rcon-protocol.h b/shared/rcon-protocol.h
index 097da1d..b3aea98 100644
--- a/shared/rcon-protocol.h
+++ b/shared/rcon-protocol.h
@@ -5,6 +5,7 @@
#include <stdint.h>
/* FIXME: FAIL is an id, not type, LOGIN_OK should be LOGIN_RESPONSE */
+/* clang-format off */
enum rcon_packet_type {
RCON_PACKET_LOGIN = 3,
RCON_PACKET_LOGIN_OK = 2,
@@ -12,6 +13,7 @@ enum rcon_packet_type {
RCON_PACKET_COMMAND = 2,
RCON_PACKET_RESPONSE = 0,
};
+/* clang-format on */
#define RCON_INT_LEN 4
@@ -22,8 +24,7 @@ enum rcon_packet_type {
/* header + reqid + type + end */
#define RCON_PKT_MIN_LEN (RCON_HDR_LEN + 2 * RCON_INT_LEN + RCON_END_LEN)
-static inline size_t
-rcon_protocol_packet_len(size_t msglen)
+static inline size_t rcon_protocol_packet_len(size_t msglen)
{
/* header + reqid + type + msg + end */
return (RCON_PKT_MIN_LEN + msglen);
diff --git a/shared/server-config-options.h b/shared/server-config-options.h
index 5aee734..5600e52 100644
--- a/shared/server-config-options.h
+++ b/shared/server-config-options.h
@@ -25,55 +25,68 @@ struct cfg_key_value_map scfg_key_map[] = {
.key_name = "type",
.key_value = SCFG_KEY_TYPE,
.value_type = CFG_VAL_TYPE_STRING,
- }, {
+ },
+ {
.key_name = "name",
.key_value = SCFG_KEY_NAME,
.value_type = CFG_VAL_TYPE_STRING,
- }, {
+ },
+ {
.key_name = "port",
.key_value = SCFG_KEY_PORT,
.value_type = CFG_VAL_TYPE_UINT16,
- }, {
+ },
+ {
.key_name = "local",
.key_value = SCFG_KEY_LOCAL,
.value_type = CFG_VAL_TYPE_ADDRS,
- }, {
+ },
+ {
.key_name = "remote",
.key_value = SCFG_KEY_REMOTE,
.value_type = CFG_VAL_TYPE_ADDRS,
- }, {
+ },
+ {
.key_name = "idle_timeout",
.key_value = SCFG_KEY_IDLE_TIMEOUT,
.value_type = CFG_VAL_TYPE_UINT16,
- }, {
+ },
+ {
.key_name = "stop_method",
.key_value = SCFG_KEY_STOP_METHOD,
.value_type = CFG_VAL_TYPE_STRING,
- }, {
+ },
+ {
.key_name = "start_method",
.key_value = SCFG_KEY_START_METHOD,
.value_type = CFG_VAL_TYPE_STRING,
- }, {
+ },
+ {
.key_name = "stop_exec",
.key_value = SCFG_KEY_STOP_EXEC,
.value_type = CFG_VAL_TYPE_STRING,
- }, {
+ },
+ {
.key_name = "start_exec",
.key_value = SCFG_KEY_START_EXEC,
.value_type = CFG_VAL_TYPE_STRING,
- }, {
+ },
+ {
.key_name = "rcon",
.key_value = SCFG_KEY_RCON,
.value_type = CFG_VAL_TYPE_ADDRS,
- }, {
+ },
+ {
.key_name = "rcon_password",
.key_value = SCFG_KEY_RCON_PASSWORD,
.value_type = CFG_VAL_TYPE_STRING,
- }, {
+ },
+ {
.key_name = "systemd_service",
.key_value = SCFG_KEY_SYSTEMD_SERVICE,
.value_type = CFG_VAL_TYPE_STRING,
- }, {
+ },
+ {
.key_name = NULL,
.key_value = SCFG_KEY_INVALID,
.value_type = CFG_VAL_TYPE_INVALID,
@@ -81,4 +94,3 @@ struct cfg_key_value_map scfg_key_map[] = {
};
#endif
-
diff --git a/shared/utils.c b/shared/utils.c
index c71f1f7..20d9809 100644
--- a/shared/utils.c
+++ b/shared/utils.c
@@ -17,8 +17,7 @@
unsigned debug_mask = 0;
-void
-socket_set_low_latency(int sfd, bool keepalive, bool iptos, bool nodelay)
+void socket_set_low_latency(int sfd, bool keepalive, bool iptos, bool nodelay)
{
int option;
@@ -27,31 +26,33 @@ socket_set_low_latency(int sfd, bool keepalive, bool iptos, bool nodelay)
/* Probably not necessary, but can't hurt */
if (keepalive) {
option = true;
- if (setsockopt(sfd, SOL_SOCKET, SO_KEEPALIVE, &option, sizeof(option)) < 0)
+ if (setsockopt(sfd, SOL_SOCKET, SO_KEEPALIVE, &option,
+ sizeof(option)) < 0)
error("setsockopt: %m");
}
/* Doubtful if it has much effect, but can't hurt */
if (iptos) {
option = IPTOS_LOWDELAY;
- if (setsockopt(sfd, IPPROTO_IP, IP_TOS, &option, sizeof(option)) < 0)
+ if (setsockopt(sfd, IPPROTO_IP, IP_TOS, &option,
+ sizeof(option)) < 0)
error("setsockopt: %m");
}
/* Nagle's algorithm is a poor fit for gaming */
if (nodelay) {
option = true;
- if (setsockopt(sfd, IPPROTO_TCP, TCP_NODELAY, &option, sizeof(option)) < 0)
+ if (setsockopt(sfd, IPPROTO_TCP, TCP_NODELAY, &option,
+ sizeof(option)) < 0)
error("setsockopt: %m");
}
}
-uint16_t
-saddr_port(struct saddr *saddr)
+uint16_t saddr_port(struct saddr *saddr)
{
- //assert_return(saddr, 0);
+ // assert_return(saddr, 0);
- switch (saddr->storage.ss_family) {
+ switch (saddr->st.ss_family) {
case AF_INET:
return ntohs(saddr->in4.sin_port);
case AF_INET6:
@@ -61,18 +62,19 @@ saddr_port(struct saddr *saddr)
}
}
-char *
-saddr_addr(struct saddr *saddr, char *buf, size_t len)
+char *saddr_addr(struct saddr *saddr, char *buf, size_t len)
{
- //assert_return(saddr && buf && len > 0, NULL);
+ // assert_return(saddr && buf && len > 0, NULL);
- switch (saddr->storage.ss_family) {
+ switch (saddr->st.ss_family) {
case AF_INET:
- if (inet_ntop(saddr->in4.sin_family, &saddr->in4.sin_addr, buf, len))
+ if (inet_ntop(saddr->in4.sin_family, &saddr->in4.sin_addr, buf,
+ len))
return buf;
break;
case AF_INET6:
- if (inet_ntop(saddr->in6.sin6_family, &saddr->in6.sin6_addr, buf, len))
+ if (inet_ntop(saddr->in6.sin6_family, &saddr->in6.sin6_addr,
+ buf, len))
return buf;
break;
default:
@@ -83,10 +85,9 @@ saddr_addr(struct saddr *saddr, char *buf, size_t len)
return buf;
}
-void
-saddr_set_ipv4(struct saddr *saddr, in_addr_t ip, in_port_t port)
+void saddr_set_ipv4(struct saddr *saddr, in_addr_t ip, in_port_t port)
{
- //assert_return(saddr);
+ // assert_return(saddr);
memset(&saddr->in4, 0, sizeof(saddr->in4));
saddr->in4.sin_family = AF_INET;
@@ -96,10 +97,10 @@ saddr_set_ipv4(struct saddr *saddr, in_addr_t ip, in_port_t port)
saddr_set_addrstr(saddr);
}
-void
-saddr_set_ipv6(struct saddr *saddr, const struct in6_addr *ip, in_port_t port)
+void saddr_set_ipv6(struct saddr *saddr, const struct in6_addr *ip,
+ in_port_t port)
{
- //assert_return(saddr && ip);
+ // assert_return(saddr && ip);
memset(&saddr->in6, 0, sizeof(saddr->in6));
saddr->in6.sin6_family = AF_INET6;
@@ -110,14 +111,13 @@ saddr_set_ipv6(struct saddr *saddr, const struct in6_addr *ip, in_port_t port)
saddr_set_addrstr(saddr);
}
-void
-saddr_set_addrstr(struct saddr *saddr)
+void saddr_set_addrstr(struct saddr *saddr)
{
- //assert_return(saddr);
+ // assert_return(saddr);
char abuf[ADDRSTRLEN];
- switch (saddr->storage.ss_family) {
+ switch (saddr->st.ss_family) {
case AF_INET:
snprintf(saddr->addrstr, sizeof(saddr->addrstr),
"AF_INET4 %s %" PRIu16,
@@ -136,8 +136,7 @@ saddr_set_addrstr(struct saddr *saddr)
}
}
-int
-strtou16_strict(const char *str, uint16_t *result)
+int strtou16_strict(const char *str, uint16_t *result)
{
char *end;
long val;
@@ -150,7 +149,7 @@ strtou16_strict(const char *str, uint16_t *result)
if (errno == ERANGE && (val == LONG_MAX || val == LONG_MIN))
return -EINVAL;
-
+
if (errno != 0 && val == 0)
return -EINVAL;
@@ -167,4 +166,3 @@ strtou16_strict(const char *str, uint16_t *result)
*result = val;
return 0;
}
-
diff --git a/shared/utils.h b/shared/utils.h
index 3ed1c87..9171648 100644
--- a/shared/utils.h
+++ b/shared/utils.h
@@ -12,14 +12,14 @@
extern unsigned debug_mask;
-#define _unused_ __attribute__((__unused__))
-#define _pure_ __attribute__((__pure__))
-#define _const_ __attribute__((__const__))
-#define _alloc_(...) __attribute__((__alloc_size__(__VA_ARGS__)))
-#define _malloc_ __attribute__((__malloc__))
+#define _unused_ __attribute__((__unused__))
+#define _pure_ __attribute__((__pure__))
+#define _const_ __attribute__((__const__))
+#define _alloc_(...) __attribute__((__alloc_size__(__VA_ARGS__)))
+#define _malloc_ __attribute__((__malloc__))
#define _printf_(a, b) __attribute__((__format__(printf, a, b)))
-#define _alignas_(x) __attribute__((__aligned__(__alignof(x))))
-#define _big_endian_ __attribute__((packed, scalar_storage_order("big-endian")))
+#define _alignas_(x) __attribute__((__aligned__(__alignof(x))))
+#define _big_endian_ __attribute__((packed, scalar_storage_order("big-endian")))
#if __GNUC__ >= 7
#define _fallthrough_ __attribute__((__fallthrough__))
@@ -35,7 +35,7 @@ extern unsigned debug_mask;
#endif
#endif
-#define STRLEN(x) (sizeof(""x"") - 1)
+#define STRLEN(x) (sizeof("" x "") - 1)
#include "list.h"
#include "debug.h"
@@ -56,7 +56,7 @@ extern unsigned debug_mask;
struct saddr {
union {
- struct sockaddr_storage storage;
+ struct sockaddr_storage st;
struct sockaddr_in in4;
struct sockaddr_in6 in6;
struct sockaddr_ll ll;
@@ -74,7 +74,8 @@ uint16_t saddr_port(struct saddr *saddr);
void saddr_set_ipv4(struct saddr *saddr, in_addr_t ip, in_port_t port);
-void saddr_set_ipv6(struct saddr *saddr, const struct in6_addr *ip, in_port_t port);
+void saddr_set_ipv6(struct saddr *saddr, const struct in6_addr *ip,
+ in_port_t port);
void saddr_set_addrstr(struct saddr *saddr);
@@ -105,9 +106,11 @@ static inline bool strcaseeq(const char *a, const char *b)
#endif
#if __BYTE_ORDER == __LITTLE_ENDIAN
-#define cinet_addr(a,b,c,d) ((uint32_t)((a)<<0|(b)<<8|(c)<<16|(d)<<24))
+#define cinet_addr(a, b, c, d) \
+ ((uint32_t)((a) << 0 | (b) << 8 | (c) << 16 | (d) << 24))
#else
-#define cinet_addr(a,b,c,d) ((uint32_t)((a)<<24|(b)<<16|(c)<<8|(d)<<0))
+#define cinet_addr(a, b, c, d) \
+ ((uint32_t)((a) << 24 | (b) << 16 | (c) << 8 | (d) << 0))
#endif
#define PIPE_RD 0
@@ -117,7 +120,6 @@ static inline bool strcaseeq(const char *a, const char *b)
#define MAX(a, b) ((a) > (b) ? (a) : (b))
-#define DIV_ROUND_UP(n, d) (((n) + (d) - 1) / (d))
+#define DIV_ROUND_UP(n, d) (((n) + (d)-1) / (d))
#endif
-