annotate src/osdep/nt/unixnt.h @ 0:ada5e610ab86

imap-2007e
author yuuji@gentei.org
date Mon, 14 Sep 2009 15:17:45 +0900
parents
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1 /* ========================================================================
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
2 * Copyright 1988-2006 University of Washington
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
3 *
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
4 * Licensed under the Apache License, Version 2.0 (the "License");
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
5 * you may not use this file except in compliance with the License.
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
6 * You may obtain a copy of the License at
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
7 *
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
8 * http://www.apache.org/licenses/LICENSE-2.0
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
9 *
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
10 *
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
11 * ========================================================================
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
12 */
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
13
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
14 /*
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
15 * Program: UNIX mail routines
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
16 *
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
17 * Author: Mark Crispin
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
18 * Networks and Distributed Computing
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
19 * Computing & Communications
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
20 * University of Washington
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
21 * Administration Building, AG-44
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
22 * Seattle, WA 98195
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
23 * Internet: MRC@CAC.Washington.EDU
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
24 *
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
25 * Date: 20 December 1989
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
26 * Last Edited: 30 August 2006
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
27 */
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
28
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
29
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
30 /* DEDICATION
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
31 *
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
32 * This file is dedicated to my dog, Unix, also known as Yun-chan and
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
33 * Unix J. Terwilliker Jehosophat Aloysius Monstrosity Animal Beast. Unix
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
34 * passed away at the age of 11 1/2 on September 14, 1996, 12:18 PM PDT, after
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
35 * a two-month bout with cirrhosis of the liver.
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
36 *
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
37 * He was a dear friend, and I miss him terribly.
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
38 *
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
39 * Lift a leg, Yunie. Luv ya forever!!!!
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
40 */
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
41
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
42 /* Validate line
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
43 * Accepts: pointer to candidate string to validate as a From header
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
44 * return pointer to end of date/time field
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
45 * return pointer to offset from t of time (hours of ``mmm dd hh:mm'')
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
46 * return pointer to offset from t of time zone (if non-zero)
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
47 * Returns: t,ti,zn set if valid From string, else ti is NIL
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
48 */
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
49
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
50 #define VALID(s,x,ti,zn) { \
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
51 ti = 0; \
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
52 if ((*s == 'F') && (s[1] == 'r') && (s[2] == 'o') && (s[3] == 'm') && \
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
53 (s[4] == ' ')) { \
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
54 for (x = s + 5; *x && *x != '\012'; x++); \
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
55 if (*x) { \
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
56 if (x[-1] == '\015') --x; \
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
57 if (x - s >= 41) { \
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
58 for (zn = -1; x[zn] != ' '; zn--); \
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
59 if ((x[zn-1] == 'm') && (x[zn-2] == 'o') && (x[zn-3] == 'r') && \
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
60 (x[zn-4] == 'f') && (x[zn-5] == ' ') && (x[zn-6] == 'e') && \
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
61 (x[zn-7] == 't') && (x[zn-8] == 'o') && (x[zn-9] == 'm') && \
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
62 (x[zn-10] == 'e') && (x[zn-11] == 'r') && (x[zn-12] == ' '))\
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
63 x += zn - 12; \
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
64 } \
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
65 if (x - s >= 27) { \
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
66 if (x[-5] == ' ') { \
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
67 if (x[-8] == ':') zn = 0,ti = -5; \
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
68 else if (x[-9] == ' ') ti = zn = -9; \
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
69 else if ((x[-11] == ' ') && ((x[-10]=='+') || (x[-10]=='-'))) \
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
70 ti = zn = -11; \
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
71 } \
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
72 else if (x[-4] == ' ') { \
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
73 if (x[-9] == ' ') zn = -4,ti = -9; \
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
74 } \
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
75 else if (x[-6] == ' ') { \
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
76 if ((x[-11] == ' ') && ((x[-5] == '+') || (x[-5] == '-'))) \
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
77 zn = -6,ti = -11; \
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
78 } \
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
79 if (ti && !((x[ti - 3] == ':') && \
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
80 (x[ti -= ((x[ti - 6] == ':') ? 9 : 6)] == ' ') && \
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
81 (x[ti - 3] == ' ') && (x[ti - 7] == ' ') && \
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
82 (x[ti - 11] == ' '))) ti = 0; \
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
83 } \
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
84 } \
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
85 } \
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
86 }
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
87
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
88 /* You are not expected to understand this macro, but read the next page if
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
89 * you are not faint of heart.
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
90 *
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
91 * Known formats to the VALID macro are:
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
92 * From user Wed Dec 2 05:53 1992
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
93 * BSD From user Wed Dec 2 05:53:22 1992
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
94 * SysV From user Wed Dec 2 05:53 PST 1992
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
95 * rn From user Wed Dec 2 05:53:22 PST 1992
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
96 * From user Wed Dec 2 05:53 -0700 1992
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
97 * emacs From user Wed Dec 2 05:53:22 -0700 1992
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
98 * From user Wed Dec 2 05:53 1992 PST
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
99 * From user Wed Dec 2 05:53:22 1992 PST
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
100 * From user Wed Dec 2 05:53 1992 -0700
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
101 * Solaris From user Wed Dec 2 05:53:22 1992 -0700
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
102 *
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
103 * Plus all of the above with `` remote from xxx'' after it. Thank you very
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
104 * much, smail and Solaris, for making my life considerably more complicated.
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
105 */
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
106
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
107 /*
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
108 * What? You want to understand the VALID macro anyway? Alright, since you
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
109 * insist. Actually, it isn't really all that difficult, provided that you
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
110 * take it step by step.
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
111 *
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
112 * Line 1 Initializes the return ti value to failure (0);
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
113 * Lines 2-3 Validates that the 1st-5th characters are ``From ''.
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
114 * Lines 4-6 Validates that there is an end of line and points x at it.
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
115 * Lines 7-14 First checks to see if the line is at least 41 characters long.
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
116 * If so, it scans backwards to find the rightmost space. From
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
117 * that point, it scans backwards to see if the string matches
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
118 * `` remote from''. If so, it sets x to point to the space at
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
119 * the start of the string.
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
120 * Line 15 Makes sure that there are at least 27 characters in the line.
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
121 * Lines 16-21 Checks if the date/time ends with the year (there is a space
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
122 * five characters back). If there is a colon three characters
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
123 * further back, there is no timezone field, so zn is set to 0
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
124 * and ti is set in front of the year. Otherwise, there must
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
125 * either to be a space four characters back for a three-letter
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
126 * timezone, or a space six characters back followed by a + or -
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
127 * for a numeric timezone; in either case, zn and ti become the
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
128 * offset of the space immediately before it.
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
129 * Lines 22-24 Are the failure case for line 14. If there is a space four
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
130 * characters back, it is a three-letter timezone; there must be a
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
131 * space for the year nine characters back. zn is the zone
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
132 * offset; ti is the offset of the space.
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
133 * Lines 25-28 Are the failure case for line 20. If there is a space six
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
134 * characters back, it is a numeric timezone; there must be a
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
135 * space eleven characters back and a + or - five characters back.
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
136 * zn is the zone offset; ti is the offset of the space.
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
137 * Line 29-32 If ti is valid, make sure that the string before ti is of the
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
138 * form www mmm dd hh:mm or www mmm dd hh:mm:ss, otherwise
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
139 * invalidate ti. There must be a colon three characters back
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
140 * and a space six or nine characters back (depending upon
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
141 * whether or not the character six characters back is a colon).
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
142 * There must be a space three characters further back (in front
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
143 * of the day), one seven characters back (in front of the month),
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
144 * and one eleven characters back (in front of the day of week).
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
145 * ti is set to be the offset of the space before the time.
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
146 *
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
147 * Why a macro? It gets invoked a *lot* in a tight loop. On some of the
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
148 * newer pipelined machines it is faster being open-coded than it would be if
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
149 * subroutines are called.
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
150 *
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
151 * Why does it scan backwards from the end of the line, instead of doing the
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
152 * much easier forward scan? There is no deterministic way to parse the
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
153 * ``user'' field, because it may contain unquoted spaces! Yes, I tested it to
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
154 * see if unquoted spaces were possible. They are, and I've encountered enough
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
155 * evil mail to be totally unwilling to trust that ``it will never happen''.
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
156 */
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
157
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
158 /* Build parameters */
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
159
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
160 #define KODRETRY 15 /* kiss-of-death retry in seconds */
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
161 #define LOCKTIMEOUT 5 /* lock timeout in minutes */

yatex.org