diff options
author | Haru <haru@dotalux.com> | 2020-05-27 13:07:04 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-05-27 13:07:04 +0200 |
commit | f1755315045b90ae1bf752c772e9d4bc747c8671 (patch) | |
tree | f796261c6623e663ae0ffd5027a6f099906dc806 | |
parent | 7b79d5d08fc43cfab1d909e107e958daf739d521 (diff) | |
parent | feaae9bc9244ee3c3f8968980b17c69d0ccd710f (diff) | |
download | hercules-f1755315045b90ae1bf752c772e9d4bc747c8671.tar.gz hercules-f1755315045b90ae1bf752c772e9d4bc747c8671.tar.bz2 hercules-f1755315045b90ae1bf752c772e9d4bc747c8671.tar.xz hercules-f1755315045b90ae1bf752c772e9d4bc747c8671.zip |
Merge pull request #2720 from Kenpachi2k13/split_mapreg_table
Split mapreg table and refactor mapreg code
-rw-r--r-- | conf/common/inter-server.conf | 4 | ||||
-rw-r--r-- | sql-files/main.sql | 22 | ||||
-rw-r--r-- | sql-files/upgrades/2020-05-10--23-11.sql | 43 | ||||
-rw-r--r-- | sql-files/upgrades/index.txt | 1 | ||||
-rw-r--r-- | src/map/map.c | 9 | ||||
-rw-r--r-- | src/map/mapreg.h | 67 | ||||
-rw-r--r-- | src/map/mapreg_sql.c | 816 | ||||
-rw-r--r-- | src/plugins/HPMHooking/HPMHooking.Defs.inc | 2 | ||||
-rw-r--r-- | src/plugins/HPMHooking/HPMHooking_map.HPMHooksCore.inc | 4 | ||||
-rw-r--r-- | src/plugins/HPMHooking/HPMHooking_map.HookingPoints.inc | 1 | ||||
-rw-r--r-- | src/plugins/HPMHooking/HPMHooking_map.Hooks.inc | 27 |
11 files changed, 676 insertions, 320 deletions
diff --git a/conf/common/inter-server.conf b/conf/common/inter-server.conf index 7696774d6..9960c46d6 100644 --- a/conf/common/inter-server.conf +++ b/conf/common/inter-server.conf @@ -76,9 +76,10 @@ inter_configuration: { acc_reg_str_db: "acc_reg_str_db" char_reg_str_db: "char_reg_str_db" char_reg_num_db: "char_reg_num_db" - global_acc_reg_num_db: "global_acc_reg_num_db" global_acc_reg_str_db: "global_acc_reg_str_db" + map_reg_num_db: "map_reg_num_db" + map_reg_str_db: "map_reg_str_db" } pc: { hotkey_db: "hotkey" @@ -113,7 +114,6 @@ inter_configuration: { position_db: "guild_position" storage_db: "guild_storage" } - mapreg_db: "mapreg" autotrade_merchants_db: "autotrade_merchants" autotrade_data_db: "autotrade_data" npc_market_data_db: "npc_market_data" diff --git a/sql-files/main.sql b/sql-files/main.sql index d5b7735fc..7aebd73fd 100644 --- a/sql-files/main.sql +++ b/sql-files/main.sql @@ -655,14 +655,25 @@ CREATE TABLE IF NOT EXISTS `login` ( INSERT IGNORE INTO `login` (`account_id`, `userid`, `user_pass`, `sex`, `email`) VALUES ('1', 's1', 'p1', 'S','athena@athena.com'); -- --- Table structure for table `mapreg` +-- Table structure for table `map_reg_num_db` -- -CREATE TABLE IF NOT EXISTS `mapreg` ( - `varname` VARCHAR(32) BINARY NOT NULL, +CREATE TABLE IF NOT EXISTS `map_reg_num_db` ( + `key` VARCHAR(32) BINARY NOT NULL DEFAULT '', + `index` INT UNSIGNED NOT NULL DEFAULT '0', + `value` INT NOT NULL DEFAULT '0', + PRIMARY KEY (`key`, `index`) +) ENGINE=MyISAM; + +-- +-- Table structure for table `map_reg_str_db` +-- + +CREATE TABLE IF NOT EXISTS `map_reg_str_db` ( + `key` VARCHAR(32) BINARY NOT NULL DEFAULT '', `index` INT UNSIGNED NOT NULL DEFAULT '0', - `value` VARCHAR(255) NOT NULL, - PRIMARY KEY (`varname`,`index`) + `value` VARCHAR(255) NOT NULL DEFAULT '0', + PRIMARY KEY (`key`, `index`) ) ENGINE=MyISAM; -- @@ -939,6 +950,7 @@ INSERT IGNORE INTO `sql_updates` (`timestamp`) VALUES (1579817630); -- 2020-01-2 INSERT IGNORE INTO `sql_updates` (`timestamp`) VALUES (1584838560); -- 2020-03-22--01-56.sql INSERT IGNORE INTO `sql_updates` (`timestamp`) VALUES (1584842940); -- 2020-03-22--03-09.sql INSERT IGNORE INTO `sql_updates` (`timestamp`) VALUES (1588301040); -- 2020-05-01--04-44.sql +INSERT IGNORE INTO `sql_updates` (`timestamp`) VALUES (1589145060); -- 2020-05-10--23-11.sql -- -- Table structure for table `storage` diff --git a/sql-files/upgrades/2020-05-10--23-11.sql b/sql-files/upgrades/2020-05-10--23-11.sql new file mode 100644 index 000000000..9f2755e76 --- /dev/null +++ b/sql-files/upgrades/2020-05-10--23-11.sql @@ -0,0 +1,43 @@ +#1589145060 + +-- This file is part of Hercules. +-- http://herc.ws - http://github.com/HerculesWS/Hercules +-- +-- Copyright (C) 2019-2020 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 +-- the Free Software Foundation, either version 3 of the License, or +-- (at your option) any later version. +-- +-- This program is distributed in the hope that it will be useful, +-- but WITHOUT ANY WARRANTY; without even the implied warranty of +-- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +-- GNU General Public License for more details. +-- +-- You should have received a copy of the GNU General Public License +-- along with this program. If not, see <http://www.gnu.org/licenses/>. + +-- Add separate tables for global integer and string variables. +CREATE TABLE IF NOT EXISTS `map_reg_num_db` ( + `key` VARCHAR(32) BINARY NOT NULL DEFAULT '', + `index` INT UNSIGNED NOT NULL DEFAULT '0', + `value` INT NOT NULL DEFAULT '0', + PRIMARY KEY (`key`, `index`) +) ENGINE=MyISAM; +CREATE TABLE IF NOT EXISTS `map_reg_str_db` ( + `key` VARCHAR(32) BINARY NOT NULL DEFAULT '', + `index` INT UNSIGNED NOT NULL DEFAULT '0', + `value` VARCHAR(255) NOT NULL DEFAULT '0', + PRIMARY KEY (`key`, `index`) +) ENGINE=MyISAM; + +-- Copy data from mapreg table to new map_reg_*_db tables. +INSERT INTO `map_reg_num_db` (`key`, `index`, `value`) SELECT `varname`, `index`, CAST(`value` AS SIGNED) FROM `mapreg` WHERE NOT RIGHT(`varname`, 1)='$'; +INSERT INTO `map_reg_str_db` (`key`, `index`, `value`) SELECT `varname`, `index`, `value` FROM `mapreg` WHERE RIGHT(`varname`, 1)='$'; + +-- Remove mapreg table. +DROP TABLE IF EXISTS `mapreg`; + +-- Add update timestamp. +INSERT INTO `sql_updates` (`timestamp`) VALUES (1589145060); diff --git a/sql-files/upgrades/index.txt b/sql-files/upgrades/index.txt index 64a7793f8..fb889c280 100644 --- a/sql-files/upgrades/index.txt +++ b/sql-files/upgrades/index.txt @@ -63,3 +63,4 @@ 2020-03-22--01-56.sql 2020-03-22--03-09.sql 2020-05-01--04-44.sql +2020-05-10--23-11.sql diff --git a/src/map/map.c b/src/map/map.c index f66f40dfc..63d05c1c0 100644 --- a/src/map/map.c +++ b/src/map/map.c @@ -4459,7 +4459,6 @@ static bool inter_config_read_connection(const char *filename, const struct conf static bool inter_config_read_database_names(const char *filename, const struct config_t *config, bool imported) { const struct config_setting_t *setting = NULL; - bool retval = true; nullpo_retr(false, filename); nullpo_retr(false, config); @@ -4477,16 +4476,14 @@ static bool inter_config_read_database_names(const char *filename, const struct libconfig->setting_lookup_mutable_string(setting, "npc_barter_data_db", map->npc_barter_data_db, sizeof(map->npc_barter_data_db)); libconfig->setting_lookup_mutable_string(setting, "npc_expanded_barter_data_db", map->npc_expanded_barter_data_db, sizeof(map->npc_expanded_barter_data_db)); - if (!mapreg->config_read(filename, setting, imported)) - retval = false; - if ((setting = libconfig->lookup(config, "inter_configuration/database_names/registry")) == NULL) { if (imported) - return retval; + return true; ShowError("inter_config_read: inter_configuration/database_names/registry was not found in %s!\n", filename); return false; } - return retval; + + return mapreg->config_read_registry(filename, setting, imported); } /*======================================= diff --git a/src/map/mapreg.h b/src/map/mapreg.h index b3b89e1b2..4318eaea8 100644 --- a/src/map/mapreg.h +++ b/src/map/mapreg.h @@ -21,55 +21,66 @@ #ifndef MAP_MAPREG_H #define MAP_MAPREG_H -#include "map/script.h" // struct reg_db -#include "common/hercules.h" +#include "map/script.h" #include "common/db.h" +#include "common/hercules.h" -/* Forward Declarations */ -struct config_setting_t; // common/conf.h +/** Forward Declarations **/ +struct config_setting_t; struct eri; -/** Container for a mapreg value */ +#ifndef MAPREG_AUTOSAVE_INTERVAL +#define MAPREG_AUTOSAVE_INTERVAL (300 * 1000) //!< Interval for auto-saving permanent global variables to the database in milliseconds. +#endif /** MAPREG_AUTOSAVE_INTERVAL **/ + +/** Global variable structure. **/ struct mapreg_save { - int64 uid; ///< Unique ID - union { - int i; ///< Numeric value - char *str; ///< String value + int64 uid; //!< The variable's unique ID. + union value { //!< The variable's value container. + int i; //!< The variable's integer value. + char *str; //!< The variable's string value. } u; - bool is_string; ///< true if it's a string, false if it's a number - bool save; ///< Whether a save operation is pending + bool is_string; //!< Whether the variable's value is a string. + bool save; //!< Whether the variable's save operation is pending. }; +/** The mapreg interface structure. **/ struct mapreg_interface { - struct reg_db regs; - /* */ - bool skip_insert; - /* */ - struct eri *ers; //[Ind/Hercules] - /* */ - char table[32]; - /* */ - bool dirty; ///< Whether there are modified regs to be saved - /* */ - void (*init) (void); - void (*final) (void); - /* */ + /** Interface variables. **/ + struct eri *ers; //!< Entry manager for global variables. + struct reg_db regs; //!< Generic database for global variables. + bool dirty; //!< Whether there are modified global variables to be saved. + bool skip_insert; //!< Whether to skip inserting the variable into the SQL database in mapreg_set_*_db(). + char num_db[32]; //!< Name of SQL table which holds permanent global integer variables. + char str_db[32]; //!< Name of SQL table which holds permanent global string variables. + + /** Interface functions. **/ int (*readreg) (int64 uid); - char* (*readregstr) (int64 uid); + char *(*readregstr) (int64 uid); + bool (*set_num_db) (int64 uid, const char *name, unsigned int index, int value); + bool (*delete_num_db) (int64 uid, const char *name, unsigned int index); bool (*setreg) (int64 uid, int val); + bool (*set_str_db) (int64 uid, const char *name, unsigned int index, const char *value); + bool (*delete_str_db) (int64 uid, const char *name, unsigned int index); bool (*setregstr) (int64 uid, const char *str); + void (*load_num_db) (void); + void (*load_str_db) (void); void (*load) (void); + void (*save_num_db) (const char *name, unsigned int index, int value); + void (*save_str_db) (const char *name, unsigned int index, const char *value); void (*save) (void); int (*save_timer) (int tid, int64 tick, int id, intptr_t data); int (*destroyreg) (union DBKey key, struct DBData *data, va_list ap); void (*reload) (void); - bool (*config_read) (const char *filename, const struct config_setting_t *config, bool imported); + bool (*config_read_registry) (const char *filename, const struct config_setting_t *config, bool imported); + void (*final) (void); + void (*init) (void); }; #ifdef HERCULES_CORE void mapreg_defaults(void); -#endif // HERCULES_CORE +#endif /** HERCULES_CORE **/ HPShared struct mapreg_interface *mapreg; -#endif /* MAP_MAPREG_H */ +#endif /** MAP_MAPREG_H **/ diff --git a/src/map/mapreg_sql.c b/src/map/mapreg_sql.c index 2963637da..16d8b0ff6 100644 --- a/src/map/mapreg_sql.c +++ b/src/map/mapreg_sql.c @@ -22,7 +22,7 @@ #include "mapreg.h" -#include "map/map.h" // map-"mysql_handle +#include "map/map.h" #include "map/script.h" #include "common/cbasetypes.h" #include "common/conf.h" @@ -38,289 +38,596 @@ #include <stdlib.h> #include <string.h> -static struct mapreg_interface mapreg_s; -struct mapreg_interface *mapreg; - -#define MAPREG_AUTOSAVE_INTERVAL (300*1000) +static struct mapreg_interface mapreg_s; //!< Private interface structure. +struct mapreg_interface *mapreg; //!< Public interface structure. /** - * Looks up the value of an integer variable using its uid. + * Looks up the value of a global integer variable using its unique ID. * - * @param uid variable's unique identifier. - * @return variable's integer value - */ -static int mapreg_readreg(int64 uid) + * @param uid The variable's unique ID. + * @return The variable's value or 0 if the variable does not exist. + * + **/ +static int mapreg_get_num_reg(int64 uid) { - struct mapreg_save *m = i64db_get(mapreg->regs.vars, uid); - return m?m->u.i:0; + struct mapreg_save *var = i64db_get(mapreg->regs.vars, uid); + return (var != NULL) ? var->u.i : 0; } /** - * Looks up the value of a string variable using its uid. + * Looks up the value of a global string variable using its unique ID. * - * @param uid variable's unique identifier - * @return variable's string value - */ -static char *mapreg_readregstr(int64 uid) + * @param uid The variable's unique ID. + * @return The variable's value or NULL if the variable does not exist. + * + **/ +static char *mapreg_get_str_reg(int64 uid) { - struct mapreg_save *m = i64db_get(mapreg->regs.vars, uid); - return m?m->u.str:NULL; + struct mapreg_save *var = i64db_get(mapreg->regs.vars, uid); + return (var != NULL) ? var->u.str : NULL; } /** - * Modifies the value of an integer variable. + * Sets the value of a global integer variable. * - * @param uid variable's unique identifier - * @param val new value - * @retval true value was successfully set - */ -static bool mapreg_setreg(int64 uid, int val) + * @param uid The variable's unique ID. + * @param name The variable's name. + * @param index The variable's array index. + * @param value The variable's new value. + * @return True on success, otherwise false. + * + **/ +static bool mapreg_set_num_db(int64 uid, const char *name, unsigned int index, int value) { - struct mapreg_save *m; - int num = script_getvarid(uid); - unsigned int i = script_getvaridx(uid); - const char* name = script->get_str(num); - - nullpo_retr(true, name); - if( val != 0 ) { - if( (m = i64db_get(mapreg->regs.vars, uid)) ) { - m->u.i = val; - if(name[1] != '@') { - m->save = true; - mapreg->dirty = true; - } - } else { - if( i ) - script->array_update(&mapreg->regs, uid, false); - - m = ers_alloc(mapreg->ers, struct mapreg_save); - - m->u.i = val; - m->uid = uid; - m->save = false; - m->is_string = false; - - if (name[1] != '@' && !mapreg->skip_insert) {// write new variable to database - char tmp_str[(SCRIPT_VARNAME_LENGTH+1)*2+1]; - SQL->EscapeStringLen(map->mysql_handle, tmp_str, name, strnlen(name, SCRIPT_VARNAME_LENGTH+1)); - if( SQL_ERROR == SQL->Query(map->mysql_handle, "INSERT INTO `%s`(`varname`,`index`,`value`) VALUES ('%s','%u','%d')", mapreg->table, tmp_str, i, val) ) - Sql_ShowDebug(map->mysql_handle); - } - i64db_put(mapreg->regs.vars, uid, m); + nullpo_retr(false, name); + Assert_retr(false, *name != '\0'); + Assert_retr(false, strlen(name) <= SCRIPT_VARNAME_LENGTH); + + if (value == 0) + return mapreg->delete_num_db(uid, name, index); + + struct mapreg_save *var = i64db_get(mapreg->regs.vars, uid); + + // Update variable. + if (var != NULL) { + var->u.i = value; + + if (script->is_permanent_variable(name)) { + var->save = true; + mapreg->dirty = true; } - } else { // val == 0 - if( i ) - script->array_update(&mapreg->regs, uid, true); - if( (m = i64db_get(mapreg->regs.vars, uid)) ) { - ers_free(mapreg->ers, m); + + return true; + } + + // Add new variable. + if (index != 0) + script->array_update(&mapreg->regs, uid, false); + + var = ers_alloc(mapreg->ers, struct mapreg_save); + var->u.i = value; + var->uid = uid; + var->save = false; + var->is_string = false; + i64db_put(mapreg->regs.vars, uid, var); + + if (script->is_permanent_variable(name) && !mapreg->skip_insert) { + struct SqlStmt *stmt = SQL->StmtMalloc(map->mysql_handle); + + if (stmt == NULL) { + SqlStmt_ShowDebug(stmt); + return false; } - i64db_remove(mapreg->regs.vars, uid); - if( name[1] != '@' ) {// Remove from database because it is unused. - if( SQL_ERROR == SQL->Query(map->mysql_handle, "DELETE FROM `%s` WHERE `varname`='%s' AND `index`='%u'", mapreg->table, name, i) ) - Sql_ShowDebug(map->mysql_handle); + const char *query = "INSERT INTO `%s` (`key`, `index`, `value`) VALUES (?, ?, ?)"; + + if (SQL_ERROR == SQL->StmtPrepare(stmt, query, mapreg->num_db) + || SQL_ERROR == SQL->StmtBindParam(stmt, 0, SQLDT_STRING, name, strlen(name)) + || SQL_ERROR == SQL->StmtBindParam(stmt, 1, SQLDT_UINT32, &index, sizeof(index)) + || SQL_ERROR == SQL->StmtBindParam(stmt, 2, SQLDT_INT32, &value, sizeof(value)) + || SQL_ERROR == SQL->StmtExecute(stmt)) { + SqlStmt_ShowDebug(stmt); + SQL->StmtFree(stmt); + return false; } + + SQL->StmtFree(stmt); } return true; } /** - * Modifies the value of a string variable. + * Deletes a global integer variable. * - * @param uid variable's unique identifier - * @param str new value - * @retval true value was successfully set - */ -static bool mapreg_setregstr(int64 uid, const char *str) + * @param uid The variable's unique ID. + * @param name The variable's name. + * @param index The variable's array index. + * @return True on success, otherwise false. + * + **/ +static bool mapreg_delete_num_db(int64 uid, const char *name, unsigned int index) { - struct mapreg_save *m; - int num = script_getvarid(uid); - unsigned int i = script_getvaridx(uid); - const char* name = script->get_str(num); - - nullpo_retr(true, name); - - if( str == NULL || *str == 0 ) { - if( i ) - script->array_update(&mapreg->regs, uid, true); - if(name[1] != '@') { - if (SQL_ERROR == SQL->Query(map->mysql_handle, "DELETE FROM `%s` WHERE `varname`='%s' AND `index`='%u'", mapreg->table, name, i)) - Sql_ShowDebug(map->mysql_handle); + nullpo_retr(false, name); + Assert_retr(false, *name != '\0'); + Assert_retr(false, strlen(name) <= SCRIPT_VARNAME_LENGTH); + + struct mapreg_save *var = i64db_get(mapreg->regs.vars, uid); + + if (var != NULL) + ers_free(mapreg->ers, var); + + if (index != 0) + script->array_update(&mapreg->regs, uid, true); + + i64db_remove(mapreg->regs.vars, uid); + + if (script->is_permanent_variable(name)) { + struct SqlStmt *stmt = SQL->StmtMalloc(map->mysql_handle); + + if (stmt == NULL) { + SqlStmt_ShowDebug(stmt); + return false; } - if( (m = i64db_get(mapreg->regs.vars, uid)) ) { - if( m->u.str != NULL ) - aFree(m->u.str); - ers_free(mapreg->ers, m); + + const char *query = "DELETE FROM `%s` WHERE `key`=? AND `index`=?"; + + if (SQL_ERROR == SQL->StmtPrepare(stmt, query, mapreg->num_db) + || SQL_ERROR == SQL->StmtBindParam(stmt, 0, SQLDT_STRING, name, strlen(name)) + || SQL_ERROR == SQL->StmtBindParam(stmt, 1, SQLDT_UINT32, &index, sizeof(index)) + || SQL_ERROR == SQL->StmtExecute(stmt)) { + SqlStmt_ShowDebug(stmt); + SQL->StmtFree(stmt); + return false; } - i64db_remove(mapreg->regs.vars, uid); - } else { - if( (m = i64db_get(mapreg->regs.vars, uid)) ) { - if( m->u.str != NULL ) - aFree(m->u.str); - m->u.str = aStrdup(str); - if(name[1] != '@') { - mapreg->dirty = true; - m->save = true; - } - } else { - if( i ) - script->array_update(&mapreg->regs, uid, false); - - m = ers_alloc(mapreg->ers, struct mapreg_save); - - m->uid = uid; - m->u.str = aStrdup(str); - m->save = false; - m->is_string = true; - - if(name[1] != '@' && !mapreg->skip_insert) { //put returned null, so we must insert. - char tmp_str[(SCRIPT_VARNAME_LENGTH+1)*2+1]; - char tmp_str2[SCRIPT_STRING_VAR_LENGTH * 2 + 1]; - SQL->EscapeStringLen(map->mysql_handle, tmp_str, name, strnlen(name, SCRIPT_VARNAME_LENGTH+1)); - SQL->EscapeStringLen(map->mysql_handle, tmp_str2, str, strnlen(str, SCRIPT_STRING_VAR_LENGTH)); - if( SQL_ERROR == SQL->Query(map->mysql_handle, "INSERT INTO `%s`(`varname`,`index`,`value`) VALUES ('%s','%u','%s')", mapreg->table, tmp_str, i, tmp_str2) ) - Sql_ShowDebug(map->mysql_handle); - } - i64db_put(mapreg->regs.vars, uid, m); + + SQL->StmtFree(stmt); + } + + return true; +} + +/** + * Sets the value of a global integer variable or deletes it if passed value is 0. + * + * @param uid The variable's unique ID. + * @param val The variable's new value. + * @return True on success, otherwise false. + * + **/ +static bool mapreg_set_num(int64 uid, int val) +{ + unsigned int index = script_getvaridx(uid); + const char *name = script->get_str(script_getvarid(uid)); + + if (val != 0) + return mapreg->set_num_db(uid, name, index, val); + else + return mapreg->delete_num_db(uid, name, index); +} + +/** + * Sets the value of a global string variable. + * + * @param uid The variable's unique ID. + * @param name The variable's name. + * @param index The variable's array index. + * @param value The variable's new value. + * @return True on success, otherwise false. + * + **/ +static bool mapreg_set_str_db(int64 uid, const char *name, unsigned int index, const char *value) +{ + nullpo_retr(false, name); + Assert_retr(false, *name != '\0'); + Assert_retr(false, strlen(name) <= SCRIPT_VARNAME_LENGTH); + + if (value == NULL || *value == '\0') + return mapreg->delete_str_db(uid, name, index); + + if (script->is_permanent_variable(name)) + Assert_retr(false, strlen(value) <= SCRIPT_STRING_VAR_LENGTH); + + struct mapreg_save *var = i64db_get(mapreg->regs.vars, uid); + + // Update variable. + if (var != NULL) { + if (var->u.str != NULL) + aFree(var->u.str); + + var->u.str = aStrdup(value); + + if (script->is_permanent_variable(name)) { + var->save = true; + mapreg->dirty = true; } + + return true; + } + + // Add new variable. + if (index != 0) + script->array_update(&mapreg->regs, uid, false); + + var = ers_alloc(mapreg->ers, struct mapreg_save); + var->u.str = aStrdup(value); + var->uid = uid; + var->save = false; + var->is_string = true; + i64db_put(mapreg->regs.vars, uid, var); + + if (script->is_permanent_variable(name) && !mapreg->skip_insert) { + struct SqlStmt *stmt = SQL->StmtMalloc(map->mysql_handle); + + if (stmt == NULL) { + SqlStmt_ShowDebug(stmt); + return false; + } + + const char *query = "INSERT INTO `%s` (`key`, `index`, `value`) VALUES (?, ?, ?)"; + + if (SQL_ERROR == SQL->StmtPrepare(stmt, query, mapreg->str_db) + || SQL_ERROR == SQL->StmtBindParam(stmt, 0, SQLDT_STRING, name, strlen(name)) + || SQL_ERROR == SQL->StmtBindParam(stmt, 1, SQLDT_UINT32, &index, sizeof(index)) + || SQL_ERROR == SQL->StmtBindParam(stmt, 2, SQLDT_STRING, value, strlen(value)) + || SQL_ERROR == SQL->StmtExecute(stmt)) { + SqlStmt_ShowDebug(stmt); + SQL->StmtFree(stmt); + return false; + } + + SQL->StmtFree(stmt); } return true; } /** - * Loads permanent variables from database. - */ -static void script_load_mapreg(void) + * Deletes a global string variable. + * + * @param uid The variable's unique ID. + * @param name The variable's name. + * @param index The variable's array index. + * @return True on success, otherwise false. + * + **/ +static bool mapreg_delete_str_db(int64 uid, const char *name, unsigned int index) +{ + nullpo_retr(false, name); + Assert_retr(false, *name != '\0'); + Assert_retr(false, strlen(name) <= SCRIPT_VARNAME_LENGTH); + + struct mapreg_save *var = i64db_get(mapreg->regs.vars, uid); + + if (var != NULL) { + if (var->u.str != NULL) + aFree(var->u.str); + + ers_free(mapreg->ers, var); + } + + if (index != 0) + script->array_update(&mapreg->regs, uid, true); + + i64db_remove(mapreg->regs.vars, uid); + + if (script->is_permanent_variable(name)) { + struct SqlStmt *stmt = SQL->StmtMalloc(map->mysql_handle); + + if (stmt == NULL) { + SqlStmt_ShowDebug(stmt); + return false; + } + + const char *query = "DELETE FROM `%s` WHERE `key`=? AND `index`=?"; + + if (SQL_ERROR == SQL->StmtPrepare(stmt, query, mapreg->str_db) + || SQL_ERROR == SQL->StmtBindParam(stmt, 0, SQLDT_STRING, name, strlen(name)) + || SQL_ERROR == SQL->StmtBindParam(stmt, 1, SQLDT_UINT32, &index, sizeof(index)) + || SQL_ERROR == SQL->StmtExecute(stmt)) { + SqlStmt_ShowDebug(stmt); + SQL->StmtFree(stmt); + return false; + } + + SQL->StmtFree(stmt); + } + + return true; +} + +/** + * Sets the value of a global string variable or deletes it if passed value is NULL or an empty string. + * + * @param uid The variable's unique ID. + * @param str The variable's new value. + * @return True on success, otherwise false. + * + **/ +static bool mapreg_set_str(int64 uid, const char *str) +{ + unsigned int index = script_getvaridx(uid); + const char *name = script->get_str(script_getvarid(uid)); + + if (str != NULL && *str != '\0') + return mapreg->set_str_db(uid, name, index, str); + else + return mapreg->delete_str_db(uid, name, index); +} + +/** + * Loads permanent global interger variables from the database. + * + **/ +static void mapreg_load_num_db(void) { - /* - 0 1 2 - +-------------------------+ - | varname | index | value | - +-------------------------+ - */ struct SqlStmt *stmt = SQL->StmtMalloc(map->mysql_handle); - char varname[SCRIPT_VARNAME_LENGTH+1]; - int index; - char value[SCRIPT_STRING_VAR_LENGTH + 1]; - uint32 length; - if ( SQL_ERROR == SQL->StmtPrepare(stmt, "SELECT `varname`, `index`, `value` FROM `%s`", mapreg->table) - || SQL_ERROR == SQL->StmtExecute(stmt) - ) { + if (stmt == NULL) { SqlStmt_ShowDebug(stmt); - SQL->StmtFree(stmt); return; } - mapreg->skip_insert = true; + const char *query = "SELECT `key`, `index`, `value` FROM `%s`"; + char name[SCRIPT_VARNAME_LENGTH + 1]; + unsigned int index; + int value; - SQL->StmtBindColumn(stmt, 0, SQLDT_STRING, &varname, sizeof varname, &length, NULL); - SQL->StmtBindColumn(stmt, 1, SQLDT_INT, &index, sizeof index, NULL, NULL); - SQL->StmtBindColumn(stmt, 2, SQLDT_STRING, &value, sizeof value, NULL, NULL); + if (SQL_ERROR == SQL->StmtPrepare(stmt, query, mapreg->num_db) + || SQL_ERROR == SQL->StmtExecute(stmt) + || SQL_ERROR == SQL->StmtBindColumn(stmt, 0, SQLDT_STRING, &name, sizeof(name), NULL, NULL) + || SQL_ERROR == SQL->StmtBindColumn(stmt, 1, SQLDT_UINT32, &index, sizeof(index), NULL, NULL) + || SQL_ERROR == SQL->StmtBindColumn(stmt, 2, SQLDT_INT32, &value, sizeof(value), NULL, NULL)) { + SqlStmt_ShowDebug(stmt); + SQL->StmtFree(stmt); + return; + } - while ( SQL_SUCCESS == SQL->StmtNextRow(stmt) ) { - int s = script->add_variable(varname); - int i = index; + if (SQL->StmtNumRows(stmt) < 1) { + SQL->StmtFree(stmt); + return; + } + mapreg->skip_insert = true; + + while (SQL_SUCCESS == SQL->StmtNextRow(stmt)) { + int var_key = script->add_variable(name); + int64 uid = reference_uid(var_key, index); - if( i64db_exists(mapreg->regs.vars, reference_uid(s, i)) ) { - ShowWarning("load_mapreg: duplicate! '%s' => '%s' skipping...\n",varname,value); + if (i64db_exists(mapreg->regs.vars, uid)) { + ShowWarning("mapreg_load_num_db: Duplicate! '%s' => '%d' Skipping...\n", name, value); continue; } - if( varname[length-1] == '$' ) { - mapreg->setregstr(reference_uid(s, i),value); - } else { - mapreg->setreg(reference_uid(s, i),atoi(value)); - } + + mapreg->setreg(uid, value); } + mapreg->skip_insert = false; SQL->StmtFree(stmt); +} + +/** + * Loads permanent global string variables from the database. + * + **/ +static void mapreg_load_str_db(void) +{ + struct SqlStmt *stmt = SQL->StmtMalloc(map->mysql_handle); + + if (stmt == NULL) { + SqlStmt_ShowDebug(stmt); + return; + } + + const char *query = "SELECT `key`, `index`, `value` FROM `%s`"; + char name[SCRIPT_VARNAME_LENGTH + 1]; + unsigned int index; + char value[SCRIPT_STRING_VAR_LENGTH + 1]; + + if (SQL_ERROR == SQL->StmtPrepare(stmt, query, mapreg->str_db) + || SQL_ERROR == SQL->StmtExecute(stmt) + || SQL_ERROR == SQL->StmtBindColumn(stmt, 0, SQLDT_STRING, &name, sizeof(name), NULL, NULL) + || SQL_ERROR == SQL->StmtBindColumn(stmt, 1, SQLDT_UINT32, &index, sizeof(index), NULL, NULL) + || SQL_ERROR == SQL->StmtBindColumn(stmt, 2, SQLDT_STRING, &value, sizeof(value), NULL, NULL)) { + SqlStmt_ShowDebug(stmt); + SQL->StmtFree(stmt); + return; + } + + if (SQL->StmtNumRows(stmt) < 1) { + SQL->StmtFree(stmt); + return; + } + + mapreg->skip_insert = true; + + while (SQL_SUCCESS == SQL->StmtNextRow(stmt)) { + int var_key = script->add_variable(name); + int64 uid = reference_uid(var_key, index); + + if (i64db_exists(mapreg->regs.vars, uid)) { + ShowWarning("mapreg_load_str_db: Duplicate! '%s' => '%s' Skipping...\n", name, value); + continue; + } + + mapreg->setregstr(uid, value); + } mapreg->skip_insert = false; + SQL->StmtFree(stmt); +} +/** + * Loads permanent global variables from the database. + * + **/ +static void mapreg_load(void) +{ + mapreg->load_num_db(); + mapreg->load_str_db(); mapreg->dirty = false; } /** - * Saves permanent variables to database. - */ -static void script_save_mapreg(void) + * Saves a permanent global integer variable to the database. + * + * @param name The variable's name. + * @param index The variable's array index. + * @param value The variable's value. + * + **/ +static void mapreg_save_num_db(const char *name, unsigned int index, int value) +{ + nullpo_retv(name); + Assert_retv(*name != '\0'); + Assert_retv(strlen(name) <= SCRIPT_VARNAME_LENGTH); + + struct SqlStmt *stmt = SQL->StmtMalloc(map->mysql_handle); + + if (stmt == NULL) { + SqlStmt_ShowDebug(stmt); + return; + } + + const char *query = "UPDATE `%s` SET `value`=? WHERE `key`=? AND `index`=? LIMIT 1"; + + if (SQL_ERROR == SQL->StmtPrepare(stmt, query, mapreg->num_db) + || SQL_ERROR == SQL->StmtBindParam(stmt, 0, SQLDT_INT32, &value, sizeof(value)) + || SQL_ERROR == SQL->StmtBindParam(stmt, 1, SQLDT_STRING, name, strlen(name)) + || SQL_ERROR == SQL->StmtBindParam(stmt, 2, SQLDT_UINT32, &index, sizeof(index)) + || SQL_ERROR == SQL->StmtExecute(stmt)) { + SqlStmt_ShowDebug(stmt); + } + + SQL->StmtFree(stmt); +} + +/** + * Saves a permanent global string variable to the database. + * + * @param name The variable's name. + * @param index The variable's array index. + * @param value The variable's value. + * + **/ +static void mapreg_save_str_db(const char *name, unsigned int index, const char *value) +{ + nullpo_retv(name); + nullpo_retv(value); + Assert_retv(*name != '\0'); + Assert_retv(strlen(name) <= SCRIPT_VARNAME_LENGTH); + Assert_retv(*value != '\0'); + Assert_retv(strlen(value) <= SCRIPT_STRING_VAR_LENGTH); + + struct SqlStmt *stmt = SQL->StmtMalloc(map->mysql_handle); + + if (stmt == NULL) { + SqlStmt_ShowDebug(stmt); + return; + } + + const char *query = "UPDATE `%s` SET `value`=? WHERE `key`=? AND `index`=? LIMIT 1"; + + if (SQL_ERROR == SQL->StmtPrepare(stmt, query, mapreg->str_db) + || SQL_ERROR == SQL->StmtBindParam(stmt, 0, SQLDT_STRING, value, strlen(value)) + || SQL_ERROR == SQL->StmtBindParam(stmt, 1, SQLDT_STRING, name, strlen(name)) + || SQL_ERROR == SQL->StmtBindParam(stmt, 2, SQLDT_UINT32, &index, sizeof(index)) + || SQL_ERROR == SQL->StmtExecute(stmt)) { + SqlStmt_ShowDebug(stmt); + } + + SQL->StmtFree(stmt); +} + +/** + * Saves permanent global variables to the database. + * + **/ +static void mapreg_save(void) { if (mapreg->dirty) { struct DBIterator *iter = db_iterator(mapreg->regs.vars); - struct mapreg_save *m = NULL; - for (m = dbi_first(iter); dbi_exists(iter); m = dbi_next(iter)) { - if (m->save) { - int num = script_getvarid(m->uid); - int i = script_getvaridx(m->uid); - const char* name = script->get_str(num); - nullpo_retv(name); - if (!m->is_string) { - if( SQL_ERROR == SQL->Query(map->mysql_handle, "UPDATE `%s` SET `value`='%d' WHERE `varname`='%s' AND `index`='%d' LIMIT 1", mapreg->table, m->u.i, name, i) ) - Sql_ShowDebug(map->mysql_handle); - } else { - char tmp_str2[SCRIPT_STRING_VAR_LENGTH * 2 + 1]; - SQL->EscapeStringLen(map->mysql_handle, tmp_str2, m->u.str, safestrnlen(m->u.str, SCRIPT_STRING_VAR_LENGTH)); - if( SQL_ERROR == SQL->Query(map->mysql_handle, "UPDATE `%s` SET `value`='%s' WHERE `varname`='%s' AND `index`='%d' LIMIT 1", mapreg->table, tmp_str2, name, i) ) - Sql_ShowDebug(map->mysql_handle); - } - m->save = false; + struct mapreg_save *var = NULL; + + for (var = dbi_first(iter); dbi_exists(iter); var = dbi_next(iter)) { + if (var->save) { + int index = script_getvaridx(var->uid); + const char *name = script->get_str(script_getvarid(var->uid)); + + if (!var->is_string) + mapreg->save_num_db(name, index, var->u.i); + else + mapreg->save_str_db(name, index, var->u.str); + + var->save = false; } } + dbi_destroy(iter); mapreg->dirty = false; } } /** - * Timer event to auto-save permanent variables. + * Timer event to auto-save permanent global variables. * - * @see timer->do_timer - */ -static int script_autosave_mapreg(int tid, int64 tick, int id, intptr_t data) + * @see timer->do_timer() + * + * @param tid Unused. + * @param tick Unused. + * @param id Unused. + * @param data Unused. + * @return Always 0. + * + **/ +static int mapreg_save_timer(int tid, int64 tick, int id, intptr_t data) { mapreg->save(); return 0; } /** - * Destroys a mapreg_save structure, freeing the contained string, if any. + * Destroys a mapreg_save structure and frees the contained string, if any. * * @see DBApply - */ -static int mapreg_destroyreg(union DBKey key, struct DBData *data, va_list ap) + * + * @param key Unused. + * @param data The DB data holding the mapreg_save data. + * @param ap Unused. + * @return 0 on success, otherwise 1. + * + **/ +static int mapreg_destroy_reg(union DBKey key, struct DBData *data, va_list ap) { - struct mapreg_save *m = NULL; + nullpo_retr(1, data); if (data->type != DB_DATA_PTR) // Sanity check - return 0; + return 1; - m = DB->data2ptr(data); + struct mapreg_save *var = DB->data2ptr(data); - if (m->is_string) { - if (m->u.str) - aFree(m->u.str); - } - ers_free(mapreg->ers, m); + if (var == NULL) + return 1; + + if (var->is_string && var->u.str != NULL) + aFree(var->u.str); + ers_free(mapreg->ers, var); return 0; } /** - * Reloads mapregs, saving to database beforehand. + * Reloads permanent global variables, saving them to the database beforehand. * - * This has the effect of clearing the temporary variables, and - * reloading the permanent ones. - */ + * This has the effect of clearing the temporary global variables and reloading the permanent ones. + * + **/ static void mapreg_reload(void) { mapreg->save(); - mapreg->regs.vars->clear(mapreg->regs.vars, mapreg->destroyreg); - if( mapreg->regs.arrays ) { + if (mapreg->regs.arrays != NULL) { mapreg->regs.arrays->destroy(mapreg->regs.arrays, script->array_free_db); mapreg->regs.arrays = NULL; } @@ -329,86 +636,105 @@ static void mapreg_reload(void) } /** - * Finalizer. - */ + * Loads the mapreg database table names from configuration file. + * + * @param filename Path to configuration file. (Used in error and warning messages). + * @param config The current config being parsed. + * @param imported Whether the current config is imported from another file. + * @return True on success, otherwise false. + * + **/ +static bool mapreg_config_read_registry(const char *filename, const struct config_setting_t *config, bool imported) +{ + nullpo_retr(false, filename); + nullpo_retr(false, config); + + bool ret_val = true; + size_t sz = sizeof(mapreg->num_db); + int result = libconfig->setting_lookup_mutable_string(config, "map_reg_num_db", mapreg->num_db, sz); + + if (result != CONFIG_TRUE && !imported) { + ShowError("%s: inter_configuration/database_names/registry/map_reg_num_db was not found in %s!\n", + __func__, filename); + ret_val = false; + } + + sz = sizeof(mapreg->str_db); + result = libconfig->setting_lookup_mutable_string(config, "map_reg_str_db", mapreg->str_db, sz); + + if (result != CONFIG_TRUE && !imported) { + ShowError("%s: inter_configuration/database_names/registry/map_reg_str_db was not found in %s!\n", + __func__, filename); + ret_val = false; + } + + return ret_val; +} + +/** + * Saves permanent global variables to the database and frees all the memory they use afterwards. + * + **/ static void mapreg_final(void) { mapreg->save(); - mapreg->regs.vars->destroy(mapreg->regs.vars, mapreg->destroyreg); - ers_destroy(mapreg->ers); - if( mapreg->regs.arrays ) + if (mapreg->regs.arrays != NULL) mapreg->regs.arrays->destroy(mapreg->regs.arrays, script->array_free_db); } /** - * Initializer. - */ + * Allocates memory for permanent global variables, loads them from the database and initializes the auto-save timer. + * + **/ static void mapreg_init(void) { mapreg->regs.vars = i64db_alloc(DB_OPT_BASE); mapreg->ers = ers_new(sizeof(struct mapreg_save), "mapreg_sql.c::mapreg_ers", ERS_OPT_CLEAN); - mapreg->load(); - - timer->add_func_list(mapreg->save_timer, "mapreg_script_autosave_mapreg"); + timer->add_func_list(mapreg->save_timer, "mapreg_save_timer"); timer->add_interval(timer->gettick() + MAPREG_AUTOSAVE_INTERVAL, mapreg->save_timer, 0, 0, MAPREG_AUTOSAVE_INTERVAL); } /** - * Loads the mapreg configuration file. - * - * @param filename Path to configuration file (used in error and warning messages). - * @param config The current config being parsed. - * @param imported Whether the current config is imported from another file. + * Initializes the mapreg interface defaults. * - * @retval false in case of error. - */ -static bool mapreg_config_read(const char *filename, const struct config_setting_t *config, bool imported) -{ - nullpo_retr(false, filename); - nullpo_retr(false, config); - - if (libconfig->setting_lookup_mutable_string(config, "mapreg_db", mapreg->table, sizeof(mapreg->table)) != CONFIG_TRUE) - return false; - - return true; -} - -/** - * Interface defaults initializer. - */ + **/ void mapreg_defaults(void) { + /** Interface structure. **/ mapreg = &mapreg_s; - /* */ - mapreg->regs.vars = NULL; + /** Interface variables. **/ mapreg->ers = NULL; - mapreg->skip_insert = false; - - safestrncpy(mapreg->table, "mapreg", sizeof(mapreg->table)); - mapreg->dirty = false; - - /* */ + mapreg->regs.vars = NULL; mapreg->regs.arrays = NULL; - - /* */ - mapreg->init = mapreg_init; - mapreg->final = mapreg_final; - - /* */ - mapreg->readreg = mapreg_readreg; - mapreg->readregstr = mapreg_readregstr; - mapreg->setreg = mapreg_setreg; - mapreg->setregstr = mapreg_setregstr; - mapreg->load = script_load_mapreg; - mapreg->save = script_save_mapreg; - mapreg->save_timer = script_autosave_mapreg; - mapreg->destroyreg = mapreg_destroyreg; + mapreg->dirty = false; + mapreg->skip_insert = false; + safestrncpy(mapreg->num_db, "map_reg_num_db", sizeof(mapreg->num_db)); + safestrncpy(mapreg->str_db, "map_reg_str_db", sizeof(mapreg->str_db)); + + /** Interface functions. **/ + mapreg->readreg = mapreg_get_num_reg; + mapreg->readregstr = mapreg_get_str_reg; + mapreg->set_num_db = mapreg_set_num_db; + mapreg->delete_num_db = mapreg_delete_num_db; + mapreg->setreg = mapreg_set_num; + mapreg->set_str_db = mapreg_set_str_db; + mapreg->delete_str_db = mapreg_delete_str_db; + mapreg->setregstr = mapreg_set_str; + mapreg->load_num_db = mapreg_load_num_db; + mapreg->load_str_db = mapreg_load_str_db; + mapreg->load = mapreg_load; + mapreg->save_num_db = mapreg_save_num_db; + mapreg->save_str_db = mapreg_save_str_db; + mapreg->save = mapreg_save; + mapreg->save_timer = mapreg_save_timer; + mapreg->destroyreg = mapreg_destroy_reg; mapreg->reload = mapreg_reload; - mapreg->config_read = mapreg_config_read; - + mapreg->config_read_registry = mapreg_config_read_registry; + mapreg->final = mapreg_final; + mapreg->init = mapreg_init; } diff --git a/src/plugins/HPMHooking/HPMHooking.Defs.inc b/src/plugins/HPMHooking/HPMHooking.Defs.inc index d20766956..6be5e2414 100644 --- a/src/plugins/HPMHooking/HPMHooking.Defs.inc +++ b/src/plugins/HPMHooking/HPMHooking.Defs.inc @@ -5246,8 +5246,6 @@ typedef int (*HPMHOOK_pre_mapreg_destroyreg) (union DBKey *key, struct DBData ** typedef int (*HPMHOOK_post_mapreg_destroyreg) (int retVal___, union DBKey key, struct DBData *data, va_list ap); typedef void (*HPMHOOK_pre_mapreg_reload) (void); typedef void (*HPMHOOK_post_mapreg_reload) (void); -typedef bool (*HPMHOOK_pre_mapreg_config_read) (const char **filename, const struct config_setting_t **config, bool *imported); -typedef bool (*HPMHOOK_post_mapreg_config_read) (bool retVal___, const char *filename, const struct config_setting_t *config, bool imported); #endif // MAP_MAPREG_H #ifdef COMMON_MD5CALC_H /* md5 */ typedef void (*HPMHOOK_pre_md5_string) (const char **string, char **output); diff --git a/src/plugins/HPMHooking/HPMHooking_map.HPMHooksCore.inc b/src/plugins/HPMHooking/HPMHooking_map.HPMHooksCore.inc index 02ba063ed..82f67a8a3 100644 --- a/src/plugins/HPMHooking/HPMHooking_map.HPMHooksCore.inc +++ b/src/plugins/HPMHooking/HPMHooking_map.HPMHooksCore.inc @@ -3850,8 +3850,6 @@ struct { struct HPMHookPoint *HP_mapreg_destroyreg_post; struct HPMHookPoint *HP_mapreg_reload_pre; struct HPMHookPoint *HP_mapreg_reload_post; - struct HPMHookPoint *HP_mapreg_config_read_pre; - struct HPMHookPoint *HP_mapreg_config_read_post; struct HPMHookPoint *HP_md5_string_pre; struct HPMHookPoint *HP_md5_string_post; struct HPMHookPoint *HP_md5_binary_pre; @@ -10753,8 +10751,6 @@ struct { int HP_mapreg_destroyreg_post; int HP_mapreg_reload_pre; int HP_mapreg_reload_post; - int HP_mapreg_config_read_pre; - int HP_mapreg_config_read_post; int HP_md5_string_pre; int HP_md5_string_post; int HP_md5_binary_pre; diff --git a/src/plugins/HPMHooking/HPMHooking_map.HookingPoints.inc b/src/plugins/HPMHooking/HPMHooking_map.HookingPoints.inc index 4a36c5a1e..1e7145aa7 100644 --- a/src/plugins/HPMHooking/HPMHooking_map.HookingPoints.inc +++ b/src/plugins/HPMHooking/HPMHooking_map.HookingPoints.inc @@ -1971,7 +1971,6 @@ struct HookingPointData HookingPoints[] = { { HP_POP(mapreg->save_timer, HP_mapreg_save_timer) }, { HP_POP(mapreg->destroyreg, HP_mapreg_destroyreg) }, { HP_POP(mapreg->reload, HP_mapreg_reload) }, - { HP_POP(mapreg->config_read, HP_mapreg_config_read) }, /* md5_interface */ { HP_POP(md5->string, HP_md5_string) }, { HP_POP(md5->binary, HP_md5_binary) }, diff --git a/src/plugins/HPMHooking/HPMHooking_map.Hooks.inc b/src/plugins/HPMHooking/HPMHooking_map.Hooks.inc index f0e395b64..7a8eac693 100644 --- a/src/plugins/HPMHooking/HPMHooking_map.Hooks.inc +++ b/src/plugins/HPMHooking/HPMHooking_map.Hooks.inc @@ -50916,33 +50916,6 @@ void HP_mapreg_reload(void) { } return; } -bool HP_mapreg_config_read(const char *filename, const struct config_setting_t *config, bool imported) { - int hIndex = 0; - bool retVal___ = false; - if (HPMHooks.count.HP_mapreg_config_read_pre > 0) { - bool (*preHookFunc) (const char **filename, const struct config_setting_t **config, bool *imported); - *HPMforce_return = false; - for (hIndex = 0; hIndex < HPMHooks.count.HP_mapreg_config_read_pre; hIndex++) { - preHookFunc = HPMHooks.list.HP_mapreg_config_read_pre[hIndex].func; - retVal___ = preHookFunc(&filename, &config, &imported); - } - if (*HPMforce_return) { - *HPMforce_return = false; - return retVal___; - } - } - { - retVal___ = HPMHooks.source.mapreg.config_read(filename, config, imported); - } - if (HPMHooks.count.HP_mapreg_config_read_post > 0) { - bool (*postHookFunc) (bool retVal___, const char *filename, const struct config_setting_t *config, bool imported); - for (hIndex = 0; hIndex < HPMHooks.count.HP_mapreg_config_read_post; hIndex++) { - postHookFunc = HPMHooks.list.HP_mapreg_config_read_post[hIndex].func; - retVal___ = postHookFunc(retVal___, filename, config, imported); - } - } - return retVal___; -} /* md5_interface */ void HP_md5_string(const char *string, char *output) { int hIndex = 0; |