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 */
50 SMCParseResult CPluginInfoDatabase::MakeError(const char *fmt, ...)
56 vsnprintf(buffer, sizeof(buffer), fmt, ap);
59 m_errmsg = m_strtab->AddString(buffer);
61 return SMCParse_HaltFail;
64 unsigned int CPluginInfoDatabase::GetSettingsNum()
66 return m_infodb_count;
69 PluginSettings *CPluginInfoDatabase::GetSettingsIfMatch(unsigned int index, const char *filename)
71 BaseMemTable *memtab = m_strtab->GetMemTable();
72 int *table = (int *)memtab->GetAddress(m_infodb);
74 if (!table || index >= m_infodb_count)
79 PluginSettings *plugin = (PluginSettings *)memtab->GetAddress(table[index]);
81 const char *name = m_strtab->GetString(plugin->name);
88 if (!g_PluginMngr.TestAliasMatch(name, filename))
96 void CPluginInfoDatabase::GetOptionsForPlugin(PluginSettings *settings, unsigned int opt_num, const char **key, const char **val)
98 PluginOpts *table = (PluginOpts *)m_strtab->GetMemTable()->GetAddress(settings->optarray);
106 if (opt_num >= settings->opts_num)
113 *key = m_strtab->GetString(table[opt_num].key);
114 *val = m_strtab->GetString(table[opt_num].val);
117 SMCParseResult CPluginInfoDatabase::ReadSMC_KeyValue(const char *key,
122 if (cur_plugin != -1)
124 PluginSettings *plugin = (PluginSettings *)m_strtab->GetMemTable()->GetAddress(cur_plugin);
127 if (strcmp(key, "pause") == 0)
129 if (strcasecmp(value, "yes") == 0)
131 plugin->pause_val = true;
133 plugin->pause_val = false;
135 } else if (strcmp(key, "lifetime") == 0) {
136 if (strcasecmp(value, "private") == 0)
138 plugin->type_val = PluginType_Private;
139 } else if (strcasecmp(value, "mapsync") == 0) {
140 plugin->type_val = PluginType_MapUpdated;
141 } else if (strcasecmp(value, "maponly") == 0) {
142 plugin->type_val = PluginType_MapOnly;
143 } else if (strcasecmp(value, "global") == 0) {
144 plugin->type_val = PluginType_Global;
146 return MakeError("Unknown value for key \"lifetime\": \"%s\"", value);
149 return MakeError("Unknown property key: \"%s\"", key);
152 /* Cache every option, valid or not */
153 int keyidx = m_strtab->AddString(key);
154 int validx = m_strtab->AddString(value);
156 BaseMemTable *memtab = m_strtab->GetMemTable();
157 if (plugin->opts_num + 1 > plugin->opts_size)
159 unsigned int oldsize = plugin->opts_size;
162 //right now we don't have many
163 plugin->opts_size = 2;
165 plugin->opts_size *= 2;
167 int newidx = memtab->CreateMem(plugin->opts_size * sizeof(PluginOpts), (void **)&table);
168 if (plugin->optarray != -1)
170 void *oldtable = memtab->GetAddress(plugin->optarray);
171 memcpy(table, oldtable, oldsize * sizeof(PluginOpts));
173 plugin->optarray = newidx;
175 table = (PluginOpts *)memtab->GetAddress(plugin->optarray);
177 PluginOpts *opt = &table[plugin->opts_num++];
181 } else if (in_plugins) {
182 return MakeError("Unknown property key: \"%s\"", key);
184 /* Ignore anything we don't know about! */
187 return SMCParse_Continue;
190 SMCParseResult CPluginInfoDatabase::ReadSMC_LeavingSection()
194 if (cur_plugin != -1)
200 /* If the plugin is ending, add it to the table */
201 BaseMemTable *memtab = m_strtab->GetMemTable();
203 if (m_infodb_count + 1 > m_infodb_size)
205 unsigned int oldsize = m_infodb_size;
212 int newidx = memtab->CreateMem(m_infodb_size, (void **)&table);
215 void *oldtable = (int *)memtab->GetAddress(m_infodb);
216 memcpy(table, oldtable, oldsize * sizeof(int));
220 table = (int *)memtab->GetAddress(m_infodb);
222 /* Assign to table and scrap the current plugin */
223 table[m_infodb_count++] = cur_plugin;
231 return SMCParse_Continue;
234 SMCParseResult CPluginInfoDatabase::ReadSMC_NewSection(const char *name, bool opt_quotes)
238 /* If we're not in the main Plugins section, and we don't get it for the name, error out */
239 if (strcmp(name, "Plugins") != 0)
241 return MakeError("Unknown root section: \"%s\"", name);
243 /* Otherwise set our states */
249 if (cur_plugin == -1)
251 /* If we get a plugin node and we don't have a current plugin, create a new one */
252 PluginSettings *plugin;
253 cur_plugin = m_strtab->GetMemTable()->CreateMem(sizeof(PluginSettings), (void **)&plugin);
255 plugin->name = m_strtab->AddString(name);
258 if (!in_options && strcmp(name, "Options") == 0)
262 return MakeError("Unknown plugin sub-section: \"%s\"", name);
267 return SMCParse_Continue;