#include <glib.h>
-#include "buxton2.h"
#include "log.h"
#include "cache.h"
#include "buxton_error.h"
typedef struct _cache {
GHashTable *hash_table;
- enum buxton_layer_type layer_type;
+ enum layer_attribute_type layer_type;
int count;
int size;
} bxt_cache;
typedef struct _cache_data {
- enum buxton_layer_type layer_type;
+ enum layer_attribute_type layer_type;
int len; /* data size */
void *data; /* raw data */
} cache_data;
static bxt_cache *g_base_db_cache;
static bxt_cache *g_normal_db_cache;
-static bxt_cache *get_cache(enum buxton_layer_type layer_type)
+static bxt_cache *get_cache(enum layer_attribute_type layer_type)
{
- return (layer_type == BUXTON_LAYER_NORMAL) ?
+ return (layer_type == LAYER_ATTRIBUTE_RW) ?
g_normal_db_cache : g_base_db_cache;
}
g_normal_db_cache->count = 0;
}
-void cache_remove(enum buxton_layer_type layer_type, const char *key)
+void cache_remove(enum layer_attribute_type layer_type, const char *key)
{
GHashTable *hash_table = NULL;
if (g_hash_table_remove(hash_table, key)) {
bxt_dbg("[%s cache] removed (%s)/count(%d)/total size(%d)",
- (layer_type == BUXTON_LAYER_NORMAL) ?
+ (layer_type == LAYER_ATTRIBUTE_RW) ?
"NORMAL" : "BASE",
key, cache->count, cache->size);
}
}
-void cache_update_data(enum buxton_layer_type layer_type,
+void cache_update_data(enum layer_attribute_type layer_type,
const char *key, uint8_t *data, int len)
{
GHashTable *hash_table = NULL;
cdata->len = len;
}
-static void cache_drop(enum buxton_layer_type layer_type, int size)
+static void cache_drop(enum layer_attribute_type layer_type, int size)
{
GHashTableIter iter;
gpointer key;
while (g_hash_table_iter_next(&iter, &key, &value)) {
if (remain > 0) {
bxt_dbg("[%s cache][%d] removed (%s)",
- (layer_type == BUXTON_LAYER_NORMAL) ?
+ (layer_type == LAYER_ATTRIBUTE_RW) ?
"NORMAL" : "BASE", remain, (char *)key);
g_hash_table_iter_remove(&iter);
remain--;
}
}
-void cache_insert(enum buxton_layer_type layer_type, const char *key,
+void cache_insert(enum layer_attribute_type layer_type, const char *key,
uint8_t *data, int len)
{
GHashTable *hash_table = NULL;
cache->size += len;
bxt_dbg("[%s cache] inserted (%s)/size(%d)/count(%d)/total size(%d)",
- (layer_type == BUXTON_LAYER_NORMAL) ?
+ (layer_type == LAYER_ATTRIBUTE_RW) ?
"NORMAL" : "BASE", key, len, cache->count, cache->size);
}
-int cache_get(enum buxton_layer_type layer_type, const char *key,
+int cache_get(enum layer_attribute_type layer_type, const char *key,
void **data, int *data_len)
{
GHashTable *hash_table = NULL;
*data_len = cdata->len;
bxt_dbg("[%s cache] get (%s)/size(%d)",
- (layer_type == BUXTON_LAYER_NORMAL) ?
+ (layer_type == LAYER_ATTRIBUTE_RW) ?
"NORMAL" : "BASE", key, cdata->len);
return BUXTON_ERROR_NONE;
}
-void cache_clear(enum buxton_layer_type layer_type)
+void cache_clear(enum layer_attribute_type layer_type)
{
bxt_cache *cache = get_cache(layer_type);
#pragma once
+#include "common.h"
+
void cache_init(void);
-void cache_insert(enum buxton_layer_type layer_type, const char *key,
+void cache_insert(enum layer_attribute_type layer_type, const char *key,
uint8_t *data, int len);
-void cache_remove(enum buxton_layer_type layer_type, const char *key);
-void cache_update_data(enum buxton_layer_type layer_type, const char *key,
+void cache_remove(enum layer_attribute_type layer_type, const char *key);
+void cache_update_data(enum layer_attribute_type layer_type, const char *key,
uint8_t *data, int len);
-int cache_get(enum buxton_layer_type layer_type, const char *key,
+int cache_get(enum layer_attribute_type layer_type, const char *key,
void **data, int *data_len);
-void cache_clear(enum buxton_layer_type layer_type);
+void cache_clear(enum layer_attribute_type layer_type);
tmp_layer->refcnt = 1;
tmp_layer->uid = getuid();
- tmp_layer->type = BUXTON_LAYER_NORMAL;
+ tmp_layer->type = LAYER_ATTRIBUTE_RW;
*layer = tmp_layer;
return;
switch (val->type) {
- case BUXTON_TYPE_STRING:
+ case VALUE_TYPE_STRING:
if (val->value.s) {
free(val->value.s);
val->value.s = NULL;
}
}
+void key_list_free(char **keys)
+{
+ char **key;
+
+ if (!keys)
+ return;
+
+ key = keys;
+ while (*key) {
+ free(*key);
+ key++;
+ }
+
+ free(keys);
+}
+
int get_search_key(const struct buxton_layer *layer, const char *key,
const char *uid, char **layer_key)
{
# define SOCKPATH "/run/buxton-0"
#endif
+
+/*
+ LAYER_SYSTEM - STORAGE_PERSISTENT - LAYER_ATTRIBUTE_RO
+ \ - LAYER_ATTRIBUTE_RW
+ STORAGE_VOLATILE - LAYER_ATTRIBUTE_RO
+ - LAYER_ATTRIBUTE_RW
+
+LAYER_USER - ...
+
+*/
enum layer_type {
LAYER_UNKNWON = 0,
LAYER_SYSTEM,
STORAGE_MAX, /* sentinel value */
};
+enum layer_attribute_type {
+ LAYER_ATTRIBUTE_RW = BUXTON_LAYER_NORMAL,
+ LAYER_ATTRIBUTE_RO = BUXTON_LAYER_BASE,
+ LAYER_ATTRIBUTE_MAX = BUXTON_LAYER_MAX, /* sentinel value */
+};
+
struct layer {
gchar *name;
enum layer_type type;
gchar *description;
};
+enum value_type {
+ VALUE_TYPE_UNKNOWN = BUXTON_TYPE_UNKNOWN, /**< Unknown type */
+ VALUE_TYPE_STRING = BUXTON_TYPE_STRING, /**< String type */
+ VALUE_TYPE_INT32 = BUXTON_TYPE_INT32, /**< 32bit integer type */
+ VALUE_TYPE_UINT32 = BUXTON_TYPE_UINT32, /**< 32bit unsigned integer type */
+ VALUE_TYPE_INT64 = BUXTON_TYPE_INT64, /**< 64bit integer type */
+ VALUE_TYPE_UINT64 = BUXTON_TYPE_UINT64, /**< 64bit unsigned integer type */
+ VALUE_TYPE_DOUBLE = BUXTON_TYPE_DOUBLE, /**< double-precision float type */
+ VALUE_TYPE_BOOLEAN = BUXTON_TYPE_BOOLEAN, /**< boolean type */
+ VALUE_TYPE_MAX = BUXTON_TYPE_MAX /* sentinel value */
+};
+
+enum priv_type {
+ PRIV_READ = BUXTON_PRIV_READ, /**< Read privilege type */
+ PRIV_WRITE = BUXTON_PRIV_WRITE, /**< Write privilege type */
+};
+
enum message_type {
MSG_UNKNOWN = 0,
/* basic request */
int refcnt;
char *name;
uid_t uid;
- enum buxton_layer_type type;
+ enum layer_attribute_type type;
};
int layer_create(const char *layer_name, struct buxton_layer **layer);
struct buxton_layer *layer_unref(struct buxton_layer *layer);
struct buxton_value {
- enum buxton_key_type type;
+ enum value_type type;
union {
char *s;
int32_t i;
};
void value_free(struct buxton_value *val);
+void key_list_free(char **keys);
int get_search_key(const struct buxton_layer *layer, const char *key,
const char *uid, char **layer_key);
#include <glib.h>
-#include "buxton2.h"
-
#include "common.h"
#include "log.h"
#include "direct.h"
#include "serialize.h"
#include "cache.h"
-static int get_path(uid_t uid, enum buxton_layer_type type,
+static int get_path(uid_t uid, enum layer_attribute_type type,
const struct layer *ly, char *path, int sz)
{
const char *prefix;
return BUXTON_ERROR_INVALID_PARAMETER;
}
- if (type == BUXTON_LAYER_NORMAL)
+ if (type == LAYER_ATTRIBUTE_RW)
prefix = (ly->storage == STORAGE_VOLATILE) ? TMPFS_DIR : DB_DIR;
else
prefix = BASE_DB_DIR;
- if (type == BUXTON_LAYER_NORMAL && ly->type == LAYER_USER)
+ if (type == LAYER_ATTRIBUTE_RW && ly->type == LAYER_USER)
snprintf(suffix, sizeof(suffix), "-%u", uid);
else
suffix[0] = '\0';
}
static int get_raw(const struct layer *ly, uid_t uid,
- enum buxton_layer_type type, const char *key,
+ enum layer_attribute_type type, const char *key,
uint8_t **data, int *len)
{
int r;
return r;
r = backend->get_value(path, key, (void **)data, len,
- (type == BUXTON_LAYER_BASE) ? true : false);
+ (type == LAYER_ATTRIBUTE_RO) ? true : false);
if (r != BUXTON_ERROR_NONE)
return r;
}
static int get_val(const struct layer *ly, uid_t uid,
- enum buxton_layer_type type, const char *key,
+ enum layer_attribute_type type, const char *key,
char **rpriv, char **wpriv, struct buxton_value *val)
{
int r;
return r;
/* First, refer to base db */
- r = get_val(ly, layer->uid, BUXTON_LAYER_BASE, key, NULL, NULL,
+ r = get_val(ly, layer->uid, LAYER_ATTRIBUTE_RO, key, NULL, NULL,
&base_val);
if (r != BUXTON_ERROR_NONE)
return r;
- if (layer->type == BUXTON_LAYER_BASE) {
+ if (layer->type == LAYER_ATTRIBUTE_RO) {
*val = base_val;
return BUXTON_ERROR_NONE;
}
- r = get_val(ly, layer->uid, BUXTON_LAYER_NORMAL, key, NULL, NULL,
+ r = get_val(ly, layer->uid, LAYER_ATTRIBUTE_RW, key, NULL, NULL,
&db_val);
if (r != BUXTON_ERROR_NONE) {
if (r == BUXTON_ERROR_NOT_EXIST) {
if (r != BUXTON_ERROR_NONE)
return r;
- r = get_val(ly, layer->uid, BUXTON_LAYER_BASE, key, NULL, NULL, &val);
+ r = get_val(ly, layer->uid, LAYER_ATTRIBUTE_RO, key, NULL, NULL, &val);
if (r != BUXTON_ERROR_NONE)
return r;
return BUXTON_ERROR_NONE;
}
-static bool is_updated_data(enum buxton_layer_type type, const char *key,
+static bool is_updated_data(enum layer_attribute_type type, const char *key,
uint8_t *data, int len)
{
uint8_t *cur_data;
}
static int set_raw(const struct layer *ly, uid_t uid,
- enum buxton_layer_type type, const char *key,
+ enum layer_attribute_type type, const char *key,
uint8_t *data, int len)
{
int r;
}
static int set_val(const struct layer *ly, uid_t uid,
- enum buxton_layer_type type, const char *key,
+ enum layer_attribute_type type, const char *key,
const char *rpriv, const char *wpriv,
const struct buxton_value *val)
{
if (r != BUXTON_ERROR_NONE)
return r;
- r = get_val(ly, layer->uid, BUXTON_LAYER_BASE, key, &rp, &wp, NULL);
+ r = get_val(ly, layer->uid, LAYER_ATTRIBUTE_RO, key, &rp, &wp, NULL);
if (r != BUXTON_ERROR_NONE)
return r;
return BUXTON_ERROR_INVALID_OPERATION;
}
- r = get_path(layer->uid, BUXTON_LAYER_BASE, ly, path, sizeof(path));
+ r = get_path(layer->uid, LAYER_ATTRIBUTE_RO, ly, path, sizeof(path));
if (r != BUXTON_ERROR_NONE)
return r;
if (r != BUXTON_ERROR_NONE)
return r;
- r = get_val(ly, layer->uid, BUXTON_LAYER_BASE, key, NULL, NULL, NULL);
+ r = get_val(ly, layer->uid, LAYER_ATTRIBUTE_RO, key, NULL, NULL, NULL);
if (r == BUXTON_ERROR_NONE)
return BUXTON_ERROR_EXIST;
return r;
}
- r = set_val(ly, layer->uid, BUXTON_LAYER_BASE, key, rpriv, wpriv, val);
+ r = set_val(ly, layer->uid, LAYER_ATTRIBUTE_RO, key, rpriv, wpriv, val);
if (r != BUXTON_ERROR_NONE) {
bxt_err("failed to create (%s: %s) %d", ly->name, key, r);
return r;
}
if (ly->storage == STORAGE_PERSISTENT) {
- r = set_val(ly, layer->uid, BUXTON_LAYER_NORMAL, key, rpriv, wpriv, val);
+ r = set_val(ly, layer->uid, LAYER_ATTRIBUTE_RW, key, rpriv, wpriv, val);
if (r != BUXTON_ERROR_NONE) {
bxt_err("failed to create (%s: %s) %d", ly->name, key, r);
unset_layer = *layer;
- unset_layer.type = BUXTON_LAYER_BASE;
+ unset_layer.type = LAYER_ATTRIBUTE_RO;
direct_unset(&unset_layer, key);
}
}
}
r = get_path(layer->uid, is_base ?
- BUXTON_LAYER_BASE : BUXTON_LAYER_NORMAL,
+ LAYER_ATTRIBUTE_RO : LAYER_ATTRIBUTE_RW,
ly, path, sizeof(path));
if (r != BUXTON_ERROR_NONE)
return r;
return BUXTON_ERROR_INVALID_OPERATION;
}
- ret = get_path(layer->uid, BUXTON_LAYER_BASE,
+ ret = get_path(layer->uid, LAYER_ATTRIBUTE_RO,
ly, path, sizeof(path));
if (ret != BUXTON_ERROR_NONE)
return ret;
return ret;
}
- ret = get_path(layer->uid, BUXTON_LAYER_NORMAL,
+ ret = get_path(layer->uid, LAYER_ATTRIBUTE_RW,
ly, path, sizeof(path));
if (ret != BUXTON_ERROR_NONE) {
bxt_err("dump: get_path failed");
*len = base_len;
out:
- buxton_free_keys((char **)base_values);
- buxton_free_keys(normal_keys);
- buxton_free_keys((char **)normal_values);
+ key_list_free((char **)base_values);
+ key_list_free(normal_keys);
+ key_list_free((char **)normal_values);
free(base_value_len);
free(normal_value_len);
if (ret != BUXTON_ERROR_NONE) {
- buxton_free_keys(base_keys);
+ key_list_free(base_keys);
if (_value_list)
free(_value_list);
}
switch (type) {
- case BUXTON_PRIV_READ:
+ case PRIV_READ:
rp = priv;
wp = NULL;
break;
- case BUXTON_PRIV_WRITE:
+ case PRIV_WRITE:
rp = NULL;
wp = priv;
break;
if (r != BUXTON_ERROR_NONE)
return r;
- r = get_val(ly, layer->uid, BUXTON_LAYER_BASE, key, rp, wp, NULL);
+ r = get_val(ly, layer->uid, LAYER_ATTRIBUTE_RO, key, rp, wp, NULL);
return r;
}
}
switch (type) {
- case BUXTON_PRIV_READ:
- case BUXTON_PRIV_WRITE:
+ case PRIV_READ:
+ case PRIV_WRITE:
break;
default:
bxt_err("Invalid parameter");
if (r != BUXTON_ERROR_NONE)
return r;
- r = get_val(ly, layer->uid, BUXTON_LAYER_BASE, key, &rp, &wp, &val);
+ r = get_val(ly, layer->uid, LAYER_ATTRIBUTE_RO, key, &rp, &wp, &val);
if (r != BUXTON_ERROR_NONE)
return r;
switch (type) {
- case BUXTON_PRIV_READ:
+ case PRIV_READ:
t_rp = priv;
t_wp = wp;
break;
- case BUXTON_PRIV_WRITE:
+ case PRIV_WRITE:
t_rp = rp;
t_wp = priv;
break;
break;
}
- r = set_val(ly, layer->uid, BUXTON_LAYER_BASE, key, t_rp, t_wp, &val);
+ r = set_val(ly, layer->uid, LAYER_ATTRIBUTE_RO, key, t_rp, t_wp, &val);
value_free(&val);
free(rp);
#pragma once
-#include "buxton2.h"
-
int direct_init(const char *moddir, const char *confpath, bool *log_on, int *max_line);
void direct_exit(void);
#include <glib.h>
-#include "buxton2.h"
-
#include "serialize.h"
#include "log.h"
return r;
}
- if (val && val->type == BUXTON_TYPE_STRING) {
+ if (val && val->type == VALUE_TYPE_STRING) {
r = check_val(val->value.s);
if (r != BUXTON_ERROR_NONE) {
bxt_err("Value string length is too long");
return g_variant_new_tuple(NULL, 0);
switch (val->type) {
- case BUXTON_TYPE_STRING:
+ case VALUE_TYPE_STRING:
if (!val->value.s) {
bxt_err("Serialize: value has NULL string");
return NULL;
gv = g_variant_new_string(val->value.s);
break;
- case BUXTON_TYPE_INT32:
+ case VALUE_TYPE_INT32:
gv = g_variant_new_int32(val->value.i);
break;
- case BUXTON_TYPE_UINT32:
+ case VALUE_TYPE_UINT32:
gv = g_variant_new_uint32(val->value.u);
break;
- case BUXTON_TYPE_INT64:
+ case VALUE_TYPE_INT64:
gv = g_variant_new_int64(val->value.i64);
break;
- case BUXTON_TYPE_UINT64:
+ case VALUE_TYPE_UINT64:
gv = g_variant_new_uint64(val->value.u64);
break;
- case BUXTON_TYPE_DOUBLE:
+ case VALUE_TYPE_DOUBLE:
gv = g_variant_new_double(val->value.d);
break;
- case BUXTON_TYPE_BOOLEAN:
+ case VALUE_TYPE_BOOLEAN:
gv = g_variant_new_boolean(val->value.b);
break;
default:
if (!strncmp(t, "()", sizeof("()"))) {
- val->type = BUXTON_TYPE_UNKNOWN;
+ val->type = VALUE_TYPE_UNKNOWN;
return BUXTON_ERROR_NONE;
}
switch (*t) {
case 's':
- val->type = BUXTON_TYPE_STRING;
+ val->type = VALUE_TYPE_STRING;
s = g_variant_get_string(v, NULL);
if (!s) {
}
break;
case 'i':
- val->type = BUXTON_TYPE_INT32;
+ val->type = VALUE_TYPE_INT32;
val->value.i = g_variant_get_int32(v);
break;
case 'u':
- val->type = BUXTON_TYPE_UINT32;
+ val->type = VALUE_TYPE_UINT32;
val->value.u = g_variant_get_uint32(v);
break;
case 'x':
- val->type = BUXTON_TYPE_INT64;
+ val->type = VALUE_TYPE_INT64;
val->value.i64 = g_variant_get_int64(v);
break;
case 't':
- val->type = BUXTON_TYPE_UINT64;
+ val->type = VALUE_TYPE_UINT64;
val->value.u64 = g_variant_get_uint64(v);
break;
case 'd':
- val->type = BUXTON_TYPE_DOUBLE;
+ val->type = VALUE_TYPE_DOUBLE;
val->value.d = g_variant_get_double(v);
break;
case 'b':
- val->type = BUXTON_TYPE_BOOLEAN;
+ val->type = VALUE_TYPE_BOOLEAN;
val->value.b = g_variant_get_boolean(v);
break;
default:
}
switch (val->type) {
- case BUXTON_TYPE_STRING:
+ case VALUE_TYPE_STRING:
if (!val->value.s) {
bxt_err("Serialize: value has NULL string");
return BUXTON_ERROR_INVALID_PARAMETER;
}
break;
- case BUXTON_TYPE_INT32:
- case BUXTON_TYPE_UINT32:
- case BUXTON_TYPE_INT64:
- case BUXTON_TYPE_UINT64:
- case BUXTON_TYPE_DOUBLE:
- case BUXTON_TYPE_BOOLEAN:
+ case VALUE_TYPE_INT32:
+ case VALUE_TYPE_UINT32:
+ case VALUE_TYPE_INT64:
+ case VALUE_TYPE_UINT64:
+ case VALUE_TYPE_DOUBLE:
+ case VALUE_TYPE_BOOLEAN:
break;
default:
bxt_err("Serialize: buxton_value has unknown type");
return r;
}
- if (val->type == BUXTON_TYPE_UNKNOWN) {
+ if (val->type == VALUE_TYPE_UNKNOWN) {
free(val);
val = NULL;
}
value_free(res->val);
free(res->val);
- buxton_free_keys(res->names);
+ key_list_free(res->names);
}
static int check_response(enum message_type type, int32_t res,
res->names[i] = NULL;
if (i < len || ret != BUXTON_ERROR_NONE) {
- buxton_free_keys(res->names);
+ key_list_free(res->names);
return ret == BUXTON_ERROR_NONE ? BUXTON_ERROR_INVALID_PARAMETER : ret;
}
g_variant_unref(v);
- if (val->type == BUXTON_TYPE_UNKNOWN) {
+ if (val->type == VALUE_TYPE_UNKNOWN) {
free(val);
val = NULL;
}
#include <stdint.h>
-#include "buxton2.h"
-
#include "common.h"
int check_key_name(const char *key);
return BUXTON_ERROR_INVALID_PARAMETER;
}
- if (val->type != type) {
+ if (val->type != (enum value_type)type) {
bxt_err("Invalid parameter : type mismatch %d %d", val->type, type);
return BUXTON_ERROR_INVALID_PARAMETER;
}
*_val = *val;
- if (val->type == BUXTON_TYPE_STRING && val->value.s) {
+ if (val->type == (enum value_type)BUXTON_TYPE_STRING && val->value.s) {
_val->value.s = strdup(val->value.s);
if (!_val->value.s) {
free(_val);