Initial CVS repository import (last CVS history was lost)
[mmondor.git] / mmsoftware / mmmail / src / mmpop3d / mmpop3d.h
CommitLineData
47071c2b
MM
1/* $Id: mmpop3d.h,v 1.1 2002/12/11 10:15:38 mmondor Exp $ */
2
3/*
4 * Copyright (C) 2000-2002, Matthew Mondor
5 * All rights reserved.
6 *
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
9 * are met:
10 * 1. Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer.
12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution.
15 * 3. All advertising materials mentioning features or use of this software
16 * must display the following acknowledgement:
17 * This product includes software written by Matthew Mondor.
18 * 4. The name of Matthew Mondor may not be used to endorse or promote
19 * products derived from this software without specific prior written
20 * permission.
21 *
22 * THIS SOFTWARE IS PROVIDED BY MATTHEW MONDOR ``AS IS'' AND ANY EXPRESS OR
23 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
24 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
25 * IN NO EVENT SHALL MATTHEW MONDOR BE LIABLE FOR ANY DIRECT, INDIRECT,
26 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
27 * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
28 * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
29 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
30 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
31 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
32 */
33
34
35
36
37#ifndef MMPOP3D_H
38#define MMPOP3D_H
39
40
41
42
43/* HEADERS */
44
45#include <sys/types.h>
46
47#include <mmtypes.h>
48#include <mmserver.h>
49#include <mmlist.h>
50#include <mmfd.h>
51#include <mmstat.h>
52
53
54
55
56/* DEFINITIONS */
57
58#define DAEMON_NAME "mmpop3d"
59#define DAEMON_VERSION "mmmail-0.0.21/mmondor"
60
61/* Negative states are used by the state swapper, others are real states */
62#define STATE_ERROR -3
63#define STATE_END -2
64#define STATE_CURRENT -1
65#define STATE_AUTH 0
66#define STATE_MAIN 1
67
68/* Asynchroneous functions we attach */
69#define ASYNC_HASHPW 1
70
71
72
73
74/* STRUCTURES */
75
76/* We store config file read results in this structure */
77typedef struct config {
78 char CHROOT_DIR[256], PID_PATH[256], USER[32], GROUPS[256],
79 LOG_FACILITY[32], LISTEN_IPS[1024], SERVER_NAMES[1024], DB_HOST[64],
80 DB_USER[32], DB_PASSWORD[32], DB_DATABASE[32];
81 long ALLOC_BUFFERS, LOG_LEVEL, LISTEN_PORT, MAX_ERRORS, MAX_IPS,
82 MAX_PER_IP, CONNECTION_RATE, CONNECTION_PERIOD, INPUT_TIMEOUT,
83 BANDWIDTH_IN, BANDWIDTH_OUT, GBANDWIDTH_IN, GBANDWIDTH_OUT,
84 ASYNC_PROCESSES;
85 bool RESOLVE_HOSTS;
86} CONFIG;
87
88/* For the messages list during the session */
89typedef struct msgnode {
90 char id[24]; /* ID in the database */
91 long size; /* Message size in bytes */
92 bool retreived, deleted; /* Flags */
93} msgnode;
94
95typedef struct clientenv {
96 node nod;
97 fdbuf *fdb; /* Buffered handler around our fd */
98 char *buffer; /* Buffer that points to last command line */
99 char *c_hostname; /* Pointer to client's hostname */
100 char *c_ipaddr; /* Pointer to client's IP address string */
101 char *mailbox; /* Mailbox, this is if USER was specified */
102 msgnode *index; /* Available messages with flags */
103 long messages; /* Number of messages, to know index size */
104 long newmessages; /* Current number of messages after deleted */
105 long size; /* Size of total messages in index */
106 long newsize; /* Current size of undeleted messages */
107 long last; /* Last message read in current session */
108 long errors; /* Total number of errors that occured */
109 int timeout; /* Timeout in ms */
110 unsigned long id; /* Our connection ID */
111 unsigned long retreived, deleted; /* Number of msgs retrieved & deleted */
112 bool login; /* For all_quit() */
113 struct iface *iface; /* Current interface user connected through */
114 struct async_clenv *aclenv; /* Thread context for async_call() */
115 MMSTAT vstat, pstat; /* mmstat(3) handles */
116} clientenv;
117
118/* This defines a state */
119typedef struct state {
120 int (**functions)(clientenv *);
121 int errcode;
122 char *errtext;
123} state;
124
125/* A command of a state */
126typedef struct command {
127 int32_t hash;
128 int loglevel;
129 char *name;
130} command;
131
132/* Used by our asynchoneous functions */
133struct async_hashpw_msg {
134 struct async_msg msg;
135 union {
136 struct {
137 char hash[33];
138 } res;
139 struct {
140 char passwd[256];
141 } args;
142 } un;
143};
144
145
146
147
148/* PROTOTYPES */
149
150int main(int, char **);
151
152static int all_noop(clientenv *);
153static int all_quit(clientenv *);
154static int all_beer(clientenv *);
155static int auth_user(clientenv *);
156static int auth_pass(clientenv *);
157static int main_rset(clientenv *);
158static int main_stat(clientenv *);
159static int main_list(clientenv *);
160static int main_retr(clientenv *);
161static int main_dele(clientenv *);
162static int main_last(clientenv *);
163static int main_top(clientenv *);
164static int main_page(clientenv *);
165
166static void packcommands(struct command *, size_t);
167static bool do_buildindex(clientenv *);
168static bool do_retreive(fdbuf *, msgnode *);
169static bool do_top(fdbuf *, msgnode *, int);
170static bool do_page(fdbuf *, msgnode *, int, int);
171static bool do_update(clientenv *);
172static bool msgwrite(fdbuf *, const void *, size_t);
173static bool reply(fdbuf *, bool, const char *, ...);
174static clientenv *alloc_clientenv(void);
175static bool init_clientenv(clientenv *);
176static clientenv *free_clientenv(clientenv *);
177static bool valid_address(char *, char *);
178static bool valid_host(char *);
179static bool valid_char(char);
180
181static int handleclient(unsigned long, int, clientlistnode *, struct iface *,
182 struct async_clenv *);
183
184static void async_hashpw(struct async_msg *);
185static bool hashpw(clientenv *, char *, const char *);
186
187
188
189
190#endif