diff options
author | Vsevolod Stakhov <vsevolod@highsecure.ru> | 2014-07-23 12:57:31 +0100 |
---|---|---|
committer | Vsevolod Stakhov <vsevolod@highsecure.ru> | 2014-07-23 12:57:31 +0100 |
commit | 379055dbbb4af997b4d3ffb161d447872d7ca357 (patch) | |
tree | 3774553d470f93e12ddeb454aad9b3b607cf8918 /src/kvstorage_bdb.c | |
parent | 602ae7a0b7e215ba2677131b8fdc70abc156b3ca (diff) | |
download | rspamd-379055dbbb4af997b4d3ffb161d447872d7ca357.tar.gz rspamd-379055dbbb4af997b4d3ffb161d447872d7ca357.zip |
Unify style without sorting headers.
Diffstat (limited to 'src/kvstorage_bdb.c')
-rw-r--r-- | src/kvstorage_bdb.c | 119 |
1 files changed, 68 insertions, 51 deletions
diff --git a/src/kvstorage_bdb.c b/src/kvstorage_bdb.c index 7970291f6..df2a5ba19 100644 --- a/src/kvstorage_bdb.c +++ b/src/kvstorage_bdb.c @@ -40,15 +40,15 @@ struct bdb_op { /* Main bdb structure */ struct rspamd_bdb_backend { - backend_init init_func; /*< this callback is called on kv storage initialization */ - backend_insert insert_func; /*< this callback is called when element is inserted */ - backend_replace replace_func; /*< this callback is called when element is replaced */ - backend_lookup lookup_func; /*< this callback is used for lookup of element */ - backend_delete delete_func; /*< this callback is called when an element is deleted */ - backend_sync sync_func; /*< this callback is called when backend need to be synced */ - backend_destroy destroy_func; /*< this callback is used for destroying all elements inside backend */ - DB_ENV *envp; /*< db environment */ - DB *dbp; /*< db pointer */ + backend_init init_func; /*< this callback is called on kv storage initialization */ + backend_insert insert_func; /*< this callback is called when element is inserted */ + backend_replace replace_func; /*< this callback is called when element is replaced */ + backend_lookup lookup_func; /*< this callback is used for lookup of element */ + backend_delete delete_func; /*< this callback is called when an element is deleted */ + backend_sync sync_func; /*< this callback is called when backend need to be synced */ + backend_destroy destroy_func; /*< this callback is used for destroying all elements inside backend */ + DB_ENV *envp; /*< db environment */ + DB *dbp; /*< db pointer */ gchar *filename; gchar *dirname; guint sync_ops; @@ -59,16 +59,19 @@ struct rspamd_bdb_backend { /* Process single bdb operation */ static gboolean -bdb_process_single_op (struct rspamd_bdb_backend *db, DB_TXN *txn, struct bdb_op *op) +bdb_process_single_op (struct rspamd_bdb_backend *db, + DB_TXN *txn, + struct bdb_op *op) { - DBT db_key, db_data; + DBT db_key, db_data; - memset (&db_key, 0, sizeof(DBT)); + memset (&db_key, 0, sizeof(DBT)); memset (&db_data, 0, sizeof(DBT)); db_key.size = op->elt->keylen; db_key.data = ELT_KEY (op->elt); - db_data.size = op->elt->size + sizeof (struct rspamd_kv_element) + op->elt->keylen + 1; + db_data.size = op->elt->size + sizeof (struct rspamd_kv_element) + + op->elt->keylen + 1; db_data.data = op->elt; switch (op->op) { @@ -96,14 +99,14 @@ bdb_process_single_op (struct rspamd_bdb_backend *db, DB_TXN *txn, struct bdb_op static gboolean bdb_process_queue (struct rspamd_kv_backend *backend) { - struct rspamd_bdb_backend *db = (struct rspamd_bdb_backend *)backend; - struct bdb_op *op; - GList *cur; + struct rspamd_bdb_backend *db = (struct rspamd_bdb_backend *)backend; + struct bdb_op *op; + GList *cur; cur = db->ops_queue->head; while (cur) { op = cur->data; - if (! bdb_process_single_op (db, NULL, op)) { + if (!bdb_process_single_op (db, NULL, op)) { return FALSE; } cur = g_list_next (cur); @@ -113,7 +116,8 @@ bdb_process_queue (struct rspamd_kv_backend *backend) cur = db->ops_queue->head; while (cur) { op = cur->data; - if (op->op == BDB_OP_DELETE || (op->elt->flags & KV_ELT_NEED_FREE) != 0) { + if (op->op == BDB_OP_DELETE || (op->elt->flags & KV_ELT_NEED_FREE) != + 0) { /* Also clean memory */ g_slice_free1 (ELT_SIZE (op->elt), op->elt); } @@ -132,9 +136,9 @@ bdb_process_queue (struct rspamd_kv_backend *backend) static void rspamd_bdb_init (struct rspamd_kv_backend *backend) { - struct rspamd_bdb_backend *db = (struct rspamd_bdb_backend *)backend; - guint32 flags; - gint ret; + struct rspamd_bdb_backend *db = (struct rspamd_bdb_backend *)backend; + guint32 flags; + gint ret; if ((ret = db_env_create (&db->envp, 0)) != 0) { /* Cannot create environment */ @@ -142,9 +146,9 @@ rspamd_bdb_init (struct rspamd_kv_backend *backend) } flags = DB_INIT_MPOOL | - DB_CREATE | /* Create the environment if it does not already exist. */ - DB_INIT_LOCK | /* Initialize locking. */ - DB_THREAD; /* Use threads */ + DB_CREATE | /* Create the environment if it does not already exist. */ + DB_INIT_LOCK | /* Initialize locking. */ + DB_THREAD; /* Use threads */ if ((ret = db->envp->open (db->envp, db->dirname, flags, 0)) != 0) { /* Cannot open environment */ @@ -168,7 +172,9 @@ rspamd_bdb_init (struct rspamd_kv_backend *backend) goto err; } - if ((ret = db->dbp->open (db->dbp, NULL, db->filename, NULL, DB_HASH, flags, 0)) != 0) { + if ((ret = + db->dbp->open (db->dbp, NULL, db->filename, NULL, DB_HASH, flags, + 0)) != 0) { goto err; } @@ -187,10 +193,13 @@ err: } static gboolean -rspamd_bdb_insert (struct rspamd_kv_backend *backend, gpointer key, guint keylen, struct rspamd_kv_element *elt) +rspamd_bdb_insert (struct rspamd_kv_backend *backend, + gpointer key, + guint keylen, + struct rspamd_kv_element *elt) { - struct rspamd_bdb_backend *db = (struct rspamd_bdb_backend *)backend; - struct bdb_op *op; + struct rspamd_bdb_backend *db = (struct rspamd_bdb_backend *)backend; + struct bdb_op *op; if (!db->initialized) { return FALSE; @@ -204,7 +213,8 @@ rspamd_bdb_insert (struct rspamd_kv_backend *backend, gpointer key, guint keylen g_queue_push_head (db->ops_queue, op); g_hash_table_insert (db->ops_hash, elt, op); - if (db->sync_ops > 0 && g_queue_get_length (db->ops_queue) >= db->sync_ops) { + if (db->sync_ops > 0 && g_queue_get_length (db->ops_queue) >= + db->sync_ops) { return bdb_process_queue (backend); } @@ -212,10 +222,13 @@ rspamd_bdb_insert (struct rspamd_kv_backend *backend, gpointer key, guint keylen } static gboolean -rspamd_bdb_replace (struct rspamd_kv_backend *backend, gpointer key, guint keylen, struct rspamd_kv_element *elt) +rspamd_bdb_replace (struct rspamd_kv_backend *backend, + gpointer key, + guint keylen, + struct rspamd_kv_element *elt) { - struct rspamd_bdb_backend *db = (struct rspamd_bdb_backend *)backend; - struct bdb_op *op; + struct rspamd_bdb_backend *db = (struct rspamd_bdb_backend *)backend; + struct bdb_op *op; if (!db->initialized) { return FALSE; @@ -229,21 +242,23 @@ rspamd_bdb_replace (struct rspamd_kv_backend *backend, gpointer key, guint keyle g_queue_push_head (db->ops_queue, op); g_hash_table_insert (db->ops_hash, elt, op); - if (db->sync_ops > 0 && g_queue_get_length (db->ops_queue) >= db->sync_ops) { + if (db->sync_ops > 0 && g_queue_get_length (db->ops_queue) >= + db->sync_ops) { return bdb_process_queue (backend); } return TRUE; } -static struct rspamd_kv_element* -rspamd_bdb_lookup (struct rspamd_kv_backend *backend, gpointer key, guint keylen) +static struct rspamd_kv_element * +rspamd_bdb_lookup (struct rspamd_kv_backend *backend, gpointer key, + guint keylen) { - struct rspamd_bdb_backend *db = (struct rspamd_bdb_backend *)backend; - struct bdb_op *op; - DBT db_key, db_data; - struct rspamd_kv_element *elt = NULL; - struct rspamd_kv_element search_elt; + struct rspamd_bdb_backend *db = (struct rspamd_bdb_backend *)backend; + struct bdb_op *op; + DBT db_key, db_data; + struct rspamd_kv_element *elt = NULL; + struct rspamd_kv_element search_elt; search_elt.keylen = keylen; search_elt.p = key; @@ -260,7 +275,7 @@ rspamd_bdb_lookup (struct rspamd_kv_backend *backend, gpointer key, guint keylen return op->elt; } - memset (&db_key, 0, sizeof(DBT)); + memset (&db_key, 0, sizeof(DBT)); memset (&db_data, 0, sizeof(DBT)); db_key.size = keylen; db_key.data = key; @@ -275,12 +290,13 @@ rspamd_bdb_lookup (struct rspamd_kv_backend *backend, gpointer key, guint keylen } static void -rspamd_bdb_delete (struct rspamd_kv_backend *backend, gpointer key, guint keylen) +rspamd_bdb_delete (struct rspamd_kv_backend *backend, gpointer key, + guint keylen) { - struct rspamd_bdb_backend *db = (struct rspamd_bdb_backend *)backend; - struct bdb_op *op; - struct rspamd_kv_element *elt; - struct rspamd_kv_element search_elt; + struct rspamd_bdb_backend *db = (struct rspamd_bdb_backend *)backend; + struct bdb_op *op; + struct rspamd_kv_element *elt; + struct rspamd_kv_element search_elt; search_elt.keylen = keylen; search_elt.p = key; @@ -306,7 +322,8 @@ rspamd_bdb_delete (struct rspamd_kv_backend *backend, gpointer key, guint keylen g_queue_push_head (db->ops_queue, op); g_hash_table_insert (db->ops_hash, elt, op); - if (db->sync_ops > 0 && g_queue_get_length (db->ops_queue) >= db->sync_ops) { + if (db->sync_ops > 0 && g_queue_get_length (db->ops_queue) >= + db->sync_ops) { bdb_process_queue (backend); } @@ -316,7 +333,7 @@ rspamd_bdb_delete (struct rspamd_kv_backend *backend, gpointer key, guint keylen static void rspamd_bdb_destroy (struct rspamd_kv_backend *backend) { - struct rspamd_bdb_backend *db = (struct rspamd_bdb_backend *)backend; + struct rspamd_bdb_backend *db = (struct rspamd_bdb_backend *)backend; if (db->initialized) { bdb_process_queue (backend); @@ -338,9 +355,9 @@ rspamd_bdb_destroy (struct rspamd_kv_backend *backend) struct rspamd_kv_backend * rspamd_kv_bdb_new (const gchar *filename, guint sync_ops) { - struct rspamd_bdb_backend *new; - struct stat st; - gchar *dirname; + struct rspamd_bdb_backend *new; + struct stat st; + gchar *dirname; if (filename == NULL) { return NULL; |