-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathcontact.h
50 lines (40 loc) · 1.23 KB
/
contact.h
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
#ifndef CONTACT_H
#define CONTACT_H
#include "ecchat.h"
#include "avl.h"
#include "txqueue.h"
struct contact {
ecchat_id_t id;
struct ecchat_clist clist;
struct tx_queue mbox;
void *priv;
u8 online;
u8 latest_client_version;
struct avl_node node;
};
typedef void (*contact_moved_cb)(struct contact *contact);
typedef void (*contact_deleted_cb)(struct contact *contact);
struct contacts {
struct avl_tree tree;
contact_moved_cb contact_moved;
contact_deleted_cb contact_deleted;
};
void contacts_init();
struct contacts * contacts_new(contact_moved_cb mov_cb,
contact_deleted_cb del_cb);
void contacts_free(struct contacts *contacts);
int contacts_load(struct contacts *contacts);
struct contact * contact_get(struct contacts *contacts, const ecchat_id_t *id);
void contacts_move_state(struct contacts *contacts_new,
struct contacts *contacts_old);
void contact_mbox_add(struct contact *c, const char *msg, const unsigned len);
void contact_mbox_del(struct contact *c);
void contact_mbox_truncate(struct contact *c);
static inline void contact_print(struct contact *c)
{
char idstr[ECCHAT_ID_MAXLEN + 2];
ecchat_id2str(idstr, &c->id);
printf("contact: %s online %hu\n", idstr, c->online);
ecchat_clist_print(&c->clist);
}
#endif