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
|
/* $OpenBSD: protocol.h,v 1.2 2001/08/13 20:19:33 camield Exp $ */
/*
* POP protocol handling.
*/
#ifndef _POP_PROTOCOL_H
#define _POP_PROTOCOL_H
/*
* Responses and events, to be returned by command and state handlers.
*/
#define POP_OK 0 /* Reply with "+OK" */
#define POP_ERROR 1 /* Reply with "-ERR" */
#define POP_QUIET 2 /* We've already replied */
#define POP_LEAVE 3 /* Leave the session */
#define POP_STATE 4 /* Advance the state */
#define POP_CRASH 5 /* Session crashed */
#define POP_TIMED_OUT 6 /* Connection timed out */
/*
* POP command description.
*/
struct pop_command {
char *name;
int (*handler)(char *params);
};
/*
* Internal POP command buffer.
*/
struct pop_buffer {
int ptr, size;
char data[POP_BUFFER_SIZE];
};
extern struct pop_buffer pop_buffer;
/*
* Initializes the buffer.
*/
extern void pop_init(void);
/*
* Zeroes out the part of the buffer that has already been processed.
*/
extern void pop_clean(void);
/*
* Checks if the buffer is sane.
*/
extern int pop_sane(void);
/*
* Handles a POP protocol state (AUTHORIZATION or TRANSACTION, as defined
* in RFC 1939), processing the supplied commands. Returns when the state
* is changed.
*/
extern int pop_handle_state(struct pop_command *commands);
/*
* Returns the next parameter, or NULL if there's none or it is too long
* to be valid (as defined in the RFC).
*/
extern char *pop_get_param(char **params);
/*
* Returns the next parameter as a non-negative number, or -1 if there's
* none or the syntax is invalid.
*/
extern int pop_get_int(char **params);
/*
* Produces a generic POP response. Returns a non-zero value on error;
* the POP session then has to crash.
*/
extern int pop_reply(char *format, ...)
#ifdef __GNUC__
__attribute__ ((format (printf, 1, 2)));
#else
;
#endif
/*
* The two simple POP responses. Return a non-zero value on error; the
* POP session then has to crash.
*/
extern int pop_reply_ok(void);
extern int pop_reply_error(void);
/*
* Produces a multi-line POP response, reading the data from the supplied
* file descriptor for up to the requested size or number of lines of the
* message body, if that number is non-negative. Returns a non-zero value
* on error; the POP session then has to crash.
*/
extern int pop_reply_multiline(int fd, long size, int lines);
/*
* Terminates a multi-line POP response. Returns a non-zero value on error;
* the POP session then has to crash.
*/
extern int pop_reply_terminate(void);
#endif
|