annotate protocol.c @ 38:8e972daaeab9 noffle

[svn] Applied patch from Jim Hague: - Forget cached group info when group database closed. - Added list of 'forbidden' newsgroup specs. - Fixed problem with article numbering if the overview file empties. - Changed %i to %d in sscanfs (%i interprets leading zeros as octal numbers) - New groups now always start numbering at article 1. - Record newsgroup posting status. Enforce it at posting time. Added --modify - Added group deletion. - Added wildmat code taken from INN
author enz
date Fri, 05 May 2000 08:23:15 +0100
parents d3fb34cb8198
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
1 /*
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
2 protocol.c
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
3
10
d3fb34cb8198 [svn] Added comment
enz
parents: 0
diff changeset
4 $Id: protocol.c 16 2000-04-11 06:50:16Z enz $
0
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
5 */
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
6
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
7 #include <ctype.h>
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
8 #include <netdb.h>
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
9 #include <sys/types.h>
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
10 #include <sys/utsname.h>
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
11 #include "common.h"
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
12 #include "dynamicstring.h"
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
13 #include "log.h"
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
14 #include "over.h"
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
15 #include "util.h"
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
16
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
17 Bool
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
18 Prt_getLn( Str line, FILE *f )
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
19 {
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
20 size_t len;
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
21
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
22 /*
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
23 We also accept lines ending with "\n" instead of "\r\n", some
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
24 clients wrongly send such lines.
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
25 */
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
26 if ( ! fgets( line, MAXCHAR, f ) )
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
27 {
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
28 Log_dbg( "Prt_getLine failed" );
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
29 return FALSE;
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
30 }
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
31 len = strlen( line );
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
32 if ( line[ len - 1 ] == '\n' )
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
33 {
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
34 line[ len - 1 ] = '\0';
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
35 if ( line[ len - 2 ] == '\r' )
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
36 line[ len - 2 ] = '\0';
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
37 }
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
38 Log_dbg( "[R] %s", line );
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
39 return TRUE;
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
40 }
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
41
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
42 Bool
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
43 Prt_getTxtLn( Str line, Bool *err, FILE *f )
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
44 {
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
45 Str buf;
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
46
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
47 if ( ! Prt_getLn( buf, f ) )
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
48 {
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
49 Log_err( "Cannot get text line" );
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
50 *err = TRUE;
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
51 return FALSE;
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
52 }
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
53 *err = FALSE;
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
54 if ( buf[ 0 ] == '.' )
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
55 {
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
56 if ( buf[ 1 ] == 0 )
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
57 return FALSE;
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
58 else
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
59 strcpy( line, buf + 1 );
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
60 }
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
61 else
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
62 strcpy( line, buf );
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
63 return TRUE;
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
64 }
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
65
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
66 Bool
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
67 Prt_putTxtLn( const char* line, FILE *f )
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
68 {
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
69 if ( line[ 0 ] == '.' )
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
70 {
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
71 Log_dbg( "[S] .%s", line );
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
72 return ( fprintf( f, ".%s\r\n", line ) == strlen( line ) + 3 );
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
73 }
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
74 else
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
75 {
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
76 Log_dbg( "[S] %s", line );
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
77 return ( fprintf( f, "%s\r\n", line ) == strlen( line ) + 2 );
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
78 }
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
79 }
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
80
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
81 Bool
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
82 Prt_putEndOfTxt( FILE *f )
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
83 {
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
84 Log_dbg( "[S] ." );
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
85 return ( fprintf( f, ".\r\n" ) == 3 );
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
86 }
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
87
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
88 /*
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
89 Write text buffer of lines each ending with '\n'.
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
90 Replace '\n' by "\r\n".
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
91 */
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
92 Bool
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
93 Prt_putTxtBuf( const char *buf, FILE *f )
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
94 {
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
95 Str line;
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
96 const char *pBuf;
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
97 char *pLn;
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
98
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
99 pBuf = buf;
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
100 pLn = line;
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
101 while ( *pBuf != '\0' )
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
102 {
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
103 if ( *pBuf == '\n' )
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
104 {
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
105 *pLn = '\0';
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
106 if ( ! Prt_putTxtLn( line, f ) )
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
107 return FALSE;
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
108 pLn = line;
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
109 ++pBuf;
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
110 }
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
111 else if ( pLn - line >= MAXCHAR - 1 )
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
112 {
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
113 /* Put it out raw to prevent String overflow */
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
114 Log_err( "Writing VERY long line" );
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
115 *pLn = '\0';
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
116 if ( fprintf( f, "%s", line ) != strlen( line ) )
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
117 return FALSE;
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
118 pLn = line;
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
119 }
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
120 else
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
121 *(pLn++) = *(pBuf++);
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
122 }
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
123 return TRUE;
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
124 }
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
125
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
126 Bool
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
127 Prt_getField( Str resultField, Str resultValue, const char* line )
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
128 {
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
129 char *dst;
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
130 const char *p;
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
131 Str lineLower, t;
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
132
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
133 Utl_cpyStr( lineLower, line );
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
134 Utl_toLower( lineLower );
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
135 p = Utl_stripWhiteSpace( lineLower );
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
136 dst = resultField;
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
137 while ( ! isspace( *p ) && *p != ':' && *p != '\0' )
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
138 *(dst++) = *(p++);
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
139 *dst = '\0';
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
140 while ( isspace( *p ) )
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
141 ++p;
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
142 if ( *p == ':' )
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
143 {
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
144 ++p;
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
145 strcpy( t, line + ( p - lineLower ) );
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
146 p = Utl_stripWhiteSpace( t );
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
147 strcpy( resultValue, p );
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
148 return TRUE;
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
149 }
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
150 return FALSE;
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
151 }
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
152
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
153 Bool
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
154 Prt_searchHeader( const char *artTxt, const char *which, Str result )
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
155 {
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
156 const char *src, *p;
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
157 char *dst;
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
158 Str line, whichLower, field;
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
159 int len;
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
160
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
161 Utl_cpyStr( whichLower, which );
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
162 Utl_toLower( whichLower );
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
163 src = artTxt;
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
164 while ( TRUE )
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
165 {
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
166 dst = line;
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
167 len = 0;
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
168 while ( *src != '\n' && len < MAXCHAR )
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
169 {
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
170 if ( *src == '\0' )
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
171 return FALSE;
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
172 *(dst++) = *(src++);
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
173 ++len;
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
174 }
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
175 if ( *src == '\n' )
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
176 ++src;
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
177 *dst = '\0';
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
178 p = Utl_stripWhiteSpace( line );
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
179 if ( *p == '\0' )
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
180 break;
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
181 if ( Prt_getField( field, result, line )
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
182 && strcmp( field, whichLower ) == 0 )
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
183 return TRUE;
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
184 }
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
185 return FALSE;
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
186 }
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
187
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
188 static Bool
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
189 getFQDN( Str result )
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
190 {
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
191 struct hostent *myHostEnt;
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
192 struct utsname myName;
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
193
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
194 if ( uname( &myName ) >= 0
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
195 && ( myHostEnt = gethostbyname( myName.nodename ) ) )
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
196 {
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
197 Utl_cpyStr( result, myHostEnt->h_name );
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
198 return TRUE;
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
199 }
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
200 return FALSE;
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
201 }
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
202
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
203 static void
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
204 getDomain( Str domain, const char *from )
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
205 {
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
206 const char *addTopLevel, *p1, *p2, *p, *domainStart;
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
207 Str myDomain;
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
208
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
209 if ( getFQDN( myDomain ) )
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
210 {
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
211 p = strstr( myDomain, "." );
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
212 if ( p != NULL )
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
213 domainStart = p + 1;
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
214 else
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
215 domainStart = myDomain;
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
216 }
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
217 else /* Take domain of From field */
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
218 {
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
219 myDomain[ 0 ] = '\0';
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
220 p1 = strstr( from, "@" );
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
221 if ( p1 != NULL )
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
222 {
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
223 p2 = strstr( p1, ">" );
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
224 if ( p2 != NULL )
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
225 Utl_cpyStrN( myDomain, p1 + 1, p2 - p1 - 1 );
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
226 }
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
227 if ( myDomain[ 0 ] == '\0' )
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
228 Utl_cpyStr( myDomain, "unknown" );
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
229 domainStart = myDomain;
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
230 }
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
231 /*
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
232 If domain contains no dot (and is probably invalid anyway),
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
233 we add ".local", because some servers insist on domainnames with dot
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
234 in message ID.
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
235 */
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
236 addTopLevel = strstr( domainStart, "." ) == NULL ? ".local" : "";
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
237 snprintf( domain, MAXCHAR, "%s%s", myDomain, addTopLevel );
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
238 }
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
239
10
d3fb34cb8198 [svn] Added comment
enz
parents: 0
diff changeset
240 /* See RFC 850, section 2.1.7 */
0
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
241 Bool
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
242 Prt_isValidMsgId( const char *msgId )
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
243 {
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
244 Str head, domain;
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
245 int len, headLen;
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
246 const char *p;
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
247
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
248 len = strlen( msgId );
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
249 p = strstr( msgId, "@" );
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
250 if ( msgId[ 0 ] != '<' || msgId[ len - 1 ] != '>' || p == NULL )
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
251 return FALSE;
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
252 strcpy( domain, p + 1 );
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
253 domain[ strlen( domain ) - 1 ] = '\0';
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
254 headLen = p - msgId - 1;
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
255 Utl_cpyStrN( head, msgId + 1, headLen );
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
256 head[ headLen ] = '\0';
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
257 /*
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
258 To do: check for special characters in head and domain (non-printable
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
259 or '@', '<', '>'). Maybe compare domain with a config option
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
260 and replace it by the config option, if not equal.
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
261 */
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
262 if ( strstr( domain, "." ) == NULL )
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
263 return FALSE;
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
264 return TRUE;
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
265 }
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
266
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
267 void
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
268 Prt_genMsgId( Str msgId, const char *from, const char *suffix )
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
269 {
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
270 Str domain, date;
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
271 time_t t;
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
272
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
273 getDomain( domain, from );
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
274 time( &t );
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
275 strftime( date, MAXCHAR, "%Y%m%d%H%M%S", gmtime( &t ) );
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
276 srand( time( NULL ) );
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
277 snprintf( msgId, MAXCHAR, "<%s.%X.%s@%s>", date, rand(), suffix, domain );
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
278 ASSERT( Prt_isValidMsgId( msgId ) );
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
279 }