Mercurial > noffle
annotate src/protocol.c @ 247:7a830ce3211e noffle
[svn] *** empty log message ***
author | mirkol |
---|---|
date | Tue, 26 Mar 2002 17:52:01 +0000 |
parents | 4e69e9b722ae |
children | 0340b9c17edc |
rev | line source |
---|---|
43
2842f50feb55
[svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff
changeset
|
1 /* |
2842f50feb55
[svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff
changeset
|
2 protocol.c |
2842f50feb55
[svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff
changeset
|
3 |
247 | 4 $Id: protocol.c 379 2002-03-26 17:52:01Z mirkol $ |
43
2842f50feb55
[svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff
changeset
|
5 */ |
2842f50feb55
[svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff
changeset
|
6 |
2842f50feb55
[svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff
changeset
|
7 #if HAVE_CONFIG_H |
2842f50feb55
[svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff
changeset
|
8 #include <config.h> |
2842f50feb55
[svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff
changeset
|
9 #endif |
2842f50feb55
[svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff
changeset
|
10 |
2842f50feb55
[svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff
changeset
|
11 #include <stdio.h> |
2842f50feb55
[svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff
changeset
|
12 #include <ctype.h> |
150
1c7303c71f66
[svn] * src/protocol.c: Fix bug in Prt_getLn if we should read a line
bears
parents:
144
diff
changeset
|
13 #include <pwd.h> |
144
8b9366fc1361
[svn] Added timeout to Prt_getLn to avoid Noffle hanging if the
enz
parents:
127
diff
changeset
|
14 #include <signal.h> |
43
2842f50feb55
[svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff
changeset
|
15 #include <sys/types.h> |
144
8b9366fc1361
[svn] Added timeout to Prt_getLn to avoid Noffle hanging if the
enz
parents:
127
diff
changeset
|
16 #include <unistd.h> |
43
2842f50feb55
[svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff
changeset
|
17 #include "common.h" |
151
cb799054bd61
[svn] Rats. Couple of warning slipped in during the last update. Fix 'em.
bears
parents:
150
diff
changeset
|
18 #include "configfile.h" |
43
2842f50feb55
[svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff
changeset
|
19 #include "dynamicstring.h" |
2842f50feb55
[svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff
changeset
|
20 #include "log.h" |
2842f50feb55
[svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff
changeset
|
21 #include "over.h" |
2842f50feb55
[svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff
changeset
|
22 #include "util.h" |
197
24d4cd032da5
[svn] * AUTHORS,INSTALL,NEWS,README,TODO,docs/NOTES,src/client.c,src/protocol.c,
bears
parents:
195
diff
changeset
|
23 #include "portable.h" |
45
32ba1198c6fa
[svn] * Makefile.in, configure, configure.in, docs/Makefile.in, src/Makefile.in:
uh1763
parents:
43
diff
changeset
|
24 #include "protocol.h" |
43
2842f50feb55
[svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff
changeset
|
25 |
144
8b9366fc1361
[svn] Added timeout to Prt_getLn to avoid Noffle hanging if the
enz
parents:
127
diff
changeset
|
26 static void |
8b9366fc1361
[svn] Added timeout to Prt_getLn to avoid Noffle hanging if the
enz
parents:
127
diff
changeset
|
27 readAlarm( int sig ) |
8b9366fc1361
[svn] Added timeout to Prt_getLn to avoid Noffle hanging if the
enz
parents:
127
diff
changeset
|
28 { |
8b9366fc1361
[svn] Added timeout to Prt_getLn to avoid Noffle hanging if the
enz
parents:
127
diff
changeset
|
29 UNUSED( sig ); |
8b9366fc1361
[svn] Added timeout to Prt_getLn to avoid Noffle hanging if the
enz
parents:
127
diff
changeset
|
30 |
8b9366fc1361
[svn] Added timeout to Prt_getLn to avoid Noffle hanging if the
enz
parents:
127
diff
changeset
|
31 return; |
8b9366fc1361
[svn] Added timeout to Prt_getLn to avoid Noffle hanging if the
enz
parents:
127
diff
changeset
|
32 } |
8b9366fc1361
[svn] Added timeout to Prt_getLn to avoid Noffle hanging if the
enz
parents:
127
diff
changeset
|
33 |
43
2842f50feb55
[svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff
changeset
|
34 Bool |
144
8b9366fc1361
[svn] Added timeout to Prt_getLn to avoid Noffle hanging if the
enz
parents:
127
diff
changeset
|
35 Prt_getLn( Str line, FILE *f, int timeoutSeconds ) |
43
2842f50feb55
[svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff
changeset
|
36 { |
2842f50feb55
[svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff
changeset
|
37 size_t len; |
144
8b9366fc1361
[svn] Added timeout to Prt_getLn to avoid Noffle hanging if the
enz
parents:
127
diff
changeset
|
38 char *ret; |
8b9366fc1361
[svn] Added timeout to Prt_getLn to avoid Noffle hanging if the
enz
parents:
127
diff
changeset
|
39 sig_t oldHandler = NULL; |
43
2842f50feb55
[svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff
changeset
|
40 |
144
8b9366fc1361
[svn] Added timeout to Prt_getLn to avoid Noffle hanging if the
enz
parents:
127
diff
changeset
|
41 if ( timeoutSeconds >= 0 ) |
8b9366fc1361
[svn] Added timeout to Prt_getLn to avoid Noffle hanging if the
enz
parents:
127
diff
changeset
|
42 { |
164
94f2e5607772
[svn] * src/client.c,src/protocol.c,src/util.h,src/util.c: Common up
bears
parents:
151
diff
changeset
|
43 oldHandler = Utl_installSignalHandler( SIGALRM, readAlarm ); |
144
8b9366fc1361
[svn] Added timeout to Prt_getLn to avoid Noffle hanging if the
enz
parents:
127
diff
changeset
|
44 if ( oldHandler == SIG_ERR ) |
8b9366fc1361
[svn] Added timeout to Prt_getLn to avoid Noffle hanging if the
enz
parents:
127
diff
changeset
|
45 { |
8b9366fc1361
[svn] Added timeout to Prt_getLn to avoid Noffle hanging if the
enz
parents:
127
diff
changeset
|
46 Log_err( "Prt_getLn: signal failed." ); |
8b9366fc1361
[svn] Added timeout to Prt_getLn to avoid Noffle hanging if the
enz
parents:
127
diff
changeset
|
47 return FALSE; |
8b9366fc1361
[svn] Added timeout to Prt_getLn to avoid Noffle hanging if the
enz
parents:
127
diff
changeset
|
48 } |
8b9366fc1361
[svn] Added timeout to Prt_getLn to avoid Noffle hanging if the
enz
parents:
127
diff
changeset
|
49 if ( alarm( timeoutSeconds ) != 0 ) |
8b9366fc1361
[svn] Added timeout to Prt_getLn to avoid Noffle hanging if the
enz
parents:
127
diff
changeset
|
50 Log_err( "Prt_getLn: Alarm was already set." ); |
8b9366fc1361
[svn] Added timeout to Prt_getLn to avoid Noffle hanging if the
enz
parents:
127
diff
changeset
|
51 } |
43
2842f50feb55
[svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff
changeset
|
52 /* |
2842f50feb55
[svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff
changeset
|
53 We also accept lines ending with "\n" instead of "\r\n", some |
2842f50feb55
[svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff
changeset
|
54 clients wrongly send such lines. |
2842f50feb55
[svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff
changeset
|
55 */ |
144
8b9366fc1361
[svn] Added timeout to Prt_getLn to avoid Noffle hanging if the
enz
parents:
127
diff
changeset
|
56 ret = fgets( line, MAXCHAR, f ); |
8b9366fc1361
[svn] Added timeout to Prt_getLn to avoid Noffle hanging if the
enz
parents:
127
diff
changeset
|
57 if ( timeoutSeconds >= 0 ) |
43
2842f50feb55
[svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff
changeset
|
58 { |
144
8b9366fc1361
[svn] Added timeout to Prt_getLn to avoid Noffle hanging if the
enz
parents:
127
diff
changeset
|
59 alarm( 0 ); |
164
94f2e5607772
[svn] * src/client.c,src/protocol.c,src/util.h,src/util.c: Common up
bears
parents:
151
diff
changeset
|
60 Utl_installSignalHandler( SIGALRM, oldHandler ); |
144
8b9366fc1361
[svn] Added timeout to Prt_getLn to avoid Noffle hanging if the
enz
parents:
127
diff
changeset
|
61 } |
8b9366fc1361
[svn] Added timeout to Prt_getLn to avoid Noffle hanging if the
enz
parents:
127
diff
changeset
|
62 if ( ret == NULL ) |
43
2842f50feb55
[svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff
changeset
|
63 return FALSE; |
2842f50feb55
[svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff
changeset
|
64 len = strlen( line ); |
150
1c7303c71f66
[svn] * src/protocol.c: Fix bug in Prt_getLn if we should read a line
bears
parents:
144
diff
changeset
|
65 if ( len > 0 && line[ len - 1 ] == '\n' ) |
43
2842f50feb55
[svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff
changeset
|
66 { |
2842f50feb55
[svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff
changeset
|
67 line[ len - 1 ] = '\0'; |
150
1c7303c71f66
[svn] * src/protocol.c: Fix bug in Prt_getLn if we should read a line
bears
parents:
144
diff
changeset
|
68 if ( len > 1 && line[ len - 2 ] == '\r' ) |
43
2842f50feb55
[svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff
changeset
|
69 line[ len - 2 ] = '\0'; |
2842f50feb55
[svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff
changeset
|
70 } |
185
fed1334d766b
[svn] * src/client.c: Change variable only used on constant to 'const'.
bears
parents:
164
diff
changeset
|
71 Log_dbg( LOG_DBG_PROTOCOL, "[R] %s", line ); |
43
2842f50feb55
[svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff
changeset
|
72 return TRUE; |
2842f50feb55
[svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff
changeset
|
73 } |
2842f50feb55
[svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff
changeset
|
74 |
2842f50feb55
[svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff
changeset
|
75 Bool |
197
24d4cd032da5
[svn] * AUTHORS,INSTALL,NEWS,README,TODO,docs/NOTES,src/client.c,src/protocol.c,
bears
parents:
195
diff
changeset
|
76 Prt_getTxtLn( Str line, Bool *err, FILE *f, int timeoutSeconds ) |
43
2842f50feb55
[svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff
changeset
|
77 { |
2842f50feb55
[svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff
changeset
|
78 Str buf; |
2842f50feb55
[svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff
changeset
|
79 |
144
8b9366fc1361
[svn] Added timeout to Prt_getLn to avoid Noffle hanging if the
enz
parents:
127
diff
changeset
|
80 if ( ! Prt_getLn( buf, f, timeoutSeconds ) ) |
43
2842f50feb55
[svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff
changeset
|
81 { |
2842f50feb55
[svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff
changeset
|
82 Log_err( "Cannot get text line" ); |
2842f50feb55
[svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff
changeset
|
83 *err = TRUE; |
2842f50feb55
[svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff
changeset
|
84 return FALSE; |
2842f50feb55
[svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff
changeset
|
85 } |
2842f50feb55
[svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff
changeset
|
86 *err = FALSE; |
2842f50feb55
[svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff
changeset
|
87 if ( buf[ 0 ] == '.' ) |
2842f50feb55
[svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff
changeset
|
88 { |
2842f50feb55
[svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff
changeset
|
89 if ( buf[ 1 ] == 0 ) |
2842f50feb55
[svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff
changeset
|
90 return FALSE; |
2842f50feb55
[svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff
changeset
|
91 else |
2842f50feb55
[svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff
changeset
|
92 strcpy( line, buf + 1 ); |
2842f50feb55
[svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff
changeset
|
93 } |
2842f50feb55
[svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff
changeset
|
94 else |
2842f50feb55
[svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff
changeset
|
95 strcpy( line, buf ); |
2842f50feb55
[svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff
changeset
|
96 return TRUE; |
2842f50feb55
[svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff
changeset
|
97 } |
2842f50feb55
[svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff
changeset
|
98 |
2842f50feb55
[svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff
changeset
|
99 Bool |
2842f50feb55
[svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff
changeset
|
100 Prt_putTxtLn( const char* line, FILE *f ) |
2842f50feb55
[svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff
changeset
|
101 { |
2842f50feb55
[svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff
changeset
|
102 if ( line[ 0 ] == '.' ) |
2842f50feb55
[svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff
changeset
|
103 { |
185
fed1334d766b
[svn] * src/client.c: Change variable only used on constant to 'const'.
bears
parents:
164
diff
changeset
|
104 Log_dbg( LOG_DBG_PROTOCOL, "[S] .%s", line ); |
59
e612b263934f
[svn] Changed some variable types and used some casts to avoid compiler
enz
parents:
54
diff
changeset
|
105 return ( fprintf( f, ".%s\r\n", line ) == (int)strlen( line ) + 3 ); |
43
2842f50feb55
[svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff
changeset
|
106 } |
2842f50feb55
[svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff
changeset
|
107 else |
2842f50feb55
[svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff
changeset
|
108 { |
185
fed1334d766b
[svn] * src/client.c: Change variable only used on constant to 'const'.
bears
parents:
164
diff
changeset
|
109 Log_dbg( LOG_DBG_PROTOCOL, "[S] %s", line ); |
59
e612b263934f
[svn] Changed some variable types and used some casts to avoid compiler
enz
parents:
54
diff
changeset
|
110 return ( fprintf( f, "%s\r\n", line ) == (int)strlen( line ) + 2 ); |
43
2842f50feb55
[svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff
changeset
|
111 } |
2842f50feb55
[svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff
changeset
|
112 } |
2842f50feb55
[svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff
changeset
|
113 |
2842f50feb55
[svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff
changeset
|
114 Bool |
2842f50feb55
[svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff
changeset
|
115 Prt_putEndOfTxt( FILE *f ) |
2842f50feb55
[svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff
changeset
|
116 { |
185
fed1334d766b
[svn] * src/client.c: Change variable only used on constant to 'const'.
bears
parents:
164
diff
changeset
|
117 Log_dbg( LOG_DBG_PROTOCOL, "[S] ." ); |
43
2842f50feb55
[svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff
changeset
|
118 return ( fprintf( f, ".\r\n" ) == 3 ); |
2842f50feb55
[svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff
changeset
|
119 } |
2842f50feb55
[svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff
changeset
|
120 |
2842f50feb55
[svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff
changeset
|
121 /* |
2842f50feb55
[svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff
changeset
|
122 Write text buffer of lines each ending with '\n'. |
2842f50feb55
[svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff
changeset
|
123 Replace '\n' by "\r\n". |
2842f50feb55
[svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff
changeset
|
124 */ |
2842f50feb55
[svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff
changeset
|
125 Bool |
2842f50feb55
[svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff
changeset
|
126 Prt_putTxtBuf( const char *buf, FILE *f ) |
2842f50feb55
[svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff
changeset
|
127 { |
2842f50feb55
[svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff
changeset
|
128 Str line; |
2842f50feb55
[svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff
changeset
|
129 const char *pBuf; |
2842f50feb55
[svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff
changeset
|
130 char *pLn; |
2842f50feb55
[svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff
changeset
|
131 |
2842f50feb55
[svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff
changeset
|
132 pBuf = buf; |
2842f50feb55
[svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff
changeset
|
133 pLn = line; |
2842f50feb55
[svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff
changeset
|
134 while ( *pBuf != '\0' ) |
2842f50feb55
[svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff
changeset
|
135 { |
2842f50feb55
[svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff
changeset
|
136 if ( *pBuf == '\n' ) |
2842f50feb55
[svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff
changeset
|
137 { |
2842f50feb55
[svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff
changeset
|
138 *pLn = '\0'; |
2842f50feb55
[svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff
changeset
|
139 if ( ! Prt_putTxtLn( line, f ) ) |
2842f50feb55
[svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff
changeset
|
140 return FALSE; |
2842f50feb55
[svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff
changeset
|
141 pLn = line; |
2842f50feb55
[svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff
changeset
|
142 ++pBuf; |
2842f50feb55
[svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff
changeset
|
143 } |
2842f50feb55
[svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff
changeset
|
144 else if ( pLn - line >= MAXCHAR - 1 ) |
2842f50feb55
[svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff
changeset
|
145 { |
2842f50feb55
[svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff
changeset
|
146 /* Put it out raw to prevent String overflow */ |
2842f50feb55
[svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff
changeset
|
147 Log_err( "Writing VERY long line" ); |
2842f50feb55
[svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff
changeset
|
148 *pLn = '\0'; |
59
e612b263934f
[svn] Changed some variable types and used some casts to avoid compiler
enz
parents:
54
diff
changeset
|
149 if ( fprintf( f, "%s", line ) != (int)strlen( line ) ) |
43
2842f50feb55
[svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff
changeset
|
150 return FALSE; |
2842f50feb55
[svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff
changeset
|
151 pLn = line; |
2842f50feb55
[svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff
changeset
|
152 } |
2842f50feb55
[svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff
changeset
|
153 else |
2842f50feb55
[svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff
changeset
|
154 *(pLn++) = *(pBuf++); |
2842f50feb55
[svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff
changeset
|
155 } |
2842f50feb55
[svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff
changeset
|
156 return TRUE; |
2842f50feb55
[svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff
changeset
|
157 } |
2842f50feb55
[svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff
changeset
|
158 |
2842f50feb55
[svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff
changeset
|
159 Bool |
2842f50feb55
[svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff
changeset
|
160 Prt_getField( Str resultField, Str resultValue, const char* line ) |
2842f50feb55
[svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff
changeset
|
161 { |
2842f50feb55
[svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff
changeset
|
162 char *dst; |
2842f50feb55
[svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff
changeset
|
163 const char *p; |
2842f50feb55
[svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff
changeset
|
164 Str lineLower, t; |
2842f50feb55
[svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff
changeset
|
165 |
2842f50feb55
[svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff
changeset
|
166 Utl_cpyStr( lineLower, line ); |
2842f50feb55
[svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff
changeset
|
167 Utl_toLower( lineLower ); |
2842f50feb55
[svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff
changeset
|
168 p = Utl_stripWhiteSpace( lineLower ); |
247 | 169 if ( p == lineLower ) |
43
2842f50feb55
[svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff
changeset
|
170 { |
247 | 171 dst = resultField; |
172 while ( ! isspace( *p ) && *p != ':' && *p != '\0' ) | |
173 *(dst++) = *(p++); | |
174 *dst = '\0'; | |
175 while ( isspace( *p ) ) | |
176 ++p; | |
177 if ( *p == ':' ) | |
178 { | |
179 ++p; | |
180 strcpy( t, line + ( p - lineLower ) ); | |
181 p = Utl_stripWhiteSpace( t ); | |
182 strcpy( resultValue, p ); | |
183 return TRUE; | |
184 } | |
185 } | |
186 else /* continued header. */ | |
187 { | |
188 strcpy( resultValue, lineLower ); /* include starting whitespace */ | |
189 return TRUE; | |
43
2842f50feb55
[svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff
changeset
|
190 } |
2842f50feb55
[svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff
changeset
|
191 return FALSE; |
2842f50feb55
[svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff
changeset
|
192 } |
2842f50feb55
[svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff
changeset
|
193 |
2842f50feb55
[svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff
changeset
|
194 Bool |
2842f50feb55
[svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff
changeset
|
195 Prt_searchHeader( const char *artTxt, const char *which, Str result ) |
2842f50feb55
[svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff
changeset
|
196 { |
2842f50feb55
[svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff
changeset
|
197 const char *src, *p; |
2842f50feb55
[svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff
changeset
|
198 char *dst; |
2842f50feb55
[svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff
changeset
|
199 Str line, whichLower, field; |
2842f50feb55
[svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff
changeset
|
200 int len; |
2842f50feb55
[svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff
changeset
|
201 |
2842f50feb55
[svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff
changeset
|
202 Utl_cpyStr( whichLower, which ); |
2842f50feb55
[svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff
changeset
|
203 Utl_toLower( whichLower ); |
2842f50feb55
[svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff
changeset
|
204 src = artTxt; |
2842f50feb55
[svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff
changeset
|
205 while ( TRUE ) |
2842f50feb55
[svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff
changeset
|
206 { |
2842f50feb55
[svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff
changeset
|
207 dst = line; |
2842f50feb55
[svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff
changeset
|
208 len = 0; |
2842f50feb55
[svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff
changeset
|
209 while ( *src != '\n' && len < MAXCHAR ) |
2842f50feb55
[svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff
changeset
|
210 { |
2842f50feb55
[svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff
changeset
|
211 if ( *src == '\0' ) |
2842f50feb55
[svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff
changeset
|
212 return FALSE; |
2842f50feb55
[svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff
changeset
|
213 *(dst++) = *(src++); |
2842f50feb55
[svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff
changeset
|
214 ++len; |
2842f50feb55
[svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff
changeset
|
215 } |
2842f50feb55
[svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff
changeset
|
216 if ( *src == '\n' ) |
2842f50feb55
[svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff
changeset
|
217 ++src; |
2842f50feb55
[svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff
changeset
|
218 *dst = '\0'; |
2842f50feb55
[svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff
changeset
|
219 p = Utl_stripWhiteSpace( line ); |
2842f50feb55
[svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff
changeset
|
220 if ( *p == '\0' ) |
2842f50feb55
[svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff
changeset
|
221 break; |
2842f50feb55
[svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff
changeset
|
222 if ( Prt_getField( field, result, line ) |
2842f50feb55
[svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff
changeset
|
223 && strcmp( field, whichLower ) == 0 ) |
2842f50feb55
[svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff
changeset
|
224 return TRUE; |
2842f50feb55
[svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff
changeset
|
225 } |
2842f50feb55
[svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff
changeset
|
226 return FALSE; |
2842f50feb55
[svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff
changeset
|
227 } |
2842f50feb55
[svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff
changeset
|
228 |
2842f50feb55
[svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff
changeset
|
229 static void |
2842f50feb55
[svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff
changeset
|
230 getDomain( Str domain, const char *from ) |
2842f50feb55
[svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff
changeset
|
231 { |
2842f50feb55
[svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff
changeset
|
232 const char *addTopLevel, *p1, *p2, *p, *domainStart; |
2842f50feb55
[svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff
changeset
|
233 Str myDomain; |
2842f50feb55
[svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff
changeset
|
234 |
244
4e69e9b722ae
[svn] * src/database.c,src/protocol.c,src/util.c,src/util.h: The latest IETF
bears
parents:
221
diff
changeset
|
235 if ( Utl_getFQDN( myDomain ) ) |
43
2842f50feb55
[svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff
changeset
|
236 { |
2842f50feb55
[svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff
changeset
|
237 p = strstr( myDomain, "." ); |
2842f50feb55
[svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff
changeset
|
238 if ( p != NULL ) |
2842f50feb55
[svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff
changeset
|
239 domainStart = p + 1; |
2842f50feb55
[svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff
changeset
|
240 else |
2842f50feb55
[svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff
changeset
|
241 domainStart = myDomain; |
2842f50feb55
[svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff
changeset
|
242 } |
2842f50feb55
[svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff
changeset
|
243 else /* Take domain of From field */ |
2842f50feb55
[svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff
changeset
|
244 { |
2842f50feb55
[svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff
changeset
|
245 myDomain[ 0 ] = '\0'; |
2842f50feb55
[svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff
changeset
|
246 p1 = strstr( from, "@" ); |
2842f50feb55
[svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff
changeset
|
247 if ( p1 != NULL ) |
2842f50feb55
[svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff
changeset
|
248 { |
2842f50feb55
[svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff
changeset
|
249 p2 = strstr( p1, ">" ); |
2842f50feb55
[svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff
changeset
|
250 if ( p2 != NULL ) |
2842f50feb55
[svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff
changeset
|
251 Utl_cpyStrN( myDomain, p1 + 1, p2 - p1 - 1 ); |
2842f50feb55
[svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff
changeset
|
252 } |
2842f50feb55
[svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff
changeset
|
253 if ( myDomain[ 0 ] == '\0' ) |
2842f50feb55
[svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff
changeset
|
254 Utl_cpyStr( myDomain, "unknown" ); |
2842f50feb55
[svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff
changeset
|
255 domainStart = myDomain; |
2842f50feb55
[svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff
changeset
|
256 } |
2842f50feb55
[svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff
changeset
|
257 /* |
2842f50feb55
[svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff
changeset
|
258 If domain contains no dot (and is probably invalid anyway), |
2842f50feb55
[svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff
changeset
|
259 we add ".local", because some servers insist on domainnames with dot |
2842f50feb55
[svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff
changeset
|
260 in message ID. |
2842f50feb55
[svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff
changeset
|
261 */ |
2842f50feb55
[svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff
changeset
|
262 addTopLevel = strstr( domainStart, "." ) == NULL ? ".local" : ""; |
2842f50feb55
[svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff
changeset
|
263 snprintf( domain, MAXCHAR, "%s%s", myDomain, addTopLevel ); |
2842f50feb55
[svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff
changeset
|
264 } |
2842f50feb55
[svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff
changeset
|
265 |
2842f50feb55
[svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff
changeset
|
266 /* See RFC 850, section 2.1.7 */ |
2842f50feb55
[svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff
changeset
|
267 Bool |
2842f50feb55
[svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff
changeset
|
268 Prt_isValidMsgId( const char *msgId ) |
2842f50feb55
[svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff
changeset
|
269 { |
2842f50feb55
[svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff
changeset
|
270 Str head, domain; |
2842f50feb55
[svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff
changeset
|
271 int len, headLen; |
2842f50feb55
[svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff
changeset
|
272 const char *p; |
2842f50feb55
[svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff
changeset
|
273 |
2842f50feb55
[svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff
changeset
|
274 len = strlen( msgId ); |
2842f50feb55
[svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff
changeset
|
275 p = strstr( msgId, "@" ); |
2842f50feb55
[svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff
changeset
|
276 if ( msgId[ 0 ] != '<' || msgId[ len - 1 ] != '>' || p == NULL ) |
2842f50feb55
[svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff
changeset
|
277 return FALSE; |
2842f50feb55
[svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff
changeset
|
278 strcpy( domain, p + 1 ); |
2842f50feb55
[svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff
changeset
|
279 domain[ strlen( domain ) - 1 ] = '\0'; |
2842f50feb55
[svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff
changeset
|
280 headLen = p - msgId - 1; |
2842f50feb55
[svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff
changeset
|
281 Utl_cpyStrN( head, msgId + 1, headLen ); |
2842f50feb55
[svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff
changeset
|
282 head[ headLen ] = '\0'; |
2842f50feb55
[svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff
changeset
|
283 /* |
2842f50feb55
[svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff
changeset
|
284 To do: check for special characters in head and domain (non-printable |
2842f50feb55
[svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff
changeset
|
285 or '@', '<', '>'). Maybe compare domain with a config option |
2842f50feb55
[svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff
changeset
|
286 and replace it by the config option, if not equal. |
2842f50feb55
[svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff
changeset
|
287 */ |
2842f50feb55
[svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff
changeset
|
288 if ( strstr( domain, "." ) == NULL ) |
2842f50feb55
[svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff
changeset
|
289 return FALSE; |
2842f50feb55
[svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff
changeset
|
290 return TRUE; |
2842f50feb55
[svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff
changeset
|
291 } |
2842f50feb55
[svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff
changeset
|
292 |
2842f50feb55
[svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff
changeset
|
293 void |
2842f50feb55
[svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff
changeset
|
294 Prt_genMsgId( Str msgId, const char *from, const char *suffix ) |
2842f50feb55
[svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff
changeset
|
295 { |
2842f50feb55
[svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff
changeset
|
296 Str domain, date; |
2842f50feb55
[svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff
changeset
|
297 time_t t; |
221
0eaf93997170
[svn] generate MessageID with pid and index number, not with random number.
mirkol
parents:
197
diff
changeset
|
298 static long count = 0; |
43
2842f50feb55
[svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff
changeset
|
299 |
2842f50feb55
[svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff
changeset
|
300 getDomain( domain, from ); |
2842f50feb55
[svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff
changeset
|
301 time( &t ); |
2842f50feb55
[svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff
changeset
|
302 strftime( date, MAXCHAR, "%Y%m%d%H%M%S", gmtime( &t ) ); |
221
0eaf93997170
[svn] generate MessageID with pid and index number, not with random number.
mirkol
parents:
197
diff
changeset
|
303 snprintf( msgId, MAXCHAR, "<%s.%X.%lx.%s@%s>", date, getpid(), count++ ,suffix, domain ); |
43
2842f50feb55
[svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff
changeset
|
304 ASSERT( Prt_isValidMsgId( msgId ) ); |
2842f50feb55
[svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff
changeset
|
305 } |
111 | 306 |
307 void | |
308 Prt_genPathHdr( Str pathHdr, const char *from ) | |
309 { | |
310 getDomain( pathHdr, from ); | |
311 Utl_catStr( pathHdr, "!not-for-mail" ); | |
312 } | |
313 | |
150
1c7303c71f66
[svn] * src/protocol.c: Fix bug in Prt_getLn if we should read a line
bears
parents:
144
diff
changeset
|
314 Bool |
1c7303c71f66
[svn] * src/protocol.c: Fix bug in Prt_getLn if we should read a line
bears
parents:
144
diff
changeset
|
315 Prt_genFromHdr( Str fromHdr ) |
1c7303c71f66
[svn] * src/protocol.c: Fix bug in Prt_getLn if we should read a line
bears
parents:
144
diff
changeset
|
316 { |
1c7303c71f66
[svn] * src/protocol.c: Fix bug in Prt_getLn if we should read a line
bears
parents:
144
diff
changeset
|
317 Str name, domain; |
1c7303c71f66
[svn] * src/protocol.c: Fix bug in Prt_getLn if we should read a line
bears
parents:
144
diff
changeset
|
318 const char *nameval; |
1c7303c71f66
[svn] * src/protocol.c: Fix bug in Prt_getLn if we should read a line
bears
parents:
144
diff
changeset
|
319 struct passwd *pwd; |
1c7303c71f66
[svn] * src/protocol.c: Fix bug in Prt_getLn if we should read a line
bears
parents:
144
diff
changeset
|
320 |
1c7303c71f66
[svn] * src/protocol.c: Fix bug in Prt_getLn if we should read a line
bears
parents:
144
diff
changeset
|
321 /* First get the domain to use. If config empty, use FQDN */ |
1c7303c71f66
[svn] * src/protocol.c: Fix bug in Prt_getLn if we should read a line
bears
parents:
144
diff
changeset
|
322 Utl_cpyStr( domain, Cfg_fromDomain() ); |
1c7303c71f66
[svn] * src/protocol.c: Fix bug in Prt_getLn if we should read a line
bears
parents:
144
diff
changeset
|
323 |
151
cb799054bd61
[svn] Rats. Couple of warning slipped in during the last update. Fix 'em.
bears
parents:
150
diff
changeset
|
324 if ( strlen( domain ) == 0 ) |
244
4e69e9b722ae
[svn] * src/database.c,src/protocol.c,src/util.c,src/util.h: The latest IETF
bears
parents:
221
diff
changeset
|
325 if ( ! Utl_getFQDN( domain ) ) |
150
1c7303c71f66
[svn] * src/protocol.c: Fix bug in Prt_getLn if we should read a line
bears
parents:
144
diff
changeset
|
326 Utl_catStr( domain, "unknown" ); |
1c7303c71f66
[svn] * src/protocol.c: Fix bug in Prt_getLn if we should read a line
bears
parents:
144
diff
changeset
|
327 |
1c7303c71f66
[svn] * src/protocol.c: Fix bug in Prt_getLn if we should read a line
bears
parents:
144
diff
changeset
|
328 /* Now get pwd for the username */ |
1c7303c71f66
[svn] * src/protocol.c: Fix bug in Prt_getLn if we should read a line
bears
parents:
144
diff
changeset
|
329 pwd = getpwuid( getuid() ); |
1c7303c71f66
[svn] * src/protocol.c: Fix bug in Prt_getLn if we should read a line
bears
parents:
144
diff
changeset
|
330 if ( pwd == NULL ) |
1c7303c71f66
[svn] * src/protocol.c: Fix bug in Prt_getLn if we should read a line
bears
parents:
144
diff
changeset
|
331 return FALSE; |
1c7303c71f66
[svn] * src/protocol.c: Fix bug in Prt_getLn if we should read a line
bears
parents:
144
diff
changeset
|
332 |
1c7303c71f66
[svn] * src/protocol.c: Fix bug in Prt_getLn if we should read a line
bears
parents:
144
diff
changeset
|
333 /* Now for their name - use env NAME if available */ |
1c7303c71f66
[svn] * src/protocol.c: Fix bug in Prt_getLn if we should read a line
bears
parents:
144
diff
changeset
|
334 nameval = getenv( "NAME" ); |
1c7303c71f66
[svn] * src/protocol.c: Fix bug in Prt_getLn if we should read a line
bears
parents:
144
diff
changeset
|
335 if ( nameval != NULL ) |
1c7303c71f66
[svn] * src/protocol.c: Fix bug in Prt_getLn if we should read a line
bears
parents:
144
diff
changeset
|
336 Utl_cpyStr( name, nameval ); |
1c7303c71f66
[svn] * src/protocol.c: Fix bug in Prt_getLn if we should read a line
bears
parents:
144
diff
changeset
|
337 else |
1c7303c71f66
[svn] * src/protocol.c: Fix bug in Prt_getLn if we should read a line
bears
parents:
144
diff
changeset
|
338 { |
1c7303c71f66
[svn] * src/protocol.c: Fix bug in Prt_getLn if we should read a line
bears
parents:
144
diff
changeset
|
339 char *p; |
1c7303c71f66
[svn] * src/protocol.c: Fix bug in Prt_getLn if we should read a line
bears
parents:
144
diff
changeset
|
340 |
1c7303c71f66
[svn] * src/protocol.c: Fix bug in Prt_getLn if we should read a line
bears
parents:
144
diff
changeset
|
341 /* |
1c7303c71f66
[svn] * src/protocol.c: Fix bug in Prt_getLn if we should read a line
bears
parents:
144
diff
changeset
|
342 Extract from GECOS field. Following the lead of the INN inews, |
1c7303c71f66
[svn] * src/protocol.c: Fix bug in Prt_getLn if we should read a line
bears
parents:
144
diff
changeset
|
343 ignore leading stuff like "23-" "stuff]-" or "stuff -" as well |
1c7303c71f66
[svn] * src/protocol.c: Fix bug in Prt_getLn if we should read a line
bears
parents:
144
diff
changeset
|
344 as trailing whitespace, or anything that comes after |
1c7303c71f66
[svn] * src/protocol.c: Fix bug in Prt_getLn if we should read a line
bears
parents:
144
diff
changeset
|
345 a comma or semicolon. |
1c7303c71f66
[svn] * src/protocol.c: Fix bug in Prt_getLn if we should read a line
bears
parents:
144
diff
changeset
|
346 */ |
1c7303c71f66
[svn] * src/protocol.c: Fix bug in Prt_getLn if we should read a line
bears
parents:
144
diff
changeset
|
347 nameval = pwd->pw_gecos; |
1c7303c71f66
[svn] * src/protocol.c: Fix bug in Prt_getLn if we should read a line
bears
parents:
144
diff
changeset
|
348 p = strchr( nameval, '-' ); |
1c7303c71f66
[svn] * src/protocol.c: Fix bug in Prt_getLn if we should read a line
bears
parents:
144
diff
changeset
|
349 if ( p != NULL && p > nameval && |
1c7303c71f66
[svn] * src/protocol.c: Fix bug in Prt_getLn if we should read a line
bears
parents:
144
diff
changeset
|
350 ( p[-1] == ']' || p[-1] == ' ' || isdigit( p[ -1 ] ) ) ) |
1c7303c71f66
[svn] * src/protocol.c: Fix bug in Prt_getLn if we should read a line
bears
parents:
144
diff
changeset
|
351 nameval = p; |
1c7303c71f66
[svn] * src/protocol.c: Fix bug in Prt_getLn if we should read a line
bears
parents:
144
diff
changeset
|
352 p = strrchr( nameval, ',' ); |
1c7303c71f66
[svn] * src/protocol.c: Fix bug in Prt_getLn if we should read a line
bears
parents:
144
diff
changeset
|
353 if ( p != NULL ) |
1c7303c71f66
[svn] * src/protocol.c: Fix bug in Prt_getLn if we should read a line
bears
parents:
144
diff
changeset
|
354 *p = '\0'; |
1c7303c71f66
[svn] * src/protocol.c: Fix bug in Prt_getLn if we should read a line
bears
parents:
144
diff
changeset
|
355 p = strchr( nameval, ';' ); |
1c7303c71f66
[svn] * src/protocol.c: Fix bug in Prt_getLn if we should read a line
bears
parents:
144
diff
changeset
|
356 if ( p != NULL ) |
1c7303c71f66
[svn] * src/protocol.c: Fix bug in Prt_getLn if we should read a line
bears
parents:
144
diff
changeset
|
357 *p = '\0'; |
1c7303c71f66
[svn] * src/protocol.c: Fix bug in Prt_getLn if we should read a line
bears
parents:
144
diff
changeset
|
358 Utl_cpyStr( name, nameval ); |
1c7303c71f66
[svn] * src/protocol.c: Fix bug in Prt_getLn if we should read a line
bears
parents:
144
diff
changeset
|
359 } |
1c7303c71f66
[svn] * src/protocol.c: Fix bug in Prt_getLn if we should read a line
bears
parents:
144
diff
changeset
|
360 |
1c7303c71f66
[svn] * src/protocol.c: Fix bug in Prt_getLn if we should read a line
bears
parents:
144
diff
changeset
|
361 /* OK, build From: contents */ |
1c7303c71f66
[svn] * src/protocol.c: Fix bug in Prt_getLn if we should read a line
bears
parents:
144
diff
changeset
|
362 Utl_cpyStr( fromHdr, pwd->pw_name ); |
1c7303c71f66
[svn] * src/protocol.c: Fix bug in Prt_getLn if we should read a line
bears
parents:
144
diff
changeset
|
363 Utl_catStr( fromHdr, "@" ); |
1c7303c71f66
[svn] * src/protocol.c: Fix bug in Prt_getLn if we should read a line
bears
parents:
144
diff
changeset
|
364 Utl_catStr( fromHdr, domain ); |
1c7303c71f66
[svn] * src/protocol.c: Fix bug in Prt_getLn if we should read a line
bears
parents:
144
diff
changeset
|
365 Utl_catStr( fromHdr, " (" ); |
1c7303c71f66
[svn] * src/protocol.c: Fix bug in Prt_getLn if we should read a line
bears
parents:
144
diff
changeset
|
366 Utl_catStr( fromHdr, name ); |
1c7303c71f66
[svn] * src/protocol.c: Fix bug in Prt_getLn if we should read a line
bears
parents:
144
diff
changeset
|
367 Utl_catStr( fromHdr, ")" ); |
1c7303c71f66
[svn] * src/protocol.c: Fix bug in Prt_getLn if we should read a line
bears
parents:
144
diff
changeset
|
368 |
1c7303c71f66
[svn] * src/protocol.c: Fix bug in Prt_getLn if we should read a line
bears
parents:
144
diff
changeset
|
369 return TRUE; |
1c7303c71f66
[svn] * src/protocol.c: Fix bug in Prt_getLn if we should read a line
bears
parents:
144
diff
changeset
|
370 } |
111 | 371 |
372 | |
373 |