-
Notifications
You must be signed in to change notification settings - Fork 0
/
mfs_imap_parse.h
84 lines (73 loc) · 1.47 KB
/
mfs_imap_parse.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
#ifndef _MFS_IMAP_PARSE_H_
#define _MFS_IMAP_PARSE_H_
#include <linux/list.h>
#include <linux/kref.h>
/**
* Imap message element type
*/
enum imap_elt_type {
IET_NIL,
IET_ATOM,
IET_NUMBER,
IET_STRING,
IET_LIST
};
/**
* XXX Are we unalgined safe ?
*/
#define IMAP_ELT_NUM(e) ((unsigned int *)(e)->data)
#define IMAP_ELT_MSG(e) ((struct imap_msg *)(e)->data)
#define IMAP_ELT_ATOM(e) ((e)->data)
#define IMAP_ELT_STR(e) ((e)->data)
/**
* Imap message element
*/
struct imap_elt {
struct list_head next;
enum imap_elt_type type;
char data[];
};
/**
* Imap message
*/
struct imap_msg {
struct kref refcnt;
struct list_head elt;
};
#define ISTACK_MAX 16
struct imap_parse_stack {
size_t idx;
struct imap_msg *st[ISTACK_MAX];
};
struct imap_parse_ctx {
struct imap_parse_stack st;
struct imap_msg *first;
struct imap_msg *msg;
struct imap_elt *elt;
size_t more;
int cr;
};
/**
* Create a new context for imap parsing
*/
struct imap_parse_ctx *mfs_imap_parse_new_ctx(void);
/**
* Delete a imap parsing context
*/
void mfs_imap_parse_del_ctx(struct imap_parse_ctx *ctx);
/**
* Transform received message into structured imap message
*/
struct imap_msg *mfs_imap_parse_msg(struct imap_parse_ctx *ctx,
char const **msg, size_t *len);
/**
* Get a reference on imap msg
*
* Returns non zero if get suceed 0 otherwise
*/
int __must_check mfs_imap_msg_get(struct imap_msg *im);
/**
* Release a reference on imap msg
*/
int mfs_imap_msg_put(struct imap_msg *im);
#endif