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

NPE fix #22886

Merged
merged 15 commits into from
Sep 27, 2022
Merged

NPE fix #22886

Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
Next Next commit
Update BUILD.gn deps for QNameString & move it to its own file to avo…
…id circular deps in /responders
  • Loading branch information
gmarcosb committed Jun 23, 2022
commit c98a86ec18bc7ef0849df0da641471af3e10181d
34 changes: 1 addition & 33 deletions src/lib/dnssd/minimal_mdns/Logging.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,45 +15,13 @@
* limitations under the License.
*/
#include <lib/dnssd/minimal_mdns/Logging.h>
#include <lib/dnssd/minimal_mdns/core/QNameString.h>
#include <lib/support/logging/CHIPLogging.h>

namespace mdns {
namespace Minimal {
namespace Logging {

QNameString::QNameString(const mdns::Minimal::FullQName & name)
{
for (unsigned i = 0; i < name.nameCount; i++)
{
if (i != 0)
{
mBuffer.Add(".");
}
mBuffer.Add(name.names[i]);
}
}

QNameString::QNameString(mdns::Minimal::SerializedQNameIterator name)
{
bool first = true;
while (name.Next())
{
if (first)
{
first = false;
}
else
{
mBuffer.Add(".");
}
mBuffer.Add(name.Value());
}
if (!name.IsValid())
{
mBuffer.Add("(!INVALID!)");
}
}

namespace {

#if CHIP_PROGRESS_LOGGING
Expand Down
17 changes: 0 additions & 17 deletions src/lib/dnssd/minimal_mdns/Logging.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,23 +29,6 @@ namespace Minimal {
/// MinMdns.
namespace Logging {

// Allows for a FullQName to be represented as a user-readable logging string
class QNameString
{
public:
QNameString(const mdns::Minimal::FullQName & name);

QNameString(mdns::Minimal::SerializedQNameIterator name);

inline const char * c_str() const { return mBuffer.c_str(); }

inline bool Fit() const { return mBuffer.Fit(); }

private:
static constexpr size_t kMaxQNameLength = 128;
chip::StringBuilder<kMaxQNameLength> mBuffer;
};

#if CHIP_MINMDNS_HIGH_VERBOSITY

void LogSendingQuery(const mdns::Minimal::Query & query);
Expand Down
2 changes: 2 additions & 0 deletions src/lib/dnssd/minimal_mdns/core/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ static_library("core") {
"DnsHeader.h",
"QName.cpp",
"QName.h",
"QNameString.cpp",
"QNameString.h",
"RecordWriter.cpp",
"RecordWriter.h",
]
Expand Down
56 changes: 56 additions & 0 deletions src/lib/dnssd/minimal_mdns/core/QNameString.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
/*
*
* Copyright (c) 2022 Project CHIP Authors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#include <lib/dnssd/minimal_mdns/core/QNameString.h>

namespace mdns {
namespace Minimal {

QNameString::QNameString(const mdns::Minimal::FullQName & name)
{
for (unsigned i = 0; i < name.nameCount; i++)
{
if (i != 0)
{
mBuffer.Add(".");
}
mBuffer.Add(name.names[i]);
}
}

QNameString::QNameString(mdns::Minimal::SerializedQNameIterator name)
{
bool first = true;
while (name.Next())
{
if (first)
{
first = false;
}
else
{
mBuffer.Add(".");
}
mBuffer.Add(name.Value());
}
if (!name.IsValid())
{
mBuffer.Add("(!INVALID!)");
}
}

} // namespace Minimal
} // namespace mdns
43 changes: 43 additions & 0 deletions src/lib/dnssd/minimal_mdns/core/QNameString.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
/*
*
* Copyright (c) 2022 Project CHIP Authors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#pragma once

#include <lib/support/StringBuilder.h>
#include <lib/dnssd/minimal_mdns/core/QName.h>

namespace mdns {
namespace Minimal {

// Allows for a FullQName to be represented as a user-readable logging string
class QNameString
{
public:
QNameString(const mdns::Minimal::FullQName & name);

QNameString(mdns::Minimal::SerializedQNameIterator name);

inline const char * c_str() const { return mBuffer.c_str(); }

inline bool Fit() const { return mBuffer.Fit(); }

private:
static constexpr size_t kMaxQNameLength = 128;
chip::StringBuilder<kMaxQNameLength> mBuffer;
};

} // namespace Minimal
} // namespace mdns
4 changes: 2 additions & 2 deletions src/lib/dnssd/minimal_mdns/responders/QueryResponder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
#include "QueryResponder.h"

#include <lib/dnssd/minimal_mdns/records/Ptr.h>
#include <lib/dnssd/minimal_mdns/Logging.h>
#include <lib/dnssd/minimal_mdns/core/QNameString.h>

#include <lib/support/logging/CHIPLogging.h>

Expand Down Expand Up @@ -57,7 +57,7 @@ QueryResponderSettings QueryResponderBase::AddResponder(RecordResponder * respon
{
return QueryResponderSettings();
}
ChipLogDetail(Discovery, "Responding with %s", Logging::QNameString(responder->GetQName()).c_str());
ChipLogDetail(Discovery, "Responding with %s", QNameString(responder->GetQName()).c_str());

for (size_t i = 0; i < mResponderInfoSize; i++)
{
Expand Down