-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathpop3d.h
174 lines (151 loc) · 3.79 KB
/
pop3d.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
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
/*
* Copyright (c) 2014 Sunil Nimmagadda <sunil@nimmagadda.net>
*
* Permission to use, copy, modify, and distribute this software for any
* purpose with or without fee is hereby granted, provided that the above
* copyright notice and this permission notice appear in all copies.
*
* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
* WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
* MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
* ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
* ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*/
#include <sys/tree.h>
#include <sha1.h>
#include "imsgev.h"
#include "iobuf.h"
#include "ioev.h"
#define ARGLEN 40
#define POP3S 0x01
#define F_DELE 0x01
struct passwd;
enum imsg_type {
IMSG_AUTH,
IMSG_MAILDROP_INIT,
IMSG_MAILDROP_RETR,
IMSG_MAILDROP_DELE,
IMSG_MAILDROP_RSET,
IMSG_MAILDROP_LIST,
IMSG_MAILDROP_LISTALL,
IMSG_MAILDROP_UPDATE
};
enum m_type {
M_MBOX,
M_MAILDIR
};
struct msg {
union {
SIMPLEQ_ENTRY(msg) q_entry;
RB_ENTRY(msg) t_entry;
} e;
char hash[SHA1_DIGEST_STRING_LENGTH];
size_t sz;
size_t nlines;
union {
long offset;
const char *fname;
} u;
int flags;
};
struct mdrop {
union {
SIMPLEQ_HEAD(, msg) q_msgs;
RB_HEAD(msgtree, msg) t_msgs;
} e;
size_t nmsgs;
size_t sz;
struct msg **msgs_index; /* random access msgs */
int fd;
};
struct stats {
size_t nmsgs;
size_t sz;
};
struct retr_req {
unsigned int idx;
unsigned int ntop;
int top;
};
struct retr_res {
size_t nlines;
long offset;
unsigned int ntop;
int top;
};
struct list_req {
unsigned int idx;
int uidl;
};
struct list_res {
unsigned int idx;
union {
size_t sz;
char hash[SHA1_DIGEST_STRING_LENGTH];
} u;
int uidl;
};
struct m_backend {
int (*init)(struct mdrop *, size_t *, size_t *);
int (*retr)(struct mdrop *, unsigned int, size_t *, long *);
int (*update)(struct mdrop *);
};
struct auth_req {
char user[ARGLEN];
char pass[ARGLEN];
};
struct listener {
struct event ev;
struct event pause;
int flags;
int sock;
};
enum state {
AUTH,
TRANSACTION,
UPDATE
};
struct session {
SPLAY_ENTRY(session) entry;
struct iobuf iobuf;
struct io io;
struct sockaddr_storage ss;
char user[ARGLEN];
char pass[ARGLEN];
size_t m_sz;
size_t nmsgs;
struct listener *l;
struct imsgev *iev_maildrop;
uint32_t id;
int flags;
enum state state;
};
/* pop3e.c */
void pop3_main(int [2], struct passwd *, const char *, const char *);
/* session.c */
void session_init(struct listener *, int, const struct sockaddr_storage *);
void session_close(struct session *, int);
void session_reply(struct session *, char *, ...);
void session_set_state(struct session *, enum state);
void session_imsgev_init(struct session *, int);
SPLAY_HEAD(session_tree, session);
int session_cmp(struct session *, struct session *);
SPLAY_PROTOTYPE(session_tree, session, entry, session_cmp);
/* maildrop.c */
pid_t maildrop_setup(uint32_t, int [2], struct passwd *);
/* util.c */
void set_nonblocking(int);
void log_init(int);
void logit(int, const char *, ...);
void vlog(int, const char *, va_list);
void fatal(const char *);
void fatalx(const char *);
void *xcalloc(size_t, size_t, const char *);
void iobuf_xfqueue(struct iobuf *, const char *, const char *, ...);
void iobuf_xqueue(struct iobuf *, const char *, const void *, size_t);
int imsgev_xcompose(struct imsgev *, u_int16_t, u_int32_t,
uint32_t, int, void *, u_int16_t, const char *);
int get_index(struct session *, const char *, unsigned int *);
void log_connect(uint32_t, struct sockaddr_storage *, socklen_t);