aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--.travis.yml15
-rw-r--r--CMakeLists.txt29
-rw-r--r--connection.cpp3
-rw-r--r--converters.h4
-rw-r--r--jobs/basejob.cpp1
-rw-r--r--jobs/gtad.yaml87
-rw-r--r--jobs/preamble.mustache3
-rw-r--r--jobs/{{base}}.cpp.mustache116
-rw-r--r--jobs/{{base}}.h.mustache67
9 files changed, 316 insertions, 9 deletions
diff --git a/.travis.yml b/.travis.yml
index 1b67119d..9c7d8a7d 100644
--- a/.travis.yml
+++ b/.travis.yml
@@ -23,9 +23,20 @@ before_install:
- eval "${ENV_EVAL}"
- if [ "$TRAVIS_OS_NAME" = "linux" ]; then . /opt/qt56/bin/qt56-env.sh; fi
-script:
+install:
+- git clone https://github.com/QMatrixClient/matrix-doc.git
+- git clone --recursive https://github.com/KitsuneRal/gtad.git
+- pushd gtad
+- cmake -DCMAKE_PREFIX_PATH=${CMAKE_PREFIX_PATH} .
+- cmake --build .
+- popd
+
+before_script:
- mkdir build && cd build
-- cmake ..
+- cmake -DMATRIX_DOC_PATH="matrix-doc" -DGTAD_PATH="gtad/gtad" -DCMAKE_PREFIX_PATH=${CMAKE_PREFIX_PATH} ..
+- cmake --build . --target update-api
+
+script:
- cmake --build . --target all
- cd ..
- qmake qmc-example.pro "QMAKE_CC = $CC" "QMAKE_CXX = $CXX" && make all
diff --git a/CMakeLists.txt b/CMakeLists.txt
index da5bac9b..c0ffc0b0 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -39,6 +39,11 @@ if (CMAKE_BUILD_TYPE)
endif(CMAKE_BUILD_TYPE)
message( STATUS "Using compiler: ${CMAKE_CXX_COMPILER_ID} ${CMAKE_CXX_COMPILER_VERSION}" )
message( STATUS "Using Qt ${Qt5_VERSION} at ${Qt5_Prefix}" )
+if (MATRIX_DOC_PATH AND GTAD_PATH)
+ message( STATUS "Generating API stubs enabled" )
+ message( STATUS " Using GTAD at ${GTAD_PATH}" )
+ message( STATUS " Using CS API files at ${MATRIX_DOC_PATH}/api/client-server" )
+endif ()
message( STATUS "=============================================================================" )
message( STATUS )
@@ -72,6 +77,30 @@ set(libqmatrixclient_SRCS
jobs/downloadfilejob.cpp
)
+set(API_DEF_PATH ${MATRIX_DOC_PATH}/api/client-server/)
+file(GLOB_RECURSE API_DEFS RELATIVE ${PROJECT_SOURCE_DIR}
+ ${API_DEF_PATH}/*.yaml
+ ${API_DEF_PATH}/definitions/*.yaml
+ ${MATRIX_DOC_PATH}/event-schemas/schema/*
+)
+if (MATRIX_DOC_PATH AND GTAD_PATH)
+ add_custom_target(update-api
+ ${GTAD_PATH} --config jobs/gtad.yaml --out jobs/generated
+ ${MATRIX_DOC_PATH}/api/client-server
+ cas_login_redirect.yaml- cas_login_ticket.yaml-
+ old_sync.yaml- room_initial_sync.yaml-
+ sync.yaml- room_state.yaml-
+ event_context.yaml- joining.yaml-
+ notifications.yaml- peeking_events.yaml-
+ pushrules.yaml- rooms.yaml- search.yaml-
+ WORKING_DIRECTORY ${PROJECT_SOURCE_DIR}
+ SOURCES jobs/gtad.yaml
+ jobs/{{base}}.h.mustache jobs/{{base}}.cpp.mustache
+ ${API_DEFS}
+ VERBATIM
+ )
+endif()
+
aux_source_directory(jobs/generated libqmatrixclient_job_SRCS)
set(example_SRCS examples/qmc-example.cpp)
diff --git a/connection.cpp b/connection.cpp
index 4b7d4abb..6a3cd957 100644
--- a/connection.cpp
+++ b/connection.cpp
@@ -191,8 +191,7 @@ void Connection::Private::connectWithToken(const QString& user,
data->setToken(accessToken.toLatin1());
data->setDeviceId(deviceId);
qCDebug(MAIN) << "Using server" << data->baseUrl() << "by user"
- << userId
- << "from device" << deviceId;
+ << userId << "from device" << deviceId;
emit q->connected();
}
diff --git a/converters.h b/converters.h
index 00d1d339..0d7f734e 100644
--- a/converters.h
+++ b/converters.h
@@ -46,11 +46,7 @@ namespace QMatrixClient
inline QJsonValue toJson(const QByteArray& bytes)
{
-#if QT_VERSION < QT_VERSION_CHECK(5, 3, 0)
- return QJsonValue(QLatin1String(bytes.constData()));
-#else
return QJsonValue(bytes.constData());
-#endif
}
template <typename T>
diff --git a/jobs/basejob.cpp b/jobs/basejob.cpp
index c35a7711..0e3e59d0 100644
--- a/jobs/basejob.cpp
+++ b/jobs/basejob.cpp
@@ -25,7 +25,6 @@
#include <QtNetwork/QNetworkReply>
#include <QtCore/QTimer>
#include <QtCore/QRegularExpression>
-//#include <QtCore/QStringBuilder>
#include <array>
diff --git a/jobs/gtad.yaml b/jobs/gtad.yaml
new file mode 100644
index 00000000..78c879e4
--- /dev/null
+++ b/jobs/gtad.yaml
@@ -0,0 +1,87 @@
+preprocess:
+ "%CLIENT_RELEASE_LABEL%": r0
+ "%CLIENT_MAJOR_VERSION%": r0
+ # FIXME: the below only fixes C++ compilation but not actual work - the code
+ # will try to reach out for wrong values in JSON payloads
+ #"signed:": "signedData:"
+ #"unsigned:": "unsignedData:"
+ #"default:": "isDefault:"
+
+# Structure:
+# swaggerType: <targetTypeSpec>
+# OR
+# swaggerType:
+# - swaggerFormat: <targetTypeSpec>
+# - /swaggerFormatRegEx/: <targetTypeSpec>
+# - //: <targetTypeSpec> # default, if the format doesn't mach anything above
+# WHERE
+# targetTypeSpec = targetType OR
+# { type: targetType, imports: <filename OR [ filenames... ]>, <other attributes...> }
+types:
+ integer:
+ - int64: qint64
+ - int32: qint32
+ - //: int
+ number:
+ - float: float
+ - //: double
+ boolean: { type: bool, initializer: false }
+ string:
+ - byte: &ByteStream
+ type: QIODevice*
+ #initializer: '"{{defaultValue}}"'
+ #string?: true
+ imports: <QtCore/QIODevice>
+ - binary: *ByteStream
+ - date:
+ type: QDate
+ initializer: QDate::fromString("{{defaultValue}}")
+ avoidCopy?: true
+ imports: <QtCore/QDate>
+ - dateTime:
+ type: QDateTime
+ initializer: QDateTime::fromString("{{defaultValue}}")
+ avoidCopy?: true
+ imports: <QtCore/QDateTime>
+ - //:
+ type: QString
+ initializer: QStringLiteral("{{defaultValue}}")
+ string?: true
+ avoidCopy?: true
+ file: *ByteStream
+ object:
+ type: QJsonObject
+ avoidCopy?: true
+ imports: <QtCore/QJsonObject>
+ array:
+ - /.+/:
+ type: "QVector<{{1}}>"
+ avoidCopy?: true
+ imports: <QtCore/QVector>
+ - //: { type: QJsonArray, "avoidCopy?": true, imports: <QtCore/QJsonArray> }
+ schema:
+ avoidCopy?: true
+
+#operations:
+
+env:
+ _scopeRenderer: "{{scopeCamelCase}}Job::"
+ _literalQuote: '"'
+ maybeCrefType: "{{#avoidCopy?}}const {{/avoidCopy?}}{{dataType.name}}{{#avoidCopy?}}&{{/avoidCopy?}}"
+ qualifiedMaybeCrefType: "{{#avoidCopy?}}const {{/avoidCopy?}}{{dataType.qualifiedName}}{{#avoidCopy?}}&{{/avoidCopy?}}"
+ initializeDefaultValue: "{{#defaultValue}}{{>initializer}}{{/defaultValue}}{{^defaultValue}}{}{{/defaultValue}}"
+ joinedParamDecl: '{{>maybeCrefType}} {{paramName}}{{^required?}} = {{>initializeDefaultValue}}{{/required?}}{{#@join}}, {{/@join}}'
+ joinedParamDef: '{{>maybeCrefType}} {{paramName}}{{#@join}}, {{/@join}}'
+ passQueryParams: '{{#queryParams}}{{paramName}}{{#@join}}, {{/@join}}{{/queryParams}}'
+ paramToString: '{{#string?}}{{nameCamelCase}}{{/string?}}{{^string?}}QString("%1").arg({{nameCamelCase}}){{/string?}}'
+# preamble: preamble.mustache
+ copyrightName: Kitsune Ral
+ copyrightEmail: <kitsune-ral@users.sf.net>
+# imports: { set: }
+
+templates:
+- "{{base}}.h.mustache"
+- "{{base}}.cpp.mustache"
+
+#outFilesList: apifiles.txt
+
diff --git a/jobs/preamble.mustache b/jobs/preamble.mustache
new file mode 100644
index 00000000..3ba87d61
--- /dev/null
+++ b/jobs/preamble.mustache
@@ -0,0 +1,3 @@
+/******************************************************************************
+ * THIS FILE IS GENERATED - ANY EDITS WILL BE OVERWRITTEN
+ */
diff --git a/jobs/{{base}}.cpp.mustache b/jobs/{{base}}.cpp.mustache
new file mode 100644
index 00000000..b8532c51
--- /dev/null
+++ b/jobs/{{base}}.cpp.mustache
@@ -0,0 +1,116 @@
+{{#@filePartial}}preamble{{/@filePartial}}
+#include "{{filenameBase}}.h"
+{{^allModels}}
+#include "converters.h"
+{{/allModels}}{{#operations}}
+{{#producesNotJson?}}#include <QtNetwork/QNetworkReply>
+{{/producesNotJson?}}#include <QtCore/QStringBuilder>
+{{/operations}}
+using namespace QMatrixClient;
+{{#models.model}}{{^trivial?}}
+{{qualifiedName}}::operator QJsonValue() const
+{
+ QJsonObject o;
+ {{#vars}}o.insert("{{baseName}}", toJson({{nameCamelCase}}));
+ {{/vars}}
+ return o;
+}
+
+{{qualifiedName}} FromJson<{{qualifiedName}}>::operator()(QJsonValue jv)
+{
+ QJsonObject o = jv.toObject();
+ {{qualifiedName}} result;
+ {{#vars}}result.{{nameCamelCase}} =
+ fromJson<{{dataType.name}}>(o.value("{{baseName}}"));
+ {{/vars}}
+ return result;
+}
+{{/trivial?}}{{/models.model}}{{#operations}}
+static const auto basePath = QStringLiteral("{{basePathWithoutHost}}");
+{{# operation}}{{#models.model}}{{^trivial?}}
+{{qualifiedName}}::operator QJsonObject() const
+{
+ QJsonObject o;
+ {{#vars}}o.insert("{{baseName}}", toJson({{nameCamelCase}}));
+ {{/vars}}
+ return o;
+}
+namespace QMatrixClient
+{
+ template <> struct FromJson<{{qualifiedName}}>
+ {
+ {{qualifiedName}} operator()(QJsonValue jv)
+ {
+ QJsonObject o = jv.toObject();
+ {{qualifiedName}} result;
+ {{#vars}}result.{{nameCamelCase}} =
+ fromJson<{{dataType.qualifiedName}}>(o.value("{{baseName}}"));
+ {{/vars}}
+ return result;
+ }
+ };
+} // namespace QMatrixClient
+{{/ trivial?}}{{/models.model}}{{#responses}}{{#normalResponse?}}{{#allProperties?}}
+class {{camelCaseOperationId}}Job::Private
+{
+ public:{{#allProperties}}
+ {{dataType.name}} {{paramName}};{{/allProperties}}
+};
+{{/ allProperties?}}{{/normalResponse?}}{{/responses}}{{#queryParams?}}
+BaseJob::Query queryTo{{camelCaseOperationId}}({{#queryParams}}{{>joinedParamDef}}{{/queryParams}})
+{
+ BaseJob::Query _q;{{#queryParams}}
+{{^required?}}{{#string?}} if (!{{nameCamelCase}}.isEmpty())
+ {{/string?}}{{/required?}} _q.addQueryItem("{{baseName}}", {{>paramToString}});{{/queryParams}}
+ return _q;
+}
+{{/queryParams?}}{{^bodyParams}}
+QUrl {{camelCaseOperationId}}Job::makeRequestUrl(QUrl baseUrl{{#allParams?}}, {{#allParams}}{{>joinedParamDef}}{{/allParams}}{{/allParams?}})
+{
+ return BaseJob::makeRequestUrl(baseUrl,
+ basePath{{#pathParts}} % {{_}}{{/pathParts}}{{#queryParams?}},
+ queryTo{{camelCaseOperationId}}({{>passQueryParams}}){{/queryParams?}});
+}
+{{/ bodyParams}}
+{{camelCaseOperationId}}Job::{{camelCaseOperationId}}Job({{#allParams}}{{>joinedParamDef}}{{/allParams}})
+ : BaseJob(HttpVerb::{{#@cap}}{{#@tolower}}{{httpMethod}}{{/@tolower}}{{/@cap}}, "{{camelCaseOperationId}}Job",
+ basePath{{#pathParts}} % {{_}}{{/pathParts}}{{#queryParams?}},
+ queryTo{{camelCaseOperationId}}({{>passQueryParams}}){{/queryParams?}}{{#skipAuth}}{{#queryParams?}},
+ {}{{/queryParams?}}, false{{/skipAuth}}){{#responses}}{{#normalResponse?}}{{#allProperties?}}
+ , d(new Private){{/allProperties?}}{{/normalResponse?}}{{/responses}}
+{
+{{#headerParams?}}{{#headerParams}} setRequestHeader("{{baseName}}", {{paramName}}.toLatin1());
+{{/headerParams}}
+{{/headerParams?}}{{!
+}}{{#bodyParams?}}{{!
+}}{{#inlineBody}} setRequestData(Data({{nameCamelCase}}));{{/inlineBody}}{{!
+}}{{^inlineBody}} QJsonObject _data;{{#bodyParams}}
+{{^required?}}{{#string?}} if (!{{paramName}}.isEmpty())
+ {{/string?}}{{/required?}} _data.insert("{{baseName}}", toJson({{paramName}}));{{/bodyParams}}
+ setRequestData(_data);{{/inlineBody}}
+{{/bodyParams?}}{{#producesNotJson?}} setExpectedContentTypes({ {{#produces}}"{{_}}"{{#@join}}, {{/@join}}{{/produces}} });
+{{/producesNotJson?}}}{{!<- mind the actual brace}}
+{{# responses}}{{#normalResponse?}}{{#allProperties?}}
+{{camelCaseOperationId}}Job::~{{camelCaseOperationId}}Job() = default;
+{{# allProperties}}
+{{>qualifiedMaybeCrefType}} {{camelCaseOperationId}}Job::{{paramName}}() const
+{
+ return d->{{paramName}};
+}
+{{/ allProperties}}{{#producesNotJson?}}
+BaseJob::Status {{camelCaseOperationId}}Job::parseReply(QNetworkReply* reply)
+{
+ {{#headers}}d->{{paramName}} = reply->rawHeader("{{baseName}}"); {{! We don't check for required headers yet }}
+ {{/headers}}{{#properties}}d->{{paramName}} = reply;{{/properties}}
+ return Success;
+}{{/ producesNotJson?}}{{^producesNotJson?}}
+BaseJob::Status {{camelCaseOperationId}}Job::parseJson(const QJsonDocument& data)
+{
+ auto json = data.object();
+ {{# properties}}{{#required?}}if (!json.contains("{{baseName}}"))
+ return { JsonParseError,
+ "The key '{{baseName}}' not found in the response" };
+ {{/required?}}d->{{paramName}} = fromJson<{{dataType.name}}>(json.value("{{baseName}}"));
+ {{/ properties}}return Success;
+}{{/ producesNotJson?}}
+{{/allProperties?}}{{/normalResponse?}}{{/responses}}{{/operation}}{{/operations}}
diff --git a/jobs/{{base}}.h.mustache b/jobs/{{base}}.h.mustache
new file mode 100644
index 00000000..63aa53e7
--- /dev/null
+++ b/jobs/{{base}}.h.mustache
@@ -0,0 +1,67 @@
+{{#@filePartial}}preamble{{/@filePartial}}
+#pragma once
+
+{{#operations}}#include "../basejob.h"
+{{/operations}}
+{{#imports}}#include {{_}}
+{{/imports}}
+{{#allModels}}#include "converters.h"
+{{/allModels}}
+namespace QMatrixClient
+{
+{{#models}} // Data structures
+{{# model}}{{#trivial?}}
+ using {{name}} = {{parent.name}};
+{{/ trivial?}}{{^trivial?}}
+ struct {{name}}{{#parents?}} : {{#parents}}{{name}}{{#@join}}, {{/@join}}{{/parents}}{{/parents?}}
+ {
+ {{#vars}}{{dataType.name}} {{nameCamelCase}};
+ {{/vars}}
+ operator QJsonObject() const;
+ };
+
+ template <> struct FromJson<{{name}}>
+ {
+ {{name}} operator()(QJsonValue jv);
+ };
+{{/ trivial?}}{{/model}}
+{{/models}}{{#operations}} // Operations
+{{# operation}}
+ class {{camelCaseOperationId}}Job : public BaseJob
+ {
+ public:{{# models}}
+ // Inner data structures
+{{# model}}{{#trivial?}}
+ using {{name}} = {{parent.name}};
+{{/ trivial?}}{{^trivial?}}
+ struct {{name}}{{#parents?}} : {{#parents}}{{name}}{{#@join}}, {{/@join}}{{/parents}}{{/parents?}}
+ {
+ {{#vars}}{{dataType.name}} {{nameCamelCase}};
+ {{/vars}}
+ operator QJsonObject() const;
+ };
+{{/ trivial?}}{{/model}}
+ // End of inner data structures
+{{/models}}{{^bodyParams}}
+ /** Construct a URL out of baseUrl and usual parameters passed to
+ * {{camelCaseOperationId}}Job. This function can be used when
+ * a URL for {{camelCaseOperationId}}Job is necessary but the job
+ * itself isn't.
+ */
+ static QUrl makeRequestUrl(QUrl baseUrl{{#allParams?}}, {{#allParams}}{{>joinedParamDecl}}{{/allParams}}{{/allParams?}});
+{{/bodyParams}}
+ explicit {{camelCaseOperationId}}Job({{#allParams}}{{>joinedParamDecl}}{{/allParams}});{{!skip EOL
+}}{{# responses}}{{#normalResponse?}}{{#allProperties?}}
+ ~{{camelCaseOperationId}}Job() override;
+{{#allProperties}}
+ {{>maybeCrefType}} {{paramName}}() const;{{/allProperties}}
+
+ protected:
+ Status {{#producesNotJson?}}parseReply(QNetworkReply* reply){{/producesNotJson?}}{{^producesNotJson?}}parseJson(const QJsonDocument& data){{/producesNotJson?}} override;
+
+ private:
+ class Private;
+ QScopedPointer<Private> d;{{/allProperties?}}{{/normalResponse?}}{{/responses}}
+ };
+{{/operation}}{{/operations}}{{!skip EOL
+}}} // namespace QMatrixClient