-
Notifications
You must be signed in to change notification settings - Fork 21
/
tokens.h
99 lines (71 loc) · 2.74 KB
/
tokens.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
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
#ifndef TOKENS_H
#define TOKENS_H
#include <stdbool.h>
#include <stddef.h>
#include <time.h>
#ifdef __cplusplus
extern "C" {
#endif
// manage user tokens and source tokens
// 'expire' fmt "2019-08-19 23:59:59"
// init tokens module, return 0 OK, -1 error
int tokens_init(const char *database);
// deinit tokens module
int tokens_cleanup();
int tokens_backup();
// ------------------ user token -------------------
// get total user token count, -1 means error
int tokens_user_count();
// check if permit a user & passwd
bool tokens_user_permit(const char *user, const char *passwd);
// get user expire time, return 0 if error or user/passwd pair not exists
time_t tokens_user_expire(const char *user, const char *passwd);
// iterate all user token and expire date
void tokens_user_iterate(void (*iter)(void *userdata,
const char *user,
const char *passwd,
const char *expire),
void *userdata);
// update an user password or expire date.
// passwd or date may be NULL, NULL will ignore, but not should both be NULL.
// return 0 means OK, -1 means error.
// if user not exists, will report error.
int tokens_user_update(const char *user, const char *passwd, const char *expire);
// add new user password and expire date.
// return 0 OK, -1 error.
int tokens_user_add(const char *user, const char *passwd, const char *expire);
// remove user entry.
// return 0 OK, -1 error
// if user not exists, will report OK.
int tokens_user_delete(const char *user);
// remove out-of-date entry.
// return 0 OK, -1 error
int tokens_user_gc();
// -------------------- src token ------------------
// get total count of src tokens.
// return -1 means error.
int tokens_src_count();
// get used src tokens count.
// return -1 means error.
int tokens_src_count_used();
// add new src token and it's expire date. token fmt "user:passwd@addr"
// return 0 OK, -1 error
int tokens_src_add(const char *token, const char *expire);
// delete src token
// return 0 OK, -1 error
int tokens_src_delete(const char *token);
// try to take usage an ide src token path. path fmt "user:passwd@addr"
// buf & bufsize: output token buffer and size.
// return NULL means could not fetch one, otherwise return buf address
char* tokens_src_take_path(char *buf, size_t bufsize);
// release usage of a src token path
void tokens_src_release_path(const char *path);
// iterate all src tokens
void tokens_src_iterate(void (*iterfunc)(void *userdata,
const char *token,
const char *expire),
void *userdata);
#ifdef __cplusplus
}
#endif
#endif // TOKENS_H