aboutsummaryrefslogtreecommitdiff
path: root/lib/csapi
diff options
context:
space:
mode:
authorKitsune Ral <Kitsune-Ral@users.sf.net>2018-06-08 23:24:51 +0900
committerKitsune Ral <Kitsune-Ral@users.sf.net>2018-06-08 23:24:51 +0900
commit6767cb8eccea7b74531f59f165a28afa0bec61f4 (patch)
treeea3ffe2fc07d3a9b7b48ee2ab37b0fe594f1af85 /lib/csapi
parent4b1b308f28bdaef598a5dfc249d7af6a0346b367 (diff)
downloadlibquotient-6767cb8eccea7b74531f59f165a28afa0bec61f4.tar.gz
libquotient-6767cb8eccea7b74531f59f165a28afa0bec61f4.zip
csapi: Fix boolean query parameters incorrectly passed
Diffstat (limited to 'lib/csapi')
-rw-r--r--lib/csapi/content-repo.cpp23
-rw-r--r--lib/csapi/event_context.cpp3
-rw-r--r--lib/csapi/gtad.yaml1
-rw-r--r--lib/csapi/keys.cpp4
-rw-r--r--lib/csapi/list_public_rooms.cpp12
-rw-r--r--lib/csapi/message_pagination.cpp13
-rw-r--r--lib/csapi/notifications.cpp9
-rw-r--r--lib/csapi/peeking_events.cpp9
-rw-r--r--lib/csapi/pushrules.cpp6
-rw-r--r--lib/csapi/registration.cpp5
-rw-r--r--lib/csapi/search.cpp3
-rw-r--r--lib/csapi/{{base}}.cpp.mustache5
12 files changed, 33 insertions, 60 deletions
diff --git a/lib/csapi/content-repo.cpp b/lib/csapi/content-repo.cpp
index a127dfad..81329345 100644
--- a/lib/csapi/content-repo.cpp
+++ b/lib/csapi/content-repo.cpp
@@ -22,8 +22,7 @@ class UploadContentJob::Private
BaseJob::Query queryToUploadContent(const QString& filename)
{
BaseJob::Query _q;
- if (!filename.isEmpty())
- _q.addQueryItem("filename", filename);
+ addToQuery<IfNotEmpty>(_q, "filename", filename);
return _q;
}
@@ -66,7 +65,7 @@ class GetContentJob::Private
BaseJob::Query queryToGetContent(bool allowRemote)
{
BaseJob::Query _q;
- _q.addQueryItem("allow_remote", QString("%1").arg(allowRemote));
+ addToQuery<IfNotEmpty>(_q, "allow_remote", allowRemote);
return _q;
}
@@ -123,7 +122,7 @@ class GetContentOverrideNameJob::Private
BaseJob::Query queryToGetContentOverrideName(bool allowRemote)
{
BaseJob::Query _q;
- _q.addQueryItem("allow_remote", QString("%1").arg(allowRemote));
+ addToQuery<IfNotEmpty>(_q, "allow_remote", allowRemote);
return _q;
}
@@ -179,13 +178,10 @@ class GetContentThumbnailJob::Private
BaseJob::Query queryToGetContentThumbnail(Omittable<int> width, Omittable<int> height, const QString& method, bool allowRemote)
{
BaseJob::Query _q;
- if (width)
- _q.addQueryItem("width", QString("%1").arg(width.value()));
- if (height)
- _q.addQueryItem("height", QString("%1").arg(height.value()));
- if (!method.isEmpty())
- _q.addQueryItem("method", method);
- _q.addQueryItem("allow_remote", QString("%1").arg(allowRemote));
+ addToQuery<IfNotEmpty>(_q, "width", width);
+ addToQuery<IfNotEmpty>(_q, "height", height);
+ addToQuery<IfNotEmpty>(_q, "method", method);
+ addToQuery<IfNotEmpty>(_q, "allow_remote", allowRemote);
return _q;
}
@@ -235,9 +231,8 @@ class GetUrlPreviewJob::Private
BaseJob::Query queryToGetUrlPreview(const QString& url, Omittable<qint64> ts)
{
BaseJob::Query _q;
- _q.addQueryItem("url", url);
- if (ts)
- _q.addQueryItem("ts", QString("%1").arg(ts.value()));
+ addToQuery<>(_q, "url", url);
+ addToQuery<IfNotEmpty>(_q, "ts", ts);
return _q;
}
diff --git a/lib/csapi/event_context.cpp b/lib/csapi/event_context.cpp
index 97494062..37de58ab 100644
--- a/lib/csapi/event_context.cpp
+++ b/lib/csapi/event_context.cpp
@@ -26,8 +26,7 @@ class GetEventContextJob::Private
BaseJob::Query queryToGetEventContext(Omittable<int> limit)
{
BaseJob::Query _q;
- if (limit)
- _q.addQueryItem("limit", QString("%1").arg(limit.value()));
+ addToQuery<IfNotEmpty>(_q, "limit", limit);
return _q;
}
diff --git a/lib/csapi/gtad.yaml b/lib/csapi/gtad.yaml
index 76418f3c..55932378 100644
--- a/lib/csapi/gtad.yaml
+++ b/lib/csapi/gtad.yaml
@@ -124,7 +124,6 @@ mustache:
joinedParamDecl: '{{>maybeCrefType}} {{paramName}}{{^required?}} = {{>initializeDefaultValue}}{{/required?}}{{#@join}}, {{/@join}}'
joinedParamDef: '{{>maybeCrefType}} {{paramName}}{{#@join}}, {{/@join}}'
passQueryParams: '{{#queryParams}}{{paramName}}{{#@join}}, {{/@join}}{{/queryParams}}'
- paramToString: '{{#isString}}{{nameCamelCase}}{{/isString}}{{^isString}}QString("%1").arg({{nameCamelCase}}{{^required?}}{{#useOmittable}}.value(){{/useOmittable}}{{/required?}}){{/isString}}'
# preamble: preamble.mustache
copyrightName: Kitsune Ral
copyrightEmail: <kitsune-ral@users.sf.net>
diff --git a/lib/csapi/keys.cpp b/lib/csapi/keys.cpp
index 2d6885dd..88d6690b 100644
--- a/lib/csapi/keys.cpp
+++ b/lib/csapi/keys.cpp
@@ -164,8 +164,8 @@ class GetKeysChangesJob::Private
BaseJob::Query queryToGetKeysChanges(const QString& from, const QString& to)
{
BaseJob::Query _q;
- _q.addQueryItem("from", from);
- _q.addQueryItem("to", to);
+ addToQuery<>(_q, "from", from);
+ addToQuery<>(_q, "to", to);
return _q;
}
diff --git a/lib/csapi/list_public_rooms.cpp b/lib/csapi/list_public_rooms.cpp
index f104786b..5952fd6e 100644
--- a/lib/csapi/list_public_rooms.cpp
+++ b/lib/csapi/list_public_rooms.cpp
@@ -100,12 +100,9 @@ class GetPublicRoomsJob::Private
BaseJob::Query queryToGetPublicRooms(Omittable<int> limit, const QString& since, const QString& server)
{
BaseJob::Query _q;
- if (limit)
- _q.addQueryItem("limit", QString("%1").arg(limit.value()));
- if (!since.isEmpty())
- _q.addQueryItem("since", since);
- if (!server.isEmpty())
- _q.addQueryItem("server", server);
+ addToQuery<IfNotEmpty>(_q, "limit", limit);
+ addToQuery<IfNotEmpty>(_q, "since", since);
+ addToQuery<IfNotEmpty>(_q, "server", server);
return _q;
}
@@ -213,8 +210,7 @@ class QueryPublicRoomsJob::Private
BaseJob::Query queryToQueryPublicRooms(const QString& server)
{
BaseJob::Query _q;
- if (!server.isEmpty())
- _q.addQueryItem("server", server);
+ addToQuery<IfNotEmpty>(_q, "server", server);
return _q;
}
diff --git a/lib/csapi/message_pagination.cpp b/lib/csapi/message_pagination.cpp
index d23dd911..1a7d6ee9 100644
--- a/lib/csapi/message_pagination.cpp
+++ b/lib/csapi/message_pagination.cpp
@@ -23,14 +23,11 @@ class GetRoomEventsJob::Private
BaseJob::Query queryToGetRoomEvents(const QString& from, const QString& to, const QString& dir, Omittable<int> limit, const QString& filter)
{
BaseJob::Query _q;
- _q.addQueryItem("from", from);
- if (!to.isEmpty())
- _q.addQueryItem("to", to);
- _q.addQueryItem("dir", dir);
- if (limit)
- _q.addQueryItem("limit", QString("%1").arg(limit.value()));
- if (!filter.isEmpty())
- _q.addQueryItem("filter", filter);
+ addToQuery<>(_q, "from", from);
+ addToQuery<IfNotEmpty>(_q, "to", to);
+ addToQuery<>(_q, "dir", dir);
+ addToQuery<IfNotEmpty>(_q, "limit", limit);
+ addToQuery<IfNotEmpty>(_q, "filter", filter);
return _q;
}
diff --git a/lib/csapi/notifications.cpp b/lib/csapi/notifications.cpp
index 9329857d..de5b41f2 100644
--- a/lib/csapi/notifications.cpp
+++ b/lib/csapi/notifications.cpp
@@ -50,12 +50,9 @@ class GetNotificationsJob::Private
BaseJob::Query queryToGetNotifications(const QString& from, Omittable<int> limit, const QString& only)
{
BaseJob::Query _q;
- if (!from.isEmpty())
- _q.addQueryItem("from", from);
- if (limit)
- _q.addQueryItem("limit", QString("%1").arg(limit.value()));
- if (!only.isEmpty())
- _q.addQueryItem("only", only);
+ addToQuery<IfNotEmpty>(_q, "from", from);
+ addToQuery<IfNotEmpty>(_q, "limit", limit);
+ addToQuery<IfNotEmpty>(_q, "only", only);
return _q;
}
diff --git a/lib/csapi/peeking_events.cpp b/lib/csapi/peeking_events.cpp
index 884abe00..53f2d280 100644
--- a/lib/csapi/peeking_events.cpp
+++ b/lib/csapi/peeking_events.cpp
@@ -23,12 +23,9 @@ class PeekEventsJob::Private
BaseJob::Query queryToPeekEvents(const QString& from, Omittable<int> timeout, const QString& roomId)
{
BaseJob::Query _q;
- if (!from.isEmpty())
- _q.addQueryItem("from", from);
- if (timeout)
- _q.addQueryItem("timeout", QString("%1").arg(timeout.value()));
- if (!roomId.isEmpty())
- _q.addQueryItem("room_id", roomId);
+ addToQuery<IfNotEmpty>(_q, "from", from);
+ addToQuery<IfNotEmpty>(_q, "timeout", timeout);
+ addToQuery<IfNotEmpty>(_q, "room_id", roomId);
return _q;
}
diff --git a/lib/csapi/pushrules.cpp b/lib/csapi/pushrules.cpp
index eca46247..807f1d0f 100644
--- a/lib/csapi/pushrules.cpp
+++ b/lib/csapi/pushrules.cpp
@@ -99,10 +99,8 @@ DeletePushRuleJob::DeletePushRuleJob(const QString& scope, const QString& kind,
BaseJob::Query queryToSetPushRule(const QString& before, const QString& after)
{
BaseJob::Query _q;
- if (!before.isEmpty())
- _q.addQueryItem("before", before);
- if (!after.isEmpty())
- _q.addQueryItem("after", after);
+ addToQuery<IfNotEmpty>(_q, "before", before);
+ addToQuery<IfNotEmpty>(_q, "after", after);
return _q;
}
diff --git a/lib/csapi/registration.cpp b/lib/csapi/registration.cpp
index 1e239d2a..85a3e256 100644
--- a/lib/csapi/registration.cpp
+++ b/lib/csapi/registration.cpp
@@ -24,8 +24,7 @@ class RegisterJob::Private
BaseJob::Query queryToRegister(const QString& kind)
{
BaseJob::Query _q;
- if (!kind.isEmpty())
- _q.addQueryItem("kind", kind);
+ addToQuery<IfNotEmpty>(_q, "kind", kind);
return _q;
}
@@ -130,7 +129,7 @@ class CheckUsernameAvailabilityJob::Private
BaseJob::Query queryToCheckUsernameAvailability(const QString& username)
{
BaseJob::Query _q;
- _q.addQueryItem("username", username);
+ addToQuery<>(_q, "username", username);
return _q;
}
diff --git a/lib/csapi/search.cpp b/lib/csapi/search.cpp
index d43f704b..d172dfbe 100644
--- a/lib/csapi/search.cpp
+++ b/lib/csapi/search.cpp
@@ -173,8 +173,7 @@ class SearchJob::Private
BaseJob::Query queryToSearch(const QString& nextBatch)
{
BaseJob::Query _q;
- if (!nextBatch.isEmpty())
- _q.addQueryItem("next_batch", nextBatch);
+ addToQuery<IfNotEmpty>(_q, "next_batch", nextBatch);
return _q;
}
diff --git a/lib/csapi/{{base}}.cpp.mustache b/lib/csapi/{{base}}.cpp.mustache
index 8a7dd3b0..0955984d 100644
--- a/lib/csapi/{{base}}.cpp.mustache
+++ b/lib/csapi/{{base}}.cpp.mustache
@@ -61,10 +61,7 @@ class {{camelCaseOperationId}}Job::Private
BaseJob::Query queryTo{{camelCaseOperationId}}({{#queryParams}}{{>joinedParamDef}}{{/queryParams}})
{
BaseJob::Query _q;{{#queryParams}}
-{{^required?}}{{#isString}} if (!{{nameCamelCase}}.isEmpty())
- {{/isString}}{{!
-}}{{#useOmittable}} if ({{nameCamelCase}})
- {{/useOmittable}}{{/required?}} _q.addQueryItem("{{baseName}}", {{>paramToString}});{{/queryParams}}
+ addToQuery<{{^required?}}IfNotEmpty{{/required?}}>(_q, "{{baseName}}", {{paramName}});{{/queryParams}}
return _q;
}
{{/queryParams?}}{{^bodyParams}}