Commit 9ed2558b authored by Karel Slaný's avatar Karel Slaný

style: Fixed indentation and removed trailing white spaces in C code.

parent 8842548d
......@@ -204,7 +204,7 @@ static int net_interfaces(lua_State *L)
}
*(p - 1) = '\0';
lua_pushstring(L, buf);
lua_setfield(L, -2, "mac");
lua_setfield(L, -2, "mac");
/* Push table */
lua_setfield(L, -2, iface.name);
......@@ -273,4 +273,4 @@ int lib_cache(lua_State *L)
register_lib(L, "cache", lib);
return 1;
}
\ No newline at end of file
}
......@@ -37,7 +37,7 @@
/** Print help and available commands. */
static int l_help(lua_State *L)
{
static const char *help_str =
static const char *help_str =
"help()\n show this help\n"
"quit()\n quit\n"
"modules.list()\n list modules\n"
......@@ -242,7 +242,7 @@ int engine_start(struct engine *engine)
return ret;
}
return uv_run(uv_default_loop(), UV_RUN_DEFAULT);
return uv_run(uv_default_loop(), UV_RUN_DEFAULT);
}
void engine_stop(struct engine *engine)
......@@ -320,8 +320,8 @@ void engine_lualib(struct engine *engine, const char *name, lua_CFunction lib_cb
struct engine *engine_luaget(lua_State *L)
{
lua_getglobal(L, "__engine");
lua_getglobal(L, "__engine");
struct engine *engine = lua_touserdata(L, -1);
lua_pop(engine->L, 1);
return engine;
}
\ No newline at end of file
}
......@@ -41,4 +41,4 @@ int engine_register(struct engine *engine, const char *module);
int engine_unregister(struct engine *engine, const char *module);
/** Return engine light userdata. */
void engine_lualib(struct engine *engine, const char *name, int (*lib_cb) (struct lua_State *));
struct engine *engine_luaget(struct lua_State *L);
\ No newline at end of file
struct engine *engine_luaget(struct lua_State *L);
......@@ -70,7 +70,7 @@ static const char *set_addr(char *addr, int *port)
*port = atoi(p + 1);
*p = '\0';
}
return addr;
}
......@@ -114,7 +114,7 @@ int main(int argc, char **argv)
return EXIT_FAILURE;
}
printf("[system] rundir '%s'\n", argv[optind]);
}
}
/* Block signals. */
uv_loop_t *loop = uv_default_loop();
......
......@@ -161,7 +161,7 @@ int network_close(struct network *net, const char *addr, uint16_t port)
break;
}
}
/* Collapse key if it has no endpoint. */
if (ep_array->len == 0) {
free(ep_array);
......
......@@ -31,7 +31,7 @@ struct worker_ctx {
/**
* Resolve query.
*
*
* @param worker
* @param answer
* @param query
......
......@@ -346,7 +346,7 @@ getdns_return_t getdns_context_set_edns_version(
/**
* Set EDNS DO (DNSSEC OK) bit.
*
*
* @param value EDNS DO bit (0 or 1, default 0).
*/
getdns_return_t getdns_context_set_edns_do_bit(
......
......@@ -163,7 +163,7 @@ knot_rrset_t kr_cache_materialize(const knot_rrset_t *src, uint32_t drift, mm_ct
if (copy.owner == NULL) {
return copy;
}
for (uint16_t i = 0; i < src->rrs.rr_count; ++i) {
knot_rdata_t *rd = knot_rdataset_at(&src->rrs, i);
if (knot_rdata_ttl(rd) > drift) {
......@@ -173,13 +173,13 @@ knot_rrset_t kr_cache_materialize(const knot_rrset_t *src, uint32_t drift, mm_ct
}
}
}
/* Update TTLs. */
for (uint16_t i = 0; i < copy.rrs.rr_count; ++i) {
knot_rdata_t *rd = knot_rdataset_at(&copy.rrs, i);
knot_rdata_set_ttl(rd, knot_rdata_ttl(rd) - drift);
}
return copy;
}
......
......@@ -15,7 +15,7 @@
*/
/** \addtogroup cache
* @{
* @{
*/
#pragma once
......
......@@ -15,7 +15,7 @@
*/
/** \addtogroup resolution
* @{
* @{
*/
#pragma once
......@@ -47,6 +47,6 @@
*/
#define KR_DNS_PORT 53
#define KR_EDNS_VERSION 0
#define KR_EDNS_PAYLOAD 4096
#define KR_EDNS_PAYLOAD 4096
/** @} */
......@@ -20,17 +20,17 @@
* \note The C has no generics, so it is implemented mostly using macros.
* Be aware of that, as direct usage of the macros in the evaluating macros
* may lead to different expectations, i.e.
*
*
* MIN(array_push(arr, val))
*
* May evaluate the code twice, leading to unexpected behaviour.
* This is a price to pay for absence of proper generics.
*
* Example usage:
*
*
* array_t(const char*) arr;
* array_init(arr);
*
*
* // Reserve memory in advance
* if (array_reserve(arr, 2) < 0) {
* return ENOMEM;
......@@ -52,9 +52,9 @@
*
* // Random delete
* array_del(arr, 0);
*
*
* \addtogroup generics
* @{
* @{
*/
#pragma once
......
......@@ -108,7 +108,7 @@ static cb_data_t *cbt_make_data(map_t *map, const uint8_t *str, size_t len, void
x->value = value;
memcpy(x->key, str, len);
}
return x;
return x;
}
/*! Creates a new, empty critbit map */
......
......@@ -7,14 +7,14 @@
* Generics - A Crit-bit tree 'map' implementation.
*
* @warning If the user provides a custom allocator, it must return addresses aligned to 2B boundary.
*
*
* Example usage:
*
*
* map_t map = map_make();
*
* // Custom allocator (optional)
* map.malloc = &mymalloc;
* map.baton = &mymalloc_context;
* // Custom allocator (optional)
* map.malloc = &mymalloc;
* map.baton = &mymalloc_context;
*
* // Insert keys
* if (map_set(&map, "princess") != 0 ||
......@@ -29,7 +29,7 @@
* }
*
* // Prefix search
* int i = 0;
* int i = 0;
* int count(const char *s, void *n) { (*(int *)n)++; return 0; }
* if (map_walk_prefixed(map, "princ", count, &i) == 0) {
* printf("%d matches\n", i);
......@@ -42,9 +42,9 @@
*
* // Clear the map
* map_clear(&map);
*
*
* \addtogroup generics
* @{
* @{
*/
#pragma once
......@@ -94,4 +94,4 @@ int map_walk_prefixed(map_t *map, const char *prefix,
}
#endif
/** @} */
\ No newline at end of file
/** @} */
......@@ -2,9 +2,9 @@
* Generics - A Crit-bit set implementation.
*
* @note The API is based on @fn map.h, see it for more examples.
*
*
* Example usage:
*
*
* set_t set = set_make();
*
* // Insert keys
......@@ -20,7 +20,7 @@
* }
*
* // Prefix search
* int i = 0;
* int i = 0;
* int count(const char *s, void *n) { (*(int *)n)++; return 0; }
* if (set_walk_prefixed(set, "princ", count, &i) == 0) {
* printf("%d matches\n", i);
......@@ -33,9 +33,9 @@
*
* // Clear the set
* set_clear(&set);
*
*
* \addtogroup generics
* @{
* @{
*/
#pragma once
......
......@@ -17,7 +17,7 @@
#pragma once
/** \addtogroup rplan
* @{
* @{
*/
#include <libknot/processing/layer.h>
......
......@@ -35,7 +35,7 @@ enum {
PKT_NOERROR = 1 << 0, /* Positive response */
PKT_NODATA = 1 << 1, /* No data response */
PKT_NXDOMAIN = 1 << 2, /* Negative response */
PKT_ERROR = 1 << 3 /* Refused or server failure */
PKT_ERROR = 1 << 3 /* Refused or server failure */
};
/* Iterator often walks through packet section, this is an abstraction. */
......@@ -155,7 +155,7 @@ int rr_update_parent(const knot_rrset_t *rr, unsigned hint, struct kr_layer_para
int rr_update_answer(const knot_rrset_t *rr, unsigned hint, struct kr_layer_param *param)
{
knot_pkt_t *answer = param->answer;
/* Write copied RR to the result packet. */
int ret = knot_pkt_put(answer, KNOT_COMPR_HINT_NONE, rr, hint);
if (ret != KNOT_EOK) {
......@@ -176,7 +176,7 @@ static bool has_glue(const knot_dname_t *ns_name, knot_pkt_t *pkt)
const knot_rrset_t *rr = knot_pkt_rr(ar, i);
if ((rr->type == KNOT_RRTYPE_A || rr->type == KNOT_RRTYPE_AAAA) &&
(knot_dname_is_equal(ns_name, rr->owner))) {
return true;
return true;
}
}
return false;
......@@ -372,7 +372,7 @@ static int prepare_query(knot_layer_t *ctx, knot_pkt_t *pkt)
query->id = dnssec_random_uint16_t();
knot_wire_set_id(pkt->wire, query->id);
/* Declare EDNS0 support. */
knot_rrset_t opt_rr;
ret = knot_edns_init(&opt_rr, KR_EDNS_PAYLOAD, 0, KR_EDNS_VERSION, &pkt->mm);
......
......@@ -50,7 +50,7 @@ static int update_answer(const knot_rrset_t *rr, unsigned drift, struct kr_layer
if (rr_copy.rrs.rr_count == 0) {
return KNOT_STATE_FAIL;
}
return rr_update_answer(&rr_copy, 0, param);
}
......
......@@ -19,20 +19,20 @@
/** Check ABI version, return error on mismatch. */
#define ABI_CHECK(m, prefix, symname, required) do { \
if ((m)->lib != RTLD_DEFAULT) { \
module_api_cb *_api = NULL; \
*(void **) (&_api) = load_symbol((m)->lib, (prefix), (symname)); \
if (_api == NULL) { \
return kr_error(ENOENT); \
} \
if (_api() != (required)) { \
return kr_error(ENOTSUP); \
} \
}\
} while (0)
/** Load ABI by symbol names. */
module_api_cb *_api = NULL; \
*(void **) (&_api) = load_symbol((m)->lib, (prefix), (symname)); \
if (_api == NULL) { \
return kr_error(ENOENT); \
} \
if (_api() != (required)) { \
return kr_error(ENOTSUP); \
} \
}\
} while (0)
/** Load ABI by symbol names. */
#define ABI_LOAD(m, prefix, s_init, s_deinit, s_config, s_layer, s_prop) do { \
module_prop_cb *module_prop = NULL; \
module_prop_cb *module_prop = NULL; \
*(void **) (&(m)->init) = load_symbol((m)->lib, (prefix), (s_init)); \
*(void **) (&(m)->deinit) = load_symbol((m)->lib, (prefix), (s_deinit)); \
*(void **) (&(m)->config) = load_symbol((m)->lib, (prefix), (s_config)); \
......@@ -76,9 +76,9 @@ static int load_library(struct kr_module *module, const char *name, const char *
/** Load C module symbols. */
static int load_sym_c(struct kr_module *module, uint32_t api_required)
{
auto_free char *module_prefix = kr_strcatdup(2, module->name, "_");
ABI_CHECK(module, module_prefix, "api", api_required);
ABI_LOAD(module, module_prefix, "init", "deinit", "config", "layer", "props");
auto_free char *module_prefix = kr_strcatdup(2, module->name, "_");
ABI_CHECK(module, module_prefix, "api", api_required);
ABI_LOAD(module, module_prefix, "init", "deinit", "config", "layer", "props");
return kr_ok();
}
......@@ -114,7 +114,7 @@ static int bootstrap_libgo(struct kr_module *module)
return kr_ok();
}
/** Load Go module symbols. */
/** Load Go module symbols. */
static int load_ffi_go(struct kr_module *module, uint32_t api_required)
{
/* Bootstrap libgo */
......@@ -149,7 +149,7 @@ int kr_module_load(struct kr_module *module, const char *name, const char *path)
auto_free char *local_path = kr_strcatdup(2, getenv("HOME"), "/.local" MODULEDIR);
if (load_library(module, name, local_path) != 0) {
if (load_library(module, name, PREFIX MODULEDIR) != 0) {
module->lib = RTLD_DEFAULT;
module->lib = RTLD_DEFAULT;
}
}
}
......@@ -168,7 +168,6 @@ int kr_module_load(struct kr_module *module, const char *name, const char *path)
kr_module_unload(module);
}
return ret;
}
......
......@@ -15,7 +15,7 @@
*/
/** \addtogroup modules
* @{
* @{
*/
#pragma once
......@@ -73,7 +73,7 @@ struct kr_module {
/**
* Load module instance into memory.
*
*
* @param module module structure
* @param name module name
* @param path module search path
......@@ -83,14 +83,14 @@ int kr_module_load(struct kr_module *module, const char *name, const char *path)
/**
* Unload module instance.
*
*
* @param module module structure
*/
void kr_module_unload(struct kr_module *module);
/**
* Export module API version (place this at the end of your module).
*
*
* @param module module name (f.e. hints)
*/
#define KR_MODULE_EXPORT(module) \
......
......@@ -4,4 +4,4 @@ int kr_nsrep_score(const knot_dname_t *ns, struct kr_layer_param *param)
{
/* TODO: stub, always returns valid */
return KR_NS_VALID;
}
\ No newline at end of file
}
......@@ -15,7 +15,7 @@
*/
/** \addtogroup nameservers
* @{
* @{
*/
#pragma once
......
......@@ -39,7 +39,7 @@ static int invalidate_ns(struct kr_rplan *rplan, struct kr_query *qry)
if (txn == NULL) {
return KNOT_EOK;
}
/* Fetch current nameserver cache. */
uint32_t drift = qry->timestamp.tv_sec;
knot_rrset_t cached;
......@@ -49,7 +49,7 @@ static int invalidate_ns(struct kr_rplan *rplan, struct kr_query *qry)
return KNOT_EOK;
}
cached = kr_cache_materialize(&cached, drift, rplan->pool);
/* Find a matching RD. */
knot_rdataset_t to_remove;
knot_rdataset_init(&to_remove);
......@@ -61,7 +61,7 @@ static int invalidate_ns(struct kr_rplan *rplan, struct kr_query *qry)
}
knot_rdataset_subtract(&cached.rrs, &to_remove, rplan->pool);
knot_rdataset_clear(&to_remove, rplan->pool);
/* Remove record(s) */
int ret = KNOT_EOK;
if (cached.rrs.rr_count == 0) {
......@@ -78,7 +78,7 @@ static int invalidate_ns(struct kr_rplan *rplan, struct kr_query *qry)
static int ns_resolve_addr(struct kr_query *cur, struct kr_layer_param *param)
{
if (kr_rplan_satisfies(cur, cur->zone_cut.ns, KNOT_CLASS_IN, KNOT_RRTYPE_A) ||
if (kr_rplan_satisfies(cur, cur->zone_cut.ns, KNOT_CLASS_IN, KNOT_RRTYPE_A) ||
kr_rplan_satisfies(cur, cur->zone_cut.ns, KNOT_CLASS_IN, KNOT_RRTYPE_AAAA)) {
DEBUG_MSG("=> dependency loop, bailing out\n");
kr_rplan_pop(param->rplan, cur);
......
......@@ -15,7 +15,7 @@
*/
/** \addtogroup resolution
* @{
* @{
*/
#pragma once
......
......@@ -15,7 +15,7 @@
*/
/** \addtogroup rplan
* @{
* @{
*/
#pragma once
......
......@@ -2,6 +2,7 @@
#include <string.h>
#include <stdlib.h>
#include <unistd.h>
#include "lib/defines.h"
#include "lib/utils.h"
......@@ -15,49 +16,49 @@
*/
void _cleanup_free(char **p)
{
free(*p);
free(*p);
}
void _cleanup_close(int *p)
{
if (*p > 0) close(*p);
if (*p > 0) close(*p);
}
void _cleanup_fclose(FILE **p)
{
if (*p) fclose(*p);
if (*p) fclose(*p);
}
char* kr_strcatdup(unsigned n, ...)
{
/* Calculate total length */
size_t total_len = 0;
va_list vl;
va_start(vl, n);
for (unsigned i = 0; i < n; ++i) {
char *item = va_arg(vl, char *);
total_len += strlen_safe(item);
}
va_end(vl);
/* Allocate result and fill */
char *result = NULL;
if (total_len > 0) {
result = malloc(total_len + 1);
}
if (result) {
char *stream = result;
va_start(vl, n);
for (unsigned i = 0; i < n; ++i) {
char *item = va_arg(vl, char *);
if (item) {
size_t len = strlen(item);
memcpy(stream, item, len + 1);
stream += len;
}
}
va_end(vl);
}
return result;
}
\ No newline at end of file
/* Calculate total length */
size_t total_len = 0;
va_list vl;
va_start(vl, n);
for (unsigned i = 0; i < n; ++i) {
char *item = va_arg(vl, char *);
total_len += strlen_safe(item);
}
va_end(vl);
/* Allocate result and fill */
char *result = NULL;
if (total_len > 0) {
result = malloc(total_len + 1);
}
if (result) {
char *stream = result;
va_start(vl, n);
for (unsigned i = 0; i < n; ++i) {
char *item = va_arg(vl, char *);
if (item) {
size_t len = strlen(item);
memcpy(stream, item, len + 1);
stream += len;
}
}
va_end(vl);
}
return result;
}
......@@ -15,7 +15,7 @@
*/
/** \addtogroup utils
* @{
* @{
*/
#pragma once
......
......@@ -137,7 +137,7 @@ static int fetch_ns(struct kr_zonecut *cut, const knot_dname_t *name, namedb_txn
if (ret != KNOT_EOK) {
return ret;
}
/* Accept only if has address records cached. */
for (unsigned i = 0; i < cached_rr.rrs.rr_count; ++i) {
kr_set_zone_cut(cut, name, knot_ns_name(&cached_rr.rrs, i));
......
......@@ -15,7 +15,7 @@
*/
/** \addtogroup rplan
* @{
* @{
*/
#pragma once
......
......@@ -40,7 +40,7 @@
*
* Input: N/A
* Output: { size: int }
*
*
*/
static char* get_size(void *env, struct kr_module *module, const char *args)
{
......@@ -57,7 +57,7 @@ static char* get_size(void *env, struct kr_module *module, const char *args)
} else {
asprintf(&result, "{ \"error\": \"%s\" }", knot_strerror(ret));
}
return result;
}
......@@ -84,7 +84,7 @@ static int is_expired(struct kr_cache_rrset *rr, uint32_t drift)
*
* Input: N/A
* Output: { pruned: int }
*
*
*/
static char* prune(void *env, struct kr_module *module, const char *args)
{
......@@ -124,7 +124,7 @@ static char* prune(void *env, struct kr_module *module, const char *args)
} else {
asprintf(&result, "{ \"pruned\": %d }", pruned);
}
return result;
}
......@@ -133,7 +133,7 @@ static char* prune(void *env, struct kr_module *module, const char *args)
*
* Input: N/A
* Output: { result: bool }
*
*
*/
static char* clear(void *env, struct kr_module *module, const char *args)
{
......@@ -164,13 +164,13 @@ static char* clear(void *env, struct kr_module *module, const char *args)
struct kr_prop *cachectl_props(void)
{
static struct kr_prop prop_list[] = {
{ &get_size, "size", "Return number of cached records.", },
{ &prune, "prune", "Prune expired/invalid records.", },
{ &clear, "clear", "Clear all cache records.", },
{ NULL, NULL, NULL }
};
return prop_list;
static struct kr_prop prop_list[] = {
{ &get_size, "size", "Return number of cached records.", },
{ &prune, "prune", "Prune expired/invalid records.", },
{ &clear, "clear", "Clear all cache records.", },
{ NULL, NULL, NULL }
};
return prop_list;
}
KR_MODULE_EXPORT(cachectl);
......@@ -31,7 +31,7 @@
/* TODO: this is an experimental (slow) proof-of-concept,
* this will be rewritten with namedb API
*/
*/
typedef int (*rr_callback_t)(const knot_rrset_t *, unsigned, struct kr_layer_param *);
......@@ -89,7 +89,7 @@ static int query(knot_layer_t *ctx, knot_pkt_t *pkt)
knot_rrset_t rr;
knot_rrset_init(&rr, pair->name, qtype, KNOT_CLASS_IN);
struct sockaddr_storage addr;
sockaddr_set(&addr, addr_type, pair->addr, 0);
sockaddr_set(&addr, addr_type, pair->addr, 0);
size_t addr_len = 0;
uint8_t *raw_addr = sockaddr_raw(&addr, &addr_len);
knot_rrset_add_rdata(&rr, raw_addr, addr_len, 0, &param->answer->mm);
......@@ -135,7 +135,7 @@ static int load_map(struct hint_map *map, FILE *fp)
if (pair->addr == NULL) {
return kr_error(ENOMEM);
}
strcpy(pair->addr, tok);
add_tail(&map->list, &pair->n);
name_tok = strtok_r(NULL, " \t\n", &saveptr);
......
......@@ -26,7 +26,7 @@ knot_rrset_t global_rr;
const char *global_env;
#define CACHE_SIZE 10 * 4096
#define CACHE_TTL 2
#define CACHE_TTL 2
/* Test invalid parameters. */
static void test_invalid(void **state)
......
......@@ -64,7 +64,7 @@ static PyObject* init(PyObject* self, PyObject* args)
memset(&global_context, 0, sizeof(struct kr_context));
global_context.pool = &global_mm;
global_context.modules = &global_modules;
global_tmpdir = test_tmpdir_create();
assert(global_tmpdir);
global_context.cache = kr_cache_open(global_tmpdir, &global_mm, 100 * 4096);
......@@ -72,7 +72,7 @@ static PyObject* init(PyObject* self, PyObject* args)
/* No configuration parsing support yet. */
if (strstr(config, "query-minimization: on") == NULL) {
global_context.options |= QUERY_NO_MINIMIZE;
global_context.options |= QUERY_NO_MINIMIZE;
}
return Py_BuildValue("");
......
......@@ -30,7 +30,7 @@ static void test_rplan_params(void **state)
assert_null(kr_rplan_txn_acquire(NULL, 0));
assert_int_equal(kr_rplan_txn_commit(NULL), KNOT_EINVAL);
kr_rplan_deinit(NULL);
/* NULL mandatory parameters */
struct kr_rplan rplan;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment