Skip to content

Commit

Permalink
trim eol char
Browse files Browse the repository at this point in the history
  • Loading branch information
dkhalife committed Nov 24, 2024
1 parent 1752252 commit 1916dc5
Showing 1 changed file with 10 additions and 9 deletions.
19 changes: 10 additions & 9 deletions src/backends/file/be_file.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,21 +33,22 @@ void BE_File::loadFile(const std::string& filePath)
mosquitto_log_printf(MOSQ_LOG_DEBUG, "*** auth-plugin: loading credentials from `%s`", filePath.c_str());

auto file = std::ifstream(filePath);
std::string line, username, password;
std::string line;
int lineNb = 1;
while (getline(file, line))
{
std::stringstream lineStream(line);

if (getline(lineStream, username, ':') && getline(lineStream, password))
{
m_credentials.emplace_back(make_pair(username, password));
}
else
int iSep = line.find_first_of(':');
if (iSep == std::string::npos)
{
mosquitto_log_printf(MOSQ_LOG_DEBUG, "*** auth-plugin: line %i is malformed, skipping it", lineNb);
mosquitto_log_printf(MOSQ_LOG_ERR, "*** auth-plugin: line %i is malformed, skipping it", lineNb);
continue;
}

std::string username = line.substr(0, iSep);
size_t remaining = line.size() - username.size() - 2U;
std::string password = line.substr(iSep + 1, remaining);
m_credentials.emplace_back(make_pair(std::move(username), std::move(password)));

++lineNb;
}
}
Expand Down

0 comments on commit 1916dc5

Please sign in to comment.