core/PluginInfoDatabase.h
author David Anderson <dvander@alliedmods.net>
Mon Sep 07 21:29:18 2009 -0700 (2009-09-07)
changeset 2798 6dd90eaa0593
parent 2411 8dfaa3d730b5
permissions -rw-r--r--
Fixed invalid array access in PluginSys (bug 3933, r=pred).
dvander@370
     1
/**
ds@653
     2
 * vim: set ts=4 :
ds@1330
     3
 * =============================================================================
dvander@1231
     4
 * SourceMod
ds@1947
     5
 * Copyright (C) 2004-2008 AlliedModders LLC.  All rights reserved.
ds@1330
     6
 * =============================================================================
dvander@370
     7
 *
ds@1330
     8
 * This program is free software; you can redistribute it and/or modify it under
ds@1330
     9
 * the terms of the GNU General Public License, version 3.0, as published by the
ds@1330
    10
 * Free Software Foundation.
dvander@1231
    11
 * 
ds@1330
    12
 * This program is distributed in the hope that it will be useful, but WITHOUT
ds@1330
    13
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
ds@1330
    14
 * FOR A PARTICULAR PURPOSE.  See the GNU General Public License for more
ds@1330
    15
 * details.
dvander@1231
    16
 *
ds@1330
    17
 * You should have received a copy of the GNU General Public License along with
ds@1330
    18
 * this program.  If not, see <http://www.gnu.org/licenses/>.
dvander@1231
    19
 *
ds@1330
    20
 * As a special exception, AlliedModders LLC gives you permission to link the
ds@1330
    21
 * code of this program (as well as its derivative works) to "Half-Life 2," the
ds@1330
    22
 * "Source Engine," the "SourcePawn JIT," and any Game MODs that run on software
ds@1330
    23
 * by the Valve Corporation.  You must obey the GNU General Public License in
ds@1330
    24
 * all respects for all other code used.  Additionally, AlliedModders LLC grants
ds@1330
    25
 * this exception to all derivative works.  AlliedModders LLC defines further
ds@1330
    26
 * exceptions, found in LICENSE.txt (as of this writing, version JULY-31-2007),
ds@1330
    27
 * or <http://www.sourcemod.net/license.php>.
dvander@370
    28
 *
dvander@370
    29
 * Version: $Id$
dvander@370
    30
 */
dvander@370
    31
dvander@203
    32
#ifndef _INCLUDE_SOURCEMOD_CORE_SYSTEM_PLUGININFODATABASE_H_
dvander@203
    33
#define _INCLUDE_SOURCEMOD_CORE_SYSTEM_PLUGININFODATABASE_H_
dvander@203
    34
dvander@203
    35
/**
dvander@203
    36
 * This file parses plugin_settings.cfg and stores the information in cached memory.
dvander@203
    37
 * It provides simplistic abstraction to retrieving the info.
dvander@203
    38
 * :TODO: currently untested
dvander@203
    39
 */
dvander@203
    40
dvander@203
    41
#include "sm_memtable.h"
dvander@203
    42
#include "ITextParsers.h"
dvander@203
    43
#include "IPluginSys.h"
dvander@203
    44
#include "sm_globals.h"
dvander@203
    45
dvander@203
    46
struct PluginOpts
dvander@203
    47
{
dvander@203
    48
	int key;
dvander@203
    49
	int val;
dvander@203
    50
};
dvander@203
    51
dvander@203
    52
struct PluginSettings
dvander@203
    53
{
dvander@203
    54
	void Init();
dvander@203
    55
	int name;
dvander@203
    56
	bool pause_val;
dvander@203
    57
	PluginType type_val;
dvander@203
    58
	int optarray;
dvander@203
    59
	size_t opts_num;
dvander@203
    60
	size_t opts_size;
dvander@1436
    61
	bool blockload_val;
dvander@203
    62
};
dvander@203
    63
dvander@203
    64
class CPluginInfoDatabase : public ITextListener_SMC
dvander@203
    65
{
dvander@203
    66
public:
dvander@203
    67
	CPluginInfoDatabase();
dvander@203
    68
	~CPluginInfoDatabase();
dvander@203
    69
public: //ITextListener_SMC
dvander@203
    70
	void ReadSMC_ParseStart();
dvander@1656
    71
	SMCResult ReadSMC_NewSection(const SMCStates *states, const char *name);
dvander@1656
    72
	SMCResult ReadSMC_KeyValue(const SMCStates *states, const char *key, const char *value);
dvander@1656
    73
	SMCResult ReadSMC_LeavingSection(const SMCStates *states);
dvander@203
    74
public:
dvander@203
    75
	/**
dvander@203
    76
	 * Returns the number of plugin settings available.
dvander@203
    77
	 */
dvander@203
    78
	unsigned int GetSettingsNum();
dvander@203
    79
dvander@203
    80
	/** 
dvander@203
    81
	 * Given an index, returns the plugin settings block if the filename matches.
dvander@203
    82
	 * Otherwise, returns NULL.
dvander@203
    83
	 */
dvander@203
    84
	PluginSettings *GetSettingsIfMatch(unsigned int index, const char *filename);
dvander@203
    85
dvander@203
    86
	/** 
dvander@203
    87
	 *  Given a plugin settings struct and an index,
dvander@203
    88
	 * returns the given JIT key/value option pair at that index.
dvander@203
    89
	 * If the input is invalid, key and val will be set to NULL.
dvander@203
    90
	 */
dvander@203
    91
	void GetOptionsForPlugin(PluginSettings *settings, unsigned int opt_num, const char **key, const char **val);
dvander@203
    92
private:
dvander@1656
    93
	SMCResult MakeError(const char *fmt, ...);
dvander@203
    94
private:
dvander@203
    95
	BaseStringTable *m_strtab;
dvander@203
    96
	int m_errmsg;
dvander@203
    97
	bool in_plugins;
dvander@203
    98
	bool in_options;
dvander@351
    99
	int m_infodb;
dvander@203
   100
	size_t m_infodb_count;
dvander@203
   101
	size_t m_infodb_size;
dvander@203
   102
	int cur_plugin;
dvander@203
   103
};
dvander@203
   104
dvander@203
   105
dvander@203
   106
#endif //_INCLUDE_SOURCEMOD_CORE_SYSTEM_PLUGININFODATABASE_H_