summaryrefslogtreecommitdiff
path: root/src/common
diff options
context:
space:
mode:
authorAndrei Karas <akaras@inbox.ru>2016-04-04 17:08:44 +0300
committerAndrei Karas <akaras@inbox.ru>2016-04-04 17:08:44 +0300
commit3732bd4a6b708651f6b4bcd32d6beb2b7f49c478 (patch)
tree83155915c35c72d018108231437248cc78d5060d /src/common
parent0bd30a0fac1db1b478b3173a22a81bd5249113f8 (diff)
parent9147fe9473b26ee32aafed65fd02b03f11397629 (diff)
downloadhercules-3732bd4a6b708651f6b4bcd32d6beb2b7f49c478.tar.gz
hercules-3732bd4a6b708651f6b4bcd32d6beb2b7f49c478.tar.bz2
hercules-3732bd4a6b708651f6b4bcd32d6beb2b7f49c478.tar.xz
hercules-3732bd4a6b708651f6b4bcd32d6beb2b7f49c478.zip
Merge pull request #1210 from HerculesWS/wcast_qual
Added -Wcast-qual compiler flag
Diffstat (limited to 'src/common')
-rw-r--r--src/common/HPM.c2
-rw-r--r--src/common/HPMi.h4
-rw-r--r--src/common/console.c3
-rw-r--r--src/common/console.h8
-rw-r--r--src/common/db.c696
-rw-r--r--src/common/db.h363
-rw-r--r--src/common/mapindex.h6
-rw-r--r--src/common/md5calc.c6
-rw-r--r--src/common/socket.c4
-rw-r--r--src/common/sql.c131
-rw-r--r--src/common/sql.h78
11 files changed, 672 insertions, 629 deletions
diff --git a/src/common/HPM.c b/src/common/HPM.c
index fa4025fb8..d3d050d27 100644
--- a/src/common/HPM.c
+++ b/src/common/HPM.c
@@ -55,7 +55,7 @@ struct HPM_interface *HPM;
/**
* (char*) data name -> (unsigned int) HPMDataCheck[] index
**/
-DBMap *datacheck_db;
+struct DBMap *datacheck_db;
int datacheck_version;
const struct s_HPMDataCheck *datacheck_data;
diff --git a/src/common/HPMi.h b/src/common/HPMi.h
index cf3e16277..72640b382 100644
--- a/src/common/HPMi.h
+++ b/src/common/HPMi.h
@@ -24,8 +24,8 @@
#include "common/console.h"
#include "common/core.h"
#include "common/showmsg.h"
-#include "common/sql.h"
+struct Sql; // common/sql.h
struct script_state;
struct AtCommandInfo;
struct socket_data;
@@ -242,7 +242,7 @@ struct HPMi_interface {
/* pc group permission */
void (*addPCGPermission) (unsigned int pluginID, char *name, unsigned int *mask);
- Sql *sql_handle;
+ struct Sql *sql_handle;
};
#ifdef HERCULES_CORE
#define HPM_SYMBOL(n, s) (HPM->share((s), (n)), true)
diff --git a/src/common/console.c b/src/common/console.c
index 10e1bee1a..0be33e5c3 100644
--- a/src/common/console.c
+++ b/src/common/console.c
@@ -523,7 +523,8 @@ void console_parse_init(void) {
timer->add_func_list(console->input->parse_timer, "console_parse_timer");
timer->add_interval(timer->gettick() + 1000, console->input->parse_timer, 0, 0, 500);/* start listening in 1s; re-try every 0.5s */
}
-void console_setSQL(Sql *SQL_handle) {
+void console_setSQL(struct Sql *SQL_handle)
+{
console->input->SQL = SQL_handle;
}
#endif /* CONSOLE_INPUT */
diff --git a/src/common/console.h b/src/common/console.h
index 43f48b865..57c750a7d 100644
--- a/src/common/console.h
+++ b/src/common/console.h
@@ -24,9 +24,11 @@
#include "common/db.h"
#include "common/mutex.h"
#include "common/spinlock.h"
-#include "common/sql.h"
#include "common/thread.h"
+/* Forward Declarations */
+struct Sql; // common/sql.h
+
/**
* Queue Max
* why is there a limit, why not make it dynamic? - I'm playing it safe, I'd rather not play with memory management between threads
@@ -78,7 +80,7 @@ struct console_input_interface {
VECTOR_DECL(struct CParseEntry *) command_list;
VECTOR_DECL(struct CParseEntry *) commands;
/* */
- Sql *SQL;
+ struct Sql *SQL;
/* */
void (*parse_init) (void);
void (*parse_final) (void);
@@ -90,7 +92,7 @@ struct console_input_interface {
void (*load_defaults) (void);
void (*parse_list_subs) (struct CParseEntry *cmd, unsigned char depth);
void (*addCommand) (char *name, CParseFunc func);
- void (*setSQL) (Sql *SQL_handle);
+ void (*setSQL) (struct Sql *SQL_handle);
#else // not CONSOLE_INPUT
UNAVAILABLE_STRUCT;
#endif
diff --git a/src/common/db.c b/src/common/db.c
index ca9a70f7c..bbcac4b33 100644
--- a/src/common/db.c
+++ b/src/common/db.c
@@ -21,7 +21,7 @@
/*****************************************************************************\
* This file is separated in five sections:
- * (1) Private typedefs, enums, structures, defines and global variables
+ * (1) Private enums, structures, defines and global variables
* (2) Private functions
* (3) Protected functions used internally
* (4) Protected functions used in the interface of the database
@@ -102,17 +102,17 @@
struct db_interface DB_s;
struct db_interface *DB;
-/*****************************************************************************\
- * (1) Private typedefs, enums, structures, defines and global variables of *
- * the database system. *
- * DB_ENABLE_STATS - Define to enable database statistics. *
- * HASH_SIZE - Define with the size of the hashtable. *
- * DBNColor - Enumeration of colors of the nodes. *
- * DBNode - Structure of a node in RED-BLACK trees. *
- * struct db_free - Structure that holds a deleted node to be freed. *
- * DBMap_impl - Structure of the database. *
- * stats - Statistics about the database system. *
-\*****************************************************************************/
+/*****************************************************************************
+ * (1) Private enums, structures, defines and global variables of the *
+ * database system. *
+ * DB_ENABLE_STATS - Define to enable database statistics. *
+ * HASH_SIZE - Define with the size of the hashtable. *
+ * enum DBNodeColor - Enumeration of colors of the nodes. *
+ * struct DBNode - Structure of a node in RED-BLACK trees. *
+ * struct db_free - Structure that holds a deleted node to be freed. *
+ * struct DBMap_impl - Structure of the database. *
+ * stats - Statistics about the database system. *
+ *****************************************************************************/
/**
* If defined statistics about database nodes, database creating/destruction
@@ -129,19 +129,19 @@ struct db_interface *DB;
/**
* Size of the hashtable in the database.
* @private
- * @see DBMap_impl#ht
+ * @see struct DBMap_impl#ht
*/
#define HASH_SIZE (256+27)
/**
* The color of individual nodes.
* @private
- * @see struct dbn
+ * @see struct DBNode
*/
-typedef enum node_color {
+enum DBNodeColor {
RED,
- BLACK
-} node_color;
+ BLACK,
+};
/**
* A node in a RED-BLACK tree of the database.
@@ -153,31 +153,31 @@ typedef enum node_color {
* @param deleted If the node is deleted
* @param color Color of the node
* @private
- * @see DBMap_impl#ht
+ * @see struct DBMap_impl#ht
*/
-typedef struct dbn {
+struct DBNode {
// Tree structure
- struct dbn *parent;
- struct dbn *left;
- struct dbn *right;
+ struct DBNode *parent;
+ struct DBNode *left;
+ struct DBNode *right;
// Node data
- DBKey key;
- DBData data;
+ union DBKey key;
+ struct DBData data;
// Other
- node_color color;
+ enum DBNodeColor color;
unsigned deleted : 1;
-} DBNode;
+};
/**
* Structure that holds a deleted node.
* @param node Deleted node
* @param root Address to the root of the tree
* @private
- * @see DBMap_impl#free_list
+ * @see struct DBMap_impl#free_list
*/
struct db_free {
- DBNode *node;
- DBNode **root;
+ struct DBNode *node;
+ struct DBNode **root;
};
/**
@@ -200,9 +200,9 @@ struct db_free {
* @param maxlen Maximum length of strings in DB_STRING and DB_ISTRING databases
* @param global_lock Global lock of the database
* @private
- * @see #db_alloc(const char*,int,DBType,DBOptions,unsigned short)
+ * @see #db_alloc()
*/
-typedef struct DBMap_impl {
+struct DBMap_impl {
// Database interface
struct DBMap vtable;
// File and line of allocation
@@ -218,14 +218,14 @@ typedef struct DBMap_impl {
DBComparator cmp;
DBHasher hash;
DBReleaser release;
- DBNode *ht[HASH_SIZE];
- DBNode *cache;
- DBType type;
- DBOptions options;
+ struct DBNode *ht[HASH_SIZE];
+ struct DBNode *cache;
+ enum DBType type;
+ enum DBOptions options;
uint32 item_count;
unsigned short maxlen;
unsigned global_lock : 1;
-} DBMap_impl;
+};
/**
* Complete iterator structure.
@@ -234,17 +234,17 @@ typedef struct DBMap_impl {
* @param ht_index Current index of the hashtable
* @param node Current node
* @private
- * @see #DBIterator
- * @see #DBMap_impl
- * @see #DBNode
+ * @see struct DBIterator
+ * @see struct DBMap_impl
+ * @see struct DBNode
*/
-typedef struct DBIterator_impl {
+struct DBIterator_impl {
// Iterator interface
struct DBIterator vtable;
- DBMap_impl* db;
+ struct DBMap_impl *db;
int ht_index;
- DBNode *node;
-} DBIterator_impl;
+ struct DBNode *node;
+};
#if defined(DB_ENABLE_STATS)
/**
@@ -382,12 +382,12 @@ struct eri *db_alloc_ers;
* @param node Node to be rotated
* @param root Pointer to the root of the tree
* @private
- * @see #db_rebalance(DBNode *,DBNode **)
- * @see #db_rebalance_erase(DBNode *,DBNode **)
+ * @see #db_rebalance()
+ * @see #db_rebalance_erase()
*/
-static void db_rotate_left(DBNode *node, DBNode **root)
+static void db_rotate_left(struct DBNode *node, struct DBNode **root)
{
- DBNode *y = node->right;
+ struct DBNode *y = node->right;
DB_COUNTSTAT(db_rotate_left);
// put the left of y at the right of node
@@ -413,12 +413,12 @@ static void db_rotate_left(DBNode *node, DBNode **root)
* @param node Node to be rotated
* @param root Pointer to the root of the tree
* @private
- * @see #db_rebalance(DBNode *,DBNode **)
- * @see #db_rebalance_erase(DBNode *,DBNode **)
+ * @see #db_rebalance()
+ * @see #db_rebalance_erase()
*/
-static void db_rotate_right(DBNode *node, DBNode **root)
+static void db_rotate_right(struct DBNode *node, struct DBNode **root)
{
- DBNode *y = node->left;
+ struct DBNode *y = node->left;
DB_COUNTSTAT(db_rotate_right);
// put the right of y at the left of node
@@ -445,13 +445,13 @@ static void db_rotate_right(DBNode *node, DBNode **root)
* @param node Node to be rebalanced
* @param root Pointer to the root of the tree
* @private
- * @see #db_rotate_left(DBNode *,DBNode **)
- * @see #db_rotate_right(DBNode *,DBNode **)
- * @see #db_obj_put(DBMap*,DBKey,DBData)
+ * @see #db_rotate_left()
+ * @see #db_rotate_right()
+ * @see #db_obj_put()
*/
-static void db_rebalance(DBNode *node, DBNode **root)
+static void db_rebalance(struct DBNode *node, struct DBNode **root)
{
- DBNode *y;
+ struct DBNode *y;
DB_COUNTSTAT(db_rebalance);
// Restore the RED-BLACK properties
@@ -507,15 +507,15 @@ static void db_rebalance(DBNode *node, DBNode **root)
* @param node Node to be erased from the tree
* @param root Root of the tree
* @private
- * @see #db_rotate_left(DBNode *,DBNode **)
- * @see #db_rotate_right(DBNode *,DBNode **)
- * @see #db_free_unlock(DBMap_impl*)
+ * @see #db_rotate_left()
+ * @see #db_rotate_right()
+ * @see #db_free_unlock()
*/
-static void db_rebalance_erase(DBNode *node, DBNode **root)
+static void db_rebalance_erase(struct DBNode *node, struct DBNode **root)
{
- DBNode *y = node;
- DBNode *x = NULL;
- DBNode *x_parent = NULL;
+ struct DBNode *y = node;
+ struct DBNode *x = NULL;
+ struct DBNode *x_parent = NULL;
DB_COUNTSTAT(db_rebalance_erase);
// Select where to change the tree
@@ -561,7 +561,7 @@ static void db_rebalance_erase(DBNode *node, DBNode **root)
y->parent = node->parent;
// switch colors
{
- node_color tmp = y->color;
+ enum DBNodeColor tmp = y->color;
y->color = node->color;
node->color = tmp;
}
@@ -583,7 +583,7 @@ static void db_rebalance_erase(DBNode *node, DBNode **root)
// Restore the RED-BLACK properties
if (y->color != RED) {
while (x != *root && (x == NULL || x->color == BLACK)) {
- DBNode *w;
+ struct DBNode *w;
if (x == x_parent->left) {
w = x_parent->right;
if (w->color == RED) {
@@ -648,11 +648,11 @@ static void db_rebalance_erase(DBNode *node, DBNode **root)
* @param key Key being tested
* @return not 0 if considered NULL, 0 otherwise
* @private
- * @see #db_obj_get(DBMap*,DBKey)
- * @see #db_obj_put(DBMap*,DBKey,DBData)
- * @see #db_obj_remove(DBMap*,DBKey)
+ * @see #db_obj_get()
+ * @see #db_obj_put()
+ * @see #db_obj_remove()
*/
-static int db_is_key_null(DBType type, DBKey key)
+static int db_is_key_null(enum DBType type, union DBKey key)
{
DB_COUNTSTAT(db_is_key_null);
switch (type) {
@@ -671,26 +671,26 @@ static int db_is_key_null(DBType type, DBKey key)
* @param key Key to be duplicated
* @param Duplicated key
* @private
- * @see #db_free_add(DBMap_impl*,DBNode *,DBNode **)
- * @see #db_free_remove(DBMap_impl*,DBNode *)
- * @see #db_obj_put(DBMap*,DBKey,void *)
- * @see #db_dup_key_free(DBMap_impl*,DBKey)
+ * @see #db_free_add()
+ * @see #db_free_remove()
+ * @see #db_obj_put()
+ * @see #db_dup_key_free()
*/
-static DBKey db_dup_key(DBMap_impl* db, DBKey key)
+static union DBKey db_dup_key(struct DBMap_impl *db, union DBKey key)
{
- char *str;
- size_t len;
-
DB_COUNTSTAT(db_dup_key);
switch (db->type) {
case DB_STRING:
case DB_ISTRING:
- len = strnlen(key.str, db->maxlen);
- str = (char*)aMalloc(len + 1);
+ {
+ size_t len = strnlen(key.str, db->maxlen);
+ char *str = aMalloc(len + 1);
+
memcpy(str, key.str, len);
str[len] = '\0';
- key.str = str;
+ key.mutstr = str;
return key;
+ }
default:
return key;
@@ -702,15 +702,15 @@ static DBKey db_dup_key(DBMap_impl* db, DBKey key)
* @param db Database the key is being used in
* @param key Key to be freed
* @private
- * @see #db_dup_key(DBMap_impl*,DBKey)
+ * @see #db_dup_key()
*/
-static void db_dup_key_free(DBMap_impl* db, DBKey key)
+static void db_dup_key_free(struct DBMap_impl *db, union DBKey key)
{
DB_COUNTSTAT(db_dup_key_free);
switch (db->type) {
case DB_STRING:
case DB_ISTRING:
- aFree((char*)key.str);
+ aFree(key.mutstr);
return;
default:
@@ -727,15 +727,15 @@ static void db_dup_key_free(DBMap_impl* db, DBKey key)
* @param node Target node
* @private
* @see #struct db_free
- * @see DBMap_impl#free_list
- * @see DBMap_impl#free_count
- * @see DBMap_impl#free_max
- * @see #db_obj_remove(DBMap*,DBKey)
- * @see #db_free_remove(DBMap_impl*,DBNode *)
+ * @see struct DBMap_impl#free_list
+ * @see struct DBMap_impl#free_count
+ * @see struct DBMap_impl#free_max
+ * @see #db_obj_remove()
+ * @see #db_free_remove()
*/
-static void db_free_add(DBMap_impl* db, DBNode *node, DBNode **root)
+static void db_free_add(struct DBMap_impl *db, struct DBNode *node, struct DBNode **root)
{
- DBKey old_key;
+ union DBKey old_key;
DB_COUNTSTAT(db_free_add);
if (db->free_lock == (unsigned int)~0) {
@@ -777,12 +777,12 @@ static void db_free_add(DBMap_impl* db, DBNode *node, DBNode **root)
* @param node Node being removed from free_list
* @private
* @see #struct db_free
- * @see DBMap_impl#free_list
- * @see DBMap_impl#free_count
- * @see #db_obj_put(DBMap*,DBKey,DBData)
- * @see #db_free_add(DBMap_impl*,DBNode**,DBNode*)
+ * @see struct DBMap_impl#free_list
+ * @see struct DBMap_impl#free_count
+ * @see #db_obj_put()
+ * @see #db_free_add()
*/
-static void db_free_remove(DBMap_impl* db, DBNode *node)
+static void db_free_remove(struct DBMap_impl *db, struct DBNode *node)
{
unsigned int i;
@@ -808,10 +808,10 @@ static void db_free_remove(DBMap_impl* db, DBNode *node)
* Increment the free_lock of the database.
* @param db Target database
* @private
- * @see DBMap_impl#free_lock
- * @see #db_unlock(DBMap_impl*)
+ * @see struct DBMap_impl#free_lock
+ * @see #db_unlock()
*/
-static void db_free_lock(DBMap_impl* db)
+static void db_free_lock(struct DBMap_impl *db)
{
DB_COUNTSTAT(db_free_lock);
if (db->free_lock == (unsigned int)~0) {
@@ -830,11 +830,11 @@ static void db_free_lock(DBMap_impl* db)
* NOTE: Frees the duplicated keys of the nodes
* @param db Target database
* @private
- * @see DBMap_impl#free_lock
- * @see #db_free_dbn(DBNode*)
- * @see #db_lock(DBMap_impl*)
+ * @see struct DBMap_impl#free_lock
+ * @see #db_free_dbn()
+ * @see #db_lock()
*/
-static void db_free_unlock(DBMap_impl* db)
+static void db_free_unlock(struct DBMap_impl *db)
{
unsigned int i;
@@ -889,11 +889,11 @@ static void db_free_unlock(DBMap_impl* db)
* @param key2 Key being compared to
* @param maxlen Maximum length of the key to hash
* @return 0 if equal, negative if lower and positive if higher
- * @see DBType#DB_INT
+ * @see enum DBType#DB_INT
* @see #DBComparator
- * @see #db_default_cmp(DBType)
+ * @see #db_default_cmp()
*/
-static int db_int_cmp(DBKey key1, DBKey key2, unsigned short maxlen)
+static int db_int_cmp(union DBKey key1, union DBKey key2, unsigned short maxlen)
{
(void)maxlen;//not used
DB_COUNTSTAT(db_int_cmp);
@@ -911,11 +911,11 @@ static int db_int_cmp(DBKey key1, DBKey key2, unsigned short maxlen)
* @param key2 Key being compared to
* @param maxlen Maximum length of the key to hash
* @return 0 if equal, negative if lower and positive if higher
- * @see DBType#DB_UINT
+ * @see enum DBType#DB_UINT
* @see #DBComparator
- * @see #db_default_cmp(DBType)
+ * @see #db_default_cmp()
*/
-static int db_uint_cmp(DBKey key1, DBKey key2, unsigned short maxlen)
+static int db_uint_cmp(union DBKey key1, union DBKey key2, unsigned short maxlen)
{
(void)maxlen;//not used
DB_COUNTSTAT(db_uint_cmp);
@@ -932,11 +932,11 @@ static int db_uint_cmp(DBKey key1, DBKey key2, unsigned short maxlen)
* @param key2 Key being compared to
* @param maxlen Maximum length of the key to hash
* @return 0 if equal, negative if lower and positive if higher
- * @see DBType#DB_STRING
+ * @see enum DBType#DB_STRING
* @see #DBComparator
- * @see #db_default_cmp(DBType)
+ * @see #db_default_cmp()
*/
-static int db_string_cmp(DBKey key1, DBKey key2, unsigned short maxlen)
+static int db_string_cmp(union DBKey key1, union DBKey key2, unsigned short maxlen)
{
DB_COUNTSTAT(db_string_cmp);
return strncmp((const char *)key1.str, (const char *)key2.str, maxlen);
@@ -950,11 +950,11 @@ static int db_string_cmp(DBKey key1, DBKey key2, unsigned short maxlen)
* @param key2 Key being compared to
* @param maxlen Maximum length of the key to hash
* @return 0 if equal, negative if lower and positive if higher
- * @see DBType#DB_ISTRING
+ * @see enum DBType#DB_ISTRING
* @see #DBComparator
- * @see #db_default_cmp(DBType)
+ * @see #db_default_cmp()
*/
-static int db_istring_cmp(DBKey key1, DBKey key2, unsigned short maxlen)
+static int db_istring_cmp(union DBKey key1, union DBKey key2, unsigned short maxlen)
{
DB_COUNTSTAT(db_istring_cmp);
return strncasecmp((const char *)key1.str, (const char *)key2.str, maxlen);
@@ -969,11 +969,11 @@ static int db_istring_cmp(DBKey key1, DBKey key2, unsigned short maxlen)
* @param key2 Key being compared to
* @param maxlen Maximum length of the key to hash
* @return 0 if equal, negative if lower and positive if higher
- * @see DBType#DB_INT64
+ * @see enum DBType#DB_INT64
* @see #DBComparator
- * @see #db_default_cmp(DBType)
+ * @see #db_default_cmp()
*/
-static int db_int64_cmp(DBKey key1, DBKey key2, unsigned short maxlen)
+static int db_int64_cmp(union DBKey key1, union DBKey key2, unsigned short maxlen)
{
(void)maxlen;//not used
DB_COUNTSTAT(db_int64_cmp);
@@ -991,11 +991,11 @@ static int db_int64_cmp(DBKey key1, DBKey key2, unsigned short maxlen)
* @param key2 Key being compared to
* @param maxlen Maximum length of the key to hash
* @return 0 if equal, negative if lower and positive if higher
- * @see DBType#DB_UINT64
+ * @see enum DBType#DB_UINT64
* @see #DBComparator
- * @see #db_default_cmp(DBType)
+ * @see #db_default_cmp()
*/
-static int db_uint64_cmp(DBKey key1, DBKey key2, unsigned short maxlen)
+static int db_uint64_cmp(union DBKey key1, union DBKey key2, unsigned short maxlen)
{
(void)maxlen;//not used
DB_COUNTSTAT(db_uint64_cmp);
@@ -1012,11 +1012,11 @@ static int db_uint64_cmp(DBKey key1, DBKey key2, unsigned short maxlen)
* @param key Key to be hashed
* @param maxlen Maximum length of the key to hash
* @return hash of the key
- * @see DBType#DB_INT
+ * @see enum DBType#DB_INT
* @see #DBHasher
- * @see #db_default_hash(DBType)
+ * @see #db_default_hash()
*/
-static uint64 db_int_hash(DBKey key, unsigned short maxlen)
+static uint64 db_int_hash(union DBKey key, unsigned short maxlen)
{
(void)maxlen;//not used
DB_COUNTSTAT(db_int_hash);
@@ -1030,11 +1030,11 @@ static uint64 db_int_hash(DBKey key, unsigned short maxlen)
* @param key Key to be hashed
* @param maxlen Maximum length of the key to hash
* @return hash of the key
- * @see DBType#DB_UINT
+ * @see enum DBType#DB_UINT
* @see #DBHasher
- * @see #db_default_hash(DBType)
+ * @see #db_default_hash()
*/
-static uint64 db_uint_hash(DBKey key, unsigned short maxlen)
+static uint64 db_uint_hash(union DBKey key, unsigned short maxlen)
{
(void)maxlen;//not used
DB_COUNTSTAT(db_uint_hash);
@@ -1046,11 +1046,11 @@ static uint64 db_uint_hash(DBKey key, unsigned short maxlen)
* @param key Key to be hashed
* @param maxlen Maximum length of the key to hash
* @return hash of the key
- * @see DBType#DB_STRING
+ * @see enum DBType#DB_STRING
* @see #DBHasher
- * @see #db_default_hash(DBType)
+ * @see #db_default_hash()
*/
-static uint64 db_string_hash(DBKey key, unsigned short maxlen)
+static uint64 db_string_hash(union DBKey key, unsigned short maxlen)
{
const char *k = key.str;
unsigned int hash = 0;
@@ -1073,10 +1073,10 @@ static uint64 db_string_hash(DBKey key, unsigned short maxlen)
* @param key Key to be hashed
* @param maxlen Maximum length of the key to hash
* @return hash of the key
- * @see DBType#DB_ISTRING
- * @see #db_default_hash(DBType)
+ * @see enum DBType#DB_ISTRING
+ * @see #db_default_hash()
*/
-static uint64 db_istring_hash(DBKey key, unsigned short maxlen)
+static uint64 db_istring_hash(union DBKey key, unsigned short maxlen)
{
const char *k = key.str;
unsigned int hash = 0;
@@ -1101,11 +1101,11 @@ static uint64 db_istring_hash(DBKey key, unsigned short maxlen)
* @param key Key to be hashed
* @param maxlen Maximum length of the key to hash
* @return hash of the key
- * @see DBType#DB_INT64
+ * @see enum DBType#DB_INT64
* @see #DBHasher
- * @see #db_default_hash(DBType)
+ * @see #db_default_hash()
*/
-static uint64 db_int64_hash(DBKey key, unsigned short maxlen)
+static uint64 db_int64_hash(union DBKey key, unsigned short maxlen)
{
(void)maxlen;//not used
DB_COUNTSTAT(db_int64_hash);
@@ -1119,11 +1119,11 @@ static uint64 db_int64_hash(DBKey key, unsigned short maxlen)
* @param key Key to be hashed
* @param maxlen Maximum length of the key to hash
* @return hash of the key
- * @see DBType#DB_UINT64
+ * @see enum DBType#DB_UINT64
* @see #DBHasher
- * @see #db_default_hash(DBType)
+ * @see #db_default_hash()
*/
-static uint64 db_uint64_hash(DBKey key, unsigned short maxlen)
+static uint64 db_uint64_hash(union DBKey key, unsigned short maxlen)
{
(void)maxlen;//not used
DB_COUNTSTAT(db_uint64_hash);
@@ -1137,9 +1137,9 @@ static uint64 db_uint64_hash(DBKey key, unsigned short maxlen)
* @param which What is being requested to be released
* @protected
* @see #DBReleaser
- * @see #db_default_releaser(DBType,DBOptions)
+ * @see #db_default_releaser()
*/
-static void db_release_nothing(DBKey key, DBData data, DBRelease which)
+static void db_release_nothing(union DBKey key, struct DBData data, enum DBReleaseOption which)
{
(void)key;(void)data;(void)which;//not used
DB_COUNTSTAT(db_release_nothing);
@@ -1152,13 +1152,14 @@ static void db_release_nothing(DBKey key, DBData data, DBRelease which)
* @param which What is being requested to be released
* @protected
* @see #DBReleaser
- * @see #db_default_release(DBType,DBOptions)
+ * @see #db_default_release()
*/
-static void db_release_key(DBKey key, DBData data, DBRelease which)
+static void db_release_key(union DBKey key, struct DBData data, enum DBReleaseOption which)
{
(void)data;//not used
DB_COUNTSTAT(db_release_key);
- if (which&DB_RELEASE_KEY) aFree((char*)key.str); // needs to be a pointer
+ if (which&DB_RELEASE_KEY)
+ aFree(key.mutstr); // FIXME: Ensure this is the right db type.
}
/**
@@ -1167,12 +1168,12 @@ static void db_release_key(DBKey key, DBData data, DBRelease which)
* @param data Data of the database entry
* @param which What is being requested to be released
* @protected
- * @see #DBData
- * @see #DBRelease
+ * @see struct DBData
+ * @see enum DBReleaseOption
* @see #DBReleaser
- * @see #db_default_release(DBType,DBOptions)
+ * @see #db_default_release()
*/
-static void db_release_data(DBKey key, DBData data, DBRelease which)
+static void db_release_data(union DBKey key, struct DBData data, enum DBReleaseOption which)
{
(void)key;//not used
DB_COUNTSTAT(db_release_data);
@@ -1188,16 +1189,17 @@ static void db_release_data(DBKey key, DBData data, DBRelease which)
* @param data Data of the database entry
* @param which What is being requested to be released
* @protected
- * @see #DBKey
- * @see #DBData
- * @see #DBRelease
+ * @see union DBKey
+ * @see struct DBData
+ * @see enum DBReleaseOption
* @see #DBReleaser
- * @see #db_default_release(DBType,DBOptions)
+ * @see #db_default_release()
*/
-static void db_release_both(DBKey key, DBData data, DBRelease which)
+static void db_release_both(union DBKey key, struct DBData data, enum DBReleaseOption which)
{
DB_COUNTSTAT(db_release_both);
- if (which&DB_RELEASE_KEY) aFree((char*)key.str); // needs to be a pointer
+ if (which&DB_RELEASE_KEY)
+ aFree(key.mutstr); // FIXME: Ensure this is the right db type.
if (which&DB_RELEASE_DATA && data.type == DB_DATA_PTR) {
aFree(data.u.ptr);
data.u.ptr = NULL;
@@ -1245,11 +1247,11 @@ static void db_release_both(DBKey key, DBData data, DBRelease which)
* @param out_key Key of the entry
* @return Data of the entry
* @protected
- * @see DBIterator#first
+ * @see struct DBIterator#first()
*/
-DBData* dbit_obj_first(DBIterator* self, DBKey* out_key)
+struct DBData *dbit_obj_first(struct DBIterator *self, union DBKey *out_key)
{
- DBIterator_impl* it = (DBIterator_impl*)self;
+ struct DBIterator_impl *it = (struct DBIterator_impl *)self;
DB_COUNTSTAT(dbit_first);
// position before the first entry
@@ -1267,11 +1269,11 @@ DBData* dbit_obj_first(DBIterator* self, DBKey* out_key)
* @param out_key Key of the entry
* @return Data of the entry
* @protected
- * @see DBIterator#last
+ * @see struct DBIterator#last()
*/
-DBData* dbit_obj_last(DBIterator* self, DBKey* out_key)
+struct DBData *dbit_obj_last(struct DBIterator *self, union DBKey *out_key)
{
- DBIterator_impl* it = (DBIterator_impl*)self;
+ struct DBIterator_impl *it = (struct DBIterator_impl *)self;
DB_COUNTSTAT(dbit_last);
// position after the last entry
@@ -1289,14 +1291,14 @@ DBData* dbit_obj_last(DBIterator* self, DBKey* out_key)
* @param out_key Key of the entry
* @return Data of the entry
* @protected
- * @see DBIterator#next
+ * @see struct DBIterator#next()
*/
-DBData* dbit_obj_next(DBIterator* self, DBKey* out_key)
+struct DBData *dbit_obj_next(struct DBIterator *self, union DBKey *out_key)
{
- DBIterator_impl* it = (DBIterator_impl*)self;
- DBNode *node;
- DBNode *parent;
- struct dbn fake;
+ struct DBIterator_impl *it = (struct DBIterator_impl *)self;
+ struct DBNode *node;
+ struct DBNode *parent;
+ struct DBNode fake;
DB_COUNTSTAT(dbit_next);
if( it->ht_index < 0 )
@@ -1348,7 +1350,7 @@ DBData* dbit_obj_next(DBIterator* self, DBKey* out_key)
{// found next entry
it->node = node;
if( out_key )
- memcpy(out_key, &node->key, sizeof(DBKey));
+ memcpy(out_key, &node->key, sizeof(union DBKey));
return &node->data;
}
}
@@ -1365,14 +1367,14 @@ DBData* dbit_obj_next(DBIterator* self, DBKey* out_key)
* @param out_key Key of the entry
* @return Data of the entry
* @protected
- * @see DBIterator#prev
+ * @see struct DBIterator#prev()
*/
-DBData* dbit_obj_prev(DBIterator* self, DBKey* out_key)
+struct DBData *dbit_obj_prev(struct DBIterator *self, union DBKey *out_key)
{
- DBIterator_impl* it = (DBIterator_impl*)self;
- DBNode *node;
- DBNode *parent;
- struct dbn fake;
+ struct DBIterator_impl *it = (struct DBIterator_impl *)self;
+ struct DBNode *node;
+ struct DBNode *parent;
+ struct DBNode fake;
DB_COUNTSTAT(dbit_prev);
if( it->ht_index >= HASH_SIZE )
@@ -1424,7 +1426,7 @@ DBData* dbit_obj_prev(DBIterator* self, DBKey* out_key)
{// found previous entry
it->node = node;
if( out_key )
- memcpy(out_key, &node->key, sizeof(DBKey));
+ memcpy(out_key, &node->key, sizeof(union DBKey));
return &node->data;
}
}
@@ -1440,11 +1442,11 @@ DBData* dbit_obj_prev(DBIterator* self, DBKey* out_key)
* @param self Iterator
* @return true if the entry exists
* @protected
- * @see DBIterator#exists
+ * @see struct DBIterator#exists()
*/
-bool dbit_obj_exists(DBIterator* self)
+bool dbit_obj_exists(struct DBIterator *self)
{
- DBIterator_impl* it = (DBIterator_impl*)self;
+ struct DBIterator_impl *it = (struct DBIterator_impl *)self;
DB_COUNTSTAT(dbit_exists);
return (it->node && !it->node->deleted);
@@ -1452,32 +1454,34 @@ bool dbit_obj_exists(DBIterator* self)
/**
* Removes the current entry from the database.
- * NOTE: {@link DBIterator#exists} will return false until another entry
- * is fetched
+ *
+ * NOTE: struct DBIterator#exists() will return false until another entry is
+ * fetched.
+ *
* Puts data of the removed entry in out_data, if out_data is not NULL (unless data has been released)
* @param self Iterator
* @param out_data Data of the removed entry.
* @return 1 if entry was removed, 0 otherwise
* @protected
- * @see DBMap#remove
- * @see DBIterator#remove
+ * @see struct DBMap#remove()
+ * @see struct DBIterator#remove()
*/
-int dbit_obj_remove(DBIterator* self, DBData *out_data)
+int dbit_obj_remove(struct DBIterator *self, struct DBData *out_data)
{
- DBIterator_impl* it = (DBIterator_impl*)self;
- DBNode *node;
+ struct DBIterator_impl *it = (struct DBIterator_impl *)self;
+ struct DBNode *node;
int retval = 0;
DB_COUNTSTAT(dbit_remove);
node = it->node;
if( node && !node->deleted )
{
- DBMap_impl* db = it->db;
+ struct DBMap_impl *db = it->db;
if( db->cache == node )
db->cache = NULL;
db->release(node->key, node->data, DB_RELEASE_DATA);
if( out_data )
- memcpy(out_data, &node->data, sizeof(DBData));
+ memcpy(out_data, &node->data, sizeof(struct DBData));
retval = 1;
db_free_add(db, node, &db->ht[it->ht_index]);
}
@@ -1489,9 +1493,9 @@ int dbit_obj_remove(DBIterator* self, DBData *out_data)
* @param self Iterator
* @protected
*/
-void dbit_obj_destroy(DBIterator* self)
+void dbit_obj_destroy(struct DBIterator *self)
{
- DBIterator_impl* it = (DBIterator_impl*)self;
+ struct DBIterator_impl *it = (struct DBIterator_impl *)self;
DB_COUNTSTAT(dbit_destroy);
// unlock the database
@@ -1509,10 +1513,10 @@ void dbit_obj_destroy(DBIterator* self)
* @return New iterator
* @protected
*/
-static DBIterator* db_obj_iterator(DBMap* self)
+static struct DBIterator *db_obj_iterator(struct DBMap *self)
{
- DBMap_impl* db = (DBMap_impl*)self;
- DBIterator_impl* it;
+ struct DBMap_impl *db = (struct DBMap_impl *)self;
+ struct DBIterator_impl *it;
DB_COUNTSTAT(db_iterator);
it = ers_alloc(db_iterator_ers, struct DBIterator_impl);
@@ -1539,12 +1543,12 @@ static DBIterator* db_obj_iterator(DBMap* self)
* @param key Key that identifies the entry
* @return true is the entry exists
* @protected
- * @see DBMap#exists
+ * @see struct DBMap#exists()
*/
-static bool db_obj_exists(DBMap* self, DBKey key)
+static bool db_obj_exists(struct DBMap *self, union DBKey key)
{
- DBMap_impl* db = (DBMap_impl*)self;
- DBNode *node;
+ struct DBMap_impl *db = (struct DBMap_impl *)self;
+ struct DBNode *node;
bool found = false;
DB_COUNTSTAT(db_exists);
@@ -1589,13 +1593,13 @@ static bool db_obj_exists(DBMap* self, DBKey key)
* @param key Key that identifies the entry
* @return Data of the entry or NULL if not found
* @protected
- * @see DBMap#get
+ * @see struct DBMap#get()
*/
-static DBData* db_obj_get(DBMap* self, DBKey key)
+static struct DBData *db_obj_get(struct DBMap *self, union DBKey key)
{
- DBMap_impl* db = (DBMap_impl*)self;
- DBNode *node;
- DBData *data = NULL;
+ struct DBMap_impl *db = (struct DBMap_impl *)self;
+ struct DBNode *node;
+ struct DBData *data = NULL;
DB_COUNTSTAT(db_get);
if (db == NULL) return NULL; // nullpo candidate
@@ -1648,14 +1652,14 @@ static DBData* db_obj_get(DBMap* self, DBKey key)
* @param ... Extra arguments for match
* @return The number of entries that matched
* @protected
- * @see DBMap#vgetall
+ * @see struct DBMap#vgetall()
*/
-static unsigned int db_obj_vgetall(DBMap* self, DBData **buf, unsigned int max, DBMatcher match, va_list args)
+static unsigned int db_obj_vgetall(struct DBMap *self, struct DBData **buf, unsigned int max, DBMatcher match, va_list args)
{
- DBMap_impl* db = (DBMap_impl*)self;
+ struct DBMap_impl *db = (struct DBMap_impl *)self;
unsigned int i;
- DBNode *node;
- DBNode *parent;
+ struct DBNode *node;
+ struct DBNode *parent;
unsigned int ret = 0;
DB_COUNTSTAT(db_vgetall);
@@ -1705,7 +1709,8 @@ static unsigned int db_obj_vgetall(DBMap* self, DBData **buf, unsigned int max,
}
/**
- * Just calls {@link DBMap#vgetall}.
+ * Just calls struct DBMap#vgetall().
+ *
* Get the data of the entries matched by <code>match</code>.
* It puts a maximum of <code>max</code> entries into <code>buf</code>.
* If <code>buf</code> is NULL, it only counts the matches.
@@ -1719,10 +1724,10 @@ static unsigned int db_obj_vgetall(DBMap* self, DBData **buf, unsigned int max,
* @param ... Extra arguments for match
* @return The number of entries that matched
* @protected
- * @see DBMap#vgetall
- * @see DBMap#getall
+ * @see struct DBMap#vgetall()
+ * @see struct DBMap#getall()
*/
-static unsigned int db_obj_getall(DBMap* self, DBData **buf, unsigned int max, DBMatcher match, ...)
+static unsigned int db_obj_getall(struct DBMap *self, struct DBData **buf, unsigned int max, DBMatcher match, ...)
{
va_list args;
unsigned int ret;
@@ -1746,16 +1751,16 @@ static unsigned int db_obj_getall(DBMap* self, DBData **buf, unsigned int max, D
* @param args Extra arguments for create
* @return Data of the entry
* @protected
- * @see DBMap#vensure
+ * @see struct DBMap#vensure()
*/
-static DBData* db_obj_vensure(DBMap* self, DBKey key, DBCreateData create, va_list args)
+static struct DBData *db_obj_vensure(struct DBMap *self, union DBKey key, DBCreateData create, va_list args)
{
- DBMap_impl* db = (DBMap_impl*)self;
- DBNode *node;
- DBNode *parent = NULL;
+ struct DBMap_impl *db = (struct DBMap_impl *)self;
+ struct DBNode *node;
+ struct DBNode *parent = NULL;
unsigned int hash;
int c = 0;
- DBData *data = NULL;
+ struct DBData *data = NULL;
DB_COUNTSTAT(db_vensure);
if (db == NULL) return NULL; // nullpo candidate
@@ -1795,7 +1800,7 @@ static DBData* db_obj_vensure(DBMap* self, DBKey key, DBCreateData create, va_li
return NULL;
}
DB_COUNTSTAT(db_node_alloc);
- node = ers_alloc(db->nodes, struct dbn);
+ node = ers_alloc(db->nodes, struct DBNode);
node->left = NULL;
node->right = NULL;
node->deleted = 0;
@@ -1835,7 +1840,8 @@ static DBData* db_obj_vensure(DBMap* self, DBKey key, DBCreateData create, va_li
}
/**
- * Just calls {@link DBMap#vensure}.
+ * Just calls struct DBMap#vensure().
+ *
* Get the data of the entry identified by the key.
* If the entry does not exist, an entry is added with the data returned by
* <code>create</code>.
@@ -1845,13 +1851,13 @@ static DBData* db_obj_vensure(DBMap* self, DBKey key, DBCreateData create, va_li
* @param ... Extra arguments for create
* @return Data of the entry
* @protected
- * @see DBMap#vensure
- * @see DBMap#ensure
+ * @see struct DBMap#vensure()
+ * @see struct DBMap#ensure()
*/
-static DBData* db_obj_ensure(DBMap* self, DBKey key, DBCreateData create, ...)
+static struct DBData *db_obj_ensure(struct DBMap *self, union DBKey key, DBCreateData create, ...)
{
va_list args;
- DBData *ret = NULL;
+ struct DBData *ret = NULL;
DB_COUNTSTAT(db_ensure);
if (self == NULL) return NULL; // nullpo candidate
@@ -1873,15 +1879,15 @@ static DBData* db_obj_ensure(DBMap* self, DBKey key, DBCreateData create, ...)
* @return 1 if if the entry already exists, 0 otherwise
* @protected
* @see #db_malloc_dbn(void)
- * @see DBMap#put
+ * @see struct DBMap#put()
* FIXME: If this method fails shouldn't it return another value?
* Other functions rely on this to know if they were able to put something [Panikon]
*/
-static int db_obj_put(DBMap* self, DBKey key, DBData data, DBData *out_data)
+static int db_obj_put(struct DBMap *self, union DBKey key, struct DBData data, struct DBData *out_data)
{
- DBMap_impl* db = (DBMap_impl*)self;
- DBNode *node;
- DBNode *parent = NULL;
+ struct DBMap_impl *db = (struct DBMap_impl *)self;
+ struct DBNode *node;
+ struct DBNode *parent = NULL;
int c = 0, retval = 0;
unsigned int hash;
@@ -1934,7 +1940,7 @@ static int db_obj_put(DBMap* self, DBKey key, DBData data, DBData *out_data)
// allocate a new node if necessary
if (node == NULL) {
DB_COUNTSTAT(db_node_alloc);
- node = ers_alloc(db->nodes, struct dbn);
+ node = ers_alloc(db->nodes, struct DBNode);
node->left = NULL;
node->right = NULL;
node->deleted = 0;
@@ -1973,19 +1979,19 @@ static int db_obj_put(DBMap* self, DBKey key, DBData data, DBData *out_data)
/**
* Remove an entry from the database.
* Puts the previous data in out_data, if out_data is not NULL. (unless data has been released)
- * NOTE: The key (of the database) is released in {@link #db_free_add(DBMap_impl*,DBNode*,DBNode **)}.
+ * NOTE: The key (of the database) is released in #db_free_add().
* @param self Interface of the database
* @param key Key that identifies the entry
* @param out_data Previous data if the entry exists
* @return 1 if if the entry already exists, 0 otherwise
* @protected
- * @see #db_free_add(DBMap_impl*,DBNode*,DBNode **)
- * @see DBMap#remove
+ * @see #db_free_add()
+ * @see struct DBMap#remove()
*/
-static int db_obj_remove(DBMap* self, DBKey key, DBData *out_data)
+static int db_obj_remove(struct DBMap *self, union DBKey key, struct DBData *out_data)
{
- DBMap_impl* db = (DBMap_impl*)self;
- DBNode *node;
+ struct DBMap_impl *db = (struct DBMap_impl *)self;
+ struct DBNode *node;
unsigned int hash;
int retval = 0;
@@ -2035,15 +2041,15 @@ static int db_obj_remove(DBMap* self, DBKey key, DBData *out_data)
* @param args Extra arguments for func
* @return Sum of the values returned by func
* @protected
- * @see DBMap#vforeach
+ * @see struct DBMap#vforeach()
*/
-static int db_obj_vforeach(DBMap* self, DBApply func, va_list args)
+static int db_obj_vforeach(struct DBMap *self, DBApply func, va_list args)
{
- DBMap_impl* db = (DBMap_impl*)self;
+ struct DBMap_impl *db = (struct DBMap_impl *)self;
unsigned int i;
int sum = 0;
- DBNode *node;
- DBNode *parent;
+ struct DBNode *node;
+ struct DBNode *parent;
DB_COUNTSTAT(db_vforeach);
if (db == NULL) return 0; // nullpo candidate
@@ -2086,7 +2092,8 @@ static int db_obj_vforeach(DBMap* self, DBApply func, va_list args)
}
/**
- * Just calls {@link DBMap#vforeach}.
+ * Just calls struct DBMap#vforeach().
+ *
* Apply <code>func</code> to every entry in the database.
* Returns the sum of values returned by func.
* @param self Interface of the database
@@ -2094,10 +2101,10 @@ static int db_obj_vforeach(DBMap* self, DBApply func, va_list args)
* @param ... Extra arguments for func
* @return Sum of the values returned by func
* @protected
- * @see DBMap#vforeach
- * @see DBMap#foreach
+ * @see struct DBMap#vforeach()
+ * @see struct DBMap#foreach()
*/
-static int db_obj_foreach(DBMap* self, DBApply func, ...)
+static int db_obj_foreach(struct DBMap *self, DBApply func, ...)
{
va_list args;
int ret;
@@ -2121,15 +2128,15 @@ static int db_obj_foreach(DBMap* self, DBApply func, ...)
* @param args Extra arguments for func
* @return Sum of values returned by func
* @protected
- * @see DBMap#vclear
+ * @see struct DBMap#vclear()
*/
-static int db_obj_vclear(DBMap* self, DBApply func, va_list args)
+static int db_obj_vclear(struct DBMap *self, DBApply func, va_list args)
{
- DBMap_impl* db = (DBMap_impl*)self;
+ struct DBMap_impl *db = (struct DBMap_impl *)self;
int sum = 0;
unsigned int i;
- DBNode *node;
- DBNode *parent;
+ struct DBNode *node;
+ struct DBNode *parent;
DB_COUNTSTAT(db_vclear);
if (db == NULL) return 0; // nullpo candidate
@@ -2182,7 +2189,8 @@ static int db_obj_vclear(DBMap* self, DBApply func, va_list args)
}
/**
- * Just calls {@link DBMap#vclear}.
+ * Just calls struct DBMap#vclear().
+ *
* Removes all entries from the database.
* Before deleting an entry, func is applied to it.
* Releases the key and the data.
@@ -2194,10 +2202,10 @@ static int db_obj_vclear(DBMap* self, DBApply func, va_list args)
* @param ... Extra arguments for func
* @return Sum of values returned by func
* @protected
- * @see DBMap#vclear
- * @see DBMap#clear
+ * @see struct DBMap#vclear()
+ * @see struct DBMap#clear()
*/
-static int db_obj_clear(DBMap* self, DBApply func, ...)
+static int db_obj_clear(struct DBMap *self, DBApply func, ...)
{
va_list args;
int ret;
@@ -2222,11 +2230,11 @@ static int db_obj_clear(DBMap* self, DBApply func, ...)
* @param args Extra arguments for func
* @return Sum of values returned by func
* @protected
- * @see DBMap#vdestroy
+ * @see struct DBMap#vdestroy()
*/
-static int db_obj_vdestroy(DBMap* self, DBApply func, va_list args)
+static int db_obj_vdestroy(struct DBMap *self, DBApply func, va_list args)
{
- DBMap_impl* db = (DBMap_impl*)self;
+ struct DBMap_impl *db = (struct DBMap_impl *)self;
int sum;
DB_COUNTSTAT(db_vdestroy);
@@ -2265,7 +2273,7 @@ static int db_obj_vdestroy(DBMap* self, DBApply func, va_list args)
}
/**
- * Just calls {@link DBMap#db_vdestroy}.
+ * Just calls struct DBMap#db_vdestroy().
* Finalize the database, feeing all the memory it uses.
* Before deleting an entry, func is applied to it.
* Releases the key and the data.
@@ -2277,10 +2285,10 @@ static int db_obj_vdestroy(DBMap* self, DBApply func, va_list args)
* @param ... Extra arguments for func
* @return Sum of values returned by func
* @protected
- * @see DBMap#vdestroy
- * @see DBMap#destroy
+ * @see struct DBMap#vdestroy()
+ * @see struct DBMap#destroy()
*/
-static int db_obj_destroy(DBMap* self, DBApply func, ...)
+static int db_obj_destroy(struct DBMap *self, DBApply func, ...)
{
va_list args;
int ret;
@@ -2299,12 +2307,12 @@ static int db_obj_destroy(DBMap* self, DBApply func, ...)
* @param self Interface of the database
* @return Size of the database
* @protected
- * @see DBMap_impl#item_count
- * @see DBMap#size
+ * @see struct DBMap_impl#item_count
+ * @see struct DBMap#size()
*/
-static unsigned int db_obj_size(DBMap* self)
+static unsigned int db_obj_size(struct DBMap *self)
{
- DBMap_impl* db = (DBMap_impl*)self;
+ struct DBMap_impl *db = (struct DBMap_impl *)self;
unsigned int item_count;
DB_COUNTSTAT(db_size);
@@ -2322,16 +2330,17 @@ static unsigned int db_obj_size(DBMap* self)
* @param self Interface of the database
* @return Type of the database
* @protected
- * @see DBMap_impl#type
- * @see DBMap#type
+ * @see struct DBMap_impl#type
+ * @see struct DBMap#type()
*/
-static DBType db_obj_type(DBMap* self)
+static enum DBType db_obj_type(struct DBMap *self)
{
- DBMap_impl* db = (DBMap_impl*)self;
- DBType type;
+ struct DBMap_impl *db = (struct DBMap_impl *)self;
+ enum DBType type;
DB_COUNTSTAT(db_type);
- if (db == NULL) return (DBType)-1; // nullpo candidate - TODO what should this return?
+ if (db == NULL)
+ return (enum DBType)-1; // nullpo candidate - TODO what should this return?
db_free_lock(db);
type = db->type;
@@ -2345,13 +2354,13 @@ static DBType db_obj_type(DBMap* self)
* @param self Interface of the database
* @return Options of the database
* @protected
- * @see DBMap_impl#options
- * @see DBMap#options
+ * @see struct DBMap_impl#options
+ * @see struct DBMap#options()
*/
-static DBOptions db_obj_options(DBMap* self)
+static enum DBOptions db_obj_options(struct DBMap *self)
{
- DBMap_impl* db = (DBMap_impl*)self;
- DBOptions options;
+ struct DBMap_impl* db = (struct DBMap_impl *)self;
+ enum DBOptions options;
DB_COUNTSTAT(db_options);
if (db == NULL) return DB_OPT_BASE; // nullpo candidate - TODO what should this return?
@@ -2371,17 +2380,17 @@ static DBOptions db_obj_options(DBMap* self)
* db_default_release - Get the default releaser for a type of database with the specified options.
* db_custom_release - Get a releaser that behaves a certain way.
* db_alloc - Allocate a new database.
- * db_i2key - Manual cast from 'int' to 'DBKey'.
- * db_ui2key - Manual cast from 'unsigned int' to 'DBKey'.
- * db_str2key - Manual cast from 'unsigned char *' to 'DBKey'.
- * db_i642key - Manual cast from 'int64' to 'DBKey'.
- * db_ui642key - Manual cast from 'uin64' to 'DBKey'.
- * db_i2data - Manual cast from 'int' to 'DBData'.
- * db_ui2data - Manual cast from 'unsigned int' to 'DBData'.
- * db_ptr2data - Manual cast from 'void*' to 'DBData'.
- * db_data2i - Gets 'int' value from 'DBData'.
- * db_data2ui - Gets 'unsigned int' value from 'DBData'.
- * db_data2ptr - Gets 'void*' value from 'DBData'.
+ * db_i2key - Manual cast from `int` to `union DBKey`.
+ * db_ui2key - Manual cast from `unsigned int` to `union DBKey`.
+ * db_str2key - Manual cast from `unsigned char *` to `union DBKey`.
+ * db_i642key - Manual cast from `int64` to `union DBKey`.
+ * db_ui642key - Manual cast from `uin64` to `union DBKey`.
+ * db_i2data - Manual cast from `int` to `struct DBData`.
+ * db_ui2data - Manual cast from `unsigned int` to `struct DBData`.
+ * db_ptr2data - Manual cast from `void*` to `struct DBData`.
+ * db_data2i - Gets `int` value from `struct DBData`.
+ * db_data2ui - Gets `unsigned int` value from `struct DBData`.
+ * db_data2ptr - Gets `void*` value from `struct DBData`.
* db_init - Initializes the database system.
* db_final - Finalizes the database system.
\*****************************************************************************/
@@ -2394,10 +2403,10 @@ static DBOptions db_obj_options(DBMap* self)
* @param options Original options of the database
* @return Fixed options of the database
* @private
- * @see #db_default_release(DBType,DBOptions)
- * @see #db_alloc(const char *,int,DBType,DBOptions,unsigned short)
+ * @see #db_default_release()
+ * @see #db_alloc()
*/
-DBOptions db_fix_options(DBType type, DBOptions options)
+enum DBOptions db_fix_options(enum DBType type, enum DBOptions options)
{
DB_COUNTSTAT(db_fix_options);
switch (type) {
@@ -2405,7 +2414,7 @@ DBOptions db_fix_options(DBType type, DBOptions options)
case DB_UINT:
case DB_INT64:
case DB_UINT64: // Numeric database, do nothing with the keys
- return (DBOptions)(options&~(DB_OPT_DUP_KEY|DB_OPT_RELEASE_KEY));
+ return (enum DBOptions)(options&~(DB_OPT_DUP_KEY|DB_OPT_RELEASE_KEY));
default:
ShowError("db_fix_options: Unknown database type %u with options %x\n", type, options);
@@ -2420,14 +2429,14 @@ DBOptions db_fix_options(DBType type, DBOptions options)
* @param type Type of database
* @return Comparator for the type of database or NULL if unknown database
* @public
- * @see #db_int_cmp(DBKey,DBKey,unsigned short)
- * @see #db_uint_cmp(DBKey,DBKey,unsigned short)
- * @see #db_string_cmp(DBKey,DBKey,unsigned short)
- * @see #db_istring_cmp(DBKey,DBKey,unsigned short)
- * @see #db_int64_cmp(DBKey,DBKey,unsigned short)
- * @see #db_uint64_cmp(DBKey,DBKey,unsigned short)
+ * @see #db_int_cmp()
+ * @see #db_uint_cmp()
+ * @see #db_string_cmp()
+ * @see #db_istring_cmp()
+ * @see #db_int64_cmp()
+ * @see #db_uint64_cmp()
*/
-DBComparator db_default_cmp(DBType type)
+DBComparator db_default_cmp(enum DBType type)
{
DB_COUNTSTAT(db_default_cmp);
switch (type) {
@@ -2448,14 +2457,14 @@ DBComparator db_default_cmp(DBType type)
* @param type Type of database
* @return Hasher of the type of database or NULL if unknown database
* @public
- * @see #db_int_hash(DBKey,unsigned short)
- * @see #db_uint_hash(DBKey,unsigned short)
- * @see #db_string_hash(DBKey,unsigned short)
- * @see #db_istring_hash(DBKey,unsigned short)
- * @see #db_int64_hash(DBKey,unsigned short)
- * @see #db_uint64_hash(DBKey,unsigned short)
+ * @see #db_int_hash()
+ * @see #db_uint_hash()
+ * @see #db_string_hash()
+ * @see #db_istring_hash()
+ * @see #db_int64_hash()
+ * @see #db_uint64_hash()
*/
-DBHasher db_default_hash(DBType type)
+DBHasher db_default_hash(enum DBType type)
{
DB_COUNTSTAT(db_default_hash);
switch (type) {
@@ -2474,19 +2483,21 @@ DBHasher db_default_hash(DBType type)
/**
* Returns the default releaser for the specified type of database with the
* specified options.
- * NOTE: the options are fixed with {@link #db_fix_options(DBType,DBOptions)}
- * before choosing the releaser.
+ *
+ * NOTE: the options are fixed with #db_fix_options() before choosing the
+ * releaser.
+ *
* @param type Type of database
* @param options Options of the database
* @return Default releaser for the type of database with the specified options
* @public
- * @see #db_release_nothing(DBKey,DBData,DBRelease)
- * @see #db_release_key(DBKey,DBData,DBRelease)
- * @see #db_release_data(DBKey,DBData,DBRelease)
- * @see #db_release_both(DBKey,DBData,DBRelease)
- * @see #db_custom_release(DBRelease)
+ * @see #db_release_nothing()
+ * @see #db_release_key()
+ * @see #db_release_data()
+ * @see #db_release_both()
+ * @see #db_custom_release()
*/
-DBReleaser db_default_release(DBType type, DBOptions options)
+DBReleaser db_default_release(enum DBType type, enum DBOptions options)
{
DB_COUNTSTAT(db_default_release);
options = DB->fix_options(type, options);
@@ -2505,13 +2516,13 @@ DBReleaser db_default_release(DBType type, DBOptions options)
* @param which Options that specified what the releaser releases
* @return Releaser for the specified release options
* @public
- * @see #db_release_nothing(DBKey,DBData,DBRelease)
- * @see #db_release_key(DBKey,DBData,DBRelease)
- * @see #db_release_data(DBKey,DBData,DBRelease)
- * @see #db_release_both(DBKey,DBData,DBRelease)
- * @see #db_default_release(DBType,DBOptions)
+ * @see #db_release_nothing()
+ * @see #db_release_key()
+ * @see #db_release_data()
+ * @see #db_release_both()
+ * @see #db_default_release()
*/
-DBReleaser db_custom_release(DBRelease which)
+DBReleaser db_custom_release(enum DBReleaseOption which)
{
DB_COUNTSTAT(db_custom_release);
switch (which) {
@@ -2527,8 +2538,10 @@ DBReleaser db_custom_release(DBRelease which)
/**
* Allocate a new database of the specified type.
- * NOTE: the options are fixed by {@link #db_fix_options(DBType,DBOptions)}
- * before creating the database.
+ *
+ * NOTE: the options are fixed by #db_fix_options() before creating the
+ * database.
+ *
* @param file File where the database is being allocated
* @param line Line of the file where the database is being allocated
* @param type Type of database
@@ -2537,11 +2550,12 @@ DBReleaser db_custom_release(DBRelease which)
* databases. If 0, the maximum number of maxlen is used (64K).
* @return The interface of the database
* @public
- * @see #DBMap_impl
- * @see #db_fix_options(DBType,DBOptions)
+ * @see struct DBMap_impl
+ * @see #db_fix_options()
*/
-DBMap* db_alloc(const char *file, const char *func, int line, DBType type, DBOptions options, unsigned short maxlen) {
- DBMap_impl* db;
+struct DBMap *db_alloc(const char *file, const char *func, int line, enum DBType type, enum DBOptions options, unsigned short maxlen)
+{
+ struct DBMap_impl *db;
unsigned int i;
char ers_name[50];
@@ -2588,7 +2602,7 @@ DBMap* db_alloc(const char *file, const char *func, int line, DBType type, DBOpt
db->free_lock = 0;
/* Other */
snprintf(ers_name, 50, "db_alloc:nodes:%s:%s:%d",func,file,line);
- db->nodes = ers_new(sizeof(struct dbn),ers_name,ERS_OPT_WAIT|ERS_OPT_FREE_NAME|ERS_OPT_CLEAN);
+ db->nodes = ers_new(sizeof(struct DBNode),ers_name,ERS_OPT_WAIT|ERS_OPT_FREE_NAME|ERS_OPT_CLEAN);
db->cmp = DB->default_cmp(type);
db->hash = DB->default_hash(type);
db->release = DB->default_release(type, options);
@@ -2613,9 +2627,9 @@ DBMap* db_alloc(const char *file, const char *func, int line, DBType type, DBOpt
* @return The key as a DBKey union
* @public
*/
-DBKey db_i2key(int key)
+union DBKey db_i2key(int key)
{
- DBKey ret;
+ union DBKey ret;
DB_COUNTSTAT(db_i2key);
ret.i = key;
@@ -2628,9 +2642,9 @@ DBKey db_i2key(int key)
* @return The key as a DBKey union
* @public
*/
-DBKey db_ui2key(unsigned int key)
+union DBKey db_ui2key(unsigned int key)
{
- DBKey ret;
+ union DBKey ret;
DB_COUNTSTAT(db_ui2key);
ret.ui = key;
@@ -2643,9 +2657,9 @@ DBKey db_ui2key(unsigned int key)
* @return The key as a DBKey union
* @public
*/
-DBKey db_str2key(const char *key)
+union DBKey db_str2key(const char *key)
{
- DBKey ret;
+ union DBKey ret;
DB_COUNTSTAT(db_str2key);
ret.str = key;
@@ -2658,9 +2672,9 @@ DBKey db_str2key(const char *key)
* @return The key as a DBKey union
* @public
*/
-DBKey db_i642key(int64 key)
+union DBKey db_i642key(int64 key)
{
- DBKey ret;
+ union DBKey ret;
DB_COUNTSTAT(db_i642key);
ret.i64 = key;
@@ -2673,9 +2687,9 @@ DBKey db_i642key(int64 key)
* @return The key as a DBKey union
* @public
*/
-DBKey db_ui642key(uint64 key)
+union DBKey db_ui642key(uint64 key)
{
- DBKey ret;
+ union DBKey ret;
DB_COUNTSTAT(db_ui642key);
ret.ui64 = key;
@@ -2688,9 +2702,9 @@ DBKey db_ui642key(uint64 key)
* @return The data as a DBData struct
* @public
*/
-DBData db_i2data(int data)
+struct DBData db_i2data(int data)
{
- DBData ret;
+ struct DBData ret;
DB_COUNTSTAT(db_i2data);
ret.type = DB_DATA_INT;
@@ -2704,9 +2718,9 @@ DBData db_i2data(int data)
* @return The data as a DBData struct
* @public
*/
-DBData db_ui2data(unsigned int data)
+struct DBData db_ui2data(unsigned int data)
{
- DBData ret;
+ struct DBData ret;
DB_COUNTSTAT(db_ui2data);
ret.type = DB_DATA_UINT;
@@ -2720,9 +2734,9 @@ DBData db_ui2data(unsigned int data)
* @return The data as a DBData struct
* @public
*/
-DBData db_ptr2data(void *data)
+struct DBData db_ptr2data(void *data)
{
- DBData ret;
+ struct DBData ret;
DB_COUNTSTAT(db_ptr2data);
ret.type = DB_DATA_PTR;
@@ -2737,7 +2751,7 @@ DBData db_ptr2data(void *data)
* @return Integer value of the data.
* @public
*/
-int db_data2i(DBData *data)
+int db_data2i(struct DBData *data)
{
DB_COUNTSTAT(db_data2i);
if (data && DB_DATA_INT == data->type)
@@ -2752,7 +2766,7 @@ int db_data2i(DBData *data)
* @return Unsigned int value of the data.
* @public
*/
-unsigned int db_data2ui(DBData *data)
+unsigned int db_data2ui(struct DBData *data)
{
DB_COUNTSTAT(db_data2ui);
if (data && DB_DATA_UINT == data->type)
@@ -2767,7 +2781,7 @@ unsigned int db_data2ui(DBData *data)
* @return Void* value of the data.
* @public
*/
-void* db_data2ptr(DBData *data)
+void *db_data2ptr(struct DBData *data)
{
DB_COUNTSTAT(db_data2ptr);
if (data && DB_DATA_PTR == data->type)
diff --git a/src/common/db.h b/src/common/db.h
index b73970947..d7d111c86 100644
--- a/src/common/db.h
+++ b/src/common/db.h
@@ -43,8 +43,7 @@
* 2007/11/09 - Added an iterator to the database. *
* 2.1 (Athena build #???#) - Portability fix *
* - Fixed the portability of casting to union and added the functions *
- * {@link DBMap#ensure(DBMap,DBKey,DBCreateData,...)} and *
- * {@link DBMap#clear(DBMap,DBApply,...)}. *
+ * struct DBMap#ensure() and struct DBMap#clear(). *
* 2.0 (Athena build 4859) - Transition version *
* - Almost everything recoded with a strategy similar to objects, *
* database structure is maintained. *
@@ -64,41 +63,42 @@
#include <stdarg.h>
-/*****************************************************************************\
+/*****************************************************************************
* (1) Section with public typedefs, enums, unions, structures and defines. *
- * DBRelease - Enumeration of release options. *
- * DBType - Enumeration of database types. *
- * DBOptions - Bitfield enumeration of database options. *
- * DBKey - Union of used key types. *
- * DBDataType - Enumeration of data types. *
- * DBData - Struct for used data types. *
- * DBApply - Format of functions applied to the databases. *
- * DBMatcher - Format of matchers used in DBMap::getall. *
- * DBComparator - Format of the comparators used by the databases. *
- * DBHasher - Format of the hashers used by the databases. *
- * DBReleaser - Format of the releasers used by the databases. *
- * DBIterator - Database iterator. *
- * DBMap - Database interface. *
-\*****************************************************************************/
+ * enum DBReleaseOption - Enumeration of release options. *
+ * enum DBType - Enumeration of database types. *
+ * enum DBOptions - Bitfield enumeration of database options. *
+ * union DBKey - Union of used key types. *
+ * enum DBDataType - Enumeration of data types. *
+ * struct DBData - Struct for used data types. *
+ * DBApply - Format of functions applied to the databases. *
+ * DBMatcher - Format of matchers used in struct DBMap#getall(). *
+ * DBComparator - Format of the comparators used by the databases. *
+ * DBHasher - Format of the hashers used by the databases. *
+ * DBReleaser - Format of the releasers used by the databases. *
+ * struct DBIterator - Database iterator. *
+ * struct DBMap - Database interface. *
+ *****************************************************************************/
/**
* Bitfield with what should be released by the releaser function (if the
* function supports it).
* @public
* @see #DBReleaser
- * @see #db_custom_release(DBRelease)
+ * @see #db_custom_release()
*/
-typedef enum DBRelease {
+enum DBReleaseOption {
DB_RELEASE_NOTHING = 0x0,
DB_RELEASE_KEY = 0x1,
DB_RELEASE_DATA = 0x2,
DB_RELEASE_BOTH = DB_RELEASE_KEY|DB_RELEASE_DATA,
-} DBRelease;
+};
/**
* Supported types of database.
- * See {@link #db_fix_options(DBType,DBOptions)} for restrictions of the
- * types of databases.
+ *
+ * See #db_fix_options() for restrictions of the types of databases.
+ *
* @param DB_INT Uses int's for keys
* @param DB_UINT Uses unsigned int's for keys
* @param DB_STRING Uses strings for keys.
@@ -106,27 +106,28 @@ typedef enum DBRelease {
* @param DB_INT64 Uses int64's for keys
* @param DB_UINT64 Uses uint64's for keys
* @public
- * @see #DBOptions
- * @see #DBKey
- * @see #db_fix_options(DBType,DBOptions)
- * @see #db_default_cmp(DBType)
- * @see #db_default_hash(DBType)
- * @see #db_default_release(DBType,DBOptions)
- * @see #db_alloc(const char *,int,DBType,DBOptions,unsigned short)
- */
-typedef enum DBType {
+ * @see enum DBOptions
+ * @see union DBKey
+ * @see #db_fix_options()
+ * @see #db_default_cmp()
+ * @see #db_default_hash()
+ * @see #db_default_release()
+ * @see #db_alloc()
+ */
+enum DBType {
DB_INT,
DB_UINT,
DB_STRING,
DB_ISTRING,
DB_INT64,
DB_UINT64,
-} DBType;
+};
/**
* Bitfield of options that define the behavior of the database.
- * See {@link #db_fix_options(DBType,DBOptions)} for restrictions of the
- * types of databases.
+ *
+ * See #db_fix_options() for restrictions of the types of databases.
+ *
* @param DB_OPT_BASE Base options: does not duplicate keys, releases nothing
* and does not allow NULL keys or NULL data.
* @param DB_OPT_DUP_KEY Duplicates the keys internally. If DB_OPT_RELEASE_KEY
@@ -134,17 +135,17 @@ typedef enum DBType {
* @param DB_OPT_RELEASE_KEY Releases the key.
* @param DB_OPT_RELEASE_DATA Releases the data whenever an entry is removed
* from the database.
- * WARNING: for functions that return the data (like DBMap::remove),
+ * WARNING: for functions that return the data (like struct DBMap#remove()),
* a dangling pointer will be returned.
* @param DB_OPT_RELEASE_BOTH Releases both key and data.
* @param DB_OPT_ALLOW_NULL_KEY Allow NULL keys in the database.
* @param DB_OPT_ALLOW_NULL_DATA Allow NULL data in the database.
* @public
- * @see #db_fix_options(DBType,DBOptions)
- * @see #db_default_release(DBType,DBOptions)
- * @see #db_alloc(const char *,int,DBType,DBOptions,unsigned short)
+ * @see #db_fix_options()
+ * @see #db_default_release()
+ * @see #db_alloc()
*/
-typedef enum DBOptions {
+enum DBOptions {
DB_OPT_BASE = 0x00,
DB_OPT_DUP_KEY = 0x01,
DB_OPT_RELEASE_KEY = 0x02,
@@ -152,7 +153,7 @@ typedef enum DBOptions {
DB_OPT_RELEASE_BOTH = DB_OPT_RELEASE_KEY|DB_OPT_RELEASE_DATA,
DB_OPT_ALLOW_NULL_KEY = 0x08,
DB_OPT_ALLOW_NULL_DATA = 0x10,
-} DBOptions;
+};
/**
* Union of key types used by the database.
@@ -160,18 +161,19 @@ typedef enum DBOptions {
* @param ui Type of key for DB_UINT databases
* @param str Type of key for DB_STRING and DB_ISTRING databases
* @public
- * @see #DBType
- * @see DBMap#get
- * @see DBMap#put
- * @see DBMap#remove
+ * @see enum DBType
+ * @see struct DBMap#get()
+ * @see struct DBMap#put()
+ * @see struct DBMap#remove()
*/
-typedef union DBKey {
+union DBKey {
int i;
unsigned int ui;
const char *str;
+ char *mutstr;
int64 i64;
uint64 ui64;
-} DBKey;
+};
/**
* Supported types of database data.
@@ -179,13 +181,13 @@ typedef union DBKey {
* @param DB_DATA_UINT Uses unsigned ints for data.
* @param DB_DATA_PTR Uses void pointers for data.
* @public
- * @see #DBData
+ * @see struct DBData
*/
-typedef enum DBDataType {
+enum DBDataType {
DB_DATA_INT,
DB_DATA_UINT,
DB_DATA_PTR,
-} DBDataType;
+};
/**
* Struct for data types used by the database.
@@ -196,14 +198,14 @@ typedef enum DBDataType {
* @param u.ptr Data of void* type
* @public
*/
-typedef struct DBData {
- DBDataType type;
+struct DBData {
+ enum DBDataType type;
union {
int i;
unsigned int ui;
void *ptr;
} u;
-} DBData;
+};
/**
* Format of functions that create the data for the key when the entry doesn't
@@ -212,10 +214,10 @@ typedef struct DBData {
* @param args Extra arguments of the function
* @return Data identified by the key to be put in the database
* @public
- * @see DBMap#vensure
- * @see DBMap#ensure
+ * @see struct DBMap#vensure()
+ * @see struct DBMap#ensure()
*/
-typedef DBData (*DBCreateData)(DBKey key, va_list args);
+typedef struct DBData (*DBCreateData)(union DBKey key, va_list args);
/**
* Format of functions to be applied to an unspecified quantity of entries of
@@ -227,12 +229,12 @@ typedef DBData (*DBCreateData)(DBKey key, va_list args);
* @param args Extra arguments of the function
* @return Value to be added up by the function that is applying this
* @public
- * @see DBMap#vforeach
- * @see DBMap#foreach
- * @see DBMap#vdestroy
- * @see DBMap#destroy
+ * @see struct DBMap#vforeach()
+ * @see struct DBMap#foreach()
+ * @see struct DBMap#vdestroy()
+ * @see struct DBMap#destroy()
*/
-typedef int (*DBApply)(DBKey key, DBData *data, va_list args);
+typedef int (*DBApply)(union DBKey key, struct DBData *data, va_list args);
/**
* Format of functions that match database entries.
@@ -243,9 +245,9 @@ typedef int (*DBApply)(DBKey key, DBData *data, va_list args);
* @param args Extra arguments of the function
* @return 0 if a match, another number otherwise
* @public
- * @see DBMap#getall
+ * @see struct DBMap#getall()
*/
-typedef int (*DBMatcher)(DBKey key, DBData data, va_list args);
+typedef int (*DBMatcher)(union DBKey key, struct DBData data, va_list args);
/**
* Format of the comparators used internally by the database system.
@@ -257,9 +259,9 @@ typedef int (*DBMatcher)(DBKey key, DBData data, va_list args);
* databases.
* @return 0 if equal, negative if lower and positive if higher
* @public
- * @see #db_default_cmp(DBType)
+ * @see #db_default_cmp()
*/
-typedef int (*DBComparator)(DBKey key1, DBKey key2, unsigned short maxlen);
+typedef int (*DBComparator)(union DBKey key1, union DBKey key2, unsigned short maxlen);
/**
* Format of the hashers used internally by the database system.
@@ -269,9 +271,9 @@ typedef int (*DBComparator)(DBKey key1, DBKey key2, unsigned short maxlen);
* databases.
* @return Hash of the key
* @public
- * @see #db_default_hash(DBType)
+ * @see #db_default_hash()
*/
-typedef uint64 (*DBHasher)(DBKey key, unsigned short maxlen);
+typedef uint64 (*DBHasher)(union DBKey key, unsigned short maxlen);
/**
* Format of the releaser used by the database system.
@@ -281,27 +283,25 @@ typedef uint64 (*DBHasher)(DBKey key, unsigned short maxlen);
* @param data Data of the database entry
* @param which What is being requested to be released
* @public
- * @see #DBRelease
- * @see #db_default_releaser(DBType,DBOptions)
- * @see #db_custom_release(DBRelease)
+ * @see enum DBReleaseOption
+ * @see #db_default_releaser()
+ * @see #db_custom_release()
*/
-typedef void (*DBReleaser)(DBKey key, DBData data, DBRelease which);
-
-typedef struct DBIterator DBIterator;
-typedef struct DBMap DBMap;
+typedef void (*DBReleaser)(union DBKey key, struct DBData data, enum DBReleaseOption which);
/**
* Database iterator.
+ *
* Supports forward iteration, backward iteration and removing entries from the database.
* The iterator is initially positioned before the first entry of the database.
+ *
* While the iterator exists the database is locked internally, so invoke
- * {@link DBIterator#destroy} as soon as possible.
+ * struct DBIterator#destroy() as soon as possible.
+ *
* @public
- * @see #DBMap
+ * @see struct DBMap
*/
-struct DBIterator
-{
-
+struct DBIterator {
/**
* Fetches the first entry in the database.
* Returns the data of the entry.
@@ -311,7 +311,7 @@ struct DBIterator
* @return Data of the entry
* @protected
*/
- DBData* (*first)(DBIterator* self, DBKey* out_key);
+ struct DBData *(*first)(struct DBIterator *self, union DBKey *out_key);
/**
* Fetches the last entry in the database.
@@ -322,7 +322,7 @@ struct DBIterator
* @return Data of the entry
* @protected
*/
- DBData* (*last)(DBIterator* self, DBKey* out_key);
+ struct DBData *(*last)(struct DBIterator *self, union DBKey *out_key);
/**
* Fetches the next entry in the database.
@@ -333,7 +333,7 @@ struct DBIterator
* @return Data of the entry
* @protected
*/
- DBData* (*next)(DBIterator* self, DBKey* out_key);
+ struct DBData *(*next)(struct DBIterator *self, union DBKey *out_key);
/**
* Fetches the previous entry in the database.
@@ -344,7 +344,7 @@ struct DBIterator
* @return Data of the entry
* @protected
*/
- DBData* (*prev)(DBIterator* self, DBKey* out_key);
+ struct DBData *(*prev)(struct DBIterator *self, union DBKey *out_key);
/**
* Returns true if the fetched entry exists.
@@ -354,27 +354,29 @@ struct DBIterator
* @return true is the entry exists
* @protected
*/
- bool (*exists)(DBIterator* self);
+ bool (*exists)(struct DBIterator *self);
/**
* Removes the current entry from the database.
- * NOTE: {@link DBIterator#exists} will return false until another entry
- * is fetched
+ *
+ * NOTE: struct DBIterator#exists() will return false until another
+ * entry is fetched.
+ *
* Puts data of the removed entry in out_data, if out_data is not NULL.
* @param self Iterator
* @param out_data Data of the removed entry.
* @return 1 if entry was removed, 0 otherwise
* @protected
- * @see DBMap#remove
+ * @see struct DBMap#remove()
*/
- int (*remove)(DBIterator* self, DBData *out_data);
+ int (*remove)(struct DBIterator *self, struct DBData *out_data);
/**
* Destroys this iterator and unlocks the database.
* @param self Iterator
* @protected
*/
- void (*destroy)(DBIterator* self);
+ void (*destroy)(struct DBIterator *self);
};
@@ -382,7 +384,7 @@ struct DBIterator
* Public interface of a database. Only contains functions.
* All the functions take the interface as the first argument.
* @public
- * @see #db_alloc(const char*,int,DBType,DBOptions,unsigned short)
+ * @see #db_alloc()
*/
struct DBMap {
@@ -395,7 +397,7 @@ struct DBMap {
* @return New iterator
* @protected
*/
- DBIterator* (*iterator)(DBMap* self);
+ struct DBIterator *(*iterator)(struct DBMap *self);
/**
* Returns true if the entry exists.
@@ -404,7 +406,7 @@ struct DBMap {
* @return true is the entry exists
* @protected
*/
- bool (*exists)(DBMap* self, DBKey key);
+ bool (*exists)(struct DBMap *self, union DBKey key);
/**
* Get the data of the entry identified by the key.
@@ -413,10 +415,11 @@ struct DBMap {
* @return Data of the entry or NULL if not found
* @protected
*/
- DBData* (*get)(DBMap* self, DBKey key);
+ struct DBData *(*get)(struct DBMap *self, union DBKey key);
/**
- * Just calls {@link DBMap#vgetall}.
+ * Just calls struct DBMap#vgetall().
+ *
* Get the data of the entries matched by <code>match</code>.
* It puts a maximum of <code>max</code> entries into <code>buf</code>.
* If <code>buf</code> is NULL, it only counts the matches.
@@ -430,9 +433,9 @@ struct DBMap {
* @param ... Extra arguments for match
* @return The number of entries that matched
* @protected
- * @see DBMap#vgetall(DBMap*,void **,unsigned int,DBMatcher,va_list)
+ * @see struct DBMap#vgetall()
*/
- unsigned int (*getall)(DBMap* self, DBData** buf, unsigned int max, DBMatcher match, ...);
+ unsigned int (*getall)(struct DBMap *self, struct DBData **buf, unsigned int max, DBMatcher match, ...);
/**
* Get the data of the entries matched by <code>match</code>.
@@ -448,24 +451,25 @@ struct DBMap {
* @param ... Extra arguments for match
* @return The number of entries that matched
* @protected
- * @see DBMap#getall(DBMap*,void **,unsigned int,DBMatcher,...)
+ * @see struct DBMap#getall()
*/
- unsigned int (*vgetall)(DBMap* self, DBData** buf, unsigned int max, DBMatcher match, va_list args);
+ unsigned int (*vgetall)(struct DBMap *self, struct DBData **buf, unsigned int max, DBMatcher match, va_list args);
/**
- * Just calls {@link DBMap#vensure}.
- * Get the data of the entry identified by the key.
- * If the entry does not exist, an entry is added with the data returned by
- * <code>create</code>.
+ * Just calls struct DBMap#vensure().
+ *
+ * Get the data of the entry identified by the key. If the entry does
+ * not exist, an entry is added with the data returned by `create`.
+ *
* @param self Database
* @param key Key that identifies the entry
* @param create Function used to create the data if the entry doesn't exist
* @param ... Extra arguments for create
* @return Data of the entry
* @protected
- * @see DBMap#vensure(DBMap*,DBKey,DBCreateData,va_list)
+ * @see struct DBMap#vensure()
*/
- DBData* (*ensure)(DBMap* self, DBKey key, DBCreateData create, ...);
+ struct DBData *(*ensure)(struct DBMap *self, union DBKey key, DBCreateData create, ...);
/**
* Get the data of the entry identified by the key.
@@ -477,9 +481,9 @@ struct DBMap {
* @param args Extra arguments for create
* @return Data of the entry
* @protected
- * @see DBMap#ensure(DBMap*,DBKey,DBCreateData,...)
+ * @see struct DBMap#ensure()
*/
- DBData* (*vensure)(DBMap* self, DBKey key, DBCreateData create, va_list args);
+ struct DBData *(*vensure)(struct DBMap *self, union DBKey key, DBCreateData create, va_list args);
/**
* Put the data identified by the key in the database.
@@ -492,7 +496,7 @@ struct DBMap {
* @return 1 if if the entry already exists, 0 otherwise
* @protected
*/
- int (*put)(DBMap* self, DBKey key, DBData data, DBData *out_data);
+ int (*put)(struct DBMap *self, union DBKey key, struct DBData data, struct DBData *out_data);
/**
* Remove an entry from the database.
@@ -504,10 +508,11 @@ struct DBMap {
* @return 1 if if the entry already exists, 0 otherwise
* @protected
*/
- int (*remove)(DBMap* self, DBKey key, DBData *out_data);
+ int (*remove)(struct DBMap *self, union DBKey key, struct DBData *out_data);
/**
- * Just calls {@link DBMap#vforeach}.
+ * Just calls struct DBMap#vforeach().
+ *
* Apply <code>func</code> to every entry in the database.
* Returns the sum of values returned by func.
* @param self Database
@@ -515,9 +520,9 @@ struct DBMap {
* @param ... Extra arguments for func
* @return Sum of the values returned by func
* @protected
- * @see DBMap#vforeach(DBMap*,DBApply,va_list)
+ * @see struct DBMap#vforeach()
*/
- int (*foreach)(DBMap* self, DBApply func, ...);
+ int (*foreach)(struct DBMap *self, DBApply func, ...);
/**
* Apply <code>func</code> to every entry in the database.
@@ -527,12 +532,13 @@ struct DBMap {
* @param args Extra arguments for func
* @return Sum of the values returned by func
* @protected
- * @see DBMap#foreach(DBMap*,DBApply,...)
+ * @see struct DBMap#foreach()
*/
- int (*vforeach)(DBMap* self, DBApply func, va_list args);
+ int (*vforeach)(struct DBMap *self, DBApply func, va_list args);
/**
- * Just calls {@link DBMap#vclear}.
+ * Just calls struct DBMap#vclear().
+ *
* Removes all entries from the database.
* Before deleting an entry, func is applied to it.
* Releases the key and the data.
@@ -542,9 +548,9 @@ struct DBMap {
* @param ... Extra arguments for func
* @return Sum of values returned by func
* @protected
- * @see DBMap#vclear(DBMap*,DBApply,va_list)
+ * @see struct DBMap#vclear()
*/
- int (*clear)(DBMap* self, DBApply func, ...);
+ int (*clear)(struct DBMap *self, DBApply func, ...);
/**
* Removes all entries from the database.
@@ -556,12 +562,12 @@ struct DBMap {
* @param args Extra arguments for func
* @return Sum of values returned by func
* @protected
- * @see DBMap#clear(DBMap*,DBApply,...)
+ * @see struct DBMap#clear()
*/
- int (*vclear)(DBMap* self, DBApply func, va_list args);
+ int (*vclear)(struct DBMap *self, DBApply func, va_list args);
/**
- * Just calls {@link DBMap#vdestroy}.
+ * Just calls DBMap#vdestroy().
* Finalize the database, feeing all the memory it uses.
* Before deleting an entry, func is applied to it.
* Releases the key and the data.
@@ -573,9 +579,9 @@ struct DBMap {
* @param ... Extra arguments for func
* @return Sum of values returned by func
* @protected
- * @see DBMap#vdestroy(DBMap*,DBApply,va_list)
+ * @see struct DBMap#vdestroy()
*/
- int (*destroy)(DBMap* self, DBApply func, ...);
+ int (*destroy)(struct DBMap *self, DBApply func, ...);
/**
* Finalize the database, feeing all the memory it uses.
@@ -588,9 +594,9 @@ struct DBMap {
* @param args Extra arguments for func
* @return Sum of values returned by func
* @protected
- * @see DBMap#destroy(DBMap*,DBApply,...)
+ * @see struct DBMap#destroy()
*/
- int (*vdestroy)(DBMap* self, DBApply func, va_list args);
+ int (*vdestroy)(struct DBMap *self, DBApply func, va_list args);
/**
* Return the size of the database (number of items in the database).
@@ -598,7 +604,7 @@ struct DBMap {
* @return Size of the database
* @protected
*/
- unsigned int (*size)(DBMap* self);
+ unsigned int (*size)(struct DBMap *self);
/**
* Return the type of the database.
@@ -606,7 +612,7 @@ struct DBMap {
* @return Type of the database
* @protected
*/
- DBType (*type)(DBMap* self);
+ enum DBType (*type)(struct DBMap *self);
/**
* Return the options of the database.
@@ -614,7 +620,7 @@ struct DBMap {
* @return Options of the database
* @protected
*/
- DBOptions (*options)(DBMap* self);
+ enum DBOptions (*options)(struct DBMap *self);
};
@@ -712,7 +718,7 @@ struct DBMap {
#define dbi_exists(dbi) ( (dbi)->exists(dbi) )
#define dbi_destroy(dbi) ( (dbi)->destroy(dbi) )
-/*****************************************************************************\
+/*****************************************************************************
* (2) Section with public functions. *
* db_fix_options - Fix the options for a type of database. *
* db_default_cmp - Get the default comparator for a type of database. *
@@ -721,20 +727,20 @@ struct DBMap {
* with the fixed options. *
* db_custom_release - Get the releaser that behaves as specified. *
* db_alloc - Allocate a new database. *
- * db_i2key - Manual cast from 'int' to 'DBKey'. *
- * db_ui2key - Manual cast from 'unsigned int' to 'DBKey'. *
- * db_str2key - Manual cast from 'unsigned char *' to 'DBKey'. *
- * db_i642key - Manual cast from 'int64' to 'DBKey'. *
- * db_ui642key - Manual cast from 'uint64' to 'DBKey'. *
- * db_i2data - Manual cast from 'int' to 'DBData'. *
- * db_ui2data - Manual cast from 'unsigned int' to 'DBData'. *
- * db_ptr2data - Manual cast from 'void*' to 'DBData'. *
- * db_data2i - Gets 'int' value from 'DBData'. *
- * db_data2ui - Gets 'unsigned int' value from 'DBData'. *
- * db_data2ptr - Gets 'void*' value from 'DBData'. *
+ * db_i2key - Manual cast from `int` to `union DBKey`. *
+ * db_ui2key - Manual cast from `unsigned int` to `union DBKey`. *
+ * db_str2key - Manual cast from `unsigned char *` to `union DBKey`.*
+ * db_i642key - Manual cast from `int64` to `union DBKey`. *
+ * db_ui642key - Manual cast from `uint64` to `union DBKey`. *
+ * db_i2data - Manual cast from `int` to `struct DBData`. *
+ * db_ui2data - Manual cast from `unsigned int` to `struct DBData`. *
+ * db_ptr2data - Manual cast from `void*` to `struct DBData`. *
+ * db_data2i - Gets `int` value from `struct DBData`. *
+ * db_data2ui - Gets `unsigned int` value from `struct DBData`. *
+ * db_data2ptr - Gets `void*` value from `struct DBData`. *
* db_init - Initializes the database system. *
* db_final - Finalizes the database system. *
-\*****************************************************************************/
+ *****************************************************************************/
struct db_interface {
/**
@@ -745,66 +751,71 @@ struct db_interface {
* @param options Original options of the database
* @return Fixed options of the database
* @private
- * @see #DBType
- * @see #DBOptions
- * @see #db_default_release(DBType,DBOptions)
+ * @see enum DBType
+ * @see enum DBOptions
+ * @see #db_default_release()
*/
-DBOptions (*fix_options) (DBType type, DBOptions options);
+enum DBOptions (*fix_options) (enum DBType type, enum DBOptions options);
/**
* Returns the default comparator for the type of database.
* @param type Type of database
* @return Comparator for the type of database or NULL if unknown database
* @public
- * @see #DBType
+ * @see enum DBType
* @see #DBComparator
*/
-DBComparator (*default_cmp) (DBType type);
+DBComparator (*default_cmp) (enum DBType type);
/**
* Returns the default hasher for the specified type of database.
* @param type Type of database
* @return Hasher of the type of database or NULL if unknown database
* @public
- * @see #DBType
+ * @see enum DBType
* @see #DBHasher
*/
-DBHasher (*default_hash) (DBType type);
+DBHasher (*default_hash) (enum DBType type);
/**
* Returns the default releaser for the specified type of database with the
* specified options.
- * NOTE: the options are fixed by {@link #db_fix_options(DBType,DBOptions)}
- * before choosing the releaser
+ *
+ * NOTE: the options are fixed by #db_fix_options() before choosing the
+ * releaser.
+ *
* @param type Type of database
* @param options Options of the database
* @return Default releaser for the type of database with the fixed options
* @public
- * @see #DBType
- * @see #DBOptions
+ * @see enum DBType
+ * @see enum DBOptions
* @see #DBReleaser
- * @see #db_fix_options(DBType,DBOptions)
- * @see #db_custom_release(DBRelease)
+ * @see #db_fix_options()
+ * @see #db_custom_release()
*/
-DBReleaser (*default_release) (DBType type, DBOptions options);
+DBReleaser (*default_release) (enum DBType type, enum DBOptions options);
/**
* Returns the releaser that behaves as <code>which</code> specifies.
* @param which Defines what the releaser releases
* @return Releaser for the specified release options
* @public
- * @see #DBRelease
+ * @see enum DBReleaseOption
* @see #DBReleaser
- * @see #db_default_release(DBType,DBOptions)
+ * @see #db_default_release()
*/
-DBReleaser (*custom_release) (DBRelease which);
+DBReleaser (*custom_release) (enum DBReleaseOption which);
/**
* Allocate a new database of the specified type.
+ *
* It uses the default comparator, hasher and releaser of the specified
* database type and fixed options.
- * NOTE: the options are fixed by {@link #db_fix_options(DBType,DBOptions)}
- * before creating the database.
+ *
+ * NOTE: the options are fixed by #db_fix_options() before creating the
+ * database.
+ *
* @param file File where the database is being allocated
* @param line Line of the file where the database is being allocated
* @param type Type of database
@@ -813,14 +824,14 @@ DBReleaser (*custom_release) (DBRelease which);
* databases. If 0, the maximum number of maxlen is used (64K).
* @return The interface of the database
* @public
- * @see #DBType
- * @see #DBMap
- * @see #db_default_cmp(DBType)
- * @see #db_default_hash(DBType)
- * @see #db_default_release(DBType,DBOptions)
- * @see #db_fix_options(DBType,DBOptions)
+ * @see enum DBType
+ * @see struct DBMap
+ * @see #db_default_cmp()
+ * @see #db_default_hash()
+ * @see #db_default_release()
+ * @see #db_fix_options()
*/
-DBMap* (*alloc) (const char *file, const char *func, int line, DBType type, DBOptions options, unsigned short maxlen);
+struct DBMap *(*alloc) (const char *file, const char *func, int line, enum DBType type, enum DBOptions options, unsigned short maxlen);
/**
* Manual cast from 'int' to the union DBKey.
@@ -828,7 +839,7 @@ DBMap* (*alloc) (const char *file, const char *func, int line, DBType type, DBOp
* @return The key as a DBKey union
* @public
*/
-DBKey (*i2key) (int key);
+union DBKey (*i2key) (int key);
/**
* Manual cast from 'unsigned int' to the union DBKey.
@@ -836,7 +847,7 @@ DBKey (*i2key) (int key);
* @return The key as a DBKey union
* @public
*/
-DBKey (*ui2key) (unsigned int key);
+union DBKey (*ui2key) (unsigned int key);
/**
* Manual cast from 'unsigned char *' to the union DBKey.
@@ -844,7 +855,7 @@ DBKey (*ui2key) (unsigned int key);
* @return The key as a DBKey union
* @public
*/
-DBKey (*str2key) (const char *key);
+union DBKey (*str2key) (const char *key);
/**
* Manual cast from 'int64' to the union DBKey.
@@ -852,7 +863,7 @@ DBKey (*str2key) (const char *key);
* @return The key as a DBKey union
* @public
*/
-DBKey (*i642key) (int64 key);
+union DBKey (*i642key) (int64 key);
/**
* Manual cast from 'uint64' to the union DBKey.
@@ -860,7 +871,7 @@ DBKey (*i642key) (int64 key);
* @return The key as a DBKey union
* @public
*/
-DBKey (*ui642key) (uint64 key);
+union DBKey (*ui642key) (uint64 key);
/**
* Manual cast from 'int' to the struct DBData.
@@ -868,7 +879,7 @@ DBKey (*ui642key) (uint64 key);
* @return The data as a DBData struct
* @public
*/
-DBData (*i2data) (int data);
+struct DBData (*i2data) (int data);
/**
* Manual cast from 'unsigned int' to the struct DBData.
@@ -876,7 +887,7 @@ DBData (*i2data) (int data);
* @return The data as a DBData struct
* @public
*/
-DBData (*ui2data) (unsigned int data);
+struct DBData (*ui2data) (unsigned int data);
/**
* Manual cast from 'void *' to the struct DBData.
@@ -884,7 +895,7 @@ DBData (*ui2data) (unsigned int data);
* @return The data as a DBData struct
* @public
*/
-DBData (*ptr2data) (void *data);
+struct DBData (*ptr2data) (void *data);
/**
* Gets int type data from struct DBData.
@@ -893,7 +904,7 @@ DBData (*ptr2data) (void *data);
* @return Integer value of the data.
* @public
*/
-int (*data2i) (DBData *data);
+int (*data2i) (struct DBData *data);
/**
* Gets unsigned int type data from struct DBData.
@@ -902,7 +913,7 @@ int (*data2i) (DBData *data);
* @return Unsigned int value of the data.
* @public
*/
-unsigned int (*data2ui) (DBData *data);
+unsigned int (*data2ui) (struct DBData *data);
/**
* Gets void* type data from struct DBData.
@@ -911,7 +922,7 @@ unsigned int (*data2ui) (DBData *data);
* @return Void* value of the data.
* @public
*/
-void* (*data2ptr) (DBData *data);
+void* (*data2ptr) (struct DBData *data);
/**
* Initialize the database system.
diff --git a/src/common/mapindex.h b/src/common/mapindex.h
index 3fb170c1f..0ebbeb04b 100644
--- a/src/common/mapindex.h
+++ b/src/common/mapindex.h
@@ -22,9 +22,11 @@
#define COMMON_MAPINDEX_H
#include "common/hercules.h"
-#include "common/db.h"
#include "common/mmo.h"
+/* Forward Declarations */
+struct DBMap; // common/db.h
+
#define MAX_MAPINDEX 2000
/* wohoo, someone look at all those |: map_default could (or *should*) be a char-server.conf */
@@ -82,7 +84,7 @@
struct mapindex_interface {
char config_file[80];
/* mapname (str) -> index (int) */
- DBMap *db;
+ struct DBMap *db;
/* number of entries in the index table */
int num;
/* default map name */
diff --git a/src/common/md5calc.c b/src/common/md5calc.c
index bc70d9006..d346c8aa4 100644
--- a/src/common/md5calc.c
+++ b/src/common/md5calc.c
@@ -169,7 +169,7 @@ static void MD5_String2binary(const char * string, unsigned char * output)
//var
/*8bit*/
unsigned char padding_message[64]; //Extended message 512bit 64byte
- const unsigned char *pstring; //The position of string in the present scanning notes is held.
+ const unsigned char *pstring; // The position of string in the present scanning notes is held.
/*32bit*/
unsigned int string_byte_len, //The byte chief of string is held.
@@ -192,7 +192,7 @@ static void MD5_String2binary(const char * string, unsigned char * output)
//Step 1.Append Padding Bits (extension of a mark bit)
//1-1
string_byte_len = (unsigned int)strlen(string); //The byte chief of a character sequence is acquired.
- pstring = (const unsigned char *)string; //The position of the present character sequence is set.
+ pstring = (const unsigned char *)string; // The position of the present character sequence is set.
//1-2 Repeat calculation until length becomes less than 64 bytes.
for (i=string_byte_len; 64<=i; i-=64,pstring+=64)
@@ -200,7 +200,7 @@ static void MD5_String2binary(const char * string, unsigned char * output)
//1-3
copy_len = string_byte_len % 64; //The number of bytes which remained is computed.
- strncpy((char *)padding_message, (const char *)pstring, copy_len); //A message is copied to an extended bit sequence.
+ strncpy((char *)padding_message, (const char *)pstring, copy_len); // A message is copied to an extended bit sequence.
memset(padding_message+copy_len, 0, 64 - copy_len); //It buries by 0 until it becomes extended bit length.
padding_message[copy_len] |= 0x80; //The next of a message is 1.
diff --git a/src/common/socket.c b/src/common/socket.c
index 10712c78b..5d4ea06a0 100644
--- a/src/common/socket.c
+++ b/src/common/socket.c
@@ -975,7 +975,7 @@ static int access_debug = 0;
static int ddos_count = 10;
static int ddos_interval = 3*1000;
static int ddos_autoreset = 10*60*1000;
-DBMap *connect_history = NULL;
+struct DBMap *connect_history = NULL;
static int connect_check_(uint32 ip);
@@ -1089,7 +1089,7 @@ static int connect_check_clear(int tid, int64 tick, int id, intptr_t data) {
int clear = 0;
int list = 0;
ConnectHistory *hist = NULL;
- DBIterator *iter;
+ struct DBIterator *iter;
if( !db_size(connect_history) )
return 0;
diff --git a/src/common/sql.c b/src/common/sql.c
index ed93169ea..65960d8ea 100644
--- a/src/common/sql.c
+++ b/src/common/sql.c
@@ -79,11 +79,11 @@ struct SqlStmt {
///////////////////////////////////////////////////////////////////////////////
/// Allocates and initializes a new Sql handle.
-Sql* Sql_Malloc(void)
+struct Sql *Sql_Malloc(void)
{
- Sql* self;
+ struct Sql *self;
- CREATE(self, Sql, 1);
+ CREATE(self, struct Sql, 1);
mysql_init(&self->handle);
StrBuf->Init(&self->buf);
self->lengths = NULL;
@@ -93,10 +93,10 @@ Sql* Sql_Malloc(void)
return self;
}
-static int Sql_P_Keepalive(Sql* self);
+static int Sql_P_Keepalive(struct Sql *self);
/// Establishes a connection.
-int Sql_Connect(Sql* self, const char* user, const char* passwd, const char* host, uint16 port, const char* db)
+int Sql_Connect(struct Sql *self, const char *user, const char *passwd, const char *host, uint16 port, const char *db)
{
if( self == NULL )
return SQL_ERROR;
@@ -119,7 +119,7 @@ int Sql_Connect(Sql* self, const char* user, const char* passwd, const char* hos
}
/// Retrieves the timeout of the connection.
-int Sql_GetTimeout(Sql* self, uint32* out_timeout)
+int Sql_GetTimeout(struct Sql *self, uint32 *out_timeout)
{
if( self && out_timeout && SQL_SUCCESS == SQL->Query(self, "SHOW VARIABLES LIKE 'wait_timeout'") ) {
char* data;
@@ -136,7 +136,7 @@ int Sql_GetTimeout(Sql* self, uint32* out_timeout)
}
/// Retrieves the name of the columns of a table into out_buf, with the separator after each name.
-int Sql_GetColumnNames(Sql* self, const char* table, char* out_buf, size_t buf_len, char sep)
+int Sql_GetColumnNames(struct Sql *self, const char *table, char *out_buf, size_t buf_len, char sep)
{
char* data;
size_t len;
@@ -164,7 +164,7 @@ int Sql_GetColumnNames(Sql* self, const char* table, char* out_buf, size_t buf_l
}
/// Changes the encoding of the connection.
-int Sql_SetEncoding(Sql* self, const char* encoding)
+int Sql_SetEncoding(struct Sql *self, const char *encoding)
{
if( self && mysql_set_character_set(&self->handle, encoding) == 0 )
return SQL_SUCCESS;
@@ -172,7 +172,7 @@ int Sql_SetEncoding(Sql* self, const char* encoding)
}
/// Pings the connection.
-int Sql_Ping(Sql* self)
+int Sql_Ping(struct Sql *self)
{
if( self && mysql_ping(&self->handle) == 0 )
return SQL_SUCCESS;
@@ -184,7 +184,7 @@ int Sql_Ping(Sql* self)
/// @private
static int Sql_P_KeepaliveTimer(int tid, int64 tick, int id, intptr_t data)
{
- Sql* self = (Sql*)data;
+ struct Sql *self = (struct Sql *)data;
ShowInfo("Pinging SQL server to keep connection alive...\n");
Sql_Ping(self);
return 0;
@@ -194,7 +194,7 @@ static int Sql_P_KeepaliveTimer(int tid, int64 tick, int id, intptr_t data)
///
/// @return the keepalive timer id, or INVALID_TIMER
/// @private
-static int Sql_P_Keepalive(Sql* self)
+static int Sql_P_Keepalive(struct Sql *self)
{
uint32 timeout, ping_interval;
@@ -214,26 +214,27 @@ static int Sql_P_Keepalive(Sql* self)
}
/// Escapes a string.
-size_t Sql_EscapeString(Sql* self, char *out_to, const char *from)
+size_t Sql_EscapeString(struct Sql *self, char *out_to, const char *from)
{
- if( self )
+ if (self != NULL)
return (size_t)mysql_real_escape_string(&self->handle, out_to, from, (unsigned long)strlen(from));
else
return (size_t)mysql_escape_string(out_to, from, (unsigned long)strlen(from));
}
/// Escapes a string.
-size_t Sql_EscapeStringLen(Sql* self, char *out_to, const char *from, size_t from_len)
+size_t Sql_EscapeStringLen(struct Sql *self, char *out_to, const char *from, size_t from_len)
{
- if( self )
+ if (self != NULL)
return (size_t)mysql_real_escape_string(&self->handle, out_to, from, (unsigned long)from_len);
else
return (size_t)mysql_escape_string(out_to, from, (unsigned long)from_len);
}
/// Executes a query.
-int Sql_Query(Sql *self, const char *query, ...) __attribute__((format(printf, 2, 3)));
-int Sql_Query(Sql *self, const char *query, ...) {
+int Sql_Query(struct Sql *self, const char *query, ...) __attribute__((format(printf, 2, 3)));
+int Sql_Query(struct Sql *self, const char *query, ...)
+{
int res;
va_list args;
@@ -245,7 +246,7 @@ int Sql_Query(Sql *self, const char *query, ...) {
}
/// Executes a query.
-int Sql_QueryV(Sql* self, const char* query, va_list args)
+int Sql_QueryV(struct Sql *self, const char *query, va_list args)
{
if( self == NULL )
return SQL_ERROR;
@@ -270,7 +271,7 @@ int Sql_QueryV(Sql* self, const char* query, va_list args)
}
/// Executes a query.
-int Sql_QueryStr(Sql* self, const char* query)
+int Sql_QueryStr(struct Sql *self, const char *query)
{
if( self == NULL )
return SQL_ERROR;
@@ -295,33 +296,34 @@ int Sql_QueryStr(Sql* self, const char* query)
}
/// Returns the number of the AUTO_INCREMENT column of the last INSERT/UPDATE query.
-uint64 Sql_LastInsertId(Sql* self)
+uint64 Sql_LastInsertId(struct Sql *self)
{
- if( self )
+ if (self != NULL)
return (uint64)mysql_insert_id(&self->handle);
else
return 0;
}
/// Returns the number of columns in each row of the result.
-uint32 Sql_NumColumns(Sql* self)
+uint32 Sql_NumColumns(struct Sql *self)
{
- if( self && self->result )
+ if (self != NULL && self->result != NULL)
return (uint32)mysql_num_fields(self->result);
return 0;
}
/// Returns the number of rows in the result.
-uint64 Sql_NumRows(Sql* self)
+uint64 Sql_NumRows(struct Sql *self)
{
- if( self && self->result )
+ if (self != NULL && self->result != NULL)
return (uint64)mysql_num_rows(self->result);
return 0;
}
/// Fetches the next row.
-int Sql_NextRow(Sql* self) {
- if( self && self->result ) {
+int Sql_NextRow(struct Sql *self)
+{
+ if (self != NULL && self->result != NULL) {
self->row = mysql_fetch_row(self->result);
if( self->row ) {
self->lengths = mysql_fetch_lengths(self->result);
@@ -335,7 +337,7 @@ int Sql_NextRow(Sql* self) {
}
/// Gets the data of a column.
-int Sql_GetData(Sql* self, size_t col, char** out_buf, size_t* out_len)
+int Sql_GetData(struct Sql *self, size_t col, char **out_buf, size_t *out_len)
{
if( self && self->row ) {
if( col < SQL->NumColumns(self) ) {
@@ -351,7 +353,8 @@ int Sql_GetData(Sql* self, size_t col, char** out_buf, size_t* out_len)
}
/// Frees the result of the query.
-void Sql_FreeResult(Sql* self) {
+void Sql_FreeResult(struct Sql *self)
+{
if( self && self->result ) {
mysql_free_result(self->result);
self->result = NULL;
@@ -361,7 +364,7 @@ void Sql_FreeResult(Sql* self) {
}
/// Shows debug information (last query).
-void Sql_ShowDebug_(Sql* self, const char* debug_file, const unsigned long debug_line)
+void Sql_ShowDebug_(struct Sql *self, const char *debug_file, const unsigned long debug_line)
{
if( self == NULL )
ShowDebug("at %s:%lu - self is NULL\n", debug_file, debug_line);
@@ -372,7 +375,7 @@ void Sql_ShowDebug_(Sql* self, const char* debug_file, const unsigned long debug
}
/// Frees a Sql handle returned by Sql_Malloc.
-void Sql_Free(Sql* self) {
+void Sql_Free(struct Sql *self) {
if( self )
{
SQL->FreeResult(self);
@@ -515,7 +518,7 @@ static void Sql_P_ShowDebugMysqlFieldInfo(const char* prefix, enum enum_field_ty
/// Reports debug information about a truncated column.
///
/// @private
-static void SqlStmt_P_ShowDebugTruncatedColumn(SqlStmt* self, size_t i)
+static void SqlStmt_P_ShowDebugTruncatedColumn(struct SqlStmt *self, size_t i)
{
MYSQL_RES* meta;
MYSQL_FIELD* field;
@@ -535,8 +538,9 @@ static void SqlStmt_P_ShowDebugTruncatedColumn(SqlStmt* self, size_t i)
}
/// Allocates and initializes a new SqlStmt handle.
-SqlStmt* SqlStmt_Malloc(Sql* sql) {
- SqlStmt* self;
+struct SqlStmt *SqlStmt_Malloc(struct Sql *sql)
+{
+ struct SqlStmt *self;
MYSQL_STMT* stmt;
if( sql == NULL )
@@ -547,7 +551,7 @@ SqlStmt* SqlStmt_Malloc(Sql* sql) {
ShowSQL("DB error - %s\n", mysql_error(&sql->handle));
return NULL;
}
- CREATE(self, SqlStmt, 1);
+ CREATE(self, struct SqlStmt, 1);
StrBuf->Init(&self->buf);
self->stmt = stmt;
self->params = NULL;
@@ -562,8 +566,9 @@ SqlStmt* SqlStmt_Malloc(Sql* sql) {
}
/// Prepares the statement.
-int SqlStmt_Prepare(SqlStmt *self, const char *query, ...) __attribute__((format(printf, 2, 3)));
-int SqlStmt_Prepare(SqlStmt *self, const char *query, ...) {
+int SqlStmt_Prepare(struct SqlStmt *self, const char *query, ...) __attribute__((format(printf, 2, 3)));
+int SqlStmt_Prepare(struct SqlStmt *self, const char *query, ...)
+{
int res;
va_list args;
@@ -575,7 +580,7 @@ int SqlStmt_Prepare(SqlStmt *self, const char *query, ...) {
}
/// Prepares the statement.
-int SqlStmt_PrepareV(SqlStmt* self, const char* query, va_list args)
+int SqlStmt_PrepareV(struct SqlStmt *self, const char *query, va_list args)
{
if( self == NULL )
return SQL_ERROR;
@@ -595,7 +600,7 @@ int SqlStmt_PrepareV(SqlStmt* self, const char* query, va_list args)
}
/// Prepares the statement.
-int SqlStmt_PrepareStr(SqlStmt* self, const char* query)
+int SqlStmt_PrepareStr(struct SqlStmt *self, const char *query)
{
if( self == NULL )
return SQL_ERROR;
@@ -615,7 +620,7 @@ int SqlStmt_PrepareStr(SqlStmt* self, const char* query)
}
/// Returns the number of parameters in the prepared statement.
-size_t SqlStmt_NumParams(SqlStmt* self)
+size_t SqlStmt_NumParams(struct SqlStmt *self)
{
if( self )
return (size_t)mysql_stmt_param_count(self->stmt);
@@ -624,7 +629,7 @@ size_t SqlStmt_NumParams(SqlStmt* self)
}
/// Binds a parameter to a buffer.
-int SqlStmt_BindParam(SqlStmt* self, size_t idx, enum SqlDataType buffer_type, void* buffer, size_t buffer_len)
+int SqlStmt_BindParam(struct SqlStmt *self, size_t idx, enum SqlDataType buffer_type, const void *buffer, size_t buffer_len)
{
if( self == NULL )
return SQL_ERROR;
@@ -645,14 +650,23 @@ int SqlStmt_BindParam(SqlStmt* self, size_t idx, enum SqlDataType buffer_type, v
self->params[i].buffer_type = MYSQL_TYPE_NULL;
self->bind_params = true;
}
- if( idx < self->max_params )
- return Sql_P_BindSqlDataType(self->params+idx, buffer_type, buffer, buffer_len, NULL, NULL);
- else
- return SQL_SUCCESS;// out of range - ignore
+ if (idx >= self->max_params)
+ return SQL_SUCCESS; // out of range - ignore
+
+#pragma GCC diagnostic push
+#pragma GCC diagnostic ignored "-Wcast-qual"
+ /*
+ * MySQL uses the same struct with a non-const buffer for both
+ * parameters (input) and columns (output).
+ * As such, we get to close our eyes and pretend we didn't see we're
+ * dropping a const qualifier here.
+ */
+ return Sql_P_BindSqlDataType(self->params+idx, buffer_type, (void *)buffer, buffer_len, NULL, NULL);
+#pragma GCC diagnostic pop
}
/// Executes the prepared statement.
-int SqlStmt_Execute(SqlStmt* self)
+int SqlStmt_Execute(struct SqlStmt *self)
{
if( self == NULL )
return SQL_ERROR;
@@ -677,7 +691,7 @@ int SqlStmt_Execute(SqlStmt* self)
}
/// Returns the number of the AUTO_INCREMENT column of the last INSERT/UPDATE statement.
-uint64 SqlStmt_LastInsertId(SqlStmt* self)
+uint64 SqlStmt_LastInsertId(struct SqlStmt *self)
{
if( self )
return (uint64)mysql_stmt_insert_id(self->stmt);
@@ -686,7 +700,7 @@ uint64 SqlStmt_LastInsertId(SqlStmt* self)
}
/// Returns the number of columns in each row of the result.
-size_t SqlStmt_NumColumns(SqlStmt* self)
+size_t SqlStmt_NumColumns(struct SqlStmt *self)
{
if( self )
return (size_t)mysql_stmt_field_count(self->stmt);
@@ -695,7 +709,8 @@ size_t SqlStmt_NumColumns(SqlStmt* self)
}
/// Binds the result of a column to a buffer.
-int SqlStmt_BindColumn(SqlStmt *self, size_t idx, enum SqlDataType buffer_type, void *buffer, size_t buffer_len, uint32 *out_length, int8 *out_is_null) {
+int SqlStmt_BindColumn(struct SqlStmt *self, size_t idx, enum SqlDataType buffer_type, void *buffer, size_t buffer_len, uint32 *out_length, int8 *out_is_null)
+{
if (self == NULL)
return SQL_ERROR;
@@ -736,16 +751,16 @@ int SqlStmt_BindColumn(SqlStmt *self, size_t idx, enum SqlDataType buffer_type,
}
/// Returns the number of rows in the result.
-uint64 SqlStmt_NumRows(SqlStmt* self)
+uint64 SqlStmt_NumRows(struct SqlStmt *self)
{
- if( self )
+ if (self != NULL)
return (uint64)mysql_stmt_num_rows(self->stmt);
else
return 0;
}
/// Fetches the next row.
-int SqlStmt_NextRow(SqlStmt* self)
+int SqlStmt_NextRow(struct SqlStmt *self)
{
int err;
size_t i;
@@ -828,14 +843,14 @@ int SqlStmt_NextRow(SqlStmt* self)
}
/// Frees the result of the statement execution.
-void SqlStmt_FreeResult(SqlStmt* self)
+void SqlStmt_FreeResult(struct SqlStmt *self)
{
if( self )
mysql_stmt_free_result(self->stmt);
}
/// Shows debug information (with statement).
-void SqlStmt_ShowDebug_(SqlStmt* self, const char* debug_file, const unsigned long debug_line)
+void SqlStmt_ShowDebug_(struct SqlStmt *self, const char *debug_file, const unsigned long debug_line)
{
if( self == NULL )
ShowDebug("at %s:%lu - self is NULL\n", debug_file, debug_line);
@@ -846,7 +861,7 @@ void SqlStmt_ShowDebug_(SqlStmt* self, const char* debug_file, const unsigned lo
}
/// Frees a SqlStmt returned by SqlStmt_Malloc.
-void SqlStmt_Free(SqlStmt* self)
+void SqlStmt_Free(struct SqlStmt *self)
{
if( self )
{
@@ -919,7 +934,8 @@ void Sql_inter_server_read(const char* cfgName, bool first) {
return;
}
-void Sql_HerculesUpdateCheck(Sql* self) {
+void Sql_HerculesUpdateCheck(struct Sql *self)
+{
char line[22];// "yyyy-mm-dd--hh-mm" (17) + ".sql" (4) + 1
FILE* ifp;/* index fp */
unsigned int performed = 0;
@@ -980,7 +996,8 @@ void Sql_HerculesUpdateCheck(Sql* self) {
StrBuf->Destroy(&buf);
}
-void Sql_HerculesUpdateSkip(Sql* self,const char *filename) {
+void Sql_HerculesUpdateSkip(struct Sql *self, const char *filename)
+{
char path[41];// "sql-files/upgrades/" (19) + "yyyy-mm-dd--hh-mm" (17) + ".sql" (4) + 1
char timestamp[11];// "1360186680" (10) + 1
FILE* ifp;/* index fp */
diff --git a/src/common/sql.h b/src/common/sql.h
index e949a8280..07be829fc 100644
--- a/src/common/sql.h
+++ b/src/common/sql.h
@@ -71,90 +71,86 @@ enum SqlDataType {
SQLDT_LASTID
};
-struct Sql;// Sql handle (private access)
-struct SqlStmt;// Sql statement (private access)
-
-typedef enum SqlDataType SqlDataType;
-typedef struct Sql Sql;
-typedef struct SqlStmt SqlStmt;
+struct Sql; ///< Sql handle (private access)
+struct SqlStmt; ///< Sql statement (private access)
struct sql_interface {
/// Establishes a connection.
///
/// @return SQL_SUCCESS or SQL_ERROR
- int (*Connect) (Sql* self, const char* user, const char* passwd, const char* host, uint16 port, const char* db);
+ int (*Connect) (struct Sql *self, const char *user, const char *passwd, const char *host, uint16 port, const char *db);
/// Retrieves the timeout of the connection.
///
/// @return SQL_SUCCESS or SQL_ERROR
- int (*GetTimeout) (Sql* self, uint32* out_timeout);
+ int (*GetTimeout) (struct Sql *self, uint32 *out_timeout);
/// Retrieves the name of the columns of a table into out_buf, with the separator after each name.
///
/// @return SQL_SUCCESS or SQL_ERROR
- int (*GetColumnNames) (Sql* self, const char* table, char* out_buf, size_t buf_len, char sep);
+ int (*GetColumnNames) (struct Sql *self, const char *table, char *out_buf, size_t buf_len, char sep);
/// Changes the encoding of the connection.
///
/// @return SQL_SUCCESS or SQL_ERROR
- int (*SetEncoding) (Sql* self, const char* encoding);
+ int (*SetEncoding) (struct Sql *self, const char *encoding);
/// Pings the connection.
///
/// @return SQL_SUCCESS or SQL_ERROR
- int (*Ping) (Sql* self);
+ int (*Ping) (struct Sql *self);
/// Escapes a string.
/// The output buffer must be at least strlen(from)*2+1 in size.
///
/// @return The size of the escaped string
- size_t (*EscapeString) (Sql* self, char* out_to, const char* from);
+ size_t (*EscapeString) (struct Sql *self, char *out_to, const char *from);
/// Escapes a string.
/// The output buffer must be at least from_len*2+1 in size.
///
/// @return The size of the escaped string
- size_t (*EscapeStringLen) (Sql* self, char* out_to, const char* from, size_t from_len);
+ size_t (*EscapeStringLen) (struct Sql *self, char *out_to, const char *from, size_t from_len);
/// Executes a query.
/// Any previous result is freed.
/// The query is constructed as if it was sprintf.
///
/// @return SQL_SUCCESS or SQL_ERROR
- int (*Query) (Sql *self, const char *query, ...) __attribute__((format(printf, 2, 3)));
+ int (*Query) (struct Sql *self, const char *query, ...) __attribute__((format(printf, 2, 3)));
/// Executes a query.
/// Any previous result is freed.
/// The query is constructed as if it was svprintf.
///
/// @return SQL_SUCCESS or SQL_ERROR
- int (*QueryV) (Sql* self, const char* query, va_list args);
+ int (*QueryV) (struct Sql *self, const char *query, va_list args);
/// Executes a query.
/// Any previous result is freed.
/// The query is used directly.
///
/// @return SQL_SUCCESS or SQL_ERROR
- int (*QueryStr) (Sql* self, const char* query);
+ int (*QueryStr) (struct Sql *self, const char *query);
/// Returns the number of the AUTO_INCREMENT column of the last INSERT/UPDATE query.
///
/// @return Value of the auto-increment column
- uint64 (*LastInsertId) (Sql* self);
+ uint64 (*LastInsertId) (struct Sql *self);
/// Returns the number of columns in each row of the result.
///
/// @return Number of columns
- uint32 (*NumColumns) (Sql* self);
+ uint32 (*NumColumns) (struct Sql *self);
/// Returns the number of rows in the result.
///
/// @return Number of rows
- uint64 (*NumRows) (Sql* self);
+ uint64 (*NumRows) (struct Sql *self);
/// Fetches the next row.
/// The data of the previous row is no longer valid.
///
/// @return SQL_SUCCESS, SQL_ERROR or SQL_NO_DATA
- int (*NextRow) (Sql* self);
+ int (*NextRow) (struct Sql *self);
/// Gets the data of a column.
/// The data remains valid until the next row is fetched or the result is freed.
///
/// @return SQL_SUCCESS or SQL_ERROR
- int (*GetData) (Sql* self, size_t col, char** out_buf, size_t* out_len);
+ int (*GetData) (struct Sql *self, size_t col, char **out_buf, size_t *out_len);
/// Frees the result of the query.
- void (*FreeResult) (Sql* self);
+ void (*FreeResult) (struct Sql *self);
/// Shows debug information (last query).
- void (*ShowDebug_) (Sql* self, const char* debug_file, const unsigned long debug_line);
+ void (*ShowDebug_) (struct Sql *self, const char *debug_file, const unsigned long debug_line);
/// Frees a Sql handle returned by Sql_Malloc.
- void (*Free) (Sql* self);
+ void (*Free) (struct Sql *self);
/// Allocates and initializes a new Sql handle.
struct Sql *(*Malloc) (void);
@@ -180,56 +176,56 @@ struct sql_interface {
/// Queries in Sql and SqlStmt are independent and don't affect each other.
///
/// @return SqlStmt handle or NULL if an error occurred
- struct SqlStmt* (*StmtMalloc)(Sql* sql);
+ struct SqlStmt* (*StmtMalloc)(struct Sql *sql);
/// Prepares the statement.
/// Any previous result is freed and all parameter bindings are removed.
/// The query is constructed as if it was sprintf.
///
/// @return SQL_SUCCESS or SQL_ERROR
- int (*StmtPrepare) (SqlStmt *self, const char *query, ...) __attribute__((format(printf, 2, 3)));
+ int (*StmtPrepare) (struct SqlStmt *self, const char *query, ...) __attribute__((format(printf, 2, 3)));
/// Prepares the statement.
/// Any previous result is freed and all parameter bindings are removed.
/// The query is constructed as if it was svprintf.
///
/// @return SQL_SUCCESS or SQL_ERROR
- int (*StmtPrepareV)(SqlStmt* self, const char* query, va_list args);
+ int (*StmtPrepareV)(struct SqlStmt *self, const char *query, va_list args);
/// Prepares the statement.
/// Any previous result is freed and all parameter bindings are removed.
/// The query is used directly.
///
/// @return SQL_SUCCESS or SQL_ERROR
- int (*StmtPrepareStr)(SqlStmt* self, const char* query);
+ int (*StmtPrepareStr)(struct SqlStmt *self, const char *query);
/// Returns the number of parameters in the prepared statement.
///
/// @return Number or parameters
- size_t (*StmtNumParams)(SqlStmt* self);
+ size_t (*StmtNumParams)(struct SqlStmt *self);
/// Binds a parameter to a buffer.
/// The buffer data will be used when the statement is executed.
/// All parameters should have bindings.
///
/// @return SQL_SUCCESS or SQL_ERROR
- int (*StmtBindParam)(SqlStmt* self, size_t idx, SqlDataType buffer_type, void* buffer, size_t buffer_len);
+ int (*StmtBindParam)(struct SqlStmt *self, size_t idx, enum SqlDataType buffer_type, const void *buffer, size_t buffer_len);
/// Executes the prepared statement.
/// Any previous result is freed and all column bindings are removed.
///
/// @return SQL_SUCCESS or SQL_ERROR
- int (*StmtExecute)(SqlStmt* self);
+ int (*StmtExecute)(struct SqlStmt *self);
/// Returns the number of the AUTO_INCREMENT column of the last INSERT/UPDATE statement.
///
/// @return Value of the auto-increment column
- uint64 (*StmtLastInsertId)(SqlStmt* self);
+ uint64 (*StmtLastInsertId)(struct SqlStmt *self);
/// Returns the number of columns in each row of the result.
///
/// @return Number of columns
- size_t (*StmtNumColumns)(SqlStmt* self);
+ size_t (*StmtNumColumns)(struct SqlStmt *self);
/// Binds the result of a column to a buffer.
/// The buffer will be filled with data when the next row is fetched.
@@ -237,26 +233,26 @@ struct sql_interface {
/// and the null-terminator (an extra byte).
///
/// @return SQL_SUCCESS or SQL_ERROR
- int (*StmtBindColumn)(SqlStmt* self, size_t idx, SqlDataType buffer_type, void* buffer, size_t buffer_len, uint32* out_length, int8* out_is_null);
+ int (*StmtBindColumn)(struct SqlStmt *self, size_t idx, enum SqlDataType buffer_type, void *buffer, size_t buffer_len, uint32 *out_length, int8 *out_is_null);
/// Returns the number of rows in the result.
///
/// @return Number of rows
- uint64 (*StmtNumRows)(SqlStmt* self);
+ uint64 (*StmtNumRows)(struct SqlStmt *self);
/// Fetches the next row.
/// All column bindings will be filled with data.
///
/// @return SQL_SUCCESS, SQL_ERROR or SQL_NO_DATA
- int (*StmtNextRow)(SqlStmt* self);
+ int (*StmtNextRow)(struct SqlStmt *self);
/// Frees the result of the statement execution.
- void (*StmtFreeResult)(SqlStmt* self);
+ void (*StmtFreeResult)(struct SqlStmt *self);
/// Frees a SqlStmt returned by SqlStmt_Malloc.
- void (*StmtFree)(SqlStmt* self);
+ void (*StmtFree)(struct SqlStmt *self);
- void (*StmtShowDebug_)(SqlStmt* self, const char* debug_file, const unsigned long debug_line);
+ void (*StmtShowDebug_)(struct SqlStmt *self, const char *debug_file, const unsigned long debug_line);
};
@@ -265,8 +261,8 @@ void sql_defaults(void);
void Sql_Init(void);
-void Sql_HerculesUpdateCheck(Sql* self);
-void Sql_HerculesUpdateSkip(Sql* self,const char *filename);
+void Sql_HerculesUpdateCheck(struct Sql *self);
+void Sql_HerculesUpdateSkip(struct Sql *self, const char *filename);
#endif // HERCULES_CORE
HPShared struct sql_interface *SQL;