Files
DIlkhush00 668ff01ef9 add matrix api implementation
- login
- get rooms
- logout
2026-03-18 06:10:47 +05:30

63 lines
1.5 KiB
C

#include "matrix.h"
#include "mbedtls/platform.h"
int main(int argc, char **argv)
{
if (argc < 3) {
mbedtls_printf("Usage: %s <username> <password>\n", argv[0]);
mbedtls_printf("Example: %s @user:matrix.org password123\n", argv[0]);
return 1;
}
const char *username = argv[1];
const char *password = argv[2];
char access_token[512];
matrix_connection_t conn;
// initialize PSA Crypto
psa_status_t psa_status = psa_crypto_init();
if (psa_status != PSA_SUCCESS) {
mbedtls_printf(" ! failed (%d)\n", (int)psa_status);
return -1;
}
// connect
if (matrix_connect(&conn) != 0) {
return -1;
}
// login
if (matrix_login(&conn, username, password, access_token, sizeof(access_token)) != 0) {
matrix_logout(&conn, access_token);
return -1;
}
// disconnect & then reconnect. I'm doing this cause after each request
// i'm closing the connection. for actual use we should use keep-alive
matrix_disconnect(&conn);
if (matrix_connect(&conn) != 0) {
return -1;
}
// get rooms
if (matrix_get_rooms(&conn, access_token) != 0) {
matrix_logout(&conn, access_token);
return -1;
}
// reconnect again
matrix_disconnect(&conn);
if (matrix_connect(&conn) != 0) {
return -1;
}
// finally logout & close the connection
if (matrix_logout(&conn, access_token) != 0) {
return -1;
}
return 0;
}