abouttreesummaryrefslogcommitdiff
path: root/src/matrix.c
diff options
context:
space:
mode:
authorPatrick2023-05-20 00:02:34 +0200
committerPatrick2023-05-20 00:02:34 +0200
commit71b13552379398dafcbc8fa8347d119a8984f448 (patch)
tree5c43d7ec7e0e87c6fb4852c77c3668880bad7d2f /src/matrix.c
parent7cba6b3cdbd3b82ec9092ce9bda8ec20739096cb (diff)
downloadmatrix_esp_thesis-71b13552379398dafcbc8fa8347d119a8984f448.tar.gz
matrix_esp_thesis-71b13552379398dafcbc8fa8347d119a8984f448.zip
get Login example working with CURL
Diffstat (limited to 'src/matrix.c')
-rw-r--r--src/matrix.c72
1 files changed, 63 insertions, 9 deletions
diff --git a/src/matrix.c b/src/matrix.c
index 082806a..90132af 100644
--- a/src/matrix.c
+++ b/src/matrix.c
@@ -1,27 +1,81 @@
#include "matrix.h"
+#include <mjson.h>
+
+
+#define LOGIN_REQUEST_SIZE 1024
+#define LOGIN_RESPONSE_SIZE 1024
+#define LOGIN_URL "/_matrix/client/v3/login"
+
bool
MatrixClientInit(
MatrixClient * client,
- FixedBuffer server
+ char * server, int serverLen
) {
+ strcpy_s(
+ client->server,
+ SERVER_SIZE,
+ server
+ );
+ client->serverLen = serverLen;
+ return true;
}
+// https://spec.matrix.org/v1.6/client-server-api/#post_matrixclientv3login
bool
MatrixClientLoginPassword(
MatrixClient * client,
- FixedBuffer username,
- FixedBuffer password
+ char * username, int usernameLen,
+ char * password, int passwordLen,
+ char * displayName, int displayNameLen
) {
+ static char requestBuffer[LOGIN_REQUEST_SIZE];
-}
+ int requestLen =
+ mjson_snprintf(requestBuffer, LOGIN_REQUEST_SIZE,
+ "{"
+ "\"type\": \"m.login.password\","
+ "\"identifier\": {"
+ "\"type\": \"m.id.user\","
+ "\"user\": \"%.*s\""
+ "},"
+ "\"password\": \"%.*s\","
+ "\"initial_device_display_name\": \"%.*s\""
+ "}",
+ usernameLen, username,
+ passwordLen, password,
+ displayNameLen, displayName);
+
+ static char responseBuffer[LOGIN_RESPONSE_SIZE];
+ int responseLen;
+ bool result =
+ MatrixHttpPost(client,
+ LOGIN_URL,
+ requestBuffer, requestLen,
+ responseBuffer, LOGIN_RESPONSE_SIZE, &responseLen);
+
+ if (!result)
+ return false;
-bool
-MatrixClientGetAccessToken(
- MatrixClient * client,
- FixedBuffer * outBuffer
-) {
+ client->accessTokenLen =
+ mjson_get_string(responseBuffer, responseLen,
+ "$.access_token",
+ client->accessTokenBuffer, ACCESS_TOKEN_SIZE);
+ client->deviceIdLen =
+ mjson_get_string(responseBuffer, responseLen,
+ "$.device_id",
+ client->deviceIdBuffer, DEVICE_ID_SIZE);
+ client->expireMsLen =
+ mjson_get_string(responseBuffer, responseLen,
+ "$.expires_in_ms",
+ client->expireMsBuffer, EXPIRE_MS_SIZE);
+ client->refreshTokenLen =
+ mjson_get_string(responseBuffer, responseLen,
+ "$.refresh_token",
+ client->refreshTokenBuffer, REFRESH_TOKEN_SIZE);
+ return true;
}
+