summaryrefslogtreecommitdiff
path: root/src/common
diff options
context:
space:
mode:
Diffstat (limited to 'src/common')
-rw-r--r--src/common/HPM.c42
-rw-r--r--src/common/HPM.h9
-rw-r--r--src/common/HPMDataCheck.h29
-rw-r--r--src/common/HPMSymbols.inc.h8
-rw-r--r--src/common/HPMi.h26
-rw-r--r--src/common/Makefile.in34
-rw-r--r--src/common/cbasetypes.h48
-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/grfio.c2
-rw-r--r--src/common/mapindex.h6
-rw-r--r--src/common/md5calc.c6
-rw-r--r--src/common/memmgr.c6
-rw-r--r--src/common/mmo.h9
-rw-r--r--src/common/showmsg.c13
-rw-r--r--src/common/socket.c4
-rw-r--r--src/common/sql.c148
-rw-r--r--src/common/sql.h78
-rw-r--r--src/common/strlib.c17
-rw-r--r--src/common/strlib.h8
-rw-r--r--src/common/sysinfo.c34
-rw-r--r--src/common/timer.c10
24 files changed, 810 insertions, 797 deletions
diff --git a/src/common/HPM.c b/src/common/HPM.c
index fa4025fb8..02b675704 100644
--- a/src/common/HPM.c
+++ b/src/common/HPM.c
@@ -38,6 +38,7 @@
#include "common/timer.h"
#include "common/utils.h"
#include "common/nullpo.h"
+#include "plugins/HPMHooking.h"
#include <stdio.h>
#include <stdlib.h>
@@ -51,11 +52,12 @@ struct malloc_interface iMalloc_HPM;
struct malloc_interface *HPMiMalloc;
struct HPM_interface HPM_s;
struct HPM_interface *HPM;
+struct HPMHooking_core_interface HPMHooking_core_s;
/**
* (char*) data name -> (unsigned int) HPMDataCheck[] index
**/
-DBMap *datacheck_db;
+struct DBMap *datacheck_db;
int datacheck_version;
const struct s_HPMDataCheck *datacheck_data;
@@ -341,13 +343,13 @@ void hplugins_removeFromHPData(enum HPluginDataTypes type, uint32 pluginID, stru
/* TODO: add ability for tracking using pID for the upcoming runtime load/unload support. */
bool HPM_AddHook(enum HPluginHookType type, const char *target, void *hook, unsigned int pID)
{
- if (!HPM->hooking) {
+ if (!HPM->hooking->enabled) {
ShowError("HPM:AddHook Fail! '%s' tried to hook to '%s' but HPMHooking is disabled!\n",HPM->pid2name(pID),target);
return false;
}
/* search if target is a known hook point within 'common' */
/* if not check if a sub-hooking list is available (from the server) and run it by */
- if (HPM->addhook_sub && HPM->addhook_sub(type,target,hook,pID))
+ if (HPM->hooking->addhook_sub != NULL && HPM->hooking->addhook_sub(type,target,hook,pID))
return true;
ShowError("HPM:AddHook: unknown Hooking Point '%s'!\n",target);
@@ -358,12 +360,12 @@ bool HPM_AddHook(enum HPluginHookType type, const char *target, void *hook, unsi
void HPM_HookStop(const char *func, unsigned int pID)
{
/* track? */
- HPM->force_return = true;
+ HPM->hooking->force_return = true;
}
-bool HPM_HookStopped (void)
+bool HPM_HookStopped(void)
{
- return HPM->force_return;
+ return HPM->hooking->force_return;
}
/**
@@ -567,16 +569,20 @@ struct hplugin *hplugin_load(const char* filename) {
plugin->hpi->addToHPData = hplugins_addToHPData;
plugin->hpi->getFromHPData = hplugins_getFromHPData;
plugin->hpi->removeFromHPData = hplugins_removeFromHPData;
- plugin->hpi->AddHook = HPM_AddHook;
- plugin->hpi->HookStop = HPM_HookStop;
- plugin->hpi->HookStopped = HPM_HookStopped;
plugin->hpi->addArg = hpm_add_arg;
plugin->hpi->addConf = hplugins_addconf;
+ if ((plugin->hpi->hooking = plugin_import(plugin->dll, "HPMHooking_s", struct HPMHooking_interface *)) != NULL) {
+ plugin->hpi->hooking->AddHook = HPM_AddHook;
+ plugin->hpi->hooking->HookStop = HPM_HookStop;
+ plugin->hpi->hooking->HookStopped = HPM_HookStopped;
+ }
/* server specific */
if( HPM->load_sub )
HPM->load_sub(plugin);
- ShowStatus("HPM: Loaded plugin '"CL_WHITE"%s"CL_RESET"' (%s).\n", plugin->info->name, plugin->info->version);
+ ShowStatus("HPM: Loaded plugin '"CL_WHITE"%s"CL_RESET"' (%s)%s.\n",
+ plugin->info->name, plugin->info->version,
+ plugin->hpi->hooking != NULL ? " built with HPMHooking support" : "");
return plugin;
}
@@ -660,12 +666,13 @@ void hplugins_config_read(void) {
bool (*addhook_sub) (enum HPluginHookType type, const char *target, void *hook, unsigned int pID);
if ((func = plugin_import(plugin->dll, "Hooked",const char * (*)(bool *))) != NULL
&& (addhook_sub = plugin_import(plugin->dll, "HPM_Plugin_AddHook",bool (*)(enum HPluginHookType, const char *, void *, unsigned int))) != NULL) {
- const char *failed = func(&HPM->force_return);
+ const char *failed = func(&HPM->hooking->force_return);
if (failed) {
ShowError("HPM: failed to retrieve '%s' for '"CL_WHITE"%s"CL_RESET"'!\n", failed, plugin_name);
} else {
- HPM->hooking = true;
- HPM->addhook_sub = addhook_sub;
+ HPM->hooking->enabled = true;
+ HPM->hooking->addhook_sub = addhook_sub;
+ HPM->hooking->Hooked = func; // The purpose of this is type-checking 'func' at compile time.
}
}
}
@@ -1046,11 +1053,10 @@ void hpm_final(void)
void hpm_defaults(void)
{
HPM = &HPM_s;
+ HPM->hooking = &HPMHooking_core_s;
memset(&HPM->filenames, 0, sizeof(HPM->filenames));
VECTOR_INIT(HPM->cmdline_load_plugins);
- HPM->force_return = false;
- HPM->hooking = false;
/* */
HPM->init = hpm_init;
HPM->final = hpm_final;
@@ -1067,7 +1073,6 @@ void hpm_defaults(void)
HPM->pid2name = hplugins_id2name;
HPM->parse_packets = hplugins_parse_packets;
HPM->load_sub = NULL;
- HPM->addhook_sub = NULL;
HPM->parseConf = hplugins_parse_conf;
HPM->getBattleConf = hplugins_get_battle_conf;
HPM->DataCheck = HPM_DataCheck;
@@ -1078,4 +1083,9 @@ void hpm_defaults(void)
HPM->data_store_create = hplugin_data_store_create;
HPM->data_store_validate = hplugin_data_store_validate;
HPM->data_store_validate_sub = NULL;
+
+ HPM->hooking->enabled = false;
+ HPM->hooking->force_return = false;
+ HPM->hooking->addhook_sub = NULL;
+ HPM->hooking->Hooked = NULL;
}
diff --git a/src/common/HPM.h b/src/common/HPM.h
index 109549aad..0b1275fde 100644
--- a/src/common/HPM.h
+++ b/src/common/HPM.h
@@ -65,6 +65,8 @@
#endif // WIN32
+struct HPMHooking_core_interface;
+
struct hplugin {
DLL dll;
unsigned int idx;
@@ -126,9 +128,6 @@ struct HPM_interface {
/* vars */
unsigned int version[2];
bool off;
- bool hooking;
- /* hooking */
- bool force_return;
/* data */
VECTOR_DECL(struct hplugin *) plugins;
VECTOR_DECL(struct hpm_symbol *) symbols;
@@ -159,7 +158,6 @@ struct HPM_interface {
char *(*pid2name) (unsigned int pid);
unsigned char (*parse_packets) (int fd, int packet_id, enum HPluginPacketHookingPoints point);
void (*load_sub) (struct hplugin *plugin);
- bool (*addhook_sub) (enum HPluginHookType type, const char *target, void *hook, unsigned int pID);
/* for custom config parsing */
bool (*parseConf) (const char *w1, const char *w2, enum HPluginConfType point);
bool (*getBattleConf) (const char* w1, int *value);
@@ -173,6 +171,9 @@ struct HPM_interface {
bool (*data_store_validate) (enum HPluginDataTypes type, struct hplugin_data_store **storeptr, bool initialize);
/* for server-specific HPData e.g. map_session_data */
bool (*data_store_validate_sub) (enum HPluginDataTypes type, struct hplugin_data_store **storeptr, bool initialize);
+
+ /* hooking */
+ struct HPMHooking_core_interface *hooking;
};
CMDLINEARG(loadplugin);
diff --git a/src/common/HPMDataCheck.h b/src/common/HPMDataCheck.h
index 7e88b5a34..3d25d7330 100644
--- a/src/common/HPMDataCheck.h
+++ b/src/common/HPMDataCheck.h
@@ -270,6 +270,32 @@ HPExport const struct s_HPMDataCheck HPMDataCheck[] = {
#else
#define LOGIN_ACCOUNT_H
#endif // LOGIN_ACCOUNT_H
+ #ifdef LOGIN_LCLIF_H
+ { "lclif_interface", sizeof(struct lclif_interface), SERVER_TYPE_LOGIN },
+ { "login_packet_db", sizeof(struct login_packet_db), SERVER_TYPE_LOGIN },
+ #else
+ #define LOGIN_LCLIF_H
+ #endif // LOGIN_LCLIF_H
+ #ifdef LOGIN_LCLIF_P_H
+ { "lclif_interface_dbs", sizeof(struct lclif_interface_dbs), SERVER_TYPE_LOGIN },
+ { "lclif_interface_private", sizeof(struct lclif_interface_private), SERVER_TYPE_LOGIN },
+ { "packet_AC_ACCEPT_LOGIN", sizeof(struct packet_AC_ACCEPT_LOGIN), SERVER_TYPE_LOGIN },
+ { "packet_AC_REFUSE_LOGIN", sizeof(struct packet_AC_REFUSE_LOGIN), SERVER_TYPE_LOGIN },
+ { "packet_AC_REFUSE_LOGIN_R2", sizeof(struct packet_AC_REFUSE_LOGIN_R2), SERVER_TYPE_LOGIN },
+ { "packet_CA_CHARSERVERCONNECT", sizeof(struct packet_CA_CHARSERVERCONNECT), SERVER_TYPE_LOGIN },
+ { "packet_CA_CONNECT_INFO_CHANGED", sizeof(struct packet_CA_CONNECT_INFO_CHANGED), SERVER_TYPE_LOGIN },
+ { "packet_CA_EXE_HASHCHECK", sizeof(struct packet_CA_EXE_HASHCHECK), SERVER_TYPE_LOGIN },
+ { "packet_CA_LOGIN", sizeof(struct packet_CA_LOGIN), SERVER_TYPE_LOGIN },
+ { "packet_CA_LOGIN2", sizeof(struct packet_CA_LOGIN2), SERVER_TYPE_LOGIN },
+ { "packet_CA_LOGIN3", sizeof(struct packet_CA_LOGIN3), SERVER_TYPE_LOGIN },
+ { "packet_CA_LOGIN4", sizeof(struct packet_CA_LOGIN4), SERVER_TYPE_LOGIN },
+ { "packet_CA_LOGIN_HAN", sizeof(struct packet_CA_LOGIN_HAN), SERVER_TYPE_LOGIN },
+ { "packet_CA_LOGIN_PCBANG", sizeof(struct packet_CA_LOGIN_PCBANG), SERVER_TYPE_LOGIN },
+ { "packet_CA_SSO_LOGIN_REQ", sizeof(struct packet_CA_SSO_LOGIN_REQ), SERVER_TYPE_LOGIN },
+ { "packet_SC_NOTIFY_BAN", sizeof(struct packet_SC_NOTIFY_BAN), SERVER_TYPE_LOGIN },
+ #else
+ #define LOGIN_LCLIF_P_H
+ #endif // LOGIN_LCLIF_P_H
#ifdef LOGIN_LOGIN_H
{ "Login_Config", sizeof(struct Login_Config), SERVER_TYPE_LOGIN },
{ "client_hash_node", sizeof(struct client_hash_node), SERVER_TYPE_LOGIN },
@@ -388,6 +414,7 @@ HPExport const struct s_HPMDataCheck HPMDataCheck[] = {
#ifdef MAP_IRC_BOT_H
{ "irc_bot_interface", sizeof(struct irc_bot_interface), SERVER_TYPE_MAP },
{ "irc_func", sizeof(struct irc_func), SERVER_TYPE_MAP },
+ { "message_flood", sizeof(struct message_flood), SERVER_TYPE_MAP },
#else
#define MAP_IRC_BOT_H
#endif // MAP_IRC_BOT_H
@@ -506,6 +533,7 @@ HPExport const struct s_HPMDataCheck HPMDataCheck[] = {
{ "packet_bgqueue_revoke_req", sizeof(struct packet_bgqueue_revoke_req), SERVER_TYPE_MAP },
{ "packet_bgqueue_update_info", sizeof(struct packet_bgqueue_update_info), SERVER_TYPE_MAP },
{ "packet_cart_additem_ack", sizeof(struct packet_cart_additem_ack), SERVER_TYPE_MAP },
+ { "packet_chat_message", sizeof(struct packet_chat_message), SERVER_TYPE_MAP },
{ "packet_damage", sizeof(struct packet_damage), SERVER_TYPE_MAP },
{ "packet_dropflooritem", sizeof(struct packet_dropflooritem), SERVER_TYPE_MAP },
{ "packet_equip_item", sizeof(struct packet_equip_item), SERVER_TYPE_MAP },
@@ -548,6 +576,7 @@ HPExport const struct s_HPMDataCheck HPMDataCheck[] = {
{ "packet_unequipitem_ack", sizeof(struct packet_unequipitem_ack), SERVER_TYPE_MAP },
{ "packet_unit_walking", sizeof(struct packet_unit_walking), SERVER_TYPE_MAP },
{ "packet_viewequip_ack", sizeof(struct packet_viewequip_ack), SERVER_TYPE_MAP },
+ { "packet_whisper_message", sizeof(struct packet_whisper_message), SERVER_TYPE_MAP },
{ "packet_wis_end", sizeof(struct packet_wis_end), SERVER_TYPE_MAP },
#else
#define MAP_PACKETS_STRUCT_H
diff --git a/src/common/HPMSymbols.inc.h b/src/common/HPMSymbols.inc.h
index b06c43bf8..a6bf1622b 100644
--- a/src/common/HPMSymbols.inc.h
+++ b/src/common/HPMSymbols.inc.h
@@ -2,7 +2,7 @@
* This file is part of Hercules.
* http://herc.ws - http://github.com/HerculesWS/Hercules
*
- * Copyright (C) 2015-2016 Hercules Dev Team
+ * Copyright (C) 2013-2016 Hercules Dev Team
*
* Hercules is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@@ -129,6 +129,9 @@ struct irc_bot_interface *ircbot;
#ifdef MAP_ITEMDB_H /* itemdb */
struct itemdb_interface *itemdb;
#endif // MAP_ITEMDB_H
+#ifdef LOGIN_LCLIF_H /* lclif */
+struct lclif_interface *lclif;
+#endif // LOGIN_LCLIF_H
#ifdef COMMON_CONF_H /* libconfig */
struct libconfig_interface *libconfig;
#endif // COMMON_CONF_H
@@ -358,6 +361,9 @@ if ((server_type&(SERVER_TYPE_MAP)) && !HPM_SYMBOL("ircbot", ircbot)) return "ir
#ifdef MAP_ITEMDB_H /* itemdb */
if ((server_type&(SERVER_TYPE_MAP)) && !HPM_SYMBOL("itemdb", itemdb)) return "itemdb";
#endif // MAP_ITEMDB_H
+#ifdef LOGIN_LCLIF_H /* lclif */
+if ((server_type&(SERVER_TYPE_LOGIN)) && !HPM_SYMBOL("lclif", lclif)) return "lclif";
+#endif // LOGIN_LCLIF_H
#ifdef COMMON_CONF_H /* libconfig */
if ((server_type&(SERVER_TYPE_ALL)) && !HPM_SYMBOL("libconfig", libconfig)) return "libconfig";
#endif // COMMON_CONF_H
diff --git a/src/common/HPMi.h b/src/common/HPMi.h
index cf3e16277..e16eb1d75 100644
--- a/src/common/HPMi.h
+++ b/src/common/HPMi.h
@@ -24,15 +24,16 @@
#include "common/console.h"
#include "common/core.h"
#include "common/showmsg.h"
-#include "common/sql.h"
+struct HPMHooking_interface;
+struct Sql; // common/sql.h
struct script_state;
struct AtCommandInfo;
struct socket_data;
struct map_session_data;
struct hplugin_data_store;
-#define HPM_VERSION "1.1"
+#define HPM_VERSION "1.2"
#define HPM_ADDCONF_LENGTH 40
struct hplugin_info {
@@ -71,11 +72,6 @@ enum HPluginPacketHookingPoints {
hpPHP_MAX,
};
-enum HPluginHookType {
- HOOK_TYPE_PRE,
- HOOK_TYPE_POST,
-};
-
/**
* Data types for plugin custom data.
*/
@@ -107,13 +103,6 @@ enum HPluginConfType {
HPCT_MAX,
};
-#define addHookPre(tname,hook) (HPMi->AddHook(HOOK_TYPE_PRE,(tname),(hook),HPMi->pid))
-#define addHookPost(tname,hook) (HPMi->AddHook(HOOK_TYPE_POST,(tname),(hook),HPMi->pid))
-/* need better names ;/ */
-/* will not run the original function after pre-hook processing is complete (other hooks will run) */
-#define hookStop() (HPMi->HookStop(__func__,HPMi->pid))
-#define hookStopped() (HPMi->HookStopped())
-
#define addArg(name, param,func,help) (HPMi->addArg(HPMi->pid,(name),(param),(cmdline_arg_ ## func),(help)))
/* HPData handy redirects */
/* session[] */
@@ -231,10 +220,6 @@ struct HPMi_interface {
void (*removeFromHPData) (enum HPluginDataTypes type, uint32 pluginID, struct hplugin_data_store *store, uint32 classid);
/* packet */
bool (*addPacket) (unsigned short cmd, unsigned short length, void (*receive)(int fd), unsigned int point, unsigned int pluginID);
- /* Hooking */
- bool (*AddHook) (enum HPluginHookType type, const char *target, void *hook, unsigned int pID);
- void (*HookStop) (const char *func, unsigned int pID);
- bool (*HookStopped) (void);
/* program --arg/-a */
bool (*addArg) (unsigned int pluginID, char *name, bool has_param, CmdlineExecFunc func, const char *help);
/* battle-config recv param */
@@ -242,7 +227,10 @@ struct HPMi_interface {
/* pc group permission */
void (*addPCGPermission) (unsigned int pluginID, char *name, unsigned int *mask);
- Sql *sql_handle;
+ struct Sql *sql_handle;
+
+ /* Hooking */
+ struct HPMHooking_interface *hooking;
};
#ifdef HERCULES_CORE
#define HPM_SYMBOL(n, s) (HPM->share((s), (n)), true)
diff --git a/src/common/Makefile.in b/src/common/Makefile.in
index 9d4b2d044..6e7ffa088 100644
--- a/src/common/Makefile.in
+++ b/src/common/Makefile.in
@@ -1,7 +1,7 @@
# This file is part of Hercules.
# http://herc.ws - http://github.com/HerculesWS/Hercules
#
-# Copyright (C) 2012-2015 Hercules Dev Team
+# Copyright (C) 2012-2016 Hercules Dev Team
# Copyright (C) Athena Dev Teams
#
# Hercules is free software: you can redistribute it and/or modify
@@ -50,7 +50,9 @@ COMMON_C += console.c core.c memmgr.c socket.c
COMMON_H = atomic.h cbasetypes.h conf.h console.h core.h db.h des.h ers.h \
grfio.h hercules.h HPM.h HPMi.h memmgr.h mapindex.h md5calc.h \
mmo.h mutex.h nullpo.h random.h showmsg.h socket.h spinlock.h \
- sql.h strlib.h sysinfo.h thread.h timer.h utils.h winapi.h
+ sql.h strlib.h sysinfo.h thread.h timer.h utils.h winapi.h \
+ ../plugins/HPMHooking.h
+COMMON_PH =
COMMON_SQL_OBJ = obj_sql/sql.o
COMMON_SQL_H = sql.h
@@ -95,7 +97,7 @@ help:
Makefile: Makefile.in
@$(MAKE) -C ../.. src/common/Makefile
-$(SYSINFO_INC): $(COMMON_C) $(COMMON_H) $(CONFIG_H) $(MT19937AR_H) $(LIBCONFIG_H)
+$(SYSINFO_INC): $(COMMON_C) $(COMMON_PH) $(COMMON_H) $(CONFIG_H) $(MT19937AR_H) $(LIBCONFIG_H)
@echo " MAKE $@"
@$(MAKE) -C ../.. sysinfo
@@ -131,25 +133,27 @@ common_mini: $(COMMON_MINI_OBJ) $(MT19937AR_OBJ) $(LIBCONFIG_OBJ) obj_all/common
common_sql: $(COMMON_SQL_OBJ) obj_sql/common_sql.a Makefile
-obj_all/sysinfo.o: sysinfo.c $(COMMON_H) $(CONFIG_H) $(MT19937AR_H) $(LIBCONFIG_H) $(SYSINFO_INC) | obj_all
+# missing object files
+$(MT19937AR_OBJ):
+ @echo " MAKE $@"
+ @$(MAKE) -C $(MT19937AR_D)
+
+$(LIBCONFIG_OBJ):
+ @echo " MAKE $@"
+ @$(MAKE) -C $(LIBCONFIG_D)
+
+.SECONDEXPANSION:
+
+obj_all/sysinfo.o: sysinfo.c $(filter sysinfo.p.h, $(COMMON_PH)) $(COMMON_H) $(CONFIG_H) $(MT19937AR_H) $(LIBCONFIG_H) $(SYSINFO_INC) | obj_all
obj_all/%.o: %.c $(COMMON_H) $(CONFIG_H) $(MT19937AR_H) $(LIBCONFIG_H) | $(SYSINFO_INC) obj_all
@echo " CC $<"
@$(CC) @CFLAGS@ @DEFS@ $(COMMON_INCLUDE) $(THIRDPARTY_INCLUDE) @CPPFLAGS@ -c $(OUTPUT_OPTION) $<
-obj_all/mini%.o: %.c $(COMMON_H) $(CONFIG_H) $(MT19937AR_H) $(LIBCONFIG_H) | $(SYSINFO_INC) obj_all
+obj_all/mini%.o: %.c $$(filter %.p.h, $(COMMON_PH)) $(COMMON_H) $(CONFIG_H) $(MT19937AR_H) $(LIBCONFIG_H) | $(SYSINFO_INC) obj_all
@echo " CC $<"
@$(CC) @CFLAGS@ @DEFS@ $(COMMON_INCLUDE) $(THIRDPARTY_INCLUDE) -DMINICORE @CPPFLAGS@ -c $(OUTPUT_OPTION) $<
-obj_sql/%.o: %.c $(COMMON_H) $(COMMON_SQL_H) $(CONFIG_H) $(LIBCONFIG_H) | $(SYSINFO_INC) obj_sql
+obj_sql/%.o: %.c $$(filter %.p.h, $(COMMON_PH)) $(COMMON_H) $(COMMON_SQL_H) $(CONFIG_H) $(LIBCONFIG_H) | $(SYSINFO_INC) obj_sql
@echo " CC $<"
@$(CC) @CFLAGS@ @DEFS@ $(COMMON_INCLUDE) $(THIRDPARTY_INCLUDE) @MYSQL_CFLAGS@ @CPPFLAGS@ -c $(OUTPUT_OPTION) $<
-
-# missing object files
-$(MT19937AR_OBJ):
- @echo " MAKE $@"
- @$(MAKE) -C $(MT19937AR_D)
-
-$(LIBCONFIG_OBJ):
- @echo " MAKE $@"
- @$(MAKE) -C $(LIBCONFIG_D)
diff --git a/src/common/cbasetypes.h b/src/common/cbasetypes.h
index 6843ce486..d3db86543 100644
--- a/src/common/cbasetypes.h
+++ b/src/common/cbasetypes.h
@@ -118,16 +118,6 @@
#include <limits.h>
#include <time.h>
-// temporary fix for bugreport:4961 (unintended conversion from signed to unsigned)
-// (-20 >= UCHAR_MAX) returns true
-// (-20 >= USHRT_MAX) returns true
-#if defined(__FreeBSD__) && defined(__x86_64)
-#undef UCHAR_MAX
-#define UCHAR_MAX ((unsigned char)0xff)
-#undef USHRT_MAX
-#define USHRT_MAX ((unsigned short)0xffff)
-#endif
-
// ILP64 isn't supported, so always 32 bits?
#ifndef UINT_MAX
#define UINT_MAX 0xffffffff
@@ -262,16 +252,13 @@ typedef uintptr_t uintptr;
#if defined(__BORLANDC__) || _MSC_VER < 1900
#define snprintf _snprintf
#endif
-#if defined(_MSC_VER) && _MSC_VER < 1400
-#define vsnprintf _vsnprintf
-#endif
#else
#define strcmpi strcasecmp
#define stricmp strcasecmp
#define strncmpi strncasecmp
#define strnicmp strncasecmp
#endif
-#if defined(_MSC_VER) && _MSC_VER > 1200
+#if defined(_MSC_VER)
#define strtoull _strtoui64
#define strtoll _strtoi64
#endif
@@ -295,6 +282,21 @@ typedef uintptr_t uintptr;
#define analyzer_noreturn
#endif
+// gcc version (if any) - borrowed from Mana Plus
+#ifdef __GNUC__
+#define GCC_VERSION (__GNUC__ * 10000 \
+ + __GNUC_MINOR__ * 100 \
+ + __GNUC_PATCHLEVEL__)
+#else
+#define GCC_VERSION 0
+#endif
+
+// Pragma macro only enabled on gcc >= 4.5 or clang - borrowed from Mana Plus
+#if defined(__GNUC__) && (defined(__clang__) || GCC_VERSION >= 40500)
+#define PRAGMA_GCC45(str) _Pragma(#str)
+#else // ! defined(__GNUC__) && (defined(__clang__) || GCC_VERSION >= 40500)
+#define PRAGMA_GCC45(str)
+#endif // ! defined(__GNUC__) && (defined(__clang__) || GCC_VERSION >= 40500)
// boolean types for C
#if !defined(_MSC_VER) || _MSC_VER >= 1800
@@ -327,24 +329,6 @@ typedef char bool;
//#define swap(a,b) if (a != b) ((a ^= b), (b ^= a), (a ^= b))
// but is vulnerable to 'if (foo) swap(bar, baz); else quux();', causing the else to nest incorrectly.
#define swap(a,b) do { if ((a) != (b)) { (a) ^= (b); (b) ^= (a); (a) ^= (b); } } while(0)
-#if 0 //to be activated soon, more tests needed on how VS works with the macro above
-#ifdef WIN32
-#undef swap
-#define swap(a,b)__asm { \
- __asm mov eax, dword ptr [a] \
- __asm cmp eax, dword ptr [b] \
- __asm je _ret \
- __asm xor eax, dword ptr [b] \
- __asm mov dword ptr [a], eax \
- __asm xor eax, dword ptr [b] \
- __asm mov dword ptr [b], eax \
- __asm xor eax, dword ptr [a] \
- __asm mov dword ptr [a], eax \
- __asm _ret: \
-}
-#endif
-#endif
-
#define swap_ptr(a,b) do { if ((a) != (b)) (a) = (void*)((intptr_t)(a) ^ (intptr_t)(b)); (b) = (void*)((intptr_t)(a) ^ (intptr_t)(b)); (a) = (void*)((intptr_t)(a) ^ (intptr_t)(b)); } while(0)
#ifndef max
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/grfio.c b/src/common/grfio.c
index 678875c91..c6e47d357 100644
--- a/src/common/grfio.c
+++ b/src/common/grfio.c
@@ -410,12 +410,12 @@ void *grfio_reads(const char *fname, int *size)
// LocalFileCheck
char lfname[256];
FILE *in;
- unsigned char *buf = NULL;
grfio_localpath_create(lfname, sizeof(lfname), (entry && entry->fnd) ? entry->fnd : fname);
in = fopen(lfname, "rb");
if (in != NULL) {
int declen;
+ unsigned char *buf = NULL;
fseek(in,0,SEEK_END);
declen = (int)ftell(in);
if (declen == -1) {
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/memmgr.c b/src/common/memmgr.c
index 15e55fbeb..dfea24465 100644
--- a/src/common/memmgr.c
+++ b/src/common/memmgr.c
@@ -154,8 +154,8 @@ void* aReallocz_(void *p, size_t size, const char *file, int line, const char *f
#ifdef USE_MEMMGR
ret = REALLOC(p, size, file, line, func);
#else
- size_t newSize;
- if (p) {
+ if (p != NULL) {
+ size_t newSize;
size_t oldSize = BUFFER_SIZE(p);
ret = REALLOC(p, size, file, line, func);
newSize = BUFFER_SIZE(ret);
@@ -167,7 +167,7 @@ void* aReallocz_(void *p, size_t size, const char *file, int line, const char *f
memset(ret, 0, BUFFER_SIZE(ret));
}
#endif
- if (ret == NULL){
+ if (ret == NULL) {
ShowFatalError("%s:%d: in func %s: aRealloc error out of memory!\n",file,line,func);
exit(EXIT_FAILURE);
}
diff --git a/src/common/mmo.h b/src/common/mmo.h
index 0abae6092..a2080d900 100644
--- a/src/common/mmo.h
+++ b/src/common/mmo.h
@@ -2,7 +2,7 @@
* This file is part of Hercules.
* http://herc.ws - http://github.com/HerculesWS/Hercules
*
- * Copyright (C) 2012-2015 Hercules Dev Team
+ * Copyright (C) 2012-2016 Hercules Dev Team
* Copyright (C) Athena Dev Teams
*
* Hercules is free software: you can redistribute it and/or modify
@@ -120,7 +120,7 @@
#define MAX_SLOTS 4
//Max amount of a single stacked item
#define MAX_AMOUNT 30000
-#define MAX_ZENY 1000000000
+#define MAX_ZENY INT_MAX
//Official Limit: 2.1b ( the var that stores the money doesn't go much higher than this by default )
#define MAX_BANK_ZENY INT_MAX
@@ -213,11 +213,6 @@
#define JOBL_BABY 0x2000 //8192
#define JOBL_THIRD 0x4000 //16384
-//Packet DB
-#define MIN_PACKET_DB 0x0064 //what's the point of minimum packet id ? [hemagx]
-#define MAX_PACKET_DB 0x0F00
-#define MAX_PACKET_POS 20
-
#define SCRIPT_VARNAME_LENGTH 32 ///< Maximum length of a script variable
#define INFINITE_DURATION (-1) // Infinite duration for status changes
diff --git a/src/common/showmsg.c b/src/common/showmsg.c
index 1c1d4ca8b..8ed8efc1d 100644
--- a/src/common/showmsg.c
+++ b/src/common/showmsg.c
@@ -244,13 +244,13 @@ int VFPRINTF(HANDLE handle, const char *fmt, va_list argptr)
continue;
} else if (*q == ';') {
// delimiter
- if (numpoint < sizeof(numbers)/sizeof(*numbers)) {
+ if (numpoint < ARRAYLENGTH(numbers)) {
// go to next array position
numpoint++;
} else {
// array is full, so we 'forget' the first value
- memmove(numbers,numbers+1,sizeof(numbers)/sizeof(*numbers)-1);
- numbers[sizeof(numbers)/sizeof(*numbers)-1]=0;
+ memmove(numbers, numbers+1, ARRAYLENGTH(numbers)-1);
+ numbers[ARRAYLENGTH(numbers)-1]=0;
}
++q;
// and next number
@@ -605,9 +605,6 @@ int vShowMessage_(enum msg_type flag, const char *string, va_list ap)
{
va_list apcopy;
char prefix[100];
-#if defined(DEBUGLOGMAP) || defined(DEBUGLOGCHAR) || defined(DEBUGLOGLOGIN)
- FILE *fp;
-#endif
if (!string || *string == '\0') {
ShowError("Empty string passed to vShowMessage_().\n");
@@ -702,8 +699,8 @@ int vShowMessage_(enum msg_type flag, const char *string, va_list ap)
}
#if defined(DEBUGLOGMAP) || defined(DEBUGLOGCHAR) || defined(DEBUGLOGLOGIN)
- if(strlen(DEBUGLOGPATH) > 0) {
- fp=fopen(DEBUGLOGPATH,"a");
+ if (strlen(DEBUGLOGPATH) > 0) {
+ FILE *fp = fopen(DEBUGLOGPATH,"a");
if (fp == NULL) {
FPRINTF(STDERR, CL_RED"[ERROR]"CL_RESET": Could not open '"CL_WHITE"%s"CL_RESET"', access denied.\n", DEBUGLOGPATH);
FFLUSH(STDERR);
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..9a90f9807 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_GCC45(GCC diagnostic push)
+PRAGMA_GCC45(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_GCC45(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;
@@ -763,8 +778,6 @@ int SqlStmt_NextRow(SqlStmt* self)
// check for errors
if (err == MYSQL_NO_DATA)
return SQL_NO_DATA;
-#if defined(MYSQL_DATA_TRUNCATED)
- // MySQL 5.0/5.1 defines and returns MYSQL_DATA_TRUNCATED [FlavioJS]
if (err == MYSQL_DATA_TRUNCATED) {
my_bool truncated;
@@ -789,7 +802,6 @@ int SqlStmt_NextRow(SqlStmt* self)
ShowSQL("DB error - data truncated (unknown source)\n");
return SQL_ERROR;
}
-#endif
if (err) {
ShowSQL("DB error - %s\n", mysql_stmt_error(self->stmt));
hercules_mysql_error_handler(mysql_stmt_errno(self->stmt));
@@ -801,18 +813,6 @@ int SqlStmt_NextRow(SqlStmt* self)
for (i = 0; i < cols; ++i) {
unsigned long length = self->column_lengths[i].length;
MYSQL_BIND *column = &self->columns[i];
-#if !defined(MYSQL_DATA_TRUNCATED)
- // MySQL 4.1/(below?) returns success even if data is truncated, so we test truncation manually [FlavioJS]
- if (column->buffer_length < length) {
- // report truncated column
- if (column->buffer_type == MYSQL_TYPE_STRING || column->buffer_type == MYSQL_TYPE_BLOB) {
- // string/enum/blob column
- SqlStmt_P_ShowDebugTruncatedColumn(self, i);
- return SQL_ERROR;
- }
- // FIXME numeric types and null [FlavioJS]
- }
-#endif
if (self->column_lengths[i].out_length)
*self->column_lengths[i].out_length = (uint32)length;
if (column->buffer_type == MYSQL_TYPE_STRING) {
@@ -828,14 +828,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 +846,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 )
{
@@ -865,10 +865,10 @@ void SqlStmt_Free(SqlStmt* self)
}
/* receives mysql error codes during runtime (not on first-time-connects) */
void hercules_mysql_error_handler(unsigned int ecode) {
- static unsigned int retry = 1;
switch( ecode ) {
case 2003:/* Can't connect to MySQL (this error only happens here when failing to reconnect) */
if( mysql_reconnect_type == 1 ) {
+ static unsigned int retry = 1;
if( ++retry > mysql_reconnect_count ) {
ShowFatalError("MySQL has been unreachable for too long, %u reconnects were attempted. Shutting Down\n", retry);
exit(EXIT_FAILURE);
@@ -919,7 +919,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 +981,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;
diff --git a/src/common/strlib.c b/src/common/strlib.c
index 997b01ffa..9690151b4 100644
--- a/src/common/strlib.c
+++ b/src/common/strlib.c
@@ -2,7 +2,7 @@
* This file is part of Hercules.
* http://herc.ws - http://github.com/HerculesWS/Hercules
*
- * Copyright (C) 2012-2015 Hercules Dev Team
+ * Copyright (C) 2012-2016 Hercules Dev Team
* Copyright (C) Athena Dev Teams
*
* Hercules is free software: you can redistribute it and/or modify
@@ -271,10 +271,9 @@ char* strlib_strtok_r(char *s1, const char *s2, char **lasts)
size_t strlib_strnlen(const char *string, size_t maxlen)
{
-// TODO: The _MSC_VER check can probably be removed (we no longer support VS
-// versions <= 2003, do we?), but this implementation might be still necessary
-// for NetBSD 5.x and possibly some Solaris versions.
-#if !(defined(WIN32) && defined(_MSC_VER) && _MSC_VER >= 1400) && !defined(HAVE_STRNLEN)
+// TODO: Verify whether this implementation is still necessary for NetBSD 5.x
+// and possibly some Solaris versions.
+#if !(defined(WIN32) && defined(_MSC_VER)) && !defined(HAVE_STRNLEN)
/* Find the length of STRING, but scan at most MAXLEN characters.
* If no '\0' terminator is found in that many characters, return MAXLEN.
*/
@@ -424,13 +423,12 @@ int strlib_strline(const char *str, size_t pos)
/// @param output Output string
/// @param input Binary input buffer
/// @param count Number of bytes to convert
-bool strlib_bin2hex(char *output, unsigned char *input, size_t count)
+bool strlib_bin2hex(char *output, const unsigned char *input, size_t count)
{
char toHex[] = "0123456789abcdef";
size_t i;
- for( i = 0; i < count; ++i )
- {
+ for (i = 0; i < count; ++i) {
*output++ = toHex[(*input & 0xF0) >> 4];
*output++ = toHex[(*input & 0x0F) >> 0];
++input;
@@ -630,6 +628,7 @@ int sv_parse(const char* str, int len, int startoff, char delim, int* out_pos, i
svstate.opt = opt;
svstate.delim = delim;
svstate.done = false;
+ svstate.start = 0;
// parse
count = 0;
@@ -1114,7 +1113,7 @@ void strlib_defaults(void) {
strlib->normalize_name_ = strlib_normalize_name;
strlib->stristr_ = strlib_stristr;
-#if !(defined(WIN32) && defined(_MSC_VER) && _MSC_VER >= 1400) && !defined(HAVE_STRNLEN)
+#if !(defined(WIN32) && defined(_MSC_VER)) && !defined(HAVE_STRNLEN)
strlib->strnlen_ = strlib_strnlen;
#else
strlib->strnlen_ = NULL;
diff --git a/src/common/strlib.h b/src/common/strlib.h
index c523f5d86..fa7d577eb 100644
--- a/src/common/strlib.h
+++ b/src/common/strlib.h
@@ -2,7 +2,7 @@
* This file is part of Hercules.
* http://herc.ws - http://github.com/HerculesWS/Hercules
*
- * Copyright (C) 2012-2015 Hercules Dev Team
+ * Copyright (C) 2012-2016 Hercules Dev Team
* Copyright (C) Athena Dev Teams
*
* Hercules is free software: you can redistribute it and/or modify
@@ -33,7 +33,7 @@
#define normalize_name(str,delims) (strlib->normalize_name_((str),(delims)))
#define stristr(haystack,needle) (strlib->stristr_((haystack),(needle)))
-#if !(defined(WIN32) && defined(_MSC_VER) && _MSC_VER >= 1400) && !defined(HAVE_STRNLEN)
+#if !(defined(WIN32) && defined(_MSC_VER)) && !defined(HAVE_STRNLEN)
#define strnlen(string,maxlen) (strlib->strnlen_((string),(maxlen)))
#endif
@@ -98,7 +98,7 @@ struct strlib_interface {
char *(*normalize_name_) (char* str,const char* delims);
const char *(*stristr_) (const char *haystack, const char *needle);
- /* only used when '!(defined(WIN32) && defined(_MSC_VER) && _MSC_VER >= 1400) && !defined(HAVE_STRNLEN)', needs to be defined at all times however */
+ /* only used when '!(defined(WIN32) && defined(_MSC_VER)) && !defined(HAVE_STRNLEN)', needs to be defined at all times however */
size_t (*strnlen_) (const char* string, size_t maxlen);
/* only used when 'WIN32' */
@@ -125,7 +125,7 @@ struct strlib_interface {
/// Produces the hexadecimal representation of the given input.
/// The output buffer must be at least count*2+1 in size.
/// Returns true on success, false on failure.
- bool (*bin2hex_) (char* output, unsigned char* input, size_t count);
+ bool (*bin2hex_) (char *output, const unsigned char *input, size_t count);
};
struct stringbuf_interface {
diff --git a/src/common/sysinfo.c b/src/common/sysinfo.c
index 95f423ff7..aeb8d8e71 100644
--- a/src/common/sysinfo.c
+++ b/src/common/sysinfo.c
@@ -291,40 +291,6 @@ bool sysinfo_svn_get_revision(char **out) {
if (*out != NULL)
return true;
}
-
- // subversion 1.6 and older?
- if ((fp = fopen(".svn/entries", "r")) != NULL) {
- char line[1024];
- int rev;
- // Check the version
- if (fgets(line, sizeof(line), fp)) {
- if (!ISDIGIT(line[0])) {
- // XML File format
- while (fgets(line,sizeof(line),fp))
- if (strstr(line,"revision=")) break;
- if (sscanf(line," %*[^\"]\"%d%*[^\n]", &rev) == 1) {
- if (*out != NULL)
- aFree(*out);
- *out = aCalloc(1, 8);
- snprintf(*out, 8, "%d", rev);
- }
- } else {
- // Bin File format
- if (fgets(line, sizeof(line), fp) == NULL) { printf("Can't get bin name\n"); } // Get the name
- if (fgets(line, sizeof(line), fp) == NULL) { printf("Can't get entries kind\n"); } // Get the entries kind
- if (fgets(line, sizeof(line), fp)) { // Get the rev numver
- if (*out != NULL)
- aFree(*out);
- *out = aCalloc(1, 8);
- snprintf(*out, 8, "%d", atoi(line));
- }
- }
- }
- fclose(fp);
-
- if (*out != NULL)
- return true;
- }
#endif
if (*out != NULL)
aFree(*out);
diff --git a/src/common/timer.c b/src/common/timer.c
index e7a57481a..0b28f6a06 100644
--- a/src/common/timer.c
+++ b/src/common/timer.c
@@ -51,7 +51,7 @@ struct timer_interface *timer;
// timers (array)
static struct TimerData* timer_data = NULL;
static int timer_data_max = 0;
-static int timer_data_num = 0;
+static int timer_data_num = 1;
// free timers (array)
static int* free_timer_list = NULL;
@@ -369,6 +369,7 @@ int timer_add_interval(int64 tick, TimerFunc func, int id, intptr_t data, int in
/// Retrieves internal timer data
const struct TimerData* timer_get(int tid) {
+ Assert_retr(NULL, tid > 0);
return ( tid >= 0 && tid < timer_data_num ) ? &timer_data[tid] : NULL;
}
@@ -379,7 +380,7 @@ int timer_do_delete(int tid, TimerFunc func)
{
nullpo_ret(func);
- if( tid < 0 || tid >= timer_data_num ) {
+ if (tid < 1 || tid >= timer_data_num) {
ShowError("timer_do_delete error : no such timer [%d](%p(%s))\n", tid, func, search_timer_func_list(func));
Assert_retr(-1, 0);
return -1;
@@ -406,6 +407,11 @@ int timer_do_delete(int tid, TimerFunc func)
/// Adjusts a timer's expiration time.
/// Returns the new tick value, or -1 if it fails.
int64 timer_addtick(int tid, int64 tick) {
+ if (tid < 1 || tid >= timer_data_num) {
+ ShowError("timer_addtick error : no such timer [%d]\n", tid);
+ Assert_retr(-1, 0);
+ return -1;
+ }
return timer->settick(tid, timer_data[tid].tick+tick);
}