forked from gregkh/bti
-
Notifications
You must be signed in to change notification settings - Fork 1
/
account.h
80 lines (71 loc) · 2.11 KB
/
account.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
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
/* -*- mode: c; c-basic-offset: 4; tab-width: 4; indent-tabs-mode: t -*- */
/*
* forked from Greg Kroah-Hartman's bti project
* see https://github.com/thesues/bti
*/
#ifndef __ACCOUNT_H
#define __ACCOUNT_H
/*void * is account data*/
struct session;
struct account {
struct ops_t *opts;
void *data;
struct account *next;
};
struct ops_t {
int (*action_update) (struct account *, struct session *);
int (*action_friends) (struct account *, struct session *);
int (*action_user) (struct account *, struct session *);
int (*action_replies) (struct account *, struct session *);
int (*action_public) (struct account *, struct session *);
int (*action_group) (struct account *, struct session *);
int (*action_retweet) (struct account *, struct session *);
int (*destory) (struct account *);
};
#define UPDATE(acc, session, ret) \
do { \
struct account *p = acc; \
while (p!=NULL) { \
if (p->opts->action_update) \
ret = p->opts->action_update(p, session); \
p = p->next; \
} \
}while(0)
#define FRIENDS(acc, session , ret) \
do { \
struct account *p = acc; \
while (p!=NULL && p->opts->action_update){ \
if (p->opts->action_update) \
ret = p->opts->action_friends(p, session); \
p = p->next; \
} \
} while(0)
#define PUBLIC(acc, session, ret) \
do { \
struct account *p = acc; \
while (p != NULL){ \
if (p->opts->action_public) \
ret = p->opts->action_public(p, session); \
p = p->next; \
} \
} while(0)
#define REPLIES(acc, session, ret) \
do { \
struct account *p = acc; \
while (p != NULL){ \
if (p->opts->action_replies) \
ret = p->opts->action_replies(p, session); \
p = p->next; \
} \
} while(0)
#define DESTORY(acc) \
do { \
struct account *p = acc; \
struct account *tmp; \
while (p!=NULL){ \
tmp=p->next; \
p->opts->destory(p); \
p=tmp; \
} \
} while(0)
#endif