Mercurial > noffle
comparison src/outgoing.c @ 43:2842f50feb55 noffle
[svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
control.c, control.h, database.c, database.h, dynamicstring.c,
dynamicstring.h, fetch.c, fetch.h, fetchlist.c, fetchlist.h, group.c,
group.h, itemlist.c, itemlist.h, lock.c, lock.h, log.c, log.h, noffle.c,
online.c, online.h, outgoing.c, outgoing.h, over.c, over.h, post.c, post.h,
protocol.c, protocol.h, pseudo.c, pseudo.h, request.c, request.h, server.c,
server.h, util.c, util.h, wildmat.c, wildmat.h: Moved files to the
subdirectory src/
* Makefile.am, acconfig.h, configure.in, docs/Makefile.am, src/Makefile.am,
Makefile.in, aclocal.m4, config.h.in, configure, install-sh, missing,
mkinstalldirs, stamp-h.in, docs/Makefile.in, src/Makefile.in: Added files.
They are used by aclocal, autoheader, autoconf and automake.
* src/config.c, src/config.h: Renamed to configfile.c and configfile.h,
because configure will generate a config.h file itself.
* src/client.c, src/content.c, src/database.c, src/fetch.c, src/fetchlist.c,
src/group.c, src/lock.c, src/noffle.c, src/online.c, src/outgoing.c,
src/over.c, src/pseudo.c, src/request.c, src/server.c, src/util.c:
Changed '#include "config.h"' to '#include "configfile.h"'.
* src/client.c, src/content.c, src/database.c, src/fetch.c, src/fetchlist.c,
src/group.c, src/lock.c, src/online.c, src/outgoing.c, src/post.c,
src/protocol.c, src/request.c, src/server.c: Files now #include <config.h>.
Added missing <stdio.h>. This removes the warnings about snprintf() not
being declared.
* Makefile: Removed. This is now generated by configure.
author | uh1763 |
---|---|
date | Fri, 05 May 2000 22:45:56 +0100 |
parents | |
children | 125d79c9e586 |
comparison
equal
deleted
inserted
replaced
42:2467ff423c15 | 43:2842f50feb55 |
---|---|
1 /* | |
2 outgoing.c | |
3 | |
4 $Id: outgoing.c 49 2000-05-05 21:45:56Z uh1763 $ | |
5 */ | |
6 | |
7 #if HAVE_CONFIG_H | |
8 #include <config.h> | |
9 #endif | |
10 | |
11 #include "outgoing.h" | |
12 | |
13 #include <stdio.h> | |
14 #include <dirent.h> | |
15 #include <errno.h> | |
16 #include <fcntl.h> | |
17 #include <sys/types.h> | |
18 #include <sys/stat.h> | |
19 #include <time.h> | |
20 #include <unistd.h> | |
21 #include "configfile.h" | |
22 #include "log.h" | |
23 #include "util.h" | |
24 | |
25 struct Outgoing | |
26 { | |
27 DIR *dir; | |
28 Str serv; | |
29 } outgoing = { NULL, "" }; | |
30 | |
31 static void | |
32 fileOutgoing( Str file, const char *serv, const char *msgId ) | |
33 { | |
34 snprintf( file, MAXCHAR, "%s/outgoing/%s/%s", | |
35 Cfg_spoolDir(), serv, msgId ); | |
36 } | |
37 | |
38 static void | |
39 createDir( const char *serv ) | |
40 { | |
41 Str dir; | |
42 int r; | |
43 | |
44 snprintf( dir, MAXCHAR, "%s/outgoing/%s", Cfg_spoolDir(), serv ); | |
45 r = mkdir( dir, 0755 ); | |
46 if ( r != 0 ) | |
47 Log_dbg( "mkdir: %s", strerror( errno ) ); | |
48 } | |
49 | |
50 Bool | |
51 Out_add( const char *serv, const char *msgId, const DynStr *artTxt ) | |
52 { | |
53 Str file; | |
54 FILE *f; | |
55 | |
56 fileOutgoing( file, serv, msgId ); | |
57 if ( ! ( f = fopen( file, "w" ) ) ) | |
58 { | |
59 createDir( serv ); | |
60 if ( ! ( f = fopen( file, "w" ) ) ) | |
61 { | |
62 Log_err( "Cannot open %s", file ); | |
63 return FALSE; | |
64 } | |
65 } | |
66 fprintf( f, "%s", DynStr_str( artTxt ) ); | |
67 fclose( f ); | |
68 return TRUE; | |
69 } | |
70 | |
71 Bool | |
72 Out_first( const char *serv, Str msgId, DynStr *artTxt ) | |
73 { | |
74 Str file; | |
75 | |
76 snprintf( file, MAXCHAR, "%s/outgoing/%s", Cfg_spoolDir(), serv ); | |
77 if ( ! ( outgoing.dir = opendir( file ) ) ) | |
78 { | |
79 Log_dbg( "Cannot open %s", file ); | |
80 return FALSE; | |
81 } | |
82 Utl_cpyStr( outgoing.serv, serv ); | |
83 Out_next( NULL, NULL ); /* "." */ | |
84 Out_next( NULL, NULL ); /* ".." */ | |
85 return Out_next( msgId, artTxt ); | |
86 } | |
87 | |
88 Bool | |
89 Out_next( Str msgId, DynStr *artTxt ) | |
90 { | |
91 struct dirent *d; | |
92 FILE *f; | |
93 Str file, line; | |
94 | |
95 ASSERT( outgoing.dir ); | |
96 if ( ! ( d = readdir( outgoing.dir ) ) ) | |
97 { | |
98 closedir( outgoing.dir ); | |
99 outgoing.dir = NULL; | |
100 return FALSE; | |
101 } | |
102 if ( artTxt == NULL ) | |
103 return ( d->d_name != NULL ); | |
104 fileOutgoing( file, outgoing.serv, d->d_name ); | |
105 if ( ! ( f = fopen( file, "r" ) ) ) | |
106 { | |
107 Log_err( "Cannot open %s for read", file ); | |
108 return FALSE; | |
109 } | |
110 DynStr_clear( artTxt ); | |
111 while ( fgets( line, MAXCHAR, f ) ) | |
112 DynStr_app( artTxt, line ); | |
113 Utl_cpyStr( msgId, d->d_name ); | |
114 fclose( f ); | |
115 return TRUE; | |
116 } | |
117 | |
118 void | |
119 Out_remove( const char *serv, const char *msgId ) | |
120 { | |
121 Str file; | |
122 | |
123 fileOutgoing( file, serv, msgId ); | |
124 if ( unlink( file ) != 0 ) | |
125 Log_err( "Cannot remove %s", file ); | |
126 } | |
127 | |
128 Bool | |
129 Out_find( const char *msgId, Str server ) | |
130 { | |
131 Str servdir; | |
132 DIR *d; | |
133 struct dirent *entry; | |
134 Bool res; | |
135 | |
136 | |
137 snprintf( servdir, MAXCHAR, "%s/outgoing", Cfg_spoolDir() ); | |
138 if ( ! ( d = opendir( servdir ) ) ) | |
139 { | |
140 Log_dbg( "Cannot open %s", servdir ); | |
141 return FALSE; | |
142 } | |
143 | |
144 readdir( d ); /* '.' */ | |
145 readdir( d ); /* '..' */ | |
146 | |
147 res = FALSE; | |
148 while ( ! res && ( entry = readdir( d ) ) != NULL ) | |
149 { | |
150 Str file; | |
151 struct stat s; | |
152 | |
153 fileOutgoing( file, entry->d_name, msgId ); | |
154 if ( stat( file, &s ) == 0 ) | |
155 { | |
156 res = TRUE; | |
157 Utl_cpyStr( server, entry->d_name ); | |
158 } | |
159 } | |
160 | |
161 closedir( d ); | |
162 return res; | |
163 } | |
164 | |
165 | |
166 | |
167 | |
168 |