ConfigService::SectionMap ConfigService::getSection ( const std::string& sectionName ) { SectionMap combinedSection; if (mInstanceConfig->findSection(sectionName)) { const SectionMap& section = mInstanceConfig->getSection(sectionName); combinedSection.insert(section.begin(), section.end()); } if (mCommandLineConfig->findSection(sectionName)) { const SectionMap& section = mCommandLineConfig->getSection(sectionName); combinedSection.insert(section.begin(), section.end()); } if (mUserConfig->findSection(sectionName)) { const SectionMap& section = mUserConfig->getSection(sectionName); combinedSection.insert(section.begin(), section.end()); } if (mGlobalConfig->findSection(sectionName)) { const SectionMap& section = mGlobalConfig->getSection(sectionName); combinedSection.insert(section.begin(), section.end()); } return combinedSection; }
int Configuration::open (const char *fileName) { if (0 == fileName) { errno = EINVAL; return -1; } FILE* in = OS::fopen (fileName, ACE_TEXT ("r")); if (!in) return -1; char buffer[4096]; SectionMap *section = 0; while (OS::fgets (buffer, sizeof buffer, in)) { char *line = this->squish (buffer); // Check for a comment and blank line if (line[0] == ';' || line[0] == '#' || line[0] == '\0') continue; if (line[0] == '[') { // We have a new section here, strip out the section name char* end = OS::strrchr (line, ']'); if (!end) { OS::fclose (in); return -3; } // edited by robert, change to memmove to handle overlapping memory // OS::memcpy (line, line + 1, OS::strlen (line) - 2); OS::memmove (line, line + 1, OS::strlen (line) - 2); line[OS::strlen (line) -2] = 0; //*end = 0; section = new SectionMap; this->m_configMap.insert (pair<string, SectionMap*> (line,section)); continue; } // We have a line; name ends at equal sign. char *end = OS::strchr (line, '='); if (end == 0) { OS::fclose (in); return -3; } *end++ = '\0'; char *name = this->squish (line); // Now find the start of the value char *value = this->squish (end); //size_t value_len = OS::strlen (value); section->insert (pair<string, string> (name, value)); } // end while fgets if (ferror (in)) { OS::fclose (in); return -1; } OS::fclose (in); return 0; }