annotate src/post.c @ 93:eb522db0d032 noffle

[svn] Renamed date format and enforce correct date format on post
author bears
date Fri, 19 May 2000 16:14:41 +0100
parents 1fcdced0246e
children af51bf245bc3
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 post.c
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
3
93
eb522db0d032 [svn] Renamed date format and enforce correct date format on post
bears
parents: 88
diff changeset
4 $Id: post.c 112 2000-05-19 15:14:41Z 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 "post.h"
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
13 #include <string.h>
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
14 #include "common.h"
88
1fcdced0246e [svn] Move posting code to post.c, add command line posting
bears
parents: 64
diff changeset
15 #include "configfile.h"
43
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
16 #include "content.h"
88
1fcdced0246e [svn] Move posting code to post.c, add command line posting
bears
parents: 64
diff changeset
17 #include "control.h"
43
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
18 #include "database.h"
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
19 #include "group.h"
88
1fcdced0246e [svn] Move posting code to post.c, add command line posting
bears
parents: 64
diff changeset
20 #include "itemlist.h"
43
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
21 #include "log.h"
88
1fcdced0246e [svn] Move posting code to post.c, add command line posting
bears
parents: 64
diff changeset
22 #include "outgoing.h"
43
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
23 #include "over.h"
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
24 #include "protocol.h"
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
25 #include "util.h"
54
125d79c9e586 [svn] * src/client.c, src/configfile.c, src/content.c, src/control.c,
uh1763
parents: 43
diff changeset
26 #include "portable.h"
43
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 OverInfo
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
29 {
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
30 Str subject;
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
31 Str from;
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
32 Str date;
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
33 Str msgId;
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
34 Str ref;
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
35 size_t bytes;
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
36 size_t lines;
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
37 };
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
38
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
39 struct Article
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
40 {
88
1fcdced0246e [svn] Move posting code to post.c, add command line posting
bears
parents: 64
diff changeset
41 DynStr *text; /* Processed article text */
1fcdced0246e [svn] Move posting code to post.c, add command line posting
bears
parents: 64
diff changeset
42 ItemList *newsgroups; /* Newsgroups for dispatch */
1fcdced0246e [svn] Move posting code to post.c, add command line posting
bears
parents: 64
diff changeset
43 ItemList *control; /* Control message? NULL if not */
1fcdced0246e [svn] Move posting code to post.c, add command line posting
bears
parents: 64
diff changeset
44 Bool posted; /* Has it been put in the article database? */
1fcdced0246e [svn] Move posting code to post.c, add command line posting
bears
parents: 64
diff changeset
45 const char *server; /* Server for external post */
43
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
46 struct OverInfo over;
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
88
1fcdced0246e [svn] Move posting code to post.c, add command line posting
bears
parents: 64
diff changeset
49 static struct Article article = { NULL, NULL, NULL, FALSE, NULL,
1fcdced0246e [svn] Move posting code to post.c, add command line posting
bears
parents: 64
diff changeset
50 { "", "", "", "", "", 0, 0 } };
43
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 /* Add the article to a group. */
88
1fcdced0246e [svn] Move posting code to post.c, add command line posting
bears
parents: 64
diff changeset
53 static Bool
1fcdced0246e [svn] Move posting code to post.c, add command line posting
bears
parents: 64
diff changeset
54 addToGroup( const char * grp )
43
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
55 {
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
56 Over * over;
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
57 const char *msgId;
88
1fcdced0246e [svn] Move posting code to post.c, add command line posting
bears
parents: 64
diff changeset
58
43
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
59 over = new_Over( article.over.subject,
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
60 article.over.from,
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
61 article.over.date,
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
62 article.over.msgId,
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
63 article.over.ref,
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
64 article.over.bytes,
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
65 article.over.lines );
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 msgId = article.over.msgId;
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
68
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
69 Cont_read( grp );
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
70 Cont_app( over );
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
71 Log_dbg( "Added message '%s' to group '%s'.", msgId, grp );
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
72
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
73 if ( !article.posted )
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
74 {
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
75 Log_inf( "Added '%s' to database.", msgId );
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
76 if ( ! Db_prepareEntry( over, Cont_grp(), Cont_last() )
88
1fcdced0246e [svn] Move posting code to post.c, add command line posting
bears
parents: 64
diff changeset
77 || ! Db_storeArt ( msgId, DynStr_str( article.text ) ) )
43
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
78 return FALSE;
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
79 article.posted = TRUE;
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
80 }
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
81 else
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
82 {
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
83 Str t;
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
84 const char *xref;
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
85
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
86 xref = Db_xref( msgId );
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
87 Log_dbg( "Adding '%s' to Xref of '%s'", grp, msgId );
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
88 snprintf( t, MAXCHAR, "%s %s:%i", xref, grp, Ov_numb( over ) );
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
89 Db_setXref( msgId, t );
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
90 }
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
91
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
92 Cont_write();
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
93 Grp_setFirstLast( Cont_grp(), Cont_first(), Cont_last() );
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
94 return TRUE;
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
95 }
88
1fcdced0246e [svn] Move posting code to post.c, add command line posting
bears
parents: 64
diff changeset
96
1fcdced0246e [svn] Move posting code to post.c, add command line posting
bears
parents: 64
diff changeset
97 static Bool
1fcdced0246e [svn] Move posting code to post.c, add command line posting
bears
parents: 64
diff changeset
98 checkPostableNewsgroup( Bool localOnly )
1fcdced0246e [svn] Move posting code to post.c, add command line posting
bears
parents: 64
diff changeset
99 {
1fcdced0246e [svn] Move posting code to post.c, add command line posting
bears
parents: 64
diff changeset
100 const char *grp;
1fcdced0246e [svn] Move posting code to post.c, add command line posting
bears
parents: 64
diff changeset
101 Bool knownGrp = FALSE;
1fcdced0246e [svn] Move posting code to post.c, add command line posting
bears
parents: 64
diff changeset
102 Bool postAllowedGrp = FALSE;
1fcdced0246e [svn] Move posting code to post.c, add command line posting
bears
parents: 64
diff changeset
103 Bool local;
1fcdced0246e [svn] Move posting code to post.c, add command line posting
bears
parents: 64
diff changeset
104
1fcdced0246e [svn] Move posting code to post.c, add command line posting
bears
parents: 64
diff changeset
105 /*
1fcdced0246e [svn] Move posting code to post.c, add command line posting
bears
parents: 64
diff changeset
106 Check at least one group is known. Look for external group and
1fcdced0246e [svn] Move posting code to post.c, add command line posting
bears
parents: 64
diff changeset
107 set server.
1fcdced0246e [svn] Move posting code to post.c, add command line posting
bears
parents: 64
diff changeset
108 */
1fcdced0246e [svn] Move posting code to post.c, add command line posting
bears
parents: 64
diff changeset
109 article.server = NULL;
1fcdced0246e [svn] Move posting code to post.c, add command line posting
bears
parents: 64
diff changeset
110 for( grp = Itl_first( article.newsgroups );
1fcdced0246e [svn] Move posting code to post.c, add command line posting
bears
parents: 64
diff changeset
111 grp != NULL;
1fcdced0246e [svn] Move posting code to post.c, add command line posting
bears
parents: 64
diff changeset
112 grp = Itl_next( article.newsgroups ) )
1fcdced0246e [svn] Move posting code to post.c, add command line posting
bears
parents: 64
diff changeset
113 {
1fcdced0246e [svn] Move posting code to post.c, add command line posting
bears
parents: 64
diff changeset
114 if ( Grp_exists( grp ) )
1fcdced0246e [svn] Move posting code to post.c, add command line posting
bears
parents: 64
diff changeset
115 {
1fcdced0246e [svn] Move posting code to post.c, add command line posting
bears
parents: 64
diff changeset
116 local = Grp_local( grp );
1fcdced0246e [svn] Move posting code to post.c, add command line posting
bears
parents: 64
diff changeset
117 if ( localOnly && ! local )
1fcdced0246e [svn] Move posting code to post.c, add command line posting
bears
parents: 64
diff changeset
118 continue;
1fcdced0246e [svn] Move posting code to post.c, add command line posting
bears
parents: 64
diff changeset
119 knownGrp = TRUE;
1fcdced0246e [svn] Move posting code to post.c, add command line posting
bears
parents: 64
diff changeset
120 switch( Grp_postAllow( grp ) )
1fcdced0246e [svn] Move posting code to post.c, add command line posting
bears
parents: 64
diff changeset
121 {
1fcdced0246e [svn] Move posting code to post.c, add command line posting
bears
parents: 64
diff changeset
122 case 'n':
1fcdced0246e [svn] Move posting code to post.c, add command line posting
bears
parents: 64
diff changeset
123 if ( localOnly )
1fcdced0246e [svn] Move posting code to post.c, add command line posting
bears
parents: 64
diff changeset
124 postAllowedGrp = TRUE;
1fcdced0246e [svn] Move posting code to post.c, add command line posting
bears
parents: 64
diff changeset
125 break;
1fcdced0246e [svn] Move posting code to post.c, add command line posting
bears
parents: 64
diff changeset
126 case 'y':
1fcdced0246e [svn] Move posting code to post.c, add command line posting
bears
parents: 64
diff changeset
127 postAllowedGrp = TRUE;
1fcdced0246e [svn] Move posting code to post.c, add command line posting
bears
parents: 64
diff changeset
128 break;
1fcdced0246e [svn] Move posting code to post.c, add command line posting
bears
parents: 64
diff changeset
129 default:
1fcdced0246e [svn] Move posting code to post.c, add command line posting
bears
parents: 64
diff changeset
130 if ( localOnly )
1fcdced0246e [svn] Move posting code to post.c, add command line posting
bears
parents: 64
diff changeset
131 postAllowedGrp = TRUE;
1fcdced0246e [svn] Move posting code to post.c, add command line posting
bears
parents: 64
diff changeset
132 else
1fcdced0246e [svn] Move posting code to post.c, add command line posting
bears
parents: 64
diff changeset
133 /* Can't post to moderated local groups. */
1fcdced0246e [svn] Move posting code to post.c, add command line posting
bears
parents: 64
diff changeset
134 postAllowedGrp = ! local;
1fcdced0246e [svn] Move posting code to post.c, add command line posting
bears
parents: 64
diff changeset
135 break;
1fcdced0246e [svn] Move posting code to post.c, add command line posting
bears
parents: 64
diff changeset
136 }
1fcdced0246e [svn] Move posting code to post.c, add command line posting
bears
parents: 64
diff changeset
137 if ( postAllowedGrp && ! local && article.server == NULL )
1fcdced0246e [svn] Move posting code to post.c, add command line posting
bears
parents: 64
diff changeset
138 article.server = Grp_server( grp );
1fcdced0246e [svn] Move posting code to post.c, add command line posting
bears
parents: 64
diff changeset
139 if ( postAllowedGrp && article.server != NULL )
1fcdced0246e [svn] Move posting code to post.c, add command line posting
bears
parents: 64
diff changeset
140 break;
1fcdced0246e [svn] Move posting code to post.c, add command line posting
bears
parents: 64
diff changeset
141 }
1fcdced0246e [svn] Move posting code to post.c, add command line posting
bears
parents: 64
diff changeset
142 }
1fcdced0246e [svn] Move posting code to post.c, add command line posting
bears
parents: 64
diff changeset
143
1fcdced0246e [svn] Move posting code to post.c, add command line posting
bears
parents: 64
diff changeset
144 if ( ! knownGrp )
1fcdced0246e [svn] Move posting code to post.c, add command line posting
bears
parents: 64
diff changeset
145 {
1fcdced0246e [svn] Move posting code to post.c, add command line posting
bears
parents: 64
diff changeset
146 Log_err( "No known group in Newsgroups header field" );
1fcdced0246e [svn] Move posting code to post.c, add command line posting
bears
parents: 64
diff changeset
147 return FALSE;
1fcdced0246e [svn] Move posting code to post.c, add command line posting
bears
parents: 64
diff changeset
148 }
1fcdced0246e [svn] Move posting code to post.c, add command line posting
bears
parents: 64
diff changeset
149 else if ( ! postAllowedGrp )
1fcdced0246e [svn] Move posting code to post.c, add command line posting
bears
parents: 64
diff changeset
150 {
1fcdced0246e [svn] Move posting code to post.c, add command line posting
bears
parents: 64
diff changeset
151 Log_err( "No group permits posting" );
1fcdced0246e [svn] Move posting code to post.c, add command line posting
bears
parents: 64
diff changeset
152 return FALSE;
1fcdced0246e [svn] Move posting code to post.c, add command line posting
bears
parents: 64
diff changeset
153 }
1fcdced0246e [svn] Move posting code to post.c, add command line posting
bears
parents: 64
diff changeset
154
1fcdced0246e [svn] Move posting code to post.c, add command line posting
bears
parents: 64
diff changeset
155 return TRUE;
1fcdced0246e [svn] Move posting code to post.c, add command line posting
bears
parents: 64
diff changeset
156 }
1fcdced0246e [svn] Move posting code to post.c, add command line posting
bears
parents: 64
diff changeset
157
1fcdced0246e [svn] Move posting code to post.c, add command line posting
bears
parents: 64
diff changeset
158 /* Get article text, check for validity & build overview. */
1fcdced0246e [svn] Move posting code to post.c, add command line posting
bears
parents: 64
diff changeset
159 static Bool
1fcdced0246e [svn] Move posting code to post.c, add command line posting
bears
parents: 64
diff changeset
160 getArticleText( const char *p )
1fcdced0246e [svn] Move posting code to post.c, add command line posting
bears
parents: 64
diff changeset
161 {
1fcdced0246e [svn] Move posting code to post.c, add command line posting
bears
parents: 64
diff changeset
162 DynStr * s;
1fcdced0246e [svn] Move posting code to post.c, add command line posting
bears
parents: 64
diff changeset
163 Str line, field, value;
1fcdced0246e [svn] Move posting code to post.c, add command line posting
bears
parents: 64
diff changeset
164 Bool replyToFound;
93
eb522db0d032 [svn] Renamed date format and enforce correct date format on post
bears
parents: 88
diff changeset
165 time_t t;
88
1fcdced0246e [svn] Move posting code to post.c, add command line posting
bears
parents: 64
diff changeset
166
1fcdced0246e [svn] Move posting code to post.c, add command line posting
bears
parents: 64
diff changeset
167 s = new_DynStr( 10000 );
1fcdced0246e [svn] Move posting code to post.c, add command line posting
bears
parents: 64
diff changeset
168 article.text = s;
1fcdced0246e [svn] Move posting code to post.c, add command line posting
bears
parents: 64
diff changeset
169
1fcdced0246e [svn] Move posting code to post.c, add command line posting
bears
parents: 64
diff changeset
170 memset( &article.over, 0, sizeof( article.over ) );
1fcdced0246e [svn] Move posting code to post.c, add command line posting
bears
parents: 64
diff changeset
171 replyToFound = FALSE;
1fcdced0246e [svn] Move posting code to post.c, add command line posting
bears
parents: 64
diff changeset
172
1fcdced0246e [svn] Move posting code to post.c, add command line posting
bears
parents: 64
diff changeset
173 /* Grab header lines first, getting overview info as we go. */
1fcdced0246e [svn] Move posting code to post.c, add command line posting
bears
parents: 64
diff changeset
174 while ( ( p = Utl_getHeaderLn( line, p ) ) != NULL
1fcdced0246e [svn] Move posting code to post.c, add command line posting
bears
parents: 64
diff changeset
175 && line[ 0 ] != '\0'
1fcdced0246e [svn] Move posting code to post.c, add command line posting
bears
parents: 64
diff changeset
176 && Prt_getField( field, value, line ) )
1fcdced0246e [svn] Move posting code to post.c, add command line posting
bears
parents: 64
diff changeset
177 {
1fcdced0246e [svn] Move posting code to post.c, add command line posting
bears
parents: 64
diff changeset
178 /* Look for headers we need to stash. */
1fcdced0246e [svn] Move posting code to post.c, add command line posting
bears
parents: 64
diff changeset
179 if ( strcmp( field, "subject" ) == 0 )
1fcdced0246e [svn] Move posting code to post.c, add command line posting
bears
parents: 64
diff changeset
180 {
1fcdced0246e [svn] Move posting code to post.c, add command line posting
bears
parents: 64
diff changeset
181 Utl_cpyStr( article.over.subject, value );
1fcdced0246e [svn] Move posting code to post.c, add command line posting
bears
parents: 64
diff changeset
182 DynStr_appLn( s, line );
1fcdced0246e [svn] Move posting code to post.c, add command line posting
bears
parents: 64
diff changeset
183 }
1fcdced0246e [svn] Move posting code to post.c, add command line posting
bears
parents: 64
diff changeset
184 else if ( strcmp ( field, "from" ) == 0 )
1fcdced0246e [svn] Move posting code to post.c, add command line posting
bears
parents: 64
diff changeset
185 {
1fcdced0246e [svn] Move posting code to post.c, add command line posting
bears
parents: 64
diff changeset
186 Utl_cpyStr( article.over.from, value );
1fcdced0246e [svn] Move posting code to post.c, add command line posting
bears
parents: 64
diff changeset
187 DynStr_appLn( s, line );
1fcdced0246e [svn] Move posting code to post.c, add command line posting
bears
parents: 64
diff changeset
188 }
1fcdced0246e [svn] Move posting code to post.c, add command line posting
bears
parents: 64
diff changeset
189 else if ( strcmp ( field, "date" ) == 0 )
1fcdced0246e [svn] Move posting code to post.c, add command line posting
bears
parents: 64
diff changeset
190 Utl_cpyStr( article.over.date, value );
1fcdced0246e [svn] Move posting code to post.c, add command line posting
bears
parents: 64
diff changeset
191 else if ( strcmp ( field, "references" ) == 0 )
1fcdced0246e [svn] Move posting code to post.c, add command line posting
bears
parents: 64
diff changeset
192 {
1fcdced0246e [svn] Move posting code to post.c, add command line posting
bears
parents: 64
diff changeset
193 Utl_cpyStr( article.over.ref, value );
1fcdced0246e [svn] Move posting code to post.c, add command line posting
bears
parents: 64
diff changeset
194 DynStr_appLn( s, line );
1fcdced0246e [svn] Move posting code to post.c, add command line posting
bears
parents: 64
diff changeset
195 }
1fcdced0246e [svn] Move posting code to post.c, add command line posting
bears
parents: 64
diff changeset
196 else if ( strcmp ( field, "message-id" ) == 0 )
1fcdced0246e [svn] Move posting code to post.c, add command line posting
bears
parents: 64
diff changeset
197 Utl_cpyStr( article.over.msgId, value );
1fcdced0246e [svn] Move posting code to post.c, add command line posting
bears
parents: 64
diff changeset
198 else if ( strcmp ( field, "newsgroups" ) == 0 )
1fcdced0246e [svn] Move posting code to post.c, add command line posting
bears
parents: 64
diff changeset
199 {
1fcdced0246e [svn] Move posting code to post.c, add command line posting
bears
parents: 64
diff changeset
200 article.newsgroups = new_Itl( value, " ,\n\t" );
1fcdced0246e [svn] Move posting code to post.c, add command line posting
bears
parents: 64
diff changeset
201 DynStr_appLn( s, line );
1fcdced0246e [svn] Move posting code to post.c, add command line posting
bears
parents: 64
diff changeset
202 }
1fcdced0246e [svn] Move posting code to post.c, add command line posting
bears
parents: 64
diff changeset
203 else if ( strcmp ( field, "control" ) == 0 )
1fcdced0246e [svn] Move posting code to post.c, add command line posting
bears
parents: 64
diff changeset
204 {
1fcdced0246e [svn] Move posting code to post.c, add command line posting
bears
parents: 64
diff changeset
205 article.control = new_Itl( value, " " );
1fcdced0246e [svn] Move posting code to post.c, add command line posting
bears
parents: 64
diff changeset
206 DynStr_appLn( s, line );
1fcdced0246e [svn] Move posting code to post.c, add command line posting
bears
parents: 64
diff changeset
207 }
1fcdced0246e [svn] Move posting code to post.c, add command line posting
bears
parents: 64
diff changeset
208 else if ( strcmp ( field, "reply-to" ) == 0 )
1fcdced0246e [svn] Move posting code to post.c, add command line posting
bears
parents: 64
diff changeset
209 {
1fcdced0246e [svn] Move posting code to post.c, add command line posting
bears
parents: 64
diff changeset
210 replyToFound = TRUE;
1fcdced0246e [svn] Move posting code to post.c, add command line posting
bears
parents: 64
diff changeset
211 DynStr_appLn( s, line );
1fcdced0246e [svn] Move posting code to post.c, add command line posting
bears
parents: 64
diff changeset
212 }
1fcdced0246e [svn] Move posting code to post.c, add command line posting
bears
parents: 64
diff changeset
213 else if ( strcmp ( field, "x-sender" ) == 0 )
1fcdced0246e [svn] Move posting code to post.c, add command line posting
bears
parents: 64
diff changeset
214 {
1fcdced0246e [svn] Move posting code to post.c, add command line posting
bears
parents: 64
diff changeset
215 DynStr_app( s, "X-NOFFLE-X-Sender: " );
1fcdced0246e [svn] Move posting code to post.c, add command line posting
bears
parents: 64
diff changeset
216 DynStr_appLn( s, value );
1fcdced0246e [svn] Move posting code to post.c, add command line posting
bears
parents: 64
diff changeset
217 }
1fcdced0246e [svn] Move posting code to post.c, add command line posting
bears
parents: 64
diff changeset
218 else if ( strcmp ( field, "xref" ) == 0 )
1fcdced0246e [svn] Move posting code to post.c, add command line posting
bears
parents: 64
diff changeset
219 Log_inf( "Xref header in post ignored" );
1fcdced0246e [svn] Move posting code to post.c, add command line posting
bears
parents: 64
diff changeset
220 else
1fcdced0246e [svn] Move posting code to post.c, add command line posting
bears
parents: 64
diff changeset
221 DynStr_appLn( s, line );
1fcdced0246e [svn] Move posting code to post.c, add command line posting
bears
parents: 64
diff changeset
222 }
1fcdced0246e [svn] Move posting code to post.c, add command line posting
bears
parents: 64
diff changeset
223
1fcdced0246e [svn] Move posting code to post.c, add command line posting
bears
parents: 64
diff changeset
224 /* Now sort header-related issues */
1fcdced0246e [svn] Move posting code to post.c, add command line posting
bears
parents: 64
diff changeset
225 if ( article.over.from[ 0 ] == '\0' )
1fcdced0246e [svn] Move posting code to post.c, add command line posting
bears
parents: 64
diff changeset
226 {
1fcdced0246e [svn] Move posting code to post.c, add command line posting
bears
parents: 64
diff changeset
227 Log_err( "Posted message has no From field" );
1fcdced0246e [svn] Move posting code to post.c, add command line posting
bears
parents: 64
diff changeset
228 return FALSE;
1fcdced0246e [svn] Move posting code to post.c, add command line posting
bears
parents: 64
diff changeset
229 }
1fcdced0246e [svn] Move posting code to post.c, add command line posting
bears
parents: 64
diff changeset
230 if ( article.over.subject[ 0 ] == '\0' )
1fcdced0246e [svn] Move posting code to post.c, add command line posting
bears
parents: 64
diff changeset
231 {
1fcdced0246e [svn] Move posting code to post.c, add command line posting
bears
parents: 64
diff changeset
232 Log_err( "Posted message has no Subject field" );
1fcdced0246e [svn] Move posting code to post.c, add command line posting
bears
parents: 64
diff changeset
233 return FALSE;
1fcdced0246e [svn] Move posting code to post.c, add command line posting
bears
parents: 64
diff changeset
234 }
1fcdced0246e [svn] Move posting code to post.c, add command line posting
bears
parents: 64
diff changeset
235 if ( article.newsgroups == NULL || Itl_count( article.newsgroups) == 0 )
1fcdced0246e [svn] Move posting code to post.c, add command line posting
bears
parents: 64
diff changeset
236 {
1fcdced0246e [svn] Move posting code to post.c, add command line posting
bears
parents: 64
diff changeset
237 Log_err( "Posted message has no valid Newsgroups field" );
1fcdced0246e [svn] Move posting code to post.c, add command line posting
bears
parents: 64
diff changeset
238 return FALSE;
1fcdced0246e [svn] Move posting code to post.c, add command line posting
bears
parents: 64
diff changeset
239 }
93
eb522db0d032 [svn] Renamed date format and enforce correct date format on post
bears
parents: 88
diff changeset
240
eb522db0d032 [svn] Renamed date format and enforce correct date format on post
bears
parents: 88
diff changeset
241 /* Ensure correctly formatted date */
eb522db0d032 [svn] Renamed date format and enforce correct date format on post
bears
parents: 88
diff changeset
242 t = Utl_parseNewsDate( article.over.date );
eb522db0d032 [svn] Renamed date format and enforce correct date format on post
bears
parents: 88
diff changeset
243 if ( t == (time_t) -1 )
eb522db0d032 [svn] Renamed date format and enforce correct date format on post
bears
parents: 88
diff changeset
244 {
eb522db0d032 [svn] Renamed date format and enforce correct date format on post
bears
parents: 88
diff changeset
245 time( &t );
eb522db0d032 [svn] Renamed date format and enforce correct date format on post
bears
parents: 88
diff changeset
246 Utl_newsDate( t, article.over.date );
eb522db0d032 [svn] Renamed date format and enforce correct date format on post
bears
parents: 88
diff changeset
247 DynStr_app( s, "Date: " );
eb522db0d032 [svn] Renamed date format and enforce correct date format on post
bears
parents: 88
diff changeset
248 DynStr_appLn( s, article.over.date );
eb522db0d032 [svn] Renamed date format and enforce correct date format on post
bears
parents: 88
diff changeset
249 }
eb522db0d032 [svn] Renamed date format and enforce correct date format on post
bears
parents: 88
diff changeset
250 else
eb522db0d032 [svn] Renamed date format and enforce correct date format on post
bears
parents: 88
diff changeset
251 DynStr_appLn( s, article.over.date );
eb522db0d032 [svn] Renamed date format and enforce correct date format on post
bears
parents: 88
diff changeset
252
eb522db0d032 [svn] Renamed date format and enforce correct date format on post
bears
parents: 88
diff changeset
253 /* Ensure Message ID is present and valid */
88
1fcdced0246e [svn] Move posting code to post.c, add command line posting
bears
parents: 64
diff changeset
254 if ( Cfg_replaceMsgId() )
1fcdced0246e [svn] Move posting code to post.c, add command line posting
bears
parents: 64
diff changeset
255 {
1fcdced0246e [svn] Move posting code to post.c, add command line posting
bears
parents: 64
diff changeset
256 Prt_genMsgId( article.over.msgId, article.over.from, "NOFFLE" );
1fcdced0246e [svn] Move posting code to post.c, add command line posting
bears
parents: 64
diff changeset
257 Log_dbg( "Replacing Message-ID with '%s'", article.over.msgId );
1fcdced0246e [svn] Move posting code to post.c, add command line posting
bears
parents: 64
diff changeset
258 }
1fcdced0246e [svn] Move posting code to post.c, add command line posting
bears
parents: 64
diff changeset
259 else if ( article.over.msgId[ 0 ] == '\0' )
1fcdced0246e [svn] Move posting code to post.c, add command line posting
bears
parents: 64
diff changeset
260 {
1fcdced0246e [svn] Move posting code to post.c, add command line posting
bears
parents: 64
diff changeset
261 Prt_genMsgId( article.over.msgId, article.over.from, "NOFFLE" );
1fcdced0246e [svn] Move posting code to post.c, add command line posting
bears
parents: 64
diff changeset
262 Log_inf( "Adding missing Message-ID '%s'", article.over.msgId );
1fcdced0246e [svn] Move posting code to post.c, add command line posting
bears
parents: 64
diff changeset
263 }
1fcdced0246e [svn] Move posting code to post.c, add command line posting
bears
parents: 64
diff changeset
264 else if ( ! Prt_isValidMsgId( article.over.msgId ) )
1fcdced0246e [svn] Move posting code to post.c, add command line posting
bears
parents: 64
diff changeset
265 {
1fcdced0246e [svn] Move posting code to post.c, add command line posting
bears
parents: 64
diff changeset
266 Log_ntc( "Replacing invalid Message-ID '%s'", article.over.msgId );
1fcdced0246e [svn] Move posting code to post.c, add command line posting
bears
parents: 64
diff changeset
267 Prt_genMsgId( article.over.msgId, article.over.from, "NOFFLE" );
1fcdced0246e [svn] Move posting code to post.c, add command line posting
bears
parents: 64
diff changeset
268 }
1fcdced0246e [svn] Move posting code to post.c, add command line posting
bears
parents: 64
diff changeset
269 DynStr_app( s, "Message-ID: " );
1fcdced0246e [svn] Move posting code to post.c, add command line posting
bears
parents: 64
diff changeset
270 DynStr_appLn( s, article.over.msgId );
93
eb522db0d032 [svn] Renamed date format and enforce correct date format on post
bears
parents: 88
diff changeset
271
eb522db0d032 [svn] Renamed date format and enforce correct date format on post
bears
parents: 88
diff changeset
272 /* Ensure Reply-To header */
88
1fcdced0246e [svn] Move posting code to post.c, add command line posting
bears
parents: 64
diff changeset
273 if ( ! replyToFound )
1fcdced0246e [svn] Move posting code to post.c, add command line posting
bears
parents: 64
diff changeset
274 {
1fcdced0246e [svn] Move posting code to post.c, add command line posting
bears
parents: 64
diff changeset
275 Log_dbg( "Adding Reply-To field to posted message." );
1fcdced0246e [svn] Move posting code to post.c, add command line posting
bears
parents: 64
diff changeset
276 DynStr_app( s, "Reply-To: " );
1fcdced0246e [svn] Move posting code to post.c, add command line posting
bears
parents: 64
diff changeset
277 DynStr_appLn( s, article.over.from );
1fcdced0246e [svn] Move posting code to post.c, add command line posting
bears
parents: 64
diff changeset
278 }
1fcdced0246e [svn] Move posting code to post.c, add command line posting
bears
parents: 64
diff changeset
279
93
eb522db0d032 [svn] Renamed date format and enforce correct date format on post
bears
parents: 88
diff changeset
280 /* OK, header ready to roll. Something to accompany it? */
88
1fcdced0246e [svn] Move posting code to post.c, add command line posting
bears
parents: 64
diff changeset
281 if ( p == NULL || p[ 0 ] == '\0' )
1fcdced0246e [svn] Move posting code to post.c, add command line posting
bears
parents: 64
diff changeset
282 {
1fcdced0246e [svn] Move posting code to post.c, add command line posting
bears
parents: 64
diff changeset
283 Log_err( "Posted message has no body" );
1fcdced0246e [svn] Move posting code to post.c, add command line posting
bears
parents: 64
diff changeset
284 return FALSE;
1fcdced0246e [svn] Move posting code to post.c, add command line posting
bears
parents: 64
diff changeset
285 }
1fcdced0246e [svn] Move posting code to post.c, add command line posting
bears
parents: 64
diff changeset
286
1fcdced0246e [svn] Move posting code to post.c, add command line posting
bears
parents: 64
diff changeset
287 /* Add the empty line separating header and body */
1fcdced0246e [svn] Move posting code to post.c, add command line posting
bears
parents: 64
diff changeset
288 DynStr_appLn( s, "" );
1fcdced0246e [svn] Move posting code to post.c, add command line posting
bears
parents: 64
diff changeset
289
1fcdced0246e [svn] Move posting code to post.c, add command line posting
bears
parents: 64
diff changeset
290 /* Now pop on the rest of the body and count the lines & bytes */
1fcdced0246e [svn] Move posting code to post.c, add command line posting
bears
parents: 64
diff changeset
291 DynStr_app( s, p );
1fcdced0246e [svn] Move posting code to post.c, add command line posting
bears
parents: 64
diff changeset
292 for ( p++, article.over.lines = 0; *p != '\0'; p++ )
1fcdced0246e [svn] Move posting code to post.c, add command line posting
bears
parents: 64
diff changeset
293 if ( *p == '\n' )
1fcdced0246e [svn] Move posting code to post.c, add command line posting
bears
parents: 64
diff changeset
294 article.over.lines++;
1fcdced0246e [svn] Move posting code to post.c, add command line posting
bears
parents: 64
diff changeset
295 article.over.bytes = DynStr_len( s );
1fcdced0246e [svn] Move posting code to post.c, add command line posting
bears
parents: 64
diff changeset
296
1fcdced0246e [svn] Move posting code to post.c, add command line posting
bears
parents: 64
diff changeset
297 return TRUE;
1fcdced0246e [svn] Move posting code to post.c, add command line posting
bears
parents: 64
diff changeset
298 }
1fcdced0246e [svn] Move posting code to post.c, add command line posting
bears
parents: 64
diff changeset
299
1fcdced0246e [svn] Move posting code to post.c, add command line posting
bears
parents: 64
diff changeset
300 /* Add article to outgoing if needs be */
1fcdced0246e [svn] Move posting code to post.c, add command line posting
bears
parents: 64
diff changeset
301 static Bool
1fcdced0246e [svn] Move posting code to post.c, add command line posting
bears
parents: 64
diff changeset
302 postExternal( void )
1fcdced0246e [svn] Move posting code to post.c, add command line posting
bears
parents: 64
diff changeset
303 {
1fcdced0246e [svn] Move posting code to post.c, add command line posting
bears
parents: 64
diff changeset
304 if ( article.server == NULL )
1fcdced0246e [svn] Move posting code to post.c, add command line posting
bears
parents: 64
diff changeset
305 return TRUE;
1fcdced0246e [svn] Move posting code to post.c, add command line posting
bears
parents: 64
diff changeset
306
1fcdced0246e [svn] Move posting code to post.c, add command line posting
bears
parents: 64
diff changeset
307 if ( ! Out_add( article.server, article.over.msgId, article.text ) )
1fcdced0246e [svn] Move posting code to post.c, add command line posting
bears
parents: 64
diff changeset
308 {
1fcdced0246e [svn] Move posting code to post.c, add command line posting
bears
parents: 64
diff changeset
309 Log_err( "Cannot add posted article to outgoing directory" );
1fcdced0246e [svn] Move posting code to post.c, add command line posting
bears
parents: 64
diff changeset
310 return FALSE;
1fcdced0246e [svn] Move posting code to post.c, add command line posting
bears
parents: 64
diff changeset
311 }
1fcdced0246e [svn] Move posting code to post.c, add command line posting
bears
parents: 64
diff changeset
312
1fcdced0246e [svn] Move posting code to post.c, add command line posting
bears
parents: 64
diff changeset
313 return TRUE;
1fcdced0246e [svn] Move posting code to post.c, add command line posting
bears
parents: 64
diff changeset
314 }
1fcdced0246e [svn] Move posting code to post.c, add command line posting
bears
parents: 64
diff changeset
315
1fcdced0246e [svn] Move posting code to post.c, add command line posting
bears
parents: 64
diff changeset
316 /* Cancel and return TRUE if need to send cancel message on to server. */
1fcdced0246e [svn] Move posting code to post.c, add command line posting
bears
parents: 64
diff changeset
317 static Bool
1fcdced0246e [svn] Move posting code to post.c, add command line posting
bears
parents: 64
diff changeset
318 controlCancel( const char *cancelId )
1fcdced0246e [svn] Move posting code to post.c, add command line posting
bears
parents: 64
diff changeset
319 {
1fcdced0246e [svn] Move posting code to post.c, add command line posting
bears
parents: 64
diff changeset
320 return ( Ctrl_cancel( cancelId ) == CANCEL_NEEDS_MSG );
1fcdced0246e [svn] Move posting code to post.c, add command line posting
bears
parents: 64
diff changeset
321 }
1fcdced0246e [svn] Move posting code to post.c, add command line posting
bears
parents: 64
diff changeset
322
1fcdced0246e [svn] Move posting code to post.c, add command line posting
bears
parents: 64
diff changeset
323 /*
1fcdced0246e [svn] Move posting code to post.c, add command line posting
bears
parents: 64
diff changeset
324 It's a control message. Currently we only know about 'cancel'
1fcdced0246e [svn] Move posting code to post.c, add command line posting
bears
parents: 64
diff changeset
325 messages; others are passed on for outside groups, and logged
1fcdced0246e [svn] Move posting code to post.c, add command line posting
bears
parents: 64
diff changeset
326 as ignored for local groups.
1fcdced0246e [svn] Move posting code to post.c, add command line posting
bears
parents: 64
diff changeset
327 */
1fcdced0246e [svn] Move posting code to post.c, add command line posting
bears
parents: 64
diff changeset
328 static Bool
1fcdced0246e [svn] Move posting code to post.c, add command line posting
bears
parents: 64
diff changeset
329 handleControl( void )
1fcdced0246e [svn] Move posting code to post.c, add command line posting
bears
parents: 64
diff changeset
330 {
1fcdced0246e [svn] Move posting code to post.c, add command line posting
bears
parents: 64
diff changeset
331 const char *grp;
1fcdced0246e [svn] Move posting code to post.c, add command line posting
bears
parents: 64
diff changeset
332 const char *op;
1fcdced0246e [svn] Move posting code to post.c, add command line posting
bears
parents: 64
diff changeset
333
1fcdced0246e [svn] Move posting code to post.c, add command line posting
bears
parents: 64
diff changeset
334 op = Itl_first( article.control );
1fcdced0246e [svn] Move posting code to post.c, add command line posting
bears
parents: 64
diff changeset
335 if ( op == NULL )
1fcdced0246e [svn] Move posting code to post.c, add command line posting
bears
parents: 64
diff changeset
336 {
1fcdced0246e [svn] Move posting code to post.c, add command line posting
bears
parents: 64
diff changeset
337 Log_err( "Malformed control line." );
1fcdced0246e [svn] Move posting code to post.c, add command line posting
bears
parents: 64
diff changeset
338 return TRUE;
1fcdced0246e [svn] Move posting code to post.c, add command line posting
bears
parents: 64
diff changeset
339 }
1fcdced0246e [svn] Move posting code to post.c, add command line posting
bears
parents: 64
diff changeset
340 else if ( strcasecmp( op, "cancel" ) == 0 )
1fcdced0246e [svn] Move posting code to post.c, add command line posting
bears
parents: 64
diff changeset
341 {
1fcdced0246e [svn] Move posting code to post.c, add command line posting
bears
parents: 64
diff changeset
342 if ( ! controlCancel( Itl_next( article.control ) ) )
1fcdced0246e [svn] Move posting code to post.c, add command line posting
bears
parents: 64
diff changeset
343 return TRUE; /* Handled entirely locally */
1fcdced0246e [svn] Move posting code to post.c, add command line posting
bears
parents: 64
diff changeset
344 }
1fcdced0246e [svn] Move posting code to post.c, add command line posting
bears
parents: 64
diff changeset
345 else
1fcdced0246e [svn] Move posting code to post.c, add command line posting
bears
parents: 64
diff changeset
346 {
1fcdced0246e [svn] Move posting code to post.c, add command line posting
bears
parents: 64
diff changeset
347 /* Log 'can't do' for internal groups. */
1fcdced0246e [svn] Move posting code to post.c, add command line posting
bears
parents: 64
diff changeset
348 for( grp = Itl_first( article.newsgroups );
1fcdced0246e [svn] Move posting code to post.c, add command line posting
bears
parents: 64
diff changeset
349 grp != NULL;
1fcdced0246e [svn] Move posting code to post.c, add command line posting
bears
parents: 64
diff changeset
350 grp = Itl_next( article.newsgroups ) )
1fcdced0246e [svn] Move posting code to post.c, add command line posting
bears
parents: 64
diff changeset
351 {
1fcdced0246e [svn] Move posting code to post.c, add command line posting
bears
parents: 64
diff changeset
352 if ( Grp_exists( grp ) && Grp_local( grp ) )
1fcdced0246e [svn] Move posting code to post.c, add command line posting
bears
parents: 64
diff changeset
353 Log_inf( "Ignoring control '%s' for '%s'.", op, grp );
1fcdced0246e [svn] Move posting code to post.c, add command line posting
bears
parents: 64
diff changeset
354 }
1fcdced0246e [svn] Move posting code to post.c, add command line posting
bears
parents: 64
diff changeset
355 }
1fcdced0246e [svn] Move posting code to post.c, add command line posting
bears
parents: 64
diff changeset
356
1fcdced0246e [svn] Move posting code to post.c, add command line posting
bears
parents: 64
diff changeset
357 return postExternal();
1fcdced0246e [svn] Move posting code to post.c, add command line posting
bears
parents: 64
diff changeset
358 }
1fcdced0246e [svn] Move posting code to post.c, add command line posting
bears
parents: 64
diff changeset
359
1fcdced0246e [svn] Move posting code to post.c, add command line posting
bears
parents: 64
diff changeset
360 static Bool
1fcdced0246e [svn] Move posting code to post.c, add command line posting
bears
parents: 64
diff changeset
361 postArticle( Bool localOnly )
1fcdced0246e [svn] Move posting code to post.c, add command line posting
bears
parents: 64
diff changeset
362 {
1fcdced0246e [svn] Move posting code to post.c, add command line posting
bears
parents: 64
diff changeset
363 const char *grp;
1fcdced0246e [svn] Move posting code to post.c, add command line posting
bears
parents: 64
diff changeset
364 Bool err;
1fcdced0246e [svn] Move posting code to post.c, add command line posting
bears
parents: 64
diff changeset
365 Bool postLocal;
1fcdced0246e [svn] Move posting code to post.c, add command line posting
bears
parents: 64
diff changeset
366 Bool local;
1fcdced0246e [svn] Move posting code to post.c, add command line posting
bears
parents: 64
diff changeset
367
1fcdced0246e [svn] Move posting code to post.c, add command line posting
bears
parents: 64
diff changeset
368 err = FALSE;
1fcdced0246e [svn] Move posting code to post.c, add command line posting
bears
parents: 64
diff changeset
369 postLocal = Cfg_postLocal();
1fcdced0246e [svn] Move posting code to post.c, add command line posting
bears
parents: 64
diff changeset
370
1fcdced0246e [svn] Move posting code to post.c, add command line posting
bears
parents: 64
diff changeset
371 /* Run round & post locally */
1fcdced0246e [svn] Move posting code to post.c, add command line posting
bears
parents: 64
diff changeset
372 for( grp = Itl_first( article.newsgroups );
1fcdced0246e [svn] Move posting code to post.c, add command line posting
bears
parents: 64
diff changeset
373 grp != NULL;
1fcdced0246e [svn] Move posting code to post.c, add command line posting
bears
parents: 64
diff changeset
374 grp = Itl_next( article.newsgroups ) )
1fcdced0246e [svn] Move posting code to post.c, add command line posting
bears
parents: 64
diff changeset
375 {
1fcdced0246e [svn] Move posting code to post.c, add command line posting
bears
parents: 64
diff changeset
376 local = Grp_local( grp );
1fcdced0246e [svn] Move posting code to post.c, add command line posting
bears
parents: 64
diff changeset
377 if ( localOnly && ! local )
1fcdced0246e [svn] Move posting code to post.c, add command line posting
bears
parents: 64
diff changeset
378 continue;
1fcdced0246e [svn] Move posting code to post.c, add command line posting
bears
parents: 64
diff changeset
379 if ( ( local || postLocal )
1fcdced0246e [svn] Move posting code to post.c, add command line posting
bears
parents: 64
diff changeset
380 && ( Grp_postAllow( grp ) == 'y' || localOnly ) )
1fcdced0246e [svn] Move posting code to post.c, add command line posting
bears
parents: 64
diff changeset
381 err = addToGroup( grp ) && err;
1fcdced0246e [svn] Move posting code to post.c, add command line posting
bears
parents: 64
diff changeset
382 }
1fcdced0246e [svn] Move posting code to post.c, add command line posting
bears
parents: 64
diff changeset
383
1fcdced0246e [svn] Move posting code to post.c, add command line posting
bears
parents: 64
diff changeset
384 if ( localOnly )
1fcdced0246e [svn] Move posting code to post.c, add command line posting
bears
parents: 64
diff changeset
385 return err;
1fcdced0246e [svn] Move posting code to post.c, add command line posting
bears
parents: 64
diff changeset
386 else
1fcdced0246e [svn] Move posting code to post.c, add command line posting
bears
parents: 64
diff changeset
387 return postExternal() && err;
1fcdced0246e [svn] Move posting code to post.c, add command line posting
bears
parents: 64
diff changeset
388 }
1fcdced0246e [svn] Move posting code to post.c, add command line posting
bears
parents: 64
diff changeset
389
1fcdced0246e [svn] Move posting code to post.c, add command line posting
bears
parents: 64
diff changeset
390 /* Register an article for posting. */
1fcdced0246e [svn] Move posting code to post.c, add command line posting
bears
parents: 64
diff changeset
391 Bool
1fcdced0246e [svn] Move posting code to post.c, add command line posting
bears
parents: 64
diff changeset
392 Post_open( const char * text )
1fcdced0246e [svn] Move posting code to post.c, add command line posting
bears
parents: 64
diff changeset
393 {
1fcdced0246e [svn] Move posting code to post.c, add command line posting
bears
parents: 64
diff changeset
394 if ( article.text != NULL )
1fcdced0246e [svn] Move posting code to post.c, add command line posting
bears
parents: 64
diff changeset
395 {
1fcdced0246e [svn] Move posting code to post.c, add command line posting
bears
parents: 64
diff changeset
396 Log_err( "Busy article in Post_open." );
1fcdced0246e [svn] Move posting code to post.c, add command line posting
bears
parents: 64
diff changeset
397 return FALSE;
1fcdced0246e [svn] Move posting code to post.c, add command line posting
bears
parents: 64
diff changeset
398 }
1fcdced0246e [svn] Move posting code to post.c, add command line posting
bears
parents: 64
diff changeset
399
1fcdced0246e [svn] Move posting code to post.c, add command line posting
bears
parents: 64
diff changeset
400 if ( ! getArticleText( text ) )
1fcdced0246e [svn] Move posting code to post.c, add command line posting
bears
parents: 64
diff changeset
401 return FALSE;
1fcdced0246e [svn] Move posting code to post.c, add command line posting
bears
parents: 64
diff changeset
402
1fcdced0246e [svn] Move posting code to post.c, add command line posting
bears
parents: 64
diff changeset
403 if ( Db_contains( article.over.msgId ) )
1fcdced0246e [svn] Move posting code to post.c, add command line posting
bears
parents: 64
diff changeset
404 {
1fcdced0246e [svn] Move posting code to post.c, add command line posting
bears
parents: 64
diff changeset
405 Log_err( "Duplicate article %s.", article.over.msgId );
1fcdced0246e [svn] Move posting code to post.c, add command line posting
bears
parents: 64
diff changeset
406 return FALSE;
1fcdced0246e [svn] Move posting code to post.c, add command line posting
bears
parents: 64
diff changeset
407 }
1fcdced0246e [svn] Move posting code to post.c, add command line posting
bears
parents: 64
diff changeset
408
1fcdced0246e [svn] Move posting code to post.c, add command line posting
bears
parents: 64
diff changeset
409 return TRUE;
1fcdced0246e [svn] Move posting code to post.c, add command line posting
bears
parents: 64
diff changeset
410 }
1fcdced0246e [svn] Move posting code to post.c, add command line posting
bears
parents: 64
diff changeset
411
1fcdced0246e [svn] Move posting code to post.c, add command line posting
bears
parents: 64
diff changeset
412 /* Process the posting */
1fcdced0246e [svn] Move posting code to post.c, add command line posting
bears
parents: 64
diff changeset
413 Bool
1fcdced0246e [svn] Move posting code to post.c, add command line posting
bears
parents: 64
diff changeset
414 Post_post( Bool localOnly )
1fcdced0246e [svn] Move posting code to post.c, add command line posting
bears
parents: 64
diff changeset
415 {
1fcdced0246e [svn] Move posting code to post.c, add command line posting
bears
parents: 64
diff changeset
416 if ( ! checkPostableNewsgroup( localOnly ) )
1fcdced0246e [svn] Move posting code to post.c, add command line posting
bears
parents: 64
diff changeset
417 return FALSE;
1fcdced0246e [svn] Move posting code to post.c, add command line posting
bears
parents: 64
diff changeset
418
1fcdced0246e [svn] Move posting code to post.c, add command line posting
bears
parents: 64
diff changeset
419 return ( article.control == NULL )
1fcdced0246e [svn] Move posting code to post.c, add command line posting
bears
parents: 64
diff changeset
420 ? ! postArticle( localOnly )
1fcdced0246e [svn] Move posting code to post.c, add command line posting
bears
parents: 64
diff changeset
421 : ! handleControl();
1fcdced0246e [svn] Move posting code to post.c, add command line posting
bears
parents: 64
diff changeset
422 }
43
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
423
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
424 /* Done with article - tidy up. */
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
425 void
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
426 Post_close( void )
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
427 {
88
1fcdced0246e [svn] Move posting code to post.c, add command line posting
bears
parents: 64
diff changeset
428 if ( article.text != NULL )
1fcdced0246e [svn] Move posting code to post.c, add command line posting
bears
parents: 64
diff changeset
429 {
1fcdced0246e [svn] Move posting code to post.c, add command line posting
bears
parents: 64
diff changeset
430 del_DynStr( article.text );
1fcdced0246e [svn] Move posting code to post.c, add command line posting
bears
parents: 64
diff changeset
431 article.text = NULL;
1fcdced0246e [svn] Move posting code to post.c, add command line posting
bears
parents: 64
diff changeset
432 }
1fcdced0246e [svn] Move posting code to post.c, add command line posting
bears
parents: 64
diff changeset
433 if ( article.newsgroups != NULL )
1fcdced0246e [svn] Move posting code to post.c, add command line posting
bears
parents: 64
diff changeset
434 {
1fcdced0246e [svn] Move posting code to post.c, add command line posting
bears
parents: 64
diff changeset
435 del_Itl( article.newsgroups );
1fcdced0246e [svn] Move posting code to post.c, add command line posting
bears
parents: 64
diff changeset
436 article.newsgroups = NULL;
1fcdced0246e [svn] Move posting code to post.c, add command line posting
bears
parents: 64
diff changeset
437 }
1fcdced0246e [svn] Move posting code to post.c, add command line posting
bears
parents: 64
diff changeset
438 if ( article.control != NULL )
1fcdced0246e [svn] Move posting code to post.c, add command line posting
bears
parents: 64
diff changeset
439 {
1fcdced0246e [svn] Move posting code to post.c, add command line posting
bears
parents: 64
diff changeset
440 del_Itl( article.control );
1fcdced0246e [svn] Move posting code to post.c, add command line posting
bears
parents: 64
diff changeset
441 article.control = NULL;
1fcdced0246e [svn] Move posting code to post.c, add command line posting
bears
parents: 64
diff changeset
442 }
43
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
443 article.posted = FALSE;
88
1fcdced0246e [svn] Move posting code to post.c, add command line posting
bears
parents: 64
diff changeset
444 article.server = NULL;
43
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
445 }
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
446