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 PluginSettings *table = (PluginSettings *)memtab->GetAddress(m_infodb);
74 if (!table || index >= m_infodb_count)
79 const char *name = m_strtab->GetString(table[index].name);
86 if (!g_PluginMngr.TestAliasMatch(name, filename))
94 void CPluginInfoDatabase::GetOptionsForPlugin(PluginSettings *settings, unsigned int opt_num, const char **key, const char **val)
96 PluginOpts *table = (PluginOpts *)m_strtab->GetMemTable()->GetAddress(settings->optarray);
104 if (opt_num >= settings->opts_num)
111 *key = m_strtab->GetString(table[opt_num].key);
112 *val = m_strtab->GetString(table[opt_num].val);
115 SMCParseResult CPluginInfoDatabase::ReadSMC_KeyValue(const char *key,
120 if (cur_plugin != -1)
122 PluginSettings *plugin = (PluginSettings *)m_strtab->GetMemTable()->GetAddress(cur_plugin);
125 if (strcmp(key, "pause") == 0)
127 if (strcasecmp(value, "yes") == 0)
129 plugin->pause_val = true;
131 plugin->pause_val = false;
133 } else if (strcmp(key, "lifetime") == 0) {
134 if (strcasecmp(value, "private") == 0)
136 plugin->type_val = PluginType_Private;
137 } else if (strcasecmp(value, "mapsync") == 0) {
138 plugin->type_val = PluginType_MapUpdated;
139 } else if (strcasecmp(value, "maponly") == 0) {
140 plugin->type_val = PluginType_MapOnly;
141 } else if (strcasecmp(value, "global") == 0) {
142 plugin->type_val = PluginType_Global;
144 return MakeError("Unknown value for key \"lifetime\": \"%s\"", value);
147 return MakeError("Unknown property key: \"%s\"", key);
150 /* Cache every option, valid or not */
151 int keyidx = m_strtab->AddString(key);
152 int validx = m_strtab->AddString(value);
154 BaseMemTable *memtab = m_strtab->GetMemTable();
155 if (plugin->opts_num + 1 > plugin->opts_size)
157 unsigned int oldsize = plugin->opts_size;
160 //right now we don't have many
161 plugin->opts_size = 2;
163 plugin->opts_size *= 2;
165 int newidx = memtab->CreateMem(plugin->opts_size * sizeof(PluginOpts), (void **)&table);
166 if (plugin->optarray != -1)
168 void *oldtable = memtab->GetAddress(plugin->optarray);
169 memcpy(table, oldtable, oldsize * sizeof(PluginOpts));
171 plugin->optarray = newidx;
173 table = (PluginOpts *)memtab->GetAddress(plugin->optarray);
175 PluginOpts *opt = &table[plugin->opts_num++];
179 } else if (in_plugins) {
180 return MakeError("Unknown property key: \"%s\"", key);
182 /* Ignore anything we don't know about! */
185 return SMCParse_Continue;
188 SMCParseResult CPluginInfoDatabase::ReadSMC_LeavingSection()
192 if (cur_plugin == -1)
198 /* If the plugin is ending, add it to the table */
199 BaseMemTable *memtab = m_strtab->GetMemTable();
201 if (m_infodb_count + 1 > m_infodb_size)
203 unsigned int oldsize = m_infodb_size;
210 int newidx = memtab->CreateMem(m_infodb_size, (void **)&table);
213 void *oldtable = (int *)memtab->GetAddress(m_infodb);
214 memcpy(table, oldtable, oldsize * sizeof(int));
218 table = (int *)memtab->GetAddress(m_infodb);
220 /* Assign to table and scrap the current plugin */
221 table[m_infodb_count++] = cur_plugin;
229 return SMCParse_Continue;
232 SMCParseResult CPluginInfoDatabase::ReadSMC_NewSection(const char *name, bool opt_quotes)
236 /* If we're not in the main Plugins section, and we don't get it for the name, error out */
237 if (strcmp(name, "Plugins") != 0)
239 return MakeError("Unknown root section: \"%s\"", name);
241 /* Otherwise set our states */
247 if (cur_plugin == -1)
249 /* If we get a plugin node and we don't have a current plugin, create a new one */
250 PluginSettings *plugin;
251 cur_plugin = m_strtab->GetMemTable()->CreateMem(sizeof(PluginSettings), (void **)&plugin);
253 plugin->name = m_strtab->AddString(name);
256 if (!in_options && strcmp(name, "Options") == 0)
260 return MakeError("Unknown plugin sub-section: \"%s\"", name);
265 return SMCParse_Continue;