33 lines
1.0 KiB
C
33 lines
1.0 KiB
C
#ifndef MATRIX_H
|
|
#define MATRIX_H
|
|
|
|
#include "mbedtls/net_sockets.h"
|
|
#include "mbedtls/ssl.h"
|
|
#include "mbedtls/x509_crt.h"
|
|
|
|
typedef struct {
|
|
mbedtls_net_context server_fd;
|
|
mbedtls_ssl_context ssl;
|
|
mbedtls_ssl_config conf;
|
|
mbedtls_x509_crt cacert;
|
|
} matrix_connection_t;
|
|
|
|
int matrix_connect(matrix_connection_t *conn);
|
|
int matrix_logout(matrix_connection_t *conn, const char *access_token);
|
|
void matrix_disconnect(matrix_connection_t *conn);
|
|
|
|
// HTTP request/response thing
|
|
int matrix_send_request(matrix_connection_t *conn,
|
|
const char *req, char *res, size_t res_len);
|
|
|
|
int matrix_login(matrix_connection_t *conn, const char *username,
|
|
const char *password, char *access_token, size_t token_len);
|
|
|
|
int matrix_get_rooms(matrix_connection_t *conn, const char *access_token);
|
|
|
|
// extract access token from JSON response (very basic, not a full JSON parser)
|
|
// we can use a real JSON parser but for demo purposes imma keep it simple
|
|
int matrix_extract_access_token(const char *res, char *token, size_t token_len);
|
|
|
|
#endif
|