Added a bunch of new file natives.
Fixed possible corruption in snprintf when input buffer was bigger than output buffer and relaying on its retval.
Fixed all cases when the above situation happened.
Fixed _PrintToHL2Log not taking va_list in.
3 #include "PluginInfoDatabase.h"
6 void PluginSettings::Init()
10 type_val = PluginType_MapUpdated;
17 * :TODO: write the logger, make these errors log instead of being static
18 * NOTE: once we do that, we will have to change some code to ignore sections
21 CPluginInfoDatabase::CPluginInfoDatabase()
29 CPluginInfoDatabase::~CPluginInfoDatabase()
34 void CPluginInfoDatabase::ReadSMC_ParseStart()
36 /* Create or reset our string table */
41 m_strtab = new BaseStringTable(1024);
44 /* Set our internal states to the beginning */
53 SMCParseResult CPluginInfoDatabase::MakeError(const char *fmt, ...)
59 vsnprintf(buffer, sizeof(buffer), fmt, ap);
62 m_errmsg = m_strtab->AddString(buffer);
64 return SMCParse_HaltFail;
67 unsigned int CPluginInfoDatabase::GetSettingsNum()
69 return m_infodb_count;
72 PluginSettings *CPluginInfoDatabase::GetSettingsIfMatch(unsigned int index, const char *filename)
74 BaseMemTable *memtab = m_strtab->GetMemTable();
75 int *table = (int *)memtab->GetAddress(m_infodb);
77 if (!table || index >= m_infodb_count)
82 PluginSettings *plugin = (PluginSettings *)memtab->GetAddress(table[index]);
84 const char *name = m_strtab->GetString(plugin->name);
91 if (!g_PluginSys.TestAliasMatch(name, filename))
99 void CPluginInfoDatabase::GetOptionsForPlugin(PluginSettings *settings, unsigned int opt_num, const char **key, const char **val)
101 PluginOpts *table = (PluginOpts *)m_strtab->GetMemTable()->GetAddress(settings->optarray);
109 if (opt_num >= settings->opts_num)
116 *key = m_strtab->GetString(table[opt_num].key);
117 *val = m_strtab->GetString(table[opt_num].val);
120 SMCParseResult CPluginInfoDatabase::ReadSMC_KeyValue(const char *key,
125 if (cur_plugin != -1)
127 PluginSettings *plugin = (PluginSettings *)m_strtab->GetMemTable()->GetAddress(cur_plugin);
130 if (strcmp(key, "pause") == 0)
132 if (strcasecmp(value, "yes") == 0)
134 plugin->pause_val = true;
136 plugin->pause_val = false;
138 } else if (strcmp(key, "lifetime") == 0) {
139 if (strcasecmp(value, "private") == 0)
141 plugin->type_val = PluginType_Private;
142 } else if (strcasecmp(value, "mapsync") == 0) {
143 plugin->type_val = PluginType_MapUpdated;
144 } else if (strcasecmp(value, "maponly") == 0) {
145 plugin->type_val = PluginType_MapOnly;
146 } else if (strcasecmp(value, "global") == 0) {
147 plugin->type_val = PluginType_Global;
149 return MakeError("Unknown value for key \"lifetime\": \"%s\"", value);
152 return MakeError("Unknown property key: \"%s\"", key);
155 /* Cache every option, valid or not */
156 int keyidx = m_strtab->AddString(key);
157 int validx = m_strtab->AddString(value);
159 BaseMemTable *memtab = m_strtab->GetMemTable();
160 if (plugin->opts_num + 1 > plugin->opts_size)
162 unsigned int oldsize = plugin->opts_size;
165 //right now we don't have many
166 plugin->opts_size = 2;
168 plugin->opts_size *= 2;
170 int newidx = memtab->CreateMem(plugin->opts_size * sizeof(PluginOpts), (void **)&table);
171 if (plugin->optarray != -1)
173 void *oldtable = memtab->GetAddress(plugin->optarray);
174 memcpy(table, oldtable, oldsize * sizeof(PluginOpts));
176 plugin->optarray = newidx;
178 table = (PluginOpts *)memtab->GetAddress(plugin->optarray);
180 PluginOpts *opt = &table[plugin->opts_num++];
184 } else if (in_plugins) {
185 return MakeError("Unknown property key: \"%s\"", key);
187 /* Ignore anything we don't know about! */
190 return SMCParse_Continue;
193 SMCParseResult CPluginInfoDatabase::ReadSMC_LeavingSection()
197 if (cur_plugin != -1)
203 /* If the plugin is ending, add it to the table */
204 BaseMemTable *memtab = m_strtab->GetMemTable();
206 if (m_infodb_count + 1 > m_infodb_size)
208 unsigned int oldsize = m_infodb_size;
215 int newidx = memtab->CreateMem(m_infodb_size, (void **)&table);
218 void *oldtable = (int *)memtab->GetAddress(m_infodb);
219 memcpy(table, oldtable, oldsize * sizeof(int));
223 table = (int *)memtab->GetAddress(m_infodb);
225 /* Assign to table and scrap the current plugin */
226 table[m_infodb_count++] = cur_plugin;
234 return SMCParse_Continue;
237 SMCParseResult CPluginInfoDatabase::ReadSMC_NewSection(const char *name, bool opt_quotes)
241 /* If we're not in the main Plugins section, and we don't get it for the name, error out */
242 if (strcmp(name, "Plugins") != 0)
244 return MakeError("Unknown root section: \"%s\"", name);
246 /* Otherwise set our states */
252 if (cur_plugin == -1)
254 /* If we get a plugin node and we don't have a current plugin, create a new one */
255 PluginSettings *plugin;
256 cur_plugin = m_strtab->GetMemTable()->CreateMem(sizeof(PluginSettings), (void **)&plugin);
258 plugin->name = m_strtab->AddString(name);
261 if (!in_options && strcmp(name, "Options") == 0)
265 return MakeError("Unknown plugin sub-section: \"%s\"", name);
270 return SMCParse_Continue;