annotate outgoing.c @ 32:45ddd5e72164 noffle

[svn] Added comment about seemingly unnessecary code.
author enz
date Sun, 30 Apr 2000 20:07:54 +0100
parents 526a4c34ee2e
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
1 /*
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
2 outgoing.c
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
3
26
526a4c34ee2e [svn] Applied patch from Jim Hague: support for local groups / new command
enz
parents: 0
diff changeset
4 $Id: outgoing.c 32 2000-04-29 14:45:56Z enz $
0
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
5 */
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
6
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
7 #include "outgoing.h"
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
8
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
9 #include <dirent.h>
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
10 #include <errno.h>
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
11 #include <fcntl.h>
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
12 #include <sys/types.h>
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
13 #include <sys/stat.h>
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
14 #include <time.h>
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
15 #include <unistd.h>
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
16 #include "config.h"
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
17 #include "log.h"
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
18 #include "util.h"
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
19
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
20 struct Outgoing
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
21 {
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
22 DIR *dir;
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
23 Str serv;
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
24 } outgoing = { NULL, "" };
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
25
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
26 static void
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
27 fileOutgoing( Str file, const char *serv, const char *msgId )
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
28 {
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
29 snprintf( file, MAXCHAR, "%s/outgoing/%s/%s",
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
30 Cfg_spoolDir(), serv, msgId );
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
31 }
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
32
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
33 static void
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
34 createDir( const char *serv )
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
35 {
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
36 Str dir;
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
37 int r;
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
38
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
39 snprintf( dir, MAXCHAR, "%s/outgoing/%s", Cfg_spoolDir(), serv );
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
40 r = mkdir( dir, 0755 );
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
41 if ( r != 0 )
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
42 Log_dbg( "mkdir: %s", strerror( errno ) );
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
43 }
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
44
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
45 Bool
26
526a4c34ee2e [svn] Applied patch from Jim Hague: support for local groups / new command
enz
parents: 0
diff changeset
46 Out_add( const char *serv, const char *msgId, const DynStr *artTxt )
0
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
47 {
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
48 Str file;
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
49 FILE *f;
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
50
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
51 fileOutgoing( file, serv, msgId );
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
52 if ( ! ( f = fopen( file, "w" ) ) )
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
53 {
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
54 createDir( serv );
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
55 if ( ! ( f = fopen( file, "w" ) ) )
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
56 {
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
57 Log_err( "Cannot open %s", file );
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
58 return FALSE;
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
59 }
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
60 }
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
61 fprintf( f, "%s", DynStr_str( artTxt ) );
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
62 fclose( f );
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
63 return TRUE;
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
64 }
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
65
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
66 Bool
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
67 Out_first( const char *serv, Str msgId, DynStr *artTxt )
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
68 {
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
69 Str file;
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
70
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
71 snprintf( file, MAXCHAR, "%s/outgoing/%s", Cfg_spoolDir(), serv );
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
72 if ( ! ( outgoing.dir = opendir( file ) ) )
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
73 {
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
74 Log_dbg( "Cannot open %s", file );
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
75 return FALSE;
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
76 }
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
77 Utl_cpyStr( outgoing.serv, serv );
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
78 Out_next( NULL, NULL ); /* "." */
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
79 Out_next( NULL, NULL ); /* ".." */
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
80 return Out_next( msgId, artTxt );
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
81 }
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
82
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
83 Bool
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
84 Out_next( Str msgId, DynStr *artTxt )
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
85 {
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
86 struct dirent *d;
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
87 FILE *f;
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
88 Str file, line;
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
89
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
90 ASSERT( outgoing.dir );
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
91 if ( ! ( d = readdir( outgoing.dir ) ) )
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
92 {
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
93 closedir( outgoing.dir );
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
94 outgoing.dir = NULL;
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
95 return FALSE;
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
96 }
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
97 if ( artTxt == NULL )
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
98 return ( d->d_name != NULL );
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
99 fileOutgoing( file, outgoing.serv, d->d_name );
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
100 if ( ! ( f = fopen( file, "r" ) ) )
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
101 {
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
102 Log_err( "Cannot open %s for read", file );
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
103 return FALSE;
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
104 }
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
105 DynStr_clear( artTxt );
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
106 while ( fgets( line, MAXCHAR, f ) )
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
107 DynStr_app( artTxt, line );
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
108 Utl_cpyStr( msgId, d->d_name );
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
109 fclose( f );
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
110 return TRUE;
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
111 }
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
112
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
113 void
26
526a4c34ee2e [svn] Applied patch from Jim Hague: support for local groups / new command
enz
parents: 0
diff changeset
114 Out_remove( const char *serv, const char *msgId )
0
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
115 {
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
116 Str file;
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
117
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
118 fileOutgoing( file, serv, msgId );
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
119 if ( unlink( file ) != 0 )
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
120 Log_err( "Cannot remove %s", file );
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
121 }
26
526a4c34ee2e [svn] Applied patch from Jim Hague: support for local groups / new command
enz
parents: 0
diff changeset
122
526a4c34ee2e [svn] Applied patch from Jim Hague: support for local groups / new command
enz
parents: 0
diff changeset
123 Bool
526a4c34ee2e [svn] Applied patch from Jim Hague: support for local groups / new command
enz
parents: 0
diff changeset
124 Out_find( const char *msgId, Str server )
526a4c34ee2e [svn] Applied patch from Jim Hague: support for local groups / new command
enz
parents: 0
diff changeset
125 {
526a4c34ee2e [svn] Applied patch from Jim Hague: support for local groups / new command
enz
parents: 0
diff changeset
126 Str servdir;
526a4c34ee2e [svn] Applied patch from Jim Hague: support for local groups / new command
enz
parents: 0
diff changeset
127 DIR *d;
526a4c34ee2e [svn] Applied patch from Jim Hague: support for local groups / new command
enz
parents: 0
diff changeset
128 struct dirent *entry;
526a4c34ee2e [svn] Applied patch from Jim Hague: support for local groups / new command
enz
parents: 0
diff changeset
129 Bool res;
526a4c34ee2e [svn] Applied patch from Jim Hague: support for local groups / new command
enz
parents: 0
diff changeset
130
526a4c34ee2e [svn] Applied patch from Jim Hague: support for local groups / new command
enz
parents: 0
diff changeset
131
526a4c34ee2e [svn] Applied patch from Jim Hague: support for local groups / new command
enz
parents: 0
diff changeset
132 snprintf( servdir, MAXCHAR, "%s/outgoing", Cfg_spoolDir() );
526a4c34ee2e [svn] Applied patch from Jim Hague: support for local groups / new command
enz
parents: 0
diff changeset
133 if ( ! ( d = opendir( servdir ) ) )
526a4c34ee2e [svn] Applied patch from Jim Hague: support for local groups / new command
enz
parents: 0
diff changeset
134 {
526a4c34ee2e [svn] Applied patch from Jim Hague: support for local groups / new command
enz
parents: 0
diff changeset
135 Log_dbg( "Cannot open %s", servdir );
526a4c34ee2e [svn] Applied patch from Jim Hague: support for local groups / new command
enz
parents: 0
diff changeset
136 return FALSE;
526a4c34ee2e [svn] Applied patch from Jim Hague: support for local groups / new command
enz
parents: 0
diff changeset
137 }
526a4c34ee2e [svn] Applied patch from Jim Hague: support for local groups / new command
enz
parents: 0
diff changeset
138
526a4c34ee2e [svn] Applied patch from Jim Hague: support for local groups / new command
enz
parents: 0
diff changeset
139 readdir( d ); /* '.' */
526a4c34ee2e [svn] Applied patch from Jim Hague: support for local groups / new command
enz
parents: 0
diff changeset
140 readdir( d ); /* '..' */
526a4c34ee2e [svn] Applied patch from Jim Hague: support for local groups / new command
enz
parents: 0
diff changeset
141
526a4c34ee2e [svn] Applied patch from Jim Hague: support for local groups / new command
enz
parents: 0
diff changeset
142 res = FALSE;
526a4c34ee2e [svn] Applied patch from Jim Hague: support for local groups / new command
enz
parents: 0
diff changeset
143 while ( ! res && ( entry = readdir( d ) ) != NULL )
526a4c34ee2e [svn] Applied patch from Jim Hague: support for local groups / new command
enz
parents: 0
diff changeset
144 {
526a4c34ee2e [svn] Applied patch from Jim Hague: support for local groups / new command
enz
parents: 0
diff changeset
145 Str file;
526a4c34ee2e [svn] Applied patch from Jim Hague: support for local groups / new command
enz
parents: 0
diff changeset
146 struct stat s;
526a4c34ee2e [svn] Applied patch from Jim Hague: support for local groups / new command
enz
parents: 0
diff changeset
147
526a4c34ee2e [svn] Applied patch from Jim Hague: support for local groups / new command
enz
parents: 0
diff changeset
148 fileOutgoing( file, entry->d_name, msgId );
526a4c34ee2e [svn] Applied patch from Jim Hague: support for local groups / new command
enz
parents: 0
diff changeset
149 if ( stat( file, &s ) == 0 )
526a4c34ee2e [svn] Applied patch from Jim Hague: support for local groups / new command
enz
parents: 0
diff changeset
150 {
526a4c34ee2e [svn] Applied patch from Jim Hague: support for local groups / new command
enz
parents: 0
diff changeset
151 res = TRUE;
526a4c34ee2e [svn] Applied patch from Jim Hague: support for local groups / new command
enz
parents: 0
diff changeset
152 Utl_cpyStr( server, entry->d_name );
526a4c34ee2e [svn] Applied patch from Jim Hague: support for local groups / new command
enz
parents: 0
diff changeset
153 }
526a4c34ee2e [svn] Applied patch from Jim Hague: support for local groups / new command
enz
parents: 0
diff changeset
154 }
526a4c34ee2e [svn] Applied patch from Jim Hague: support for local groups / new command
enz
parents: 0
diff changeset
155
526a4c34ee2e [svn] Applied patch from Jim Hague: support for local groups / new command
enz
parents: 0
diff changeset
156 closedir( d );
526a4c34ee2e [svn] Applied patch from Jim Hague: support for local groups / new command
enz
parents: 0
diff changeset
157 return res;
526a4c34ee2e [svn] Applied patch from Jim Hague: support for local groups / new command
enz
parents: 0
diff changeset
158 }
526a4c34ee2e [svn] Applied patch from Jim Hague: support for local groups / new command
enz
parents: 0
diff changeset
159
526a4c34ee2e [svn] Applied patch from Jim Hague: support for local groups / new command
enz
parents: 0
diff changeset
160
526a4c34ee2e [svn] Applied patch from Jim Hague: support for local groups / new command
enz
parents: 0
diff changeset
161
526a4c34ee2e [svn] Applied patch from Jim Hague: support for local groups / new command
enz
parents: 0
diff changeset
162
526a4c34ee2e [svn] Applied patch from Jim Hague: support for local groups / new command
enz
parents: 0
diff changeset
163