]> Pileus Git - ~andy/fetchmail/blob - fetchmail.h
Change type of socket descriptors from FILE * to int. Change SockGets
[~andy/fetchmail] / fetchmail.h
1 /*
2  * For license terms, see the file COPYING in this directory.
3  */
4
5 /* constants designating the various supported protocols */
6 #define         P_AUTO          0
7 #define         P_POP2          2
8 #define         P_POP3          3
9 #define         P_IMAP          4
10 #define         P_APOP          5
11 #define         P_RPOP          6
12 #define         P_ETRN          7
13
14 #define         KPOP_PORT       1109
15
16 /* authentication types */
17 #define         A_PASSWORD      0       /* password or inline authentication */
18 #define         A_KERBEROS_V4   1       /* preauthenticate w/ Kerberos V4 */
19
20 /* definitions for buffer sizes -- somewhat arbitrary */
21 #define         POPBUFSIZE      512     /* per RFC 937 */
22 #define         MSGBUFSIZE      2048    /* size of message read buffer */
23 #define         HOSTLEN         128     /* max hostname length */
24 #define         USERNAMELEN     32      /* max user-name length */
25 #define         PASSWORDLEN     64      /* max password length */
26 #define         DIGESTLEN       33      /* length of MD5 digest */
27 #define         IDLEN           128     /* length of UIDL message ID */
28
29 /* exit code values */
30 #define         PS_SUCCESS      0       /* successful receipt of messages */
31 #define         PS_NOMAIL       1       /* no mail available */
32 #define         PS_SOCKET       2       /* socket I/O woes */
33 #define         PS_AUTHFAIL     3       /* user authorization failed */
34 #define         PS_PROTOCOL     4       /* protocol violation */
35 #define         PS_SYNTAX       5       /* command-line syntax error */
36 #define         PS_IOERR        6       /* bad permissions on rc file */
37 #define         PS_ERROR        7       /* protocol error */
38 #define         PS_EXCLUDE      8       /* exclusion error */
39 #define         PS_SMTP         9       /* SMTP error */
40 #define         PS_UNDEFINED    10      /* something I hadn't thought of */
41 #define         PS_TRANSIENT    11      /* transient failure (internal use) */
42
43 /* output noise level */
44 #define         O_SILENT        0       /* mute, max squelch, etc. */
45 #define         O_NORMAL        1       /* user-friendly */
46 #define         O_VERBOSE       2       /* excessive */
47
48 #define         SIZETICKER      1024    /* print 1 dot per this many bytes */
49
50 /* we need to use zero as a flag-uninitialized value */
51 #define FLAG_TRUE       2
52 #define FLAG_FALSE      1
53
54 struct idlist
55 {
56     char *id;
57     union
58     {
59         int num;
60         char *id2;
61     } val;
62     struct idlist *next;
63 };
64
65
66 struct hostdata         /* shared among all user connections to given server */
67 {
68     /* rc file data */
69     struct idlist *names;               /* server name first, then akas */
70     struct idlist *localdomains;        /* list of pass-through domains */
71     int protocol;
72     int port;
73     int authenticate;
74     int timeout;
75     char *envelope;
76     int skip;
77     int dns;
78     int uidl;
79
80 #ifdef linux
81     char *interface;
82     char *monitor;
83     int  monitor_io;
84     struct interface_pair_s *interface_pair;
85 #endif /* linux */
86
87     /* computed for internal use */
88 #ifdef HAVE_GETHOSTBYNAME
89     char *canonical_name;               /* DNS canonical name of server host */
90 #endif /* HAVE_GETHOSTBYNAME */
91     struct hostdata *lead_server;       /* ptr to lead query for this server */
92     int esmtp_options;
93 };
94
95 struct query
96 {
97     /* mailserver connection controls */
98     struct hostdata server;
99
100     /* per-user data */
101     struct idlist *localnames;          /* including calling user's name */
102     int wildcard;               /* should unmatched names be passed through */
103     char *remotename;
104     char *password;
105     char *mailbox;
106     struct idlist *smtphunt;
107     char *smtphost;
108     char *mda;
109     char *preconnect;
110
111     /* per-user control flags */
112     int keep;
113     int fetchall;
114     int flush;
115     int rewrite;
116     int stripcr;
117     int forcecr;
118     int limit;
119     int fetchlimit;
120     int batchlimit;
121
122     /* unseen, previous state of mailbox (initially from .fetchids) */
123     struct idlist *oldsaved, *newsaved;
124
125     /* internal use */
126     int active;
127     int errcount;               /* count transient errors in last pass */
128     struct query *next;         /* next query control block in chain */
129     int smtp_socket;            /* socket descriptor for SMTP connection */
130     unsigned int uid;           /* UID of user to deliver to */
131     char digest [DIGESTLEN];    /* md5 digest buffer */
132 };
133
134 #define MULTIDROP(ctl)  (ctl->wildcard || \
135                                 ((ctl)->localnames && (ctl)->localnames->next))
136
137 struct method
138 {
139     char *name;                 /* protocol name */
140     int port;                   /* service port */
141     int tagged;                 /* if true, generate & expect command tags */
142     int delimited;              /* if true, accept "." message delimiter */
143     int (*parse_response)();    /* response_parsing function */
144     int (*getauth)();           /* authorization fetcher */
145     int (*getrange)();          /* get message range to fetch */
146     int (*getsizes)();          /* get sizes of messages */
147     int (*is_old)();            /* check for old message */
148     int (*fetch)();             /* fetch a given message */
149     int (*trail)();             /* eat trailer of a message */
150     int (*delete)();            /* delete method */
151     char *exit_cmd;             /* exit command */
152 };
153
154 #define TAGLEN  6
155 extern char tag[TAGLEN];
156
157 /* list of hosts assembled from run control file and command line */
158 extern struct query cmd_opts, *querylist;
159
160 /* controls the detail level of status/progress messages written to stderr */
161 extern int outlevel;            /* see the O_.* constants above */
162 extern int yydebug;             /* enable parse debugging */
163
164 /* daemon mode control */
165 extern int poll_interval;       /* poll interval in seconds */
166 extern int nodetach;            /* if TRUE, don't detach daemon process */
167 extern char *logfile;           /* log file for daemon mode */
168 extern int use_syslog;          /* if --syslog was set */
169 extern int quitmode;            /* if --quit was set */
170 extern int check_only;          /* if --check was set */
171 extern char *cmd_logfile;       /* if --logfile was set */
172 extern int cmd_daemon;          /* if --daemon was set */
173
174 /* these get computed */
175 extern int batchcount;          /* count of messages sent in current batch */
176 extern int peek_capable;        /* can we read msgs without setting seen? */
177
178 /* miscellaneous global controls */
179 extern char *rcfile;            /* path name of rc file */
180 extern char *idfile;            /* path name of UID file */
181 extern int linelimit;           /* limit # lines retrieved per site */
182 extern int versioninfo;         /* emit only version info */
183 extern char *user;              /* name of invoking user */
184 extern char *fetchmailhost;     /* the name of the host running fetchmail */
185
186 /* prototypes for globally callable functions */
187 #if defined(HAVE_STDARG_H)
188 void error_init(int foreground);
189 void error (int status, int errnum, const char *format, ...);
190 void error_build (const char *format, ...);
191 void error_complete (int status, int errnum, const char *format, ...);
192 void gen_send (int sock, char *, ... );
193 int gen_recv(int sock, char *buf, int size);
194 int gen_transact (int sock, char *, ... );
195 #else
196 void error ();
197 void error_build ();
198 void error_complete ();
199 void gen_send ();
200 int gen_transact ();
201 #endif
202
203 int do_protocol(struct query *, const struct method *);
204 int doPOP2 (struct query *); 
205 int doPOP3 (struct query *);
206 int doIMAP (struct query *);
207 int doETRN (struct query *);
208
209 void reply_hack(char *, const char *);
210 char *nxtaddr(const char *);
211
212 void initialize_saved_lists(struct query *, const char *);
213 struct idlist *save_str(struct idlist **, int, const char *);
214 void free_str_list(struct idlist **);
215 void save_str_pair(struct idlist **, const char *, const char *);
216 void free_str_pair_list(struct idlist **);
217 int delete_str(struct idlist **, int);
218 int str_in_list(struct idlist **, const char *);
219 char *str_find(struct idlist **, int);
220 char *idpair_find(struct idlist **, const char *);
221 void append_str_list(struct idlist **, struct idlist **);
222 void update_str_lists(struct query *);
223 void write_saved_lists(struct query *, const char *);
224
225 struct query *hostalloc(struct query *); 
226 int parsecmdline (int, char **, struct query *);
227 void optmerge(struct query *, struct query *);
228 char *MD5Digest (char *);
229 int daemonize(const char *, void (*)(int));
230
231 int prc_parse_file(const char *);
232 int prc_filecheck(const char *);
233
234 void interface_parse(char *, struct hostdata *);
235 void interface_note_activity(struct hostdata *);
236 int interface_approve(struct hostdata *);
237
238 char *getpassword(char *);
239
240 void escapes(const char *, char *);
241
242 void yyerror(const char *);
243 int yylex(void);
244
245 #if defined(HAVE_VOIDPOINTER)
246 #define XMALLOCTYPE void
247 #else
248 #define XMALLOCTYPE char
249 #endif
250
251 XMALLOCTYPE *xmalloc(int);
252 XMALLOCTYPE *xrealloc(XMALLOCTYPE *, int);
253 char *xstrdup(const char *);
254
255 #define FALSE   0
256 #define TRUE    1
257
258 #define STRING_DISABLED (char *)-1