abouttreesummaryrefslogcommitdiff
path: root/src/matrix.h
blob: 2e7f6e0e9a6861fa70839a18b2c8dd8ca27b19b4 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
#ifndef MATRIX__H
#define MATRIX__H

#include <stdbool.h>
#include <string.h>

#include <olm/olm.h>



// TODO: fix
#define SERVER_SIZE 20
#define ACCESS_TOKEN_SIZE 40
#define DEVICE_ID_SIZE 20
#define EXPIRE_MS_SIZE 20
#define REFRESH_TOKEN_SIZE 20
#define MAX_URL_LEN 128


typedef struct MatrixClient {
    OlmAccount * olmAccount;
    OlmSession * olmSession;
    
    char server[SERVER_SIZE+1];
    char accessTokenBuffer[ACCESS_TOKEN_SIZE];
    char deviceIdBuffer[DEVICE_ID_SIZE];
    char expireMsBuffer[EXPIRE_MS_SIZE];
    char refreshTokenBuffer[REFRESH_TOKEN_SIZE];

    void * httpUserData;
} MatrixClient;

bool
MatrixClientInit(
    MatrixClient * client,
    const char * server);

bool
MatrixClientSetAccessToken(
    MatrixClient * client,
    const char * accessToken);

bool
MatrixClientLoginPassword(
    MatrixClient * client,
    const char * username,
    const char * password,
    const char * displayName);
    
bool
MatrixClientSendEvent(
    MatrixClient * client,
    const char * roomId,
    const char * msgType,
    const char * msgBody);

bool
MatrixHttpInit(
    MatrixClient * client);

bool
MatrixHttpDeinit(
    MatrixClient * client);

bool
MatrixHttpGet(
    MatrixClient * client,
    const char * url,
    char * outResponseBuffer, int outResponseCap,
    bool authenticated);

bool
MatrixHttpPost(
    MatrixClient * client,
    const char * url,
    const char * requestBuffer,
    char * outResponseBuffer, int outResponseCap,
    bool authenticated);

bool
MatrixHttpPut(
    MatrixClient * client,
    const char * url,
    const char * requestBuffer,
    char * outResponseBuffer, int outResponseCap,
    bool authenticated);

#endif