Skip to content

Commit

Permalink
save
Browse files Browse the repository at this point in the history
  • Loading branch information
superwhd committed Dec 11, 2023
1 parent 98db630 commit 598cbcf
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 43 deletions.
11 changes: 11 additions & 0 deletions src/dbus/common/dbus_message_helper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,17 @@
namespace otbr {
namespace DBus {

otbrError DbusMessageIterRecurse(DBusMessageIter *aIter, DBusMessageIter *aSubIter, int aType)
{
otbrError error = OTBR_ERROR_NONE;

VerifyOrExit(dbus_message_iter_get_arg_type(aIter) == aType, error = OTBR_ERROR_DBUS);
dbus_message_iter_recurse(aIter, aSubIter);

exit:
return error;
}

otbrError DBusMessageExtract(DBusMessageIter *aIter, bool &aValue)
{
otbrError error = OTBR_ERROR_DBUS;
Expand Down
2 changes: 2 additions & 0 deletions src/dbus/common/dbus_message_helper.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -448,6 +448,8 @@ template <> struct DBusTypeTrait<bool>
static constexpr const char *TYPE_AS_STRING = DBUS_TYPE_BOOLEAN_AS_STRING;
};

otbrError DbusMessageIterRecurse(DBusMessageIter *aIter, DBusMessageIter *aSubIter, int aType);

otbrError DBusMessageEncode(DBusMessageIter *aIter, bool aValue);
otbrError DBusMessageEncode(DBusMessageIter *aIter, int8_t aValue);
otbrError DBusMessageEncode(DBusMessageIter *aIter, const std::string &aValue);
Expand Down
74 changes: 31 additions & 43 deletions src/dbus/common/dbus_message_helper_openthread.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,7 @@ otbrError DBusMessageExtract(DBusMessageIter *aIter, ActiveScanResult &aScanResu
// Dbus doesn't have the concept of a signed byte
int16_t rssi = 0;

VerifyOrExit(dbus_message_iter_get_arg_type(aIter) == DBUS_TYPE_STRUCT, error = OTBR_ERROR_DBUS);
dbus_message_iter_recurse(aIter, &sub);
SuccessOrExit(error = DbusMessageIterRecurse(aIter, &sub, DBUS_TYPE_STRUCT));

SuccessOrExit(error = DBusMessageExtract(&sub, aScanResult.mExtAddress));
SuccessOrExit(error = DBusMessageExtract(&sub, aScanResult.mNetworkName));
Expand Down Expand Up @@ -117,8 +116,7 @@ otbrError DBusMessageExtract(DBusMessageIter *aIter, EnergyScanResult &aResult)
DBusMessageIter sub;
otbrError error = OTBR_ERROR_NONE;

VerifyOrExit(dbus_message_iter_get_arg_type(aIter) == DBUS_TYPE_STRUCT, error = OTBR_ERROR_DBUS);
dbus_message_iter_recurse(aIter, &sub);
SuccessOrExit(error = DbusMessageIterRecurse(aIter, &sub, DBUS_TYPE_STRUCT));

SuccessOrExit(error = DBusMessageExtract(&sub, aResult.mChannel));
SuccessOrExit(error = DBusMessageExtract(&sub, aResult.mMaxRssi));
Expand Down Expand Up @@ -166,8 +164,7 @@ otbrError DBusMessageExtract(DBusMessageIter *aIter, LinkModeConfig &aConfig)
otbrError error = OTBR_ERROR_DBUS;
DBusMessageIter sub;

VerifyOrExit(dbus_message_iter_get_arg_type(aIter) == DBUS_TYPE_STRUCT);
dbus_message_iter_recurse(aIter, &sub);
SuccessOrExit(error = DbusMessageIterRecurse(aIter, &sub, DBUS_TYPE_STRUCT));

SuccessOrExit(DBusMessageExtract(&sub, aConfig.mRxOnWhenIdle));
SuccessOrExit(DBusMessageExtract(&sub, aConfig.mDeviceType));
Expand Down Expand Up @@ -201,7 +198,7 @@ otbrError DBusMessageExtract(DBusMessageIter *aIter, Ip6Prefix &aPrefix)
DBusMessageIter sub;
otbrError error = OTBR_ERROR_NONE;

dbus_message_iter_recurse(aIter, &sub);
SuccessOrExit(error = DbusMessageIterRecurse(aIter, &sub, DBUS_TYPE_STRUCT));
SuccessOrExit(error = DBusMessageExtract(&sub, aPrefix.mPrefix));
VerifyOrExit(aPrefix.mPrefix.size() <= OTBR_IP6_PREFIX_SIZE, error = OTBR_ERROR_DBUS);
SuccessOrExit(error = DBusMessageExtract(&sub, aPrefix.mLength));
Expand Down Expand Up @@ -236,7 +233,7 @@ otbrError DBusMessageExtract(DBusMessageIter *aIter, ExternalRoute &aRoute)
DBusMessageIter sub;
otbrError error = OTBR_ERROR_NONE;

dbus_message_iter_recurse(aIter, &sub);
SuccessOrExit(error = DbusMessageIterRecurse(aIter, &sub, DBUS_TYPE_STRUCT));
SuccessOrExit(error = DBusMessageExtract(&sub, aRoute.mPrefix));
SuccessOrExit(error = DBusMessageExtract(&sub, aRoute.mRloc16));
SuccessOrExit(error = DBusMessageExtract(&sub, aRoute.mPreference));
Expand Down Expand Up @@ -280,7 +277,7 @@ otbrError DBusMessageExtract(DBusMessageIter *aIter, OnMeshPrefix &aPrefix)
DBusMessageIter sub;
otbrError error = OTBR_ERROR_NONE;

dbus_message_iter_recurse(aIter, &sub);
SuccessOrExit(error = DbusMessageIterRecurse(aIter, &sub, DBUS_TYPE_STRUCT));
SuccessOrExit(error = DBusMessageExtract(&sub, aPrefix.mPrefix));
SuccessOrExit(error = DBusMessageExtract(&sub, aPrefix.mRloc16));
SuccessOrExit(error = DBusMessageExtract(&sub, aPrefix.mPreference));
Expand Down Expand Up @@ -335,8 +332,7 @@ otbrError DBusMessageExtract(DBusMessageIter *aIter, MacCounters &aCounters)
DBusMessageIter sub;
otbrError error = OTBR_ERROR_NONE;

VerifyOrExit(dbus_message_iter_get_arg_type(aIter) == DBUS_TYPE_STRUCT, error = OTBR_ERROR_DBUS);
dbus_message_iter_recurse(aIter, &sub);
SuccessOrExit(error = DbusMessageIterRecurse(aIter, &sub, DBUS_TYPE_STRUCT));
SuccessOrExit(error = ConvertToTuple(&sub, args));
dbus_message_iter_next(aIter);
exit:
Expand All @@ -362,8 +358,7 @@ otbrError DBusMessageExtract(DBusMessageIter *aIter, IpCounters &aCounters)
otbrError error = OTBR_ERROR_NONE;
auto args = std::tie(aCounters.mTxSuccess, aCounters.mRxSuccess, aCounters.mTxFailure, aCounters.mRxFailure);

VerifyOrExit(dbus_message_iter_get_arg_type(aIter) == DBUS_TYPE_STRUCT, error = OTBR_ERROR_DBUS);
dbus_message_iter_recurse(aIter, &sub);
SuccessOrExit(error = DbusMessageIterRecurse(aIter, &sub, DBUS_TYPE_STRUCT));
SuccessOrExit(error = ConvertToTuple(&sub, args));
dbus_message_iter_next(aIter);
exit:
Expand Down Expand Up @@ -397,8 +392,7 @@ otbrError DBusMessageExtract(DBusMessageIter *aIter, ChildInfo &aChildInfo)
aChildInfo.mMessageErrorRate, aChildInfo.mRxOnWhenIdle, aChildInfo.mFullThreadDevice,
aChildInfo.mFullNetworkData, aChildInfo.mIsStateRestoring);

VerifyOrExit(dbus_message_iter_get_arg_type(aIter) == DBUS_TYPE_STRUCT, error = OTBR_ERROR_DBUS);
dbus_message_iter_recurse(aIter, &sub);
SuccessOrExit(error = DbusMessageIterRecurse(aIter, &sub, DBUS_TYPE_STRUCT));
SuccessOrExit(error = ConvertToTuple(&sub, args));
dbus_message_iter_next(aIter);
exit:
Expand Down Expand Up @@ -432,8 +426,7 @@ otbrError DBusMessageExtract(DBusMessageIter *aIter, NeighborInfo &aNeighborInfo
aNeighborInfo.mMessageErrorRate, aNeighborInfo.mVersion, aNeighborInfo.mRxOnWhenIdle,
aNeighborInfo.mFullThreadDevice, aNeighborInfo.mFullNetworkData, aNeighborInfo.mIsChild);

VerifyOrExit(dbus_message_iter_get_arg_type(aIter) == DBUS_TYPE_STRUCT, error = OTBR_ERROR_DBUS);
dbus_message_iter_recurse(aIter, &sub);
SuccessOrExit(error = DbusMessageIterRecurse(aIter, &sub, DBUS_TYPE_STRUCT));
SuccessOrExit(error = ConvertToTuple(&sub, args));
dbus_message_iter_next(aIter);
exit:
Expand Down Expand Up @@ -461,8 +454,7 @@ otbrError DBusMessageExtract(DBusMessageIter *aIter, LeaderData &aLeaderData)
auto args = std::tie(aLeaderData.mPartitionId, aLeaderData.mWeighting, aLeaderData.mDataVersion,
aLeaderData.mStableDataVersion, aLeaderData.mLeaderRouterId);

VerifyOrExit(dbus_message_iter_get_arg_type(aIter) == DBUS_TYPE_STRUCT, error = OTBR_ERROR_DBUS);
dbus_message_iter_recurse(aIter, &sub);
SuccessOrExit(error = DbusMessageIterRecurse(aIter, &sub, DBUS_TYPE_STRUCT));
SuccessOrExit(error = ConvertToTuple(&sub, args));
dbus_message_iter_next(aIter);
exit:
Expand All @@ -488,8 +480,7 @@ otbrError DBusMessageExtract(DBusMessageIter *aIter, ChannelQuality &aQuality)
otbrError error = OTBR_ERROR_NONE;
auto args = std::tie(aQuality.mChannel, aQuality.mOccupancy);

VerifyOrExit(dbus_message_iter_get_arg_type(aIter) == DBUS_TYPE_STRUCT, error = OTBR_ERROR_DBUS);
dbus_message_iter_recurse(aIter, &sub);
SuccessOrExit(error = DbusMessageIterRecurse(aIter, &sub, DBUS_TYPE_STRUCT));
SuccessOrExit(error = ConvertToTuple(&sub, args));
dbus_message_iter_next(aIter);
exit:
Expand All @@ -515,8 +506,7 @@ otbrError DBusMessageExtract(DBusMessageIter *aIter, TxtEntry &aTxtEntry)
otbrError error = OTBR_ERROR_NONE;
auto args = std::tie(aTxtEntry.mKey, aTxtEntry.mValue);

VerifyOrExit(dbus_message_iter_get_arg_type(aIter) == DBUS_TYPE_STRUCT, error = OTBR_ERROR_DBUS);
dbus_message_iter_recurse(aIter, &sub);
SuccessOrExit(error = DbusMessageIterRecurse(aIter, &sub, DBUS_TYPE_STRUCT));
SuccessOrExit(error = ConvertToTuple(&sub, args));
dbus_message_iter_next(aIter);
exit:
Expand Down Expand Up @@ -546,8 +536,7 @@ otbrError DBusMessageExtract(DBusMessageIter *aIter, SrpServerInfo::Registration
aRegistration.mKeyLeaseTimeTotal, aRegistration.mRemainingLeaseTimeTotal,
aRegistration.mRemainingKeyLeaseTimeTotal);

VerifyOrExit(dbus_message_iter_get_arg_type(aIter) == DBUS_TYPE_STRUCT, error = OTBR_ERROR_DBUS);
dbus_message_iter_recurse(aIter, &sub);
SuccessOrExit(error = DbusMessageIterRecurse(aIter, &sub, DBUS_TYPE_STRUCT));
SuccessOrExit(error = ConvertToTuple(&sub, args));
dbus_message_iter_next(aIter);
exit:
Expand Down Expand Up @@ -575,8 +564,7 @@ otbrError DBusMessageExtract(DBusMessageIter *aIter, SrpServerInfo::ResponseCoun
auto args = std::tie(aResponseCounters.mSuccess, aResponseCounters.mServerFailure, aResponseCounters.mFormatError,
aResponseCounters.mNameExists, aResponseCounters.mRefused, aResponseCounters.mOther);

VerifyOrExit(dbus_message_iter_get_arg_type(aIter) == DBUS_TYPE_STRUCT, error = OTBR_ERROR_DBUS);
dbus_message_iter_recurse(aIter, &sub);
SuccessOrExit(error = DbusMessageIterRecurse(aIter, &sub, DBUS_TYPE_STRUCT));
SuccessOrExit(error = ConvertToTuple(&sub, args));
dbus_message_iter_next(aIter);
exit:
Expand Down Expand Up @@ -607,7 +595,7 @@ otbrError DBusMessageExtract(DBusMessageIter *aIter, SrpServerInfo &aSrpServerIn
DBusMessageIter sub;
otbrError error = OTBR_ERROR_NONE;

dbus_message_iter_recurse(aIter, &sub);
DbusMessageIterRecurse(aIter, &sub, DBUS_TYPE_STRUCT);
SuccessOrExit(error = DBusMessageExtract(&sub, aSrpServerInfo.mState));
SuccessOrExit(error = DBusMessageExtract(&sub, aSrpServerInfo.mPort));
SuccessOrExit(error = DBusMessageExtract(&sub, aSrpServerInfo.mAddressMode));
Expand Down Expand Up @@ -646,7 +634,7 @@ otbrError DBusMessageExtract(DBusMessageIter *aIter, DnssdCounters &aDnssdCounte
DBusMessageIter sub;
otbrError error = OTBR_ERROR_NONE;

dbus_message_iter_recurse(aIter, &sub);
SuccessOrExit(error = DbusMessageIterRecurse(aIter, &sub, DBUS_TYPE_STRUCT));

SuccessOrExit(error = DBusMessageExtract(&sub, aDnssdCounters.mSuccessResponse));
SuccessOrExit(error = DBusMessageExtract(&sub, aDnssdCounters.mServerFailureResponse));
Expand Down Expand Up @@ -688,7 +676,7 @@ otbrError DBusMessageExtract(DBusMessageIter *aIter, MdnsResponseCounters &aMdns
DBusMessageIter sub;
otbrError error = OTBR_ERROR_NONE;

dbus_message_iter_recurse(aIter, &sub);
SuccessOrExit(error = DbusMessageIterRecurse(aIter, &sub, DBUS_TYPE_STRUCT));

SuccessOrExit(error = DBusMessageExtract(&sub, aMdnsResponseCounters.mSuccess));
SuccessOrExit(error = DBusMessageExtract(&sub, aMdnsResponseCounters.mNotFound));
Expand Down Expand Up @@ -731,7 +719,7 @@ otbrError DBusMessageExtract(DBusMessageIter *aIter, MdnsTelemetryInfo &aMdnsTel
DBusMessageIter sub;
otbrError error = OTBR_ERROR_NONE;

dbus_message_iter_recurse(aIter, &sub);
SuccessOrExit(error = DbusMessageIterRecurse(aIter, &sub, DBUS_TYPE_STRUCT));

SuccessOrExit(error = DBusMessageExtract(&sub, aMdnsTelemetryInfo.mHostRegistrations));
SuccessOrExit(error = DBusMessageExtract(&sub, aMdnsTelemetryInfo.mServiceRegistrations));
Expand Down Expand Up @@ -770,7 +758,7 @@ otbrError DBusMessageExtract(DBusMessageIter *aIter, RadioSpinelMetrics &aRadioS
DBusMessageIter sub;
otbrError error = OTBR_ERROR_NONE;

dbus_message_iter_recurse(aIter, &sub);
SuccessOrExit(error = DbusMessageIterRecurse(aIter, &sub, DBUS_TYPE_STRUCT));

SuccessOrExit(error = DBusMessageExtract(&sub, aRadioSpinelMetrics.mRcpTimeoutCount));
SuccessOrExit(error = DBusMessageExtract(&sub, aRadioSpinelMetrics.mRcpUnexpectedResetCount));
Expand Down Expand Up @@ -808,7 +796,7 @@ otbrError DBusMessageExtract(DBusMessageIter *aIter, RcpInterfaceMetrics &aRcpIn
DBusMessageIter sub;
otbrError error = OTBR_ERROR_NONE;

dbus_message_iter_recurse(aIter, &sub);
SuccessOrExit(error = DbusMessageIterRecurse(aIter, &sub, DBUS_TYPE_STRUCT));

SuccessOrExit(error = DBusMessageExtract(&sub, aRcpInterfaceMetrics.mRcpInterfaceType));
SuccessOrExit(error = DBusMessageExtract(&sub, aRcpInterfaceMetrics.mTransferredFrameCount));
Expand Down Expand Up @@ -861,7 +849,7 @@ otbrError DBusMessageExtract(DBusMessageIter *aIter, RadioCoexMetrics &aRadioCoe
DBusMessageIter sub;
otbrError error = OTBR_ERROR_NONE;

dbus_message_iter_recurse(aIter, &sub);
SuccessOrExit(error = DbusMessageIterRecurse(aIter, &sub, DBUS_TYPE_STRUCT));

SuccessOrExit(error = DBusMessageExtract(&sub, aRadioCoexMetrics.mNumGrantGlitch));
SuccessOrExit(error = DBusMessageExtract(&sub, aRadioCoexMetrics.mNumTxRequest));
Expand Down Expand Up @@ -909,7 +897,7 @@ otbrError DBusMessageExtract(DBusMessageIter *aIter, BorderRoutingCounters::Pack
DBusMessageIter sub;
otbrError error = OTBR_ERROR_NONE;

dbus_message_iter_recurse(aIter, &sub);
SuccessOrExit(error = DbusMessageIterRecurse(aIter, &sub, DBUS_TYPE_STRUCT));

SuccessOrExit(error = DBusMessageExtract(&sub, aPacketsAndBytes.mPackets));
SuccessOrExit(error = DBusMessageExtract(&sub, aPacketsAndBytes.mBytes));
Expand Down Expand Up @@ -949,7 +937,7 @@ otbrError DBusMessageExtract(DBusMessageIter *aIter, BorderRoutingCounters &aBor
DBusMessageIter sub;
otbrError error = OTBR_ERROR_NONE;

dbus_message_iter_recurse(aIter, &sub);
SuccessOrExit(error = DbusMessageIterRecurse(aIter, &sub, DBUS_TYPE_STRUCT));

SuccessOrExit(error = DBusMessageExtract(&sub, aBorderRoutingCounters.mInboundUnicast));
SuccessOrExit(error = DBusMessageExtract(&sub, aBorderRoutingCounters.mInboundMulticast));
Expand Down Expand Up @@ -988,7 +976,7 @@ otbrError DBusMessageExtract(DBusMessageIter *aIter, Nat64ComponentState &aNat64
DBusMessageIter sub;
otbrError error = OTBR_ERROR_NONE;

dbus_message_iter_recurse(aIter, &sub);
SuccessOrExit(error = DbusMessageIterRecurse(aIter, &sub, DBUS_TYPE_STRUCT));

SuccessOrExit(error = DBusMessageExtract(&sub, aNat64State.mPrefixManagerState));
SuccessOrExit(error = DBusMessageExtract(&sub, aNat64State.mTranslatorState));
Expand Down Expand Up @@ -1020,7 +1008,7 @@ otbrError DBusMessageExtract(DBusMessageIter *aIter, Nat64TrafficCounters &aCoun
DBusMessageIter sub;
otbrError error = OTBR_ERROR_NONE;

dbus_message_iter_recurse(aIter, &sub);
SuccessOrExit(error = DbusMessageIterRecurse(aIter, &sub, DBUS_TYPE_STRUCT));

SuccessOrExit(error = DBusMessageExtract(&sub, aCounters.m4To6Packets));
SuccessOrExit(error = DBusMessageExtract(&sub, aCounters.m4To6Bytes));
Expand Down Expand Up @@ -1052,7 +1040,7 @@ otbrError DBusMessageExtract(DBusMessageIter *aIter, Nat64PacketCounters &aCount
DBusMessageIter sub;
otbrError error = OTBR_ERROR_NONE;

dbus_message_iter_recurse(aIter, &sub);
SuccessOrExit(error = DbusMessageIterRecurse(aIter, &sub, DBUS_TYPE_STRUCT));

SuccessOrExit(error = DBusMessageExtract(&sub, aCounters.m4To6Packets));
SuccessOrExit(error = DBusMessageExtract(&sub, aCounters.m6To4Packets));
Expand Down Expand Up @@ -1084,7 +1072,7 @@ otbrError DBusMessageExtract(DBusMessageIter *aIter, Nat64ProtocolCounters &aCou
DBusMessageIter sub;
otbrError error = OTBR_ERROR_NONE;

dbus_message_iter_recurse(aIter, &sub);
SuccessOrExit(error = DbusMessageIterRecurse(aIter, &sub, DBUS_TYPE_STRUCT));

SuccessOrExit(error = DBusMessageExtract(&sub, aCounters.mTotal));
SuccessOrExit(error = DBusMessageExtract(&sub, aCounters.mIcmp));
Expand Down Expand Up @@ -1119,7 +1107,7 @@ otbrError DBusMessageExtract(DBusMessageIter *aIter, Nat64AddressMapping &aMappi
DBusMessageIter sub;
otbrError error = OTBR_ERROR_NONE;

dbus_message_iter_recurse(aIter, &sub);
SuccessOrExit(error = DbusMessageIterRecurse(aIter, &sub, DBUS_TYPE_STRUCT));

SuccessOrExit(error = DBusMessageExtract(&sub, aMapping.mId));
SuccessOrExit(error = DBusMessageExtract(&sub, aMapping.mIp4));
Expand Down Expand Up @@ -1154,7 +1142,7 @@ otbrError DBusMessageExtract(DBusMessageIter *aIter, Nat64ErrorCounters &aCounte
DBusMessageIter sub;
otbrError error = OTBR_ERROR_NONE;

dbus_message_iter_recurse(aIter, &sub);
SuccessOrExit(error = DbusMessageIterRecurse(aIter, &sub, DBUS_TYPE_STRUCT));

SuccessOrExit(error = DBusMessageExtract(&sub, aCounters.mUnknown));
SuccessOrExit(error = DBusMessageExtract(&sub, aCounters.mIllegalPacket));
Expand Down Expand Up @@ -1191,7 +1179,7 @@ otbrError DBusMessageExtract(DBusMessageIter *aIter, InfraLinkInfo &aInfraLinkIn
DBusMessageIter sub;
otbrError error = OTBR_ERROR_NONE;

dbus_message_iter_recurse(aIter, &sub);
SuccessOrExit(error = DbusMessageIterRecurse(aIter, &sub, DBUS_TYPE_STRUCT));

SuccessOrExit(error = DBusMessageExtract(&sub, aInfraLinkInfo.mName));
SuccessOrExit(error = DBusMessageExtract(&sub, aInfraLinkInfo.mIsUp));
Expand Down

0 comments on commit 598cbcf

Please sign in to comment.