annotate src/protocol.c @ 500:614a3177b15c noffle tip

Add mail-from option. Some modern mail systems will try and ensure the sender email is a legitimate address. Which will fail if there isn't such an address.
author Jim Hague <jim.hague@acm.org>
date Wed, 14 Aug 2013 12:04:39 +0100
parents 4426f4dc6e8b
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
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
436
4426f4dc6e8b [svn] * src/protocol.c: Reading of long lines broken in Prt_getLn(). Fix and
bears
parents: 287
diff changeset
4 $Id: protocol.c 579 2003-06-25 09:40:02Z bears $
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
436
4426f4dc6e8b [svn] * src/protocol.c: Reading of long lines broken in Prt_getLn(). Fix and
bears
parents: 287
diff changeset
34 /*
4426f4dc6e8b [svn] * src/protocol.c: Reading of long lines broken in Prt_getLn(). Fix and
bears
parents: 287
diff changeset
35 * Read and return the next line from f.
4426f4dc6e8b [svn] * src/protocol.c: Reading of long lines broken in Prt_getLn(). Fix and
bears
parents: 287
diff changeset
36 *
4426f4dc6e8b [svn] * src/protocol.c: Reading of long lines broken in Prt_getLn(). Fix and
bears
parents: 287
diff changeset
37 * The line is considered terminated by '\n' or '\r\n'. If present,
4426f4dc6e8b [svn] * src/protocol.c: Reading of long lines broken in Prt_getLn(). Fix and
bears
parents: 287
diff changeset
38 * these are removed before the line is returned to the caller. NNTP
4426f4dc6e8b [svn] * src/protocol.c: Reading of long lines broken in Prt_getLn(). Fix and
bears
parents: 287
diff changeset
39 * says text should be terminated by '\r\n', but just '\n' is
4426f4dc6e8b [svn] * src/protocol.c: Reading of long lines broken in Prt_getLn(). Fix and
bears
parents: 287
diff changeset
40 * not unknown in the wild.
4426f4dc6e8b [svn] * src/protocol.c: Reading of long lines broken in Prt_getLn(). Fix and
bears
parents: 287
diff changeset
41 *
4426f4dc6e8b [svn] * src/protocol.c: Reading of long lines broken in Prt_getLn(). Fix and
bears
parents: 287
diff changeset
42 * Should the line be longer than can fit into the fixed MAXCHAR
4426f4dc6e8b [svn] * src/protocol.c: Reading of long lines broken in Prt_getLn(). Fix and
bears
parents: 287
diff changeset
43 * buffer of a Str, then return the first MAXCHAR - 2 characters (so
4426f4dc6e8b [svn] * src/protocol.c: Reading of long lines broken in Prt_getLn(). Fix and
bears
parents: 287
diff changeset
44 * the rest of the system can deal with that line plus a '\n') and
4426f4dc6e8b [svn] * src/protocol.c: Reading of long lines broken in Prt_getLn(). Fix and
bears
parents: 287
diff changeset
45 * push back the last character, leaving it to be read as the first
4426f4dc6e8b [svn] * src/protocol.c: Reading of long lines broken in Prt_getLn(). Fix and
bears
parents: 287
diff changeset
46 * character of a subsequent new 'next' line. This is a Bad Thing -
4426f4dc6e8b [svn] * src/protocol.c: Reading of long lines broken in Prt_getLn(). Fix and
bears
parents: 287
diff changeset
47 * news transports shouldn't bugger around with even pathalogical
4426f4dc6e8b [svn] * src/protocol.c: Reading of long lines broken in Prt_getLn(). Fix and
bears
parents: 287
diff changeset
48 * articles - but we'll have to live with it for now until someone
4426f4dc6e8b [svn] * src/protocol.c: Reading of long lines broken in Prt_getLn(). Fix and
bears
parents: 287
diff changeset
49 * gets round to FIXME.
4426f4dc6e8b [svn] * src/protocol.c: Reading of long lines broken in Prt_getLn(). Fix and
bears
parents: 287
diff changeset
50 *
4426f4dc6e8b [svn] * src/protocol.c: Reading of long lines broken in Prt_getLn(). Fix and
bears
parents: 287
diff changeset
51 * Lines that are terminated by EOF are returned as normal. Only if
4426f4dc6e8b [svn] * src/protocol.c: Reading of long lines broken in Prt_getLn(). Fix and
bears
parents: 287
diff changeset
52 * EOF occurs before any characters are read will this routine return
4426f4dc6e8b [svn] * src/protocol.c: Reading of long lines broken in Prt_getLn(). Fix and
bears
parents: 287
diff changeset
53 * FALSE.
4426f4dc6e8b [svn] * src/protocol.c: Reading of long lines broken in Prt_getLn(). Fix and
bears
parents: 287
diff changeset
54 */
43
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
55 Bool
144
8b9366fc1361 [svn] Added timeout to Prt_getLn to avoid Noffle hanging if the
enz
parents: 127
diff changeset
56 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
57 {
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
58 size_t len;
144
8b9366fc1361 [svn] Added timeout to Prt_getLn to avoid Noffle hanging if the
enz
parents: 127
diff changeset
59 char *ret;
271
3477050e8d10 [svn] * src/client.c,src/fetch.c,src/lock.c.src/protocol.c,src/util.h,src/util.c:
bears
parents: 251
diff changeset
60 SignalHandler oldHandler = NULL;
43
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
61
144
8b9366fc1361 [svn] Added timeout to Prt_getLn to avoid Noffle hanging if the
enz
parents: 127
diff changeset
62 if ( timeoutSeconds >= 0 )
8b9366fc1361 [svn] Added timeout to Prt_getLn to avoid Noffle hanging if the
enz
parents: 127
diff changeset
63 {
164
94f2e5607772 [svn] * src/client.c,src/protocol.c,src/util.h,src/util.c: Common up
bears
parents: 151
diff changeset
64 oldHandler = Utl_installSignalHandler( SIGALRM, readAlarm );
144
8b9366fc1361 [svn] Added timeout to Prt_getLn to avoid Noffle hanging if the
enz
parents: 127
diff changeset
65 if ( oldHandler == SIG_ERR )
8b9366fc1361 [svn] Added timeout to Prt_getLn to avoid Noffle hanging if the
enz
parents: 127
diff changeset
66 {
8b9366fc1361 [svn] Added timeout to Prt_getLn to avoid Noffle hanging if the
enz
parents: 127
diff changeset
67 Log_err( "Prt_getLn: signal failed." );
8b9366fc1361 [svn] Added timeout to Prt_getLn to avoid Noffle hanging if the
enz
parents: 127
diff changeset
68 return FALSE;
8b9366fc1361 [svn] Added timeout to Prt_getLn to avoid Noffle hanging if the
enz
parents: 127
diff changeset
69 }
8b9366fc1361 [svn] Added timeout to Prt_getLn to avoid Noffle hanging if the
enz
parents: 127
diff changeset
70 if ( alarm( timeoutSeconds ) != 0 )
8b9366fc1361 [svn] Added timeout to Prt_getLn to avoid Noffle hanging if the
enz
parents: 127
diff changeset
71 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
72 }
436
4426f4dc6e8b [svn] * src/protocol.c: Reading of long lines broken in Prt_getLn(). Fix and
bears
parents: 287
diff changeset
73
144
8b9366fc1361 [svn] Added timeout to Prt_getLn to avoid Noffle hanging if the
enz
parents: 127
diff changeset
74 ret = fgets( line, MAXCHAR, f );
8b9366fc1361 [svn] Added timeout to Prt_getLn to avoid Noffle hanging if the
enz
parents: 127
diff changeset
75 if ( timeoutSeconds >= 0 )
43
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
76 {
144
8b9366fc1361 [svn] Added timeout to Prt_getLn to avoid Noffle hanging if the
enz
parents: 127
diff changeset
77 alarm( 0 );
164
94f2e5607772 [svn] * src/client.c,src/protocol.c,src/util.h,src/util.c: Common up
bears
parents: 151
diff changeset
78 Utl_installSignalHandler( SIGALRM, oldHandler );
144
8b9366fc1361 [svn] Added timeout to Prt_getLn to avoid Noffle hanging if the
enz
parents: 127
diff changeset
79 }
8b9366fc1361 [svn] Added timeout to Prt_getLn to avoid Noffle hanging if the
enz
parents: 127
diff changeset
80 if ( ret == NULL )
43
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
81 return FALSE;
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
82 len = strlen( line );
436
4426f4dc6e8b [svn] * src/protocol.c: Reading of long lines broken in Prt_getLn(). Fix and
bears
parents: 287
diff changeset
83 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
84 {
436
4426f4dc6e8b [svn] * src/protocol.c: Reading of long lines broken in Prt_getLn(). Fix and
bears
parents: 287
diff changeset
85 line[ len - 1 ] = '\0';
4426f4dc6e8b [svn] * src/protocol.c: Reading of long lines broken in Prt_getLn(). Fix and
bears
parents: 287
diff changeset
86 if ( len > 1 && line[ len - 2 ] == '\r' )
4426f4dc6e8b [svn] * src/protocol.c: Reading of long lines broken in Prt_getLn(). Fix and
bears
parents: 287
diff changeset
87 line[ len - 2 ] = '\0';
43
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
88 }
436
4426f4dc6e8b [svn] * src/protocol.c: Reading of long lines broken in Prt_getLn(). Fix and
bears
parents: 287
diff changeset
89 else if ( len >= MAXCHAR - 1 )
4426f4dc6e8b [svn] * src/protocol.c: Reading of long lines broken in Prt_getLn(). Fix and
bears
parents: 287
diff changeset
90 {
4426f4dc6e8b [svn] * src/protocol.c: Reading of long lines broken in Prt_getLn(). Fix and
bears
parents: 287
diff changeset
91 ungetc( line[ len - 1 ], f );
4426f4dc6e8b [svn] * src/protocol.c: Reading of long lines broken in Prt_getLn(). Fix and
bears
parents: 287
diff changeset
92 line[ len - 1 ] = '\0';
4426f4dc6e8b [svn] * src/protocol.c: Reading of long lines broken in Prt_getLn(). Fix and
bears
parents: 287
diff changeset
93 Log_err( "Prt_getLn: Input line too long, splitting." );
4426f4dc6e8b [svn] * src/protocol.c: Reading of long lines broken in Prt_getLn(). Fix and
bears
parents: 287
diff changeset
94 }
4426f4dc6e8b [svn] * src/protocol.c: Reading of long lines broken in Prt_getLn(). Fix and
bears
parents: 287
diff changeset
95
185
fed1334d766b [svn] * src/client.c: Change variable only used on constant to 'const'.
bears
parents: 164
diff changeset
96 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
97 return TRUE;
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
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
100 Bool
197
24d4cd032da5 [svn] * AUTHORS,INSTALL,NEWS,README,TODO,docs/NOTES,src/client.c,src/protocol.c,
bears
parents: 195
diff changeset
101 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
102 {
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
103 Str buf;
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
104
144
8b9366fc1361 [svn] Added timeout to Prt_getLn to avoid Noffle hanging if the
enz
parents: 127
diff changeset
105 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
106 {
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
107 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
108 *err = TRUE;
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
109 return FALSE;
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
110 }
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
111 *err = FALSE;
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
112 if ( buf[ 0 ] == '.' )
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 if ( buf[ 1 ] == 0 )
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
115 return FALSE;
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
116 else
287
01755687c565 [svn] * src/configfile.c: Change snprintf() to Utl_cpyStr();
bears
parents: 282
diff changeset
117 Utl_cpyStr( line, buf + 1 );
43
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
118 }
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
119 else
287
01755687c565 [svn] * src/configfile.c: Change snprintf() to Utl_cpyStr();
bears
parents: 282
diff changeset
120 Utl_cpyStr( line, buf );
43
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
121 return TRUE;
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
122 }
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
123
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
124 Bool
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
125 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
126 {
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
127 if ( line[ 0 ] == '.' )
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
128 {
185
fed1334d766b [svn] * src/client.c: Change variable only used on constant to 'const'.
bears
parents: 164
diff changeset
129 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
130 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
131 }
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
132 else
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
133 {
185
fed1334d766b [svn] * src/client.c: Change variable only used on constant to 'const'.
bears
parents: 164
diff changeset
134 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
135 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
136 }
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
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
139 Bool
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
140 Prt_putEndOfTxt( FILE *f )
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
141 {
185
fed1334d766b [svn] * src/client.c: Change variable only used on constant to 'const'.
bears
parents: 164
diff changeset
142 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
143 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
144 }
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 /*
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
147 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
148 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
149 */
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
150 Bool
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
151 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
152 {
436
4426f4dc6e8b [svn] * src/protocol.c: Reading of long lines broken in Prt_getLn(). Fix and
bears
parents: 287
diff changeset
153 DynStr *line;
4426f4dc6e8b [svn] * src/protocol.c: Reading of long lines broken in Prt_getLn(). Fix and
bears
parents: 287
diff changeset
154 const char *eol;
4426f4dc6e8b [svn] * src/protocol.c: Reading of long lines broken in Prt_getLn(). Fix and
bears
parents: 287
diff changeset
155 Bool res = TRUE;
43
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
156
436
4426f4dc6e8b [svn] * src/protocol.c: Reading of long lines broken in Prt_getLn(). Fix and
bears
parents: 287
diff changeset
157 line = new_DynStr(MAXCHAR);
4426f4dc6e8b [svn] * src/protocol.c: Reading of long lines broken in Prt_getLn(). Fix and
bears
parents: 287
diff changeset
158
4426f4dc6e8b [svn] * src/protocol.c: Reading of long lines broken in Prt_getLn(). Fix and
bears
parents: 287
diff changeset
159 while ( res && *buf != '\0' )
43
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
160 {
436
4426f4dc6e8b [svn] * src/protocol.c: Reading of long lines broken in Prt_getLn(). Fix and
bears
parents: 287
diff changeset
161 eol = strchr( buf, '\n' );
4426f4dc6e8b [svn] * src/protocol.c: Reading of long lines broken in Prt_getLn(). Fix and
bears
parents: 287
diff changeset
162 if ( eol != NULL )
4426f4dc6e8b [svn] * src/protocol.c: Reading of long lines broken in Prt_getLn(). Fix and
bears
parents: 287
diff changeset
163 {
4426f4dc6e8b [svn] * src/protocol.c: Reading of long lines broken in Prt_getLn(). Fix and
bears
parents: 287
diff changeset
164 DynStr_appN( line, buf, eol - buf );
4426f4dc6e8b [svn] * src/protocol.c: Reading of long lines broken in Prt_getLn(). Fix and
bears
parents: 287
diff changeset
165 buf = eol + 1;
4426f4dc6e8b [svn] * src/protocol.c: Reading of long lines broken in Prt_getLn(). Fix and
bears
parents: 287
diff changeset
166 res = Prt_putTxtLn( DynStr_str( line ), f );
4426f4dc6e8b [svn] * src/protocol.c: Reading of long lines broken in Prt_getLn(). Fix and
bears
parents: 287
diff changeset
167 DynStr_clear( line );
4426f4dc6e8b [svn] * src/protocol.c: Reading of long lines broken in Prt_getLn(). Fix and
bears
parents: 287
diff changeset
168 }
4426f4dc6e8b [svn] * src/protocol.c: Reading of long lines broken in Prt_getLn(). Fix and
bears
parents: 287
diff changeset
169 else
4426f4dc6e8b [svn] * src/protocol.c: Reading of long lines broken in Prt_getLn(). Fix and
bears
parents: 287
diff changeset
170 {
4426f4dc6e8b [svn] * src/protocol.c: Reading of long lines broken in Prt_getLn(). Fix and
bears
parents: 287
diff changeset
171 res = Prt_putTxtLn( buf, f );
4426f4dc6e8b [svn] * src/protocol.c: Reading of long lines broken in Prt_getLn(). Fix and
bears
parents: 287
diff changeset
172 break;
4426f4dc6e8b [svn] * src/protocol.c: Reading of long lines broken in Prt_getLn(). Fix and
bears
parents: 287
diff changeset
173 }
43
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
174 }
436
4426f4dc6e8b [svn] * src/protocol.c: Reading of long lines broken in Prt_getLn(). Fix and
bears
parents: 287
diff changeset
175
4426f4dc6e8b [svn] * src/protocol.c: Reading of long lines broken in Prt_getLn(). Fix and
bears
parents: 287
diff changeset
176 del_DynStr( line );
4426f4dc6e8b [svn] * src/protocol.c: Reading of long lines broken in Prt_getLn(). Fix and
bears
parents: 287
diff changeset
177 return res;
43
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
178 }
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
179
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
180 Bool
282
baa6408d1bbc [svn] * src/database.c,src/post.c,src/protocol.h,src/protocol.c: When posting,
bears
parents: 271
diff changeset
181 Prt_getField( Str resultField, Str resultValue,
baa6408d1bbc [svn] * src/database.c,src/post.c,src/protocol.h,src/protocol.c: When posting,
bears
parents: 271
diff changeset
182 Bool* isContinuation, const char* line )
43
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
183 {
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
184 char *dst;
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
185 const char *p;
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
186 Str lineLower, t;
282
baa6408d1bbc [svn] * src/database.c,src/post.c,src/protocol.h,src/protocol.c: When posting,
bears
parents: 271
diff changeset
187
baa6408d1bbc [svn] * src/database.c,src/post.c,src/protocol.h,src/protocol.c: When posting,
bears
parents: 271
diff changeset
188 ASSERT( isContinuation );
43
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
189
282
baa6408d1bbc [svn] * src/database.c,src/post.c,src/protocol.h,src/protocol.c: When posting,
bears
parents: 271
diff changeset
190 *isContinuation = FALSE;
43
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
191 Utl_cpyStr( lineLower, line );
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
192 Utl_toLower( lineLower );
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
193 p = Utl_stripWhiteSpace( lineLower );
247
7a830ce3211e [svn] *** empty log message ***
mirkol
parents: 244
diff changeset
194 if ( p == lineLower )
43
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
195 {
247
7a830ce3211e [svn] *** empty log message ***
mirkol
parents: 244
diff changeset
196 dst = resultField;
7a830ce3211e [svn] *** empty log message ***
mirkol
parents: 244
diff changeset
197 while ( ! isspace( *p ) && *p != ':' && *p != '\0' )
7a830ce3211e [svn] *** empty log message ***
mirkol
parents: 244
diff changeset
198 *(dst++) = *(p++);
7a830ce3211e [svn] *** empty log message ***
mirkol
parents: 244
diff changeset
199 *dst = '\0';
7a830ce3211e [svn] *** empty log message ***
mirkol
parents: 244
diff changeset
200 while ( isspace( *p ) )
7a830ce3211e [svn] *** empty log message ***
mirkol
parents: 244
diff changeset
201 ++p;
7a830ce3211e [svn] *** empty log message ***
mirkol
parents: 244
diff changeset
202 if ( *p == ':' )
7a830ce3211e [svn] *** empty log message ***
mirkol
parents: 244
diff changeset
203 {
7a830ce3211e [svn] *** empty log message ***
mirkol
parents: 244
diff changeset
204 ++p;
287
01755687c565 [svn] * src/configfile.c: Change snprintf() to Utl_cpyStr();
bears
parents: 282
diff changeset
205 Utl_cpyStr( t, line + ( p - lineLower ) );
247
7a830ce3211e [svn] *** empty log message ***
mirkol
parents: 244
diff changeset
206 p = Utl_stripWhiteSpace( t );
287
01755687c565 [svn] * src/configfile.c: Change snprintf() to Utl_cpyStr();
bears
parents: 282
diff changeset
207 Utl_cpyStr( resultValue, p );
247
7a830ce3211e [svn] *** empty log message ***
mirkol
parents: 244
diff changeset
208 return TRUE;
282
baa6408d1bbc [svn] * src/database.c,src/post.c,src/protocol.h,src/protocol.c: When posting,
bears
parents: 271
diff changeset
209 } else
baa6408d1bbc [svn] * src/database.c,src/post.c,src/protocol.h,src/protocol.c: When posting,
bears
parents: 271
diff changeset
210 return FALSE; /* Not a header line */
247
7a830ce3211e [svn] *** empty log message ***
mirkol
parents: 244
diff changeset
211 }
282
baa6408d1bbc [svn] * src/database.c,src/post.c,src/protocol.h,src/protocol.c: When posting,
bears
parents: 271
diff changeset
212 else
247
7a830ce3211e [svn] *** empty log message ***
mirkol
parents: 244
diff changeset
213 {
282
baa6408d1bbc [svn] * src/database.c,src/post.c,src/protocol.h,src/protocol.c: When posting,
bears
parents: 271
diff changeset
214 /*
baa6408d1bbc [svn] * src/database.c,src/post.c,src/protocol.h,src/protocol.c: When posting,
bears
parents: 271
diff changeset
215 * If the line starts with white space, it can be a header
baa6408d1bbc [svn] * src/database.c,src/post.c,src/protocol.h,src/protocol.c: When posting,
bears
parents: 271
diff changeset
216 * continuation.
baa6408d1bbc [svn] * src/database.c,src/post.c,src/protocol.h,src/protocol.c: When posting,
bears
parents: 271
diff changeset
217 */
baa6408d1bbc [svn] * src/database.c,src/post.c,src/protocol.h,src/protocol.c: When posting,
bears
parents: 271
diff changeset
218 if( ! isspace( *line ) )
baa6408d1bbc [svn] * src/database.c,src/post.c,src/protocol.h,src/protocol.c: When posting,
bears
parents: 271
diff changeset
219 return FALSE;
baa6408d1bbc [svn] * src/database.c,src/post.c,src/protocol.h,src/protocol.c: When posting,
bears
parents: 271
diff changeset
220
baa6408d1bbc [svn] * src/database.c,src/post.c,src/protocol.h,src/protocol.c: When posting,
bears
parents: 271
diff changeset
221 Utl_cpyStr( resultValue, line );
baa6408d1bbc [svn] * src/database.c,src/post.c,src/protocol.h,src/protocol.c: When posting,
bears
parents: 271
diff changeset
222 *isContinuation = TRUE;
baa6408d1bbc [svn] * src/database.c,src/post.c,src/protocol.h,src/protocol.c: When posting,
bears
parents: 271
diff changeset
223 return TRUE;
43
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
224 }
282
baa6408d1bbc [svn] * src/database.c,src/post.c,src/protocol.h,src/protocol.c: When posting,
bears
parents: 271
diff changeset
225 /* NOTREACHED */
43
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
226 }
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 Bool
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
229 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
230 {
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
231 const char *src, *p;
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
232 char *dst;
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
233 Str line, whichLower, field;
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
234 int len;
282
baa6408d1bbc [svn] * src/database.c,src/post.c,src/protocol.h,src/protocol.c: When posting,
bears
parents: 271
diff changeset
235 Bool continuation;
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 Utl_cpyStr( whichLower, which );
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
238 Utl_toLower( whichLower );
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
239 src = artTxt;
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
240 while ( TRUE )
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
241 {
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
242 dst = line;
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
243 len = 0;
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
244 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
245 {
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
246 if ( *src == '\0' )
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
247 return FALSE;
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
248 *(dst++) = *(src++);
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
249 ++len;
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
250 }
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
251 if ( *src == '\n' )
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
252 ++src;
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
253 *dst = '\0';
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
254 p = Utl_stripWhiteSpace( line );
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
255 if ( *p == '\0' )
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
256 break;
282
baa6408d1bbc [svn] * src/database.c,src/post.c,src/protocol.h,src/protocol.c: When posting,
bears
parents: 271
diff changeset
257 if ( Prt_getField( field, result, &continuation, line )
43
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
258 && strcmp( field, whichLower ) == 0 )
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
259 return TRUE;
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
260 }
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
261 return FALSE;
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
262 }
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
263
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
264 static void
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
265 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
266 {
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
267 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
268 Str myDomain;
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
269
244
4e69e9b722ae [svn] * src/database.c,src/protocol.c,src/util.c,src/util.h: The latest IETF
bears
parents: 221
diff changeset
270 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
271 {
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
272 p = strstr( myDomain, "." );
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
273 if ( p != NULL )
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
274 domainStart = p + 1;
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
275 else
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
276 domainStart = myDomain;
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
277 }
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
278 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
279 {
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
280 myDomain[ 0 ] = '\0';
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
281 p1 = strstr( from, "@" );
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
282 if ( p1 != NULL )
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 p2 = strstr( p1, ">" );
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
285 if ( p2 != NULL )
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
286 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
287 }
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
288 if ( myDomain[ 0 ] == '\0' )
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
289 Utl_cpyStr( myDomain, "unknown" );
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
290 domainStart = myDomain;
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 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
294 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
295 in message ID.
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
296 */
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
297 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
298 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
299 }
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
300
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
301 /* 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
302 Bool
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
303 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
304 {
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
305 Str head, domain;
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
306 int len, headLen;
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
307 const char *p;
249
0340b9c17edc [svn] *** empty log message ***
mirkol
parents: 247
diff changeset
308 const char * specials = "\t\r\n ()@<>"; /* hmm, check "\\\'\"[]" as well? */
43
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
309
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
310 len = strlen( msgId );
249
0340b9c17edc [svn] *** empty log message ***
mirkol
parents: 247
diff changeset
311 if ( len > 250 )
0340b9c17edc [svn] *** empty log message ***
mirkol
parents: 247
diff changeset
312 return FALSE; /* see draft-ietf-usefor-article-06.txt, ch 5.3 */
0340b9c17edc [svn] *** empty log message ***
mirkol
parents: 247
diff changeset
313 p = strchr( msgId, '@' );
43
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
314 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
315 return FALSE;
251
030c41dfd9ba [svn] * src/protocol.c: Change strcpy to Utl_strcpy and replace ascii check
bears
parents: 250
diff changeset
316 Utl_cpyStr( domain, p + 1 );
43
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
317 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
318 headLen = p - msgId - 1;
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
319 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
320 head[ headLen ] = '\0';
249
0340b9c17edc [svn] *** empty log message ***
mirkol
parents: 247
diff changeset
321 for ( p = msgId ; *p != '\0' ; p++ )
0340b9c17edc [svn] *** empty log message ***
mirkol
parents: 247
diff changeset
322 {
251
030c41dfd9ba [svn] * src/protocol.c: Change strcpy to Utl_strcpy and replace ascii check
bears
parents: 250
diff changeset
323 if ( ! isascii( *p ) )
030c41dfd9ba [svn] * src/protocol.c: Change strcpy to Utl_strcpy and replace ascii check
bears
parents: 250
diff changeset
324 return FALSE;
249
0340b9c17edc [svn] *** empty log message ***
mirkol
parents: 247
diff changeset
325 }
0340b9c17edc [svn] *** empty log message ***
mirkol
parents: 247
diff changeset
326 if ( strpbrk( head, specials ) )
0340b9c17edc [svn] *** empty log message ***
mirkol
parents: 247
diff changeset
327 return FALSE;
0340b9c17edc [svn] *** empty log message ***
mirkol
parents: 247
diff changeset
328 if ( strpbrk( domain, specials ) )
0340b9c17edc [svn] *** empty log message ***
mirkol
parents: 247
diff changeset
329 return FALSE;
43
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
330 return TRUE;
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
331 }
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
332
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
333 void
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
334 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
335 {
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
336 Str domain, date;
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
337 time_t t;
249
0340b9c17edc [svn] *** empty log message ***
mirkol
parents: 247
diff changeset
338 static long count = 0;
0340b9c17edc [svn] *** empty log message ***
mirkol
parents: 247
diff changeset
339 const char *pattern;
43
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
340
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
341 getDomain( domain, from );
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
342 time( &t );
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
343 strftime( date, MAXCHAR, "%Y%m%d%H%M%S", gmtime( &t ) );
249
0340b9c17edc [svn] *** empty log message ***
mirkol
parents: 247
diff changeset
344 if ( strchr( domain, '@' ) )
0340b9c17edc [svn] *** empty log message ***
mirkol
parents: 247
diff changeset
345 pattern = "<%s.%X.%lx.%s%s>";
0340b9c17edc [svn] *** empty log message ***
mirkol
parents: 247
diff changeset
346 else
0340b9c17edc [svn] *** empty log message ***
mirkol
parents: 247
diff changeset
347 pattern = "<%s.%X.%lx.%s@%s>";
0340b9c17edc [svn] *** empty log message ***
mirkol
parents: 247
diff changeset
348 snprintf( msgId, MAXCHAR, pattern , 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
349 ASSERT( Prt_isValidMsgId( msgId ) );
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
350 }
111
6f681d41734c [svn] path-header added.
bears
parents: 59
diff changeset
351
6f681d41734c [svn] path-header added.
bears
parents: 59
diff changeset
352 void
6f681d41734c [svn] path-header added.
bears
parents: 59
diff changeset
353 Prt_genPathHdr( Str pathHdr, const char *from )
6f681d41734c [svn] path-header added.
bears
parents: 59
diff changeset
354 {
6f681d41734c [svn] path-header added.
bears
parents: 59
diff changeset
355 getDomain( pathHdr, from );
6f681d41734c [svn] path-header added.
bears
parents: 59
diff changeset
356 Utl_catStr( pathHdr, "!not-for-mail" );
6f681d41734c [svn] path-header added.
bears
parents: 59
diff changeset
357 }
6f681d41734c [svn] path-header added.
bears
parents: 59
diff changeset
358
150
1c7303c71f66 [svn] * src/protocol.c: Fix bug in Prt_getLn if we should read a line
bears
parents: 144
diff changeset
359 Bool
1c7303c71f66 [svn] * src/protocol.c: Fix bug in Prt_getLn if we should read a line
bears
parents: 144
diff changeset
360 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
361 {
1c7303c71f66 [svn] * src/protocol.c: Fix bug in Prt_getLn if we should read a line
bears
parents: 144
diff changeset
362 Str name, domain;
1c7303c71f66 [svn] * src/protocol.c: Fix bug in Prt_getLn if we should read a line
bears
parents: 144
diff changeset
363 const char *nameval;
1c7303c71f66 [svn] * src/protocol.c: Fix bug in Prt_getLn if we should read a line
bears
parents: 144
diff changeset
364 struct passwd *pwd;
1c7303c71f66 [svn] * src/protocol.c: Fix bug in Prt_getLn if we should read a line
bears
parents: 144
diff changeset
365
1c7303c71f66 [svn] * src/protocol.c: Fix bug in Prt_getLn if we should read a line
bears
parents: 144
diff changeset
366 /* 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
367 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
368
151
cb799054bd61 [svn] Rats. Couple of warning slipped in during the last update. Fix 'em.
bears
parents: 150
diff changeset
369 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
370 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
371 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
372
1c7303c71f66 [svn] * src/protocol.c: Fix bug in Prt_getLn if we should read a line
bears
parents: 144
diff changeset
373 /* 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
374 pwd = getpwuid( getuid() );
1c7303c71f66 [svn] * src/protocol.c: Fix bug in Prt_getLn if we should read a line
bears
parents: 144
diff changeset
375 if ( pwd == NULL )
1c7303c71f66 [svn] * src/protocol.c: Fix bug in Prt_getLn if we should read a line
bears
parents: 144
diff changeset
376 return FALSE;
1c7303c71f66 [svn] * src/protocol.c: Fix bug in Prt_getLn if we should read a line
bears
parents: 144
diff changeset
377
1c7303c71f66 [svn] * src/protocol.c: Fix bug in Prt_getLn if we should read a line
bears
parents: 144
diff changeset
378 /* 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
379 nameval = getenv( "NAME" );
1c7303c71f66 [svn] * src/protocol.c: Fix bug in Prt_getLn if we should read a line
bears
parents: 144
diff changeset
380 if ( nameval != NULL )
1c7303c71f66 [svn] * src/protocol.c: Fix bug in Prt_getLn if we should read a line
bears
parents: 144
diff changeset
381 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
382 else
1c7303c71f66 [svn] * src/protocol.c: Fix bug in Prt_getLn if we should read a line
bears
parents: 144
diff changeset
383 {
1c7303c71f66 [svn] * src/protocol.c: Fix bug in Prt_getLn if we should read a line
bears
parents: 144
diff changeset
384 char *p;
1c7303c71f66 [svn] * src/protocol.c: Fix bug in Prt_getLn if we should read a line
bears
parents: 144
diff changeset
385
1c7303c71f66 [svn] * src/protocol.c: Fix bug in Prt_getLn if we should read a line
bears
parents: 144
diff changeset
386 /*
1c7303c71f66 [svn] * src/protocol.c: Fix bug in Prt_getLn if we should read a line
bears
parents: 144
diff changeset
387 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
388 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
389 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
390 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
391 */
1c7303c71f66 [svn] * src/protocol.c: Fix bug in Prt_getLn if we should read a line
bears
parents: 144
diff changeset
392 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
393 p = strchr( nameval, '-' );
1c7303c71f66 [svn] * src/protocol.c: Fix bug in Prt_getLn if we should read a line
bears
parents: 144
diff changeset
394 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
395 ( 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
396 nameval = p;
1c7303c71f66 [svn] * src/protocol.c: Fix bug in Prt_getLn if we should read a line
bears
parents: 144
diff changeset
397 p = strrchr( nameval, ',' );
1c7303c71f66 [svn] * src/protocol.c: Fix bug in Prt_getLn if we should read a line
bears
parents: 144
diff changeset
398 if ( p != NULL )
1c7303c71f66 [svn] * src/protocol.c: Fix bug in Prt_getLn if we should read a line
bears
parents: 144
diff changeset
399 *p = '\0';
1c7303c71f66 [svn] * src/protocol.c: Fix bug in Prt_getLn if we should read a line
bears
parents: 144
diff changeset
400 p = strchr( nameval, ';' );
1c7303c71f66 [svn] * src/protocol.c: Fix bug in Prt_getLn if we should read a line
bears
parents: 144
diff changeset
401 if ( p != NULL )
1c7303c71f66 [svn] * src/protocol.c: Fix bug in Prt_getLn if we should read a line
bears
parents: 144
diff changeset
402 *p = '\0';
1c7303c71f66 [svn] * src/protocol.c: Fix bug in Prt_getLn if we should read a line
bears
parents: 144
diff changeset
403 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
404 }
1c7303c71f66 [svn] * src/protocol.c: Fix bug in Prt_getLn if we should read a line
bears
parents: 144
diff changeset
405
1c7303c71f66 [svn] * src/protocol.c: Fix bug in Prt_getLn if we should read a line
bears
parents: 144
diff changeset
406 /* OK, build From: contents */
249
0340b9c17edc [svn] *** empty log message ***
mirkol
parents: 247
diff changeset
407 /* deprecated.
150
1c7303c71f66 [svn] * src/protocol.c: Fix bug in Prt_getLn if we should read a line
bears
parents: 144
diff changeset
408 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
409 Utl_catStr( fromHdr, "@" );
1c7303c71f66 [svn] * src/protocol.c: Fix bug in Prt_getLn if we should read a line
bears
parents: 144
diff changeset
410 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
411 Utl_catStr( fromHdr, " (" );
1c7303c71f66 [svn] * src/protocol.c: Fix bug in Prt_getLn if we should read a line
bears
parents: 144
diff changeset
412 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
413 Utl_catStr( fromHdr, ")" );
249
0340b9c17edc [svn] *** empty log message ***
mirkol
parents: 247
diff changeset
414 */
0340b9c17edc [svn] *** empty log message ***
mirkol
parents: 247
diff changeset
415 Utl_cpyStr( fromHdr, "\"" );
0340b9c17edc [svn] *** empty log message ***
mirkol
parents: 247
diff changeset
416 Utl_catStr( fromHdr, name );
0340b9c17edc [svn] *** empty log message ***
mirkol
parents: 247
diff changeset
417 Utl_catStr( fromHdr, "\" <" );
0340b9c17edc [svn] *** empty log message ***
mirkol
parents: 247
diff changeset
418 Utl_catStr( fromHdr, pwd->pw_name );
0340b9c17edc [svn] *** empty log message ***
mirkol
parents: 247
diff changeset
419 Utl_catStr( fromHdr, "@" );
0340b9c17edc [svn] *** empty log message ***
mirkol
parents: 247
diff changeset
420 Utl_catStr( fromHdr, domain );
0340b9c17edc [svn] *** empty log message ***
mirkol
parents: 247
diff changeset
421 Utl_catStr( fromHdr, ">" );
150
1c7303c71f66 [svn] * src/protocol.c: Fix bug in Prt_getLn if we should read a line
bears
parents: 144
diff changeset
422
1c7303c71f66 [svn] * src/protocol.c: Fix bug in Prt_getLn if we should read a line
bears
parents: 144
diff changeset
423 return TRUE;
1c7303c71f66 [svn] * src/protocol.c: Fix bug in Prt_getLn if we should read a line
bears
parents: 144
diff changeset
424 }
111
6f681d41734c [svn] path-header added.
bears
parents: 59
diff changeset
425
6f681d41734c [svn] path-header added.
bears
parents: 59
diff changeset
426
6f681d41734c [svn] path-header added.
bears
parents: 59
diff changeset
427