63 lines
1.5 KiB
C
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;
|
|
}
|
|
|