void ParseSectionDeclaration()

in src/aws-cpp-sdk-core/source/config/AWSConfigFileProfileConfigLoader.cpp [274:405]


            void ParseSectionDeclaration(const Aws::String& line,
                                         Aws::String& ioSectionName,
                                         State& ioState)
            {
                do { // goto in a form of "do { break; } while(0);"
                    Aws::String::size_type pos = 0;
                    pos = line.find_first_not_of(WHITESPACE_CHARACTERS, pos);
                    if(pos != Aws::String::npos && LEFT_BRACKET != line[pos])
                    {
                        AWS_LOGSTREAM_ERROR(PARSER_TAG, "First non-blank space character of a section definition must be [, line:" << line);
                        break;
                    }
                    pos++;
                    pos = line.find_first_not_of(WHITESPACE_CHARACTERS, pos);
                    if(pos == Aws::String::npos || pos >= line.size())
                    {
                        AWS_LOGSTREAM_ERROR(PARSER_TAG, "Unknown section found in the aws config file: " << line);
                        break;
                    }
                    bool defaultProfileOrSsoSectionRequired = false;
                    if (m_useProfilePrefix)
                    {
                        // in configuration files, the profile name must start with profile. (eg. [profile profile-name]),
                        // except where the profile name is default. When the profile name is default it may start with profile
                        static const size_t PROFILE_KEYWORD_LENGTH = 7;
                        if(line.rfind(PROFILE_SECTION, pos + PROFILE_KEYWORD_LENGTH) != Aws::String::npos)
                        {
                            // skipping required (optional for default) profile keyword
                            pos += PROFILE_KEYWORD_LENGTH;
                            if(pos >= line.size() ||
                               std::find(WHITESPACE_CHARACTERS,
                                         WHITESPACE_CHARACTERS + WHITESPACE_CHARACTERS_SZ,
                                         line[pos]) == WHITESPACE_CHARACTERS + WHITESPACE_CHARACTERS_SZ)
                            {
                                AWS_LOGSTREAM_ERROR(PARSER_TAG, "Expected a blank space after \"profile\" keyword: " << line);
                                break;
                            }
                            pos = line.find_first_not_of(WHITESPACE_CHARACTERS, pos);
                        }
                        else
                        {
                            defaultProfileOrSsoSectionRequired = true;
                        }
                    }

                    Aws::String errorMsg;
                    Aws::String sectionIdentifier = ParseIdentifier(line, pos, errorMsg);
                    if (!errorMsg.empty())
                    {
                        AWS_LOGSTREAM_ERROR(PARSER_TAG, "Failed to parse section identifier: " << errorMsg << " " << line);
                        break;
                    }
                    pos += sectionIdentifier.length();

                    if(defaultProfileOrSsoSectionRequired)
                    {
                        if (sectionIdentifier != DEFAULT && sectionIdentifier != SSO_SESSION_SECTION)
                        {
                            AWS_LOGSTREAM_ERROR(PARSER_TAG, "In configuration files, the profile name must start with "
                                                            "profile keyword (except default profile): " << line);
                            break;
                        }
                        if (sectionIdentifier != SSO_SESSION_SECTION)
                        {
                            // profile found, still pending check for closing bracket
                            ioState = PROFILE_FOUND;
                            ioSectionName = sectionIdentifier;
                        }
                    }

                    if(!m_useProfilePrefix || sectionIdentifier != SSO_SESSION_SECTION)
                    {
                        // profile found, still pending check for closing bracket
                        ioState = PROFILE_FOUND;
                        ioSectionName = sectionIdentifier;
                    }

                    if(m_useProfilePrefix && sectionIdentifier == SSO_SESSION_SECTION)
                    {
                        // "[sso_session..." found, continue parsing for sso_session identifier
                        pos = line.find_first_not_of(WHITESPACE_CHARACTERS, pos);
                        if(pos == Aws::String::npos)
                        {
                            AWS_LOGSTREAM_ERROR(PARSER_TAG, "Expected a blank space after \"sso_session\" keyword: " << line);
                            break;
                        }

                        sectionIdentifier = ParseIdentifier(line, pos, errorMsg);
                        if (!errorMsg.empty())
                        {
                            AWS_LOGSTREAM_ERROR(PARSER_TAG, "Failed to parse section identifier: " << errorMsg << " " << line);
                            break;
                        }
                        pos += sectionIdentifier.length();
                        // sso_session found, still pending check for closing bracket
                        ioState = SSO_SESSION_FOUND;
                        ioSectionName = sectionIdentifier;
                    }

                    pos = line.find_first_not_of(WHITESPACE_CHARACTERS, pos);
                    if(pos == Aws::String::npos)
                    {
                        AWS_LOGSTREAM_ERROR(PARSER_TAG, "Expected a non-blank space after section identifier (i.e. missing \"]\"): " << line);
                        break;
                    }
                    if(line[pos] != RIGHT_BRACKET)
                    {
                        AWS_LOGSTREAM_ERROR(PARSER_TAG, "Missing closing bracket after Section Identifier "
                                                        "(i.e. missing \"]\" or extra non-blank characters before \"]\"): " << line);
                        break;
                    }
                    pos++;
                    pos = line.find_first_not_of(WHITESPACE_CHARACTERS, pos);
                    if(pos != Aws::String::npos &&
                       std::find(COMMENT_START, COMMENT_START + COMMENT_START_SZ, line[pos]) == COMMENT_START + COMMENT_START_SZ)
                    {
                        AWS_LOGSTREAM_ERROR(PARSER_TAG, "Found unexpected characters after closing bracket of Section Identifier " << line);
                        break;
                    }
                    // the rest is a comment, and we don't care about it.
                    if ((ioState != SSO_SESSION_FOUND && ioState != PROFILE_FOUND) || ioSectionName.empty())
                    {
                        AWS_LOGSTREAM_FATAL(PARSER_TAG, "Unexpected parser state after attempting to parse section " << line);
                        break;
                    }
                    return;
                } while(0); // end of goto in a form of "do { break; } while(0);"

                ioSectionName.erase();
                ioState = UNKNOWN_SECTION_FOUND;
                return;
            }