abouttreesummaryrefslogcommitdiff
path: root/src/matrix.c
diff options
context:
space:
mode:
authorPatrick2023-05-28 17:27:25 +0200
committerPatrick2023-05-28 17:27:25 +0200
commitd382d193cb2d550cc769afa76e55823865a39023 (patch)
tree45ee240e02e28ed65b566fb8ece7ad0fbbe4064e /src/matrix.c
parentc1547dd3565f979d08a9e8e9eec8f42956e6901c (diff)
downloadmatrix_esp_thesis-d382d193cb2d550cc769afa76e55823865a39023.tar.gz
matrix_esp_thesis-d382d193cb2d550cc769afa76e55823865a39023.zip
send example, http PUT
Diffstat (limited to 'src/matrix.c')
-rw-r--r--src/matrix.c46
1 files changed, 45 insertions, 1 deletions
diff --git a/src/matrix.c b/src/matrix.c
index 5759ba2..7cc4de9 100644
--- a/src/matrix.c
+++ b/src/matrix.c
@@ -1,5 +1,6 @@
#include "matrix.h"
+#include <time.h>
#include <stdio.h>
#include <mjson.h>
@@ -8,6 +9,10 @@
#define LOGIN_RESPONSE_SIZE 1024
#define LOGIN_URL "/_matrix/client/v3/login"
+#define ROOMEVENT_REQUEST_SIZE 1024
+#define ROOMEVENT_RESPONSE_SIZE 1024
+#define ROOMEVENT_URL "/_matrix/client/v3/rooms/%s/send/%s/%d"
+
bool
MatrixClientInit(
@@ -23,6 +28,22 @@ MatrixClientInit(
return true;
}
+bool
+MatrixClientSetAccessToken(
+ MatrixClient * client,
+ const char * accessToken)
+{
+ int accessTokenLen = strlen(accessToken);
+
+ if (accessTokenLen < ACCESS_TOKEN_SIZE - 1)
+ return false;
+
+ for (int i = 0; i < accessTokenLen; i++)
+ client->accessTokenBuffer[i] = accessToken[i];
+
+ return true;
+}
+
// https://spec.matrix.org/v1.6/client-server-api/#post_matrixclientv3login
bool
MatrixClientLoginPassword(
@@ -52,7 +73,8 @@ MatrixClientLoginPassword(
MatrixHttpPost(client,
LOGIN_URL,
requestBuffer,
- responseBuffer, LOGIN_RESPONSE_SIZE);
+ responseBuffer, LOGIN_RESPONSE_SIZE,
+ false);
int responseLen = strlen(responseBuffer);
@@ -74,4 +96,26 @@ MatrixClientLoginPassword(
return true;
}
+
+bool
+MatrixClientSendEvent(
+ MatrixClient * client,
+ const char * roomId,
+ const char * msgType,
+ const char * msgBody)
+{
+ static char requestUrl[MAX_URL_LEN];
+ sprintf_s(requestUrl, MAX_URL_LEN,
+ ROOMEVENT_URL, roomId, msgType, time(NULL));
+
+ static char responseBuffer[ROOMEVENT_RESPONSE_SIZE];
+ bool result =
+ MatrixHttpPut(client,
+ requestUrl,
+ msgBody,
+ responseBuffer, ROOMEVENT_RESPONSE_SIZE,
+ true);
+
+ return result;
+}