14 #include "../macros.h" 15 #include "../stringutils.h" 21 static const char nullArray[] = {
'\0',
'\0'};
23 const std::string MatchRule::nullArg{nullArray, nullArray + 1};
28 std::string destination, std::string path,
29 std::string interface, std::string name,
30 std::vector<std::string> argumentMatch,
bool eavesdrop)
31 : type_(type), service_(std::move(service)),
32 destination_(std::move(destination)), path_(std::move(path)),
33 interface_(std::move(interface)), name_(std::move(name)),
34 argumentMatch_(std::move(argumentMatch)), eavesdrop_(eavesdrop),
37 FCITX_INLINE_DEFINE_DEFAULT_DTOR_COPY_AND_MOVE_WITHOUT_SPEC(
42 std::string destination_;
44 std::string interface_;
46 std::vector<std::string> argumentMatch_;
47 bool eavesdrop_ =
false;
50 std::string buildRule()
const {
53 case MessageType::Signal:
54 result =
"type='signal',";
56 case MessageType::MethodCall:
57 result =
"type='method_call',";
59 case MessageType::Reply:
60 result =
"type='method_return',";
62 case MessageType::Error:
63 result =
"type='error',";
68 if (!service_.empty()) {
69 result += stringutils::concat(
"sender='", service_,
"',");
71 if (!destination_.empty()) {
72 result += stringutils::concat(
"destination='", destination_,
"',");
75 result += stringutils::concat(
"path='", path_,
"',");
77 if (!interface_.empty()) {
78 result += stringutils::concat(
"interface='", interface_,
"',");
81 result += stringutils::concat(
"member='", name_,
"',");
83 for (
size_t i = 0; i < argumentMatch_.size(); i++) {
84 if (argumentMatch_[i] == MatchRule::nullArg) {
88 stringutils::concat(
"arg", i,
"='", argumentMatch_[i],
"',");
91 result +=
"eavesdrop='true',";
98 bool check(
Message &message,
const std::string &alterName)
const {
100 if (!service_.empty() && service_ != message.
sender() &&
101 alterName != message.
sender()) {
104 if (!path_.empty() && path_ != message.
path()) {
107 if (!interface_.empty() && interface_ != message.
interface()) {
110 if (!name_.empty() && name_ != message.
member()) {
113 if (!argumentMatch_.empty()) {
115 auto args = splitDBusSignature(sig);
116 for (
size_t i = 0; i < argumentMatch_.size(); i++) {
117 if (argumentMatch_[i] == MatchRule::nullArg) {
118 if (i < args.size()) {
123 if (i >= args.size() || args[i] !=
"s") {
127 if (message >> arg) {
128 if (arg != argumentMatch_[i]) {
140 MatchRule::MatchRule(std::string service, std::string path,
141 std::string interface, std::string name,
142 std::vector<std::string> argumentMatch)
143 :
MatchRule(MessageType::Signal, std::move(service),
"", std::move(path),
144 std::move(interface), std::move(name), std::move(argumentMatch),
147 MatchRule::MatchRule(MessageType type, std::string service,
148 std::string destination, std::string path,
149 std::string interface, std::string name,
150 std::vector<std::string> argumentMatch,
bool eavesdrop)
151 : d_ptr(std::make_unique<MatchRulePrivate>(
152 type, std::move(service), std::move(destination), std::move(path),
153 std::move(interface), std::move(name), std::move(argumentMatch),
156 FCITX_DEFINE_DPTR_COPY_AND_DEFAULT_DTOR_AND_MOVE(
MatchRule);
158 const std::string &MatchRule::service()
const noexcept {
162 const std::string &MatchRule::destination()
const noexcept {
164 return d->destination_;
167 const std::string &MatchRule::path()
const noexcept {
172 const std::string &MatchRule::interface()
const noexcept {
174 return d->interface_;
177 const std::string &MatchRule::name()
const noexcept {
182 const std::vector<std::string> &MatchRule::argumentMatch()
const noexcept {
184 return d->argumentMatch_;
187 const std::string &MatchRule::rule()
const noexcept {
192 bool MatchRule::eavesdrop()
const noexcept {
194 return d->eavesdrop_;
197 bool MatchRule::check(
Message &message,
const std::string &alterName)
const {
199 auto result = d->check(message, alterName);
Basic DBus type of a DBus message.
std::string path() const
Return the path of the message.
A dbus matching rule to be used with add match.
void rewind()
Rewind the message to the beginning.
std::string sender() const
Return the sender of the message.
std::string member() const
Return the member of the message.
std::string interface() const
Return the interface of the message.
API for DBus matching rule.
void skip()
Skip the next data.
std::string signature() const
Return the signature of the message.