annotate src/fetchlist.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 01755687c565
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 fetchlist.c
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
3
287
01755687c565 [svn] * src/configfile.c: Change snprintf() to Utl_cpyStr();
bears
parents: 281
diff changeset
4 $Id: fetchlist.c 419 2003-01-10 23:11:43Z 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>
232
6767c6f3218f [svn] * src/fetchlist.c: Write fetchlist to new file and update if written
bears
parents: 185
diff changeset
12 #include <errno.h>
6767c6f3218f [svn] * src/fetchlist.c: Write fetchlist to new file and update if written
bears
parents: 185
diff changeset
13 #include <unistd.h>
43
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
14 #include "fetchlist.h"
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
15 #include "configfile.h"
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
16 #include "log.h"
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
17 #include "util.h"
54
125d79c9e586 [svn] * src/client.c, src/configfile.c, src/content.c, src/control.c,
uh1763
parents: 45
diff changeset
18 #include "portable.h"
43
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
19
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
20 struct Elem
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
21 {
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
22 Str name;
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
23 FetchMode mode;
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
24 };
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
25
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
26 static struct Fetchlist
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
27 {
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
28 struct Elem *elem;
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
29 int size;
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
30 int max;
232
6767c6f3218f [svn] * src/fetchlist.c: Write fetchlist to new file and update if written
bears
parents: 185
diff changeset
31 Bool dirty;
6767c6f3218f [svn] * src/fetchlist.c: Write fetchlist to new file and update if written
bears
parents: 185
diff changeset
32 } fetchlist = { NULL, 0, 0, FALSE };
43
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
33
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
34 static void
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
35 clearList( void )
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 fetchlist.size = 0;
232
6767c6f3218f [svn] * src/fetchlist.c: Write fetchlist to new file and update if written
bears
parents: 185
diff changeset
38 fetchlist.dirty = FALSE;
43
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
39 }
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
40
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
41 static int
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
42 compareElem( const void *elem1, const void *elem2 )
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
43 {
62
53cfa011a08c [svn] Avoid compiler warning because of cast from const to non-const.
enz
parents: 61
diff changeset
44 const struct Elem* e1 = (const struct Elem*)elem1;
53cfa011a08c [svn] Avoid compiler warning because of cast from const to non-const.
enz
parents: 61
diff changeset
45 const struct Elem* e2 = (const struct Elem*)elem2;
43
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
46 return strcmp( e1->name, e2->name );
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
47 }
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
48
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
49 static struct Elem *
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
50 searchElem( const char *name )
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
51 {
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
52 int i;
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
53
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
54 for ( i = 0; i < fetchlist.size; ++i )
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
55 if ( strcmp( name, fetchlist.elem[ i ].name ) == 0 )
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
56 return &fetchlist.elem[ i ];
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
57 return NULL;
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
58 }
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
59
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
60 static void
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
61 appGrp( const char *name, FetchMode mode )
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
62 {
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
63 struct Elem elem;
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
64
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
65 if ( fetchlist.max < fetchlist.size + 1 )
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 if ( ! ( fetchlist.elem
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
68 = realloc( fetchlist.elem,
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
69 ( fetchlist.max + 50 )
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
70 * sizeof( fetchlist.elem[ 0 ] ) ) ) )
281
5eece4dfd945 [svn] * src/log.c,src/log.h: Add Log_fatal() for reporting fatal errors
bears
parents: 237
diff changeset
71 Log_fatal( "Could not realloc fetchlist" );
43
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
72 fetchlist.max += 50;
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
73 }
287
01755687c565 [svn] * src/configfile.c: Change snprintf() to Utl_cpyStr();
bears
parents: 281
diff changeset
74 Utl_cpyStr( elem.name, name );
43
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
75 elem.mode = mode;
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
76 fetchlist.elem[ fetchlist.size++ ] = elem;
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
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
79 void
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
80 Fetchlist_read( void )
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 FILE *f;
232
6767c6f3218f [svn] * src/fetchlist.c: Write fetchlist to new file and update if written
bears
parents: 185
diff changeset
83 Str file;
43
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
84 char *p;
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
85 FetchMode mode = OVER;
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
86 Bool valid;
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
87 int ret;
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
88 Str line, grp, modeStr;
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
89
185
fed1334d766b [svn] * src/client.c: Change variable only used on constant to 'const'.
bears
parents: 62
diff changeset
90 Log_dbg( LOG_DBG_FETCH, "Reading %s", file );
232
6767c6f3218f [svn] * src/fetchlist.c: Write fetchlist to new file and update if written
bears
parents: 185
diff changeset
91 snprintf( file, MAXCHAR, "%s/fetchlist", Cfg_spoolDir() );
43
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
92 clearList();
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
93 if ( ! ( f = fopen( file, "r" ) ) )
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
94 {
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
95 Log_inf( "No file %s", file );
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
96 return;
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 while ( fgets( line, MAXCHAR, f ) )
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 p = Utl_stripWhiteSpace( line );
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
101 if ( *p == '#' || *p == '\0' )
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
102 continue;
287
01755687c565 [svn] * src/configfile.c: Change snprintf() to Utl_cpyStr();
bears
parents: 281
diff changeset
103 ret = sscanf( p, MAXCHAR_FMT " " MAXCHAR_FMT, grp, modeStr );
43
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
104 valid = TRUE;
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
105 if ( ret < 1 || ret > 2 )
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
106 valid = FALSE;
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
107 else if ( ret >= 2 )
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
108 {
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
109 if ( strcmp( modeStr, "full" ) == 0 )
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
110 mode = FULL;
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
111 else if ( strcmp( modeStr, "thread" ) == 0 )
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
112 mode = THREAD;
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
113 else if ( strcmp( modeStr, "over" ) == 0 )
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
114 mode = OVER;
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
115 else
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
116 valid = FALSE;
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
117 }
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
118 if ( ! valid )
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 Log_err( "Invalid entry in %s: %s", file, line );
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
121 continue;
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 appGrp( grp, mode );
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
124 }
232
6767c6f3218f [svn] * src/fetchlist.c: Write fetchlist to new file and update if written
bears
parents: 185
diff changeset
125 if ( ferror( f ) )
6767c6f3218f [svn] * src/fetchlist.c: Write fetchlist to new file and update if written
bears
parents: 185
diff changeset
126 Log_err( "Error reading %s: %s", file, strerror( errno ) );
6767c6f3218f [svn] * src/fetchlist.c: Write fetchlist to new file and update if written
bears
parents: 185
diff changeset
127 if ( fclose( f ) != 0 )
6767c6f3218f [svn] * src/fetchlist.c: Write fetchlist to new file and update if written
bears
parents: 185
diff changeset
128 Log_err( "Error closing %s; %s", file, strerror( errno ) );
43
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
129 }
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
130
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
131 Bool
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
132 Fetchlist_write( void )
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
133 {
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
134 int i;
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
135 FILE *f;
232
6767c6f3218f [svn] * src/fetchlist.c: Write fetchlist to new file and update if written
bears
parents: 185
diff changeset
136 Str file, tmpfname;
43
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
137 const char *modeStr = "";
232
6767c6f3218f [svn] * src/fetchlist.c: Write fetchlist to new file and update if written
bears
parents: 185
diff changeset
138 Bool res;
43
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
139
232
6767c6f3218f [svn] * src/fetchlist.c: Write fetchlist to new file and update if written
bears
parents: 185
diff changeset
140 /* Any changes? */
6767c6f3218f [svn] * src/fetchlist.c: Write fetchlist to new file and update if written
bears
parents: 185
diff changeset
141 if ( ! fetchlist.dirty )
6767c6f3218f [svn] * src/fetchlist.c: Write fetchlist to new file and update if written
bears
parents: 185
diff changeset
142 return TRUE;
6767c6f3218f [svn] * src/fetchlist.c: Write fetchlist to new file and update if written
bears
parents: 185
diff changeset
143
45
32ba1198c6fa [svn] * Makefile.in, configure, configure.in, docs/Makefile.in, src/Makefile.in:
uh1763
parents: 43
diff changeset
144 qsort( fetchlist.elem, (size_t)fetchlist.size,
32ba1198c6fa [svn] * Makefile.in, configure, configure.in, docs/Makefile.in, src/Makefile.in:
uh1763
parents: 43
diff changeset
145 sizeof( fetchlist.elem[ 0 ] ), compareElem );
232
6767c6f3218f [svn] * src/fetchlist.c: Write fetchlist to new file and update if written
bears
parents: 185
diff changeset
146
6767c6f3218f [svn] * src/fetchlist.c: Write fetchlist to new file and update if written
bears
parents: 185
diff changeset
147 snprintf( file, MAXCHAR, "%s/fetchlist", Cfg_spoolDir() );
6767c6f3218f [svn] * src/fetchlist.c: Write fetchlist to new file and update if written
bears
parents: 185
diff changeset
148 snprintf( tmpfname, MAXCHAR, "%s/.#%d.fetchlist",
6767c6f3218f [svn] * src/fetchlist.c: Write fetchlist to new file and update if written
bears
parents: 185
diff changeset
149 Cfg_spoolDir(), (int) getpid() );
6767c6f3218f [svn] * src/fetchlist.c: Write fetchlist to new file and update if written
bears
parents: 185
diff changeset
150
6767c6f3218f [svn] * src/fetchlist.c: Write fetchlist to new file and update if written
bears
parents: 185
diff changeset
151 if ( ! ( f = fopen( tmpfname, "w" ) ) )
43
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 Log_err( "Could not open %s for writing", file );
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
154 return FALSE;
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
155 }
232
6767c6f3218f [svn] * src/fetchlist.c: Write fetchlist to new file and update if written
bears
parents: 185
diff changeset
156 res = TRUE;
43
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
157 for ( i = 0; i < fetchlist.size; ++i )
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 switch ( fetchlist.elem[ i ].mode )
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
160 {
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
161 case FULL:
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
162 modeStr = "full"; break;
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
163 case THREAD:
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
164 modeStr = "thread"; break;
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
165 case OVER:
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
166 modeStr = "over"; break;
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
167 }
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
168 fprintf( f, "%s %s\n", fetchlist.elem[ i ].name, modeStr );
232
6767c6f3218f [svn] * src/fetchlist.c: Write fetchlist to new file and update if written
bears
parents: 185
diff changeset
169 if ( ferror( f ) )
6767c6f3218f [svn] * src/fetchlist.c: Write fetchlist to new file and update if written
bears
parents: 185
diff changeset
170 {
6767c6f3218f [svn] * src/fetchlist.c: Write fetchlist to new file and update if written
bears
parents: 185
diff changeset
171 Log_err( "Error writing %s: %s", tmpfname, strerror( errno ) );
6767c6f3218f [svn] * src/fetchlist.c: Write fetchlist to new file and update if written
bears
parents: 185
diff changeset
172 clearerr( f );
6767c6f3218f [svn] * src/fetchlist.c: Write fetchlist to new file and update if written
bears
parents: 185
diff changeset
173 res = FALSE;
6767c6f3218f [svn] * src/fetchlist.c: Write fetchlist to new file and update if written
bears
parents: 185
diff changeset
174 }
43
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
175 }
232
6767c6f3218f [svn] * src/fetchlist.c: Write fetchlist to new file and update if written
bears
parents: 185
diff changeset
176 if ( fclose( f ) != 0 )
6767c6f3218f [svn] * src/fetchlist.c: Write fetchlist to new file and update if written
bears
parents: 185
diff changeset
177 {
6767c6f3218f [svn] * src/fetchlist.c: Write fetchlist to new file and update if written
bears
parents: 185
diff changeset
178 Log_err( "Error closing %s: %s", tmpfname, strerror( errno ) );
6767c6f3218f [svn] * src/fetchlist.c: Write fetchlist to new file and update if written
bears
parents: 185
diff changeset
179 res = FALSE;
6767c6f3218f [svn] * src/fetchlist.c: Write fetchlist to new file and update if written
bears
parents: 185
diff changeset
180 }
6767c6f3218f [svn] * src/fetchlist.c: Write fetchlist to new file and update if written
bears
parents: 185
diff changeset
181
6767c6f3218f [svn] * src/fetchlist.c: Write fetchlist to new file and update if written
bears
parents: 185
diff changeset
182 if ( res )
6767c6f3218f [svn] * src/fetchlist.c: Write fetchlist to new file and update if written
bears
parents: 185
diff changeset
183 {
6767c6f3218f [svn] * src/fetchlist.c: Write fetchlist to new file and update if written
bears
parents: 185
diff changeset
184 if ( rename( tmpfname, file ) < 0 )
6767c6f3218f [svn] * src/fetchlist.c: Write fetchlist to new file and update if written
bears
parents: 185
diff changeset
185 {
6767c6f3218f [svn] * src/fetchlist.c: Write fetchlist to new file and update if written
bears
parents: 185
diff changeset
186 Log_err( "Rename of %s to %s failed: %s", tmpfname, file,
6767c6f3218f [svn] * src/fetchlist.c: Write fetchlist to new file and update if written
bears
parents: 185
diff changeset
187 strerror( errno ) );
6767c6f3218f [svn] * src/fetchlist.c: Write fetchlist to new file and update if written
bears
parents: 185
diff changeset
188 res = FALSE;
6767c6f3218f [svn] * src/fetchlist.c: Write fetchlist to new file and update if written
bears
parents: 185
diff changeset
189 }
6767c6f3218f [svn] * src/fetchlist.c: Write fetchlist to new file and update if written
bears
parents: 185
diff changeset
190 }
6767c6f3218f [svn] * src/fetchlist.c: Write fetchlist to new file and update if written
bears
parents: 185
diff changeset
191
6767c6f3218f [svn] * src/fetchlist.c: Write fetchlist to new file and update if written
bears
parents: 185
diff changeset
192 return res;
43
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
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
195 int
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
196 Fetchlist_size( void )
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
197 {
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
198 return fetchlist.size;
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
199 }
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
200
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
201 Bool
237
f8a91e2b4060 [svn] * src/fetchlist.h,src/fetchlist.c,src/noffle.c: Provide fetchmode for
bears
parents: 232
diff changeset
202 Fetchlist_contains( const char *name, FetchMode *mode )
43
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
203 {
237
f8a91e2b4060 [svn] * src/fetchlist.h,src/fetchlist.c,src/noffle.c: Provide fetchmode for
bears
parents: 232
diff changeset
204 struct Elem *elem = searchElem( name );
f8a91e2b4060 [svn] * src/fetchlist.h,src/fetchlist.c,src/noffle.c: Provide fetchmode for
bears
parents: 232
diff changeset
205 if ( elem == NULL )
f8a91e2b4060 [svn] * src/fetchlist.h,src/fetchlist.c,src/noffle.c: Provide fetchmode for
bears
parents: 232
diff changeset
206 return FALSE;
f8a91e2b4060 [svn] * src/fetchlist.h,src/fetchlist.c,src/noffle.c: Provide fetchmode for
bears
parents: 232
diff changeset
207 if ( mode != NULL )
f8a91e2b4060 [svn] * src/fetchlist.h,src/fetchlist.c,src/noffle.c: Provide fetchmode for
bears
parents: 232
diff changeset
208 *mode = elem->mode;
f8a91e2b4060 [svn] * src/fetchlist.h,src/fetchlist.c,src/noffle.c: Provide fetchmode for
bears
parents: 232
diff changeset
209 return TRUE;
43
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
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
212 Bool
61
adf0af5152f7 [svn] Renamed some variables and function names, because they caused compiler
enz
parents: 54
diff changeset
213 Fetchlist_element( const char **name, FetchMode *mode, int idx )
43
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
214 {
61
adf0af5152f7 [svn] Renamed some variables and function names, because they caused compiler
enz
parents: 54
diff changeset
215 if ( idx < 0 || idx >= fetchlist.size )
43
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
216 return FALSE;
61
adf0af5152f7 [svn] Renamed some variables and function names, because they caused compiler
enz
parents: 54
diff changeset
217 *name = fetchlist.elem[ idx ].name;
adf0af5152f7 [svn] Renamed some variables and function names, because they caused compiler
enz
parents: 54
diff changeset
218 *mode = fetchlist.elem[ idx ].mode;
43
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
219 return TRUE;
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
220 }
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
221
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
222 Bool
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
223 Fetchlist_add( const char *name, FetchMode mode )
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
224 {
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
225 struct Elem *elem = searchElem( name );
232
6767c6f3218f [svn] * src/fetchlist.c: Write fetchlist to new file and update if written
bears
parents: 185
diff changeset
226 fetchlist.dirty = TRUE;
43
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
227 if ( elem == NULL )
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 appGrp( name, mode );
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
230 return TRUE;
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
231 }
287
01755687c565 [svn] * src/configfile.c: Change snprintf() to Utl_cpyStr();
bears
parents: 281
diff changeset
232 Utl_cpyStr( elem->name, name );
43
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
233 elem->mode = mode;
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
234 return FALSE;
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
235 }
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 Bool
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
238 Fetchlist_remove( const char *name )
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
239 {
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
240 struct Elem *elem = searchElem( name );
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
241 if ( elem == NULL )
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
242 return FALSE;
232
6767c6f3218f [svn] * src/fetchlist.c: Write fetchlist to new file and update if written
bears
parents: 185
diff changeset
243 fetchlist.dirty = TRUE;
43
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
244 *elem = fetchlist.elem[ fetchlist.size - 1 ];
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
245 --fetchlist.size;
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
246 return TRUE;
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
247 }