Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chip-tool PersistentStorage: support for CASE resumption keys #20220

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 26 additions & 0 deletions examples/chip-tool/config/PersistentStorage.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,28 @@ std::string Base64ToString(const std::string & b64Value)
return std::string(reinterpret_cast<const char *>(buffer.get()), len);
}

void AdjustConfig(Sections & sections)
{
Section section = sections[kDefaultSectionName];
Section newSection;

for (auto it = section.begin(); it != section.end(); it++)
{
std::string key = it->first;
const char * value = it->second.c_str();

while (value[0] == '=')
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So this is assuming that values don't actually ever start with '=', right? I guess that's true because we base64-encode the values? Might be worth documenting that...

{
key += '=';
value++;
}

newSection[key] = value;
}

sections[kDefaultSectionName] = newSection;
}

} // namespace

CHIP_ERROR PersistentStorage::Init(const char * name)
Expand All @@ -95,6 +117,10 @@ CHIP_ERROR PersistentStorage::Init(const char * name)
mName = name;
mConfig.parse(ifs);
ifs.close();

// inipp.h cannot deal with keys containing '=' and does not support escapes either
AdjustConfig(mConfig.sections);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We could escape the key any way we want though.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes but not in any standard way such as backslash=. It would also slow down all operations. This way we only do it once.


exit:
return err;
}
Expand Down