1 /* $MirOS: src/usr.sbin/popa3d/protocol.h,v 1.2 2013/10/31 20:07:29 tg Exp $ */ 2 /* $OpenBSD: protocol.h,v 1.3 2003/05/12 19:28:22 camield Exp $ */ 3 4 /* 5 * POP protocol handling. 6 */ 7 8 #ifndef _POP_PROTOCOL_H 9 #define _POP_PROTOCOL_H 10 11 /* 12 * Responses and events, to be returned by command and state handlers. 13 */ 14 #define POP_OK 0 /* Reply with "+OK" */ 15 #define POP_ERROR 1 /* Reply with "-ERR" */ 16 #define POP_QUIET 2 /* We've already replied */ 17 #define POP_LEAVE 3 /* Leave the session */ 18 #define POP_STATE 4 /* Advance the state */ 19 #define POP_CRASH_NETFAIL 5 /* Network failure */ 20 #define POP_CRASH_NETTIME 6 /* Network timeout */ 21 #define POP_CRASH_SERVER 7 /* POP server failure */ 22 23 /* 24 * POP command description. 25 */ 26 struct pop_command { 27 char *name; 28 int (*handler)(char *params); 29 }; 30 31 /* 32 * Internal POP command buffer. 33 */ 34 struct pop_buffer { 35 unsigned int ptr, size; 36 char data[POP_BUFFER_SIZE]; 37 }; 38 39 extern struct pop_buffer pop_buffer; 40 41 /* 42 * Initializes the buffer. 43 */ 44 extern void pop_init(void); 45 46 /* 47 * Zeroes out the part of the buffer that has already been processed. 48 */ 49 extern void pop_clean(void); 50 51 /* 52 * Checks if the buffer is sane. 53 */ 54 extern int pop_sane(void); 55 56 /* 57 * Handles a POP protocol state (AUTHORIZATION or TRANSACTION, as defined 58 * in RFC 1939), processing the supplied commands. Returns when the state 59 * is changed. 60 */ 61 extern int pop_handle_state(struct pop_command *commands); 62 63 /* 64 * Returns the next parameter, or NULL if there's none or it is too long 65 * to be valid (as defined in the RFC). 66 */ 67 extern char *pop_get_param(char **params); 68 69 /* 70 * Returns the next parameter as a non-negative number, or -1 if there's 71 * none or the syntax is invalid. 72 */ 73 extern int pop_get_int(char **params); 74 75 /* 76 * Produces a generic POP response. Returns a non-zero value on error; 77 * the POP session then has to crash. 78 */ 79 extern int pop_reply(char *format, ...) 80 #ifdef __GNUC__ 81 __attribute__((__format__(__printf__, 1, 2))); 82 #else 83 ; 84 #endif 85 86 /* 87 * The two simple POP responses. Return a non-zero value on error; the 88 * POP session then has to crash. 89 */ 90 extern int pop_reply_ok(void); 91 extern int pop_reply_error(void); 92 93 /* 94 * Produces a multi-line POP response, reading the data from the supplied 95 * file descriptor for up to the requested size or number of lines of the 96 * message body, if that number is non-negative. Returns POP_OK or one of 97 * the POP_CRASH_* event codes. 98 */ 99 extern int pop_reply_multiline(int fd, unsigned long size, int lines); 100 101 /* 102 * Terminates a multi-line POP response. Returns a non-zero value on error; 103 * the POP session then has to crash. 104 */ 105 extern int pop_reply_terminate(void); 106 107 #endif 108