diff options
| author | Karel Klic <kklic@redhat.com> | 2010-02-15 10:13:34 +0100 |
|---|---|---|
| committer | Karel Klic <kklic@redhat.com> | 2010-02-15 10:13:34 +0100 |
| commit | f49b4e72dc22d004ada91292fcd7179956de81c4 (patch) | |
| tree | 92edd09227bd41e738e004c0e45444d39452c012 /lib/Utils/Plugin.cpp | |
| parent | e245149118bff4a364fb6fbb0651b1f09e0ce0bc (diff) | |
| parent | f97428655a81cea935fd0a8cc93af83e712df299 (diff) | |
| download | abrt-f49b4e72dc22d004ada91292fcd7179956de81c4.tar.gz abrt-f49b4e72dc22d004ada91292fcd7179956de81c4.tar.xz abrt-f49b4e72dc22d004ada91292fcd7179956de81c4.zip | |
Merge branch 'master' of ssh://git.fedorahosted.org/git/abrt
Diffstat (limited to 'lib/Utils/Plugin.cpp')
| -rw-r--r-- | lib/Utils/Plugin.cpp | 69 |
1 files changed, 69 insertions, 0 deletions
diff --git a/lib/Utils/Plugin.cpp b/lib/Utils/Plugin.cpp index 2865027f..40cd2a02 100644 --- a/lib/Utils/Plugin.cpp +++ b/lib/Utils/Plugin.cpp @@ -17,6 +17,7 @@ 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. */ #include "Plugin.h" +#include "abrtlib.h" CPlugin::CPlugin() {} @@ -33,3 +34,71 @@ const map_plugin_settings_t& CPlugin::GetSettings() { return m_pSettings; } + +bool LoadPluginSettings(const char *pPath, map_plugin_settings_t& pSettings, + bool skipKeysWithoutValue /*= true*/) +{ + FILE *fp = fopen(pPath, "r"); + if (!fp) + return false; + + char line[512]; + while (fgets(line, sizeof(line), fp)) + { + strchrnul(line, '\n')[0] = '\0'; + unsigned ii; + bool is_value = false; + bool valid = false; + bool in_quote = false; + std::string key; + std::string value; + for (ii = 0; line[ii] != '\0'; ii++) + { + if (line[ii] == '"') + { + in_quote = !in_quote; + } + if (isspace(line[ii]) && !in_quote) + { + continue; + } + if (line[ii] == '#' && !in_quote && key == "") + { + break; + } + if (line[ii] == '=' && !in_quote) + { + is_value = true; + valid = true; + continue; + } + if (!is_value) + { + key += line[ii]; + } + else + { + value += line[ii]; + } + } + + /* Skip broken or empty lines. */ + if (!valid) + continue; + + /* Skip lines with empty key. */ + if (key.length() == 0) + continue; + + if (skipKeysWithoutValue && value.length() == 0) + continue; + + /* Skip lines with unclosed quotes. */ + if (in_quote) + continue; + + pSettings[key] = value; + } + fclose(fp); + return true; +} |
