core/systems/PluginInfoDatabase.h
author David Anderson <dvander@alliedmods.net>
Fri Feb 16 04:16:31 2007 +0000 (2007-02-16)
changeset 502 4530ea065a8b
parent 370 d3a484f98f6d
child 653 ef60870067ff
permissions -rw-r--r--
fixed a serious potential bug with swapping plugins to debug mode, leaving stale function pointers without plugin removal
     1 /**
     2  * ===============================================================
     3  * SourceMod (C)2004-2007 AlliedModders LLC.  All rights reserved.
     4  * ===============================================================
     5  *
     6  * This file is not open source and may not be copied without explicit
     7  * written permission of AlliedModders LLC.  This file may not be redistributed 
     8  * in whole or significant part.
     9  * For information, see LICENSE.txt or http://www.sourcemod.net/license.php
    10  *
    11  * Version: $Id$
    12  */
    13 
    14 #ifndef _INCLUDE_SOURCEMOD_CORE_SYSTEM_PLUGININFODATABASE_H_
    15 #define _INCLUDE_SOURCEMOD_CORE_SYSTEM_PLUGININFODATABASE_H_
    16 
    17 /**
    18  * This file parses plugin_settings.cfg and stores the information in cached memory.
    19  * It provides simplistic abstraction to retrieving the info.
    20  * :TODO: currently untested
    21  */
    22 
    23 #include "sm_memtable.h"
    24 #include "ITextParsers.h"
    25 #include "IPluginSys.h"
    26 #include "sm_globals.h"
    27 
    28 struct PluginOpts
    29 {
    30 	int key;
    31 	int val;
    32 };
    33 
    34 struct PluginSettings
    35 {
    36 	void Init();
    37 	int name;
    38 	bool pause_val;
    39 	PluginType type_val;
    40 	int optarray;
    41 	size_t opts_num;
    42 	size_t opts_size;
    43 };
    44 
    45 class CPluginInfoDatabase : public ITextListener_SMC
    46 {
    47 public:
    48 	CPluginInfoDatabase();
    49 	~CPluginInfoDatabase();
    50 public: //ITextListener_SMC
    51 	void ReadSMC_ParseStart();
    52 	SMCParseResult ReadSMC_NewSection(const char *name, bool opt_quotes);
    53 	SMCParseResult ReadSMC_KeyValue(const char *key, const char *value, bool key_quotes, bool value_quotes);
    54 	SMCParseResult ReadSMC_LeavingSection();
    55 public:
    56 	/**
    57 	 * Returns the number of plugin settings available.
    58 	 */
    59 	unsigned int GetSettingsNum();
    60 
    61 	/** 
    62 	 * Given an index, returns the plugin settings block if the filename matches.
    63 	 * Otherwise, returns NULL.
    64 	 */
    65 	PluginSettings *GetSettingsIfMatch(unsigned int index, const char *filename);
    66 
    67 	/** 
    68 	 *  Given a plugin settings struct and an index,
    69 	 * returns the given JIT key/value option pair at that index.
    70 	 * If the input is invalid, key and val will be set to NULL.
    71 	 */
    72 	void GetOptionsForPlugin(PluginSettings *settings, unsigned int opt_num, const char **key, const char **val);
    73 private:
    74 	SMCParseResult MakeError(const char *fmt, ...);
    75 private:
    76 	BaseStringTable *m_strtab;
    77 	int m_errmsg;
    78 	bool in_plugins;
    79 	bool in_options;
    80 	int m_infodb;
    81 	size_t m_infodb_count;
    82 	size_t m_infodb_size;
    83 	int cur_plugin;
    84 };
    85 
    86 
    87 #endif //_INCLUDE_SOURCEMOD_CORE_SYSTEM_PLUGININFODATABASE_H_