Browse Source

* backend.c:

* use function generation by macro
  * more actions
master
Alex 'AdUser' Z 9 years ago
parent
commit
79dd568297
  1. 26
      src/backend.c
  2. 5
      src/backend.h

26
src/backend.c

@ -87,16 +87,24 @@ f2b_backend_destroy(f2b_backend_t *backend) {
free(backend); free(backend);
} }
bool #define BACKEND_CMD_ARG0(CMD) \
f2b_backend_ban(f2b_backend_t *backend, const char *ip) { bool \
assert(backend != NULL); f2b_backend_ ## CMD(f2b_backend_t *backend) { \
assert(backend != NULL); \
return backend->CMD(backend->cfg); \
}
return backend->ban(backend->cfg, ip); #define BACKEND_CMD_ARG1(CMD) \
bool \
f2b_backend_ ## CMD(f2b_backend_t *backend, const char *ip) { \
assert(backend != NULL); \
return backend->CMD(backend->cfg, ip); \
} }
bool BACKEND_CMD_ARG0(ping)
f2b_backend_unban(f2b_backend_t *backend, const char *ip) { BACKEND_CMD_ARG0(start)
assert(backend != NULL); BACKEND_CMD_ARG0(stop)
return backend->unban(backend->cfg, ip); BACKEND_CMD_ARG1(check)
} BACKEND_CMD_ARG1(ban)
BACKEND_CMD_ARG1(unban)

5
src/backend.h

@ -22,7 +22,12 @@ typedef struct f2b_backend_t {
f2b_backend_t * f2b_backend_create (f2b_config_section_t *config, const char *id); f2b_backend_t * f2b_backend_create (f2b_config_section_t *config, const char *id);
void f2b_backend_destroy(f2b_backend_t *b); void f2b_backend_destroy(f2b_backend_t *b);
bool f2b_backend_start (f2b_backend_t *b);
bool f2b_backend_stop (f2b_backend_t *b);
bool f2b_backend_ping (f2b_backend_t *b);
bool f2b_backend_ban (f2b_backend_t *b, const char *ip); bool f2b_backend_ban (f2b_backend_t *b, const char *ip);
bool f2b_backend_check (f2b_backend_t *b, const char *ip);
bool f2b_backend_unban (f2b_backend_t *b, const char *ip); bool f2b_backend_unban (f2b_backend_t *b, const char *ip);
#endif /* BACKEND_H_ */ #endif /* BACKEND_H_ */

Loading…
Cancel
Save