Skip to content

Commit ccb2170

Browse files
committed
protocol: add attribute GENERATOR
1 parent cf17de0 commit ccb2170

9 files changed

+39
-3
lines changed

debian/changelog

+1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
cm4all-pond (0.32) unstable; urgency=low
22

33
* client: add JSON Lines output format
4+
* protocol: add attribute GENERATOR
45

56
--
67

doc/index.rst

+2
Original file line numberDiff line numberDiff line change
@@ -264,6 +264,8 @@ The following filters are available:
264264
all.
265265
- :samp:`uri-prefix=URI` shows only records whos HTTP request URI
266266
starts with the specified string.
267+
- :samp:`generator=NAME` shows only records with the specified
268+
"generator" value.
267269
- :samp:`since=ISO8601` shows only records since the given time stamp.
268270
See :ref:`timestamps` for details.
269271
- :samp:`until=ISO8601` shows only records until the given time stamp.

src/Connection.cxx

+14
Original file line numberDiff line numberDiff line change
@@ -470,6 +470,20 @@ try {
470470
throw SimplePondError{"Duplicate FILTER_HOST"};
471471

472472
return BufferedResult::AGAIN;
473+
474+
case PondRequestCommand::FILTER_GENERATOR:
475+
if (!current.MatchId(id) ||
476+
current.command != PondRequestCommand::QUERY)
477+
throw SimplePondError{"Misplaced FILTER_GENERATOR"};
478+
479+
if (HasNullByte(ToStringView(payload)))
480+
throw SimplePondError{"Malformed FILTER_GENERATOR"};
481+
482+
if (auto e = current.filter.generators.emplace(ToStringView(payload));
483+
!e.second)
484+
throw SimplePondError{"Duplicate FILTER_GENERATOR"};
485+
486+
return BufferedResult::AGAIN;
473487
}
474488

475489
throw SimplePondError{"Command not implemented"};

src/Filter.cxx

+4-1
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,9 @@ MatchHttpUriStartsWith(const char *http_uri,
4141
inline bool
4242
Filter::MatchMore(std::span<const std::byte> raw) const noexcept
4343
{
44-
if (!http_status && hosts.empty() && http_uri_starts_with.empty())
44+
if (!http_status && hosts.empty() &&
45+
generators.empty() &&
46+
http_uri_starts_with.empty())
4547
return true;
4648

4749
try {
@@ -51,6 +53,7 @@ Filter::MatchMore(std::span<const std::byte> raw) const noexcept
5153
return false;
5254

5355
return MatchFilter(d.host, hosts) &&
56+
MatchFilter(d.generator, generators) &&
5457
MatchHttpUriStartsWith(d.http_uri, http_uri_starts_with);
5558
} catch (...) {
5659
return false;

src/Filter.hxx

+1-1
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ struct SmallDatagram;
1717
namespace Net { namespace Log { struct Datagram; }}
1818

1919
struct Filter {
20-
std::set<std::string, std::less<>> sites, hosts;
20+
std::set<std::string, std::less<>> sites, hosts, generators;
2121

2222
std::string http_uri_starts_with;
2323

src/Protocol.hxx

+6
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,12 @@ enum class PondRequestCommand : uint16_t {
115115
* exact string to compare with.
116116
*/
117117
FILTER_HOST = 17,
118+
119+
/**
120+
* Specify a filter on the "generator" attribute. Payload is
121+
* the exact string to compare with.
122+
*/
123+
FILTER_GENERATOR = 18,
118124
};
119125

120126
enum class PondResponseCommand : uint16_t {

src/client/FormatJson.cxx

+3
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,9 @@ FormatJson(char *buffer, char *end,
3838
if (d.analytics_id != nullptr)
3939
o.AddMember("analytics_id", d.analytics_id);
4040

41+
if (d.generator != nullptr)
42+
o.AddMember("generator", d.generator);
43+
4144
if (d.forwarded_to != nullptr)
4245
o.AddMember("forwarded_to", d.forwarded_to);
4346

src/client/Main.cxx

+7
Original file line numberDiff line numberDiff line change
@@ -138,6 +138,9 @@ ParseFilterItem(Filter &filter, PondGroupSitePayload &group_site,
138138
} else if (auto host = IsFilter(p, "host")) {
139139
if (!filter.hosts.emplace(host).second)
140140
throw "Duplicate host name";
141+
} else if (auto generator = IsFilter(p, "generator")) {
142+
if (!filter.generators.emplace(generator).second)
143+
throw "Duplicate generator name";
141144
} else if (auto since = IsFilter(p, "since")) {
142145
auto t = ParseTimePoint(since);
143146
filter.since = Net::Log::FromSystem(t.first);
@@ -270,6 +273,9 @@ Query(const PondServerSpecification &server, ConstBuffer<const char *> args)
270273
for (const auto &i : filter.hosts)
271274
client.Send(id, PondRequestCommand::FILTER_HOST, i);
272275

276+
for (const auto &i : filter.generators)
277+
client.Send(id, PondRequestCommand::FILTER_GENERATOR, i);
278+
273279
const bool single_site = filter.sites.begin() != filter.sites.end() &&
274280
std::next(filter.sites.begin()) == filter.sites.end();
275281

@@ -575,6 +581,7 @@ try {
575581
" [site=VALUE] [group_site=[MAX][@SKIP]]\n"
576582
" [host=VALUE]\n"
577583
" [uri-prefix=VALUE]\n"
584+
" [generator=VALUE]\n"
578585
" [since=ISO8601] [until=ISO8601] [date=YYYY-MM-DD] [today]\n"
579586
" [window=COUNT[@SKIP]]\n"
580587
" stats\n"

0 commit comments

Comments
 (0)