Mercurial > noffle
comparison src/post.c @ 282:baa6408d1bbc noffle
[svn] * src/database.c,src/post.c,src/protocol.h,src/protocol.c: When posting,
check the article for those headers that are specified in section
5 of the IETF draft and ensure they only occur once.
* src/post.c: Clean up a conditional.
| author | bears |
|---|---|
| date | Mon, 06 Jan 2003 18:16:18 +0000 |
| parents | 7a830ce3211e |
| children | b0ee77fa24d4 |
comparison
equal
deleted
inserted
replaced
| 281:5eece4dfd945 | 282:baa6408d1bbc |
|---|---|
| 1 /* | 1 /* |
| 2 post.c | 2 post.c |
| 3 | 3 |
| 4 $Id: post.c 379 2002-03-26 17:52:01Z mirkol $ | 4 $Id: post.c 414 2003-01-06 18:16:18Z bears $ |
| 5 */ | 5 */ |
| 6 | 6 |
| 7 #if HAVE_CONFIG_H | 7 #if HAVE_CONFIG_H |
| 8 #include <config.h> | 8 #include <config.h> |
| 9 #endif | 9 #endif |
| 174 static Bool | 174 static Bool |
| 175 getArticleText( const char *p ) | 175 getArticleText( const char *p ) |
| 176 { | 176 { |
| 177 DynStr * s; | 177 DynStr * s; |
| 178 Str line, field, value; | 178 Str line, field, value; |
| 179 Bool replyToFound, pathFound, orgFound; | 179 Bool dateFound, fromFound, msgIdFound, subjectFound; |
| 180 Bool newsgroupsFound, pathFound; | |
| 181 Bool replyToFound, orgFound; | |
| 182 Bool continuation; | |
| 180 time_t t; | 183 time_t t; |
| 181 int sigLines; | 184 int sigLines; |
| 182 | 185 |
| 183 s = new_DynStr( 10000 ); | 186 s = new_DynStr( 10000 ); |
| 184 article.text = s; | 187 article.text = s; |
| 185 | 188 |
| 186 replyToFound = pathFound = orgFound = FALSE; | 189 /* RFC says only one of these headers. */ |
| 190 dateFound = fromFound = msgIdFound = subjectFound = | |
| 191 newsgroupsFound = pathFound = FALSE; | |
| 192 | |
| 193 /* Stuff we might want to add. */ | |
| 194 replyToFound = orgFound = FALSE; | |
| 187 | 195 |
| 188 field[ 0 ] = '\0'; | 196 field[ 0 ] = '\0'; |
| 189 | 197 |
| 190 /* Grab header lines first, getting overview info as we go. */ | 198 /* |
| 199 * Grab header lines first, getting overview info as we go. | |
| 200 * Note that a line may be a continuation line, hence we always | |
| 201 * cat the information into the destination. | |
| 202 */ | |
| 191 while ( ( p = Utl_getHeaderLn( line, p ) ) != NULL | 203 while ( ( p = Utl_getHeaderLn( line, p ) ) != NULL |
| 192 && line[ 0 ] != '\0' | 204 && line[ 0 ] != '\0' |
| 193 && Prt_getField( field, value, line ) ) | 205 && Prt_getField( field, value, &continuation, line ) ) |
| 194 { | 206 { |
| 195 if ( field [ 0 ] == '\0' ) | 207 if ( field [ 0 ] == '\0' ) |
| 196 { | 208 { |
| 197 /* Error! Continuation without preceding header. */ | 209 /* Error! Continuation without preceding header. */ |
| 198 Log_err( "First header line started with white space" ); | 210 Log_err( "First header line started with white space" ); |
| 199 return FALSE; | 211 return FALSE; |
| 200 } | 212 } |
| 201 /* Look for headers we need to stash. */ | 213 /* Look for headers we need to stash. */ |
| 202 if ( strcmp( field, "subject" ) == 0 ) | 214 if ( strcmp( field, "subject" ) == 0 ) |
| 203 { | 215 { |
| 216 if ( !continuation && subjectFound ) | |
| 217 { | |
| 218 Log_err( "Duplicate Subject: header" ); | |
| 219 return FALSE; | |
| 220 } | |
| 204 Utl_catStr( article.over.subject, value ); | 221 Utl_catStr( article.over.subject, value ); |
| 205 DynStr_appLn( s, line ); | 222 DynStr_appLn( s, line ); |
| 223 subjectFound = TRUE; | |
| 206 } | 224 } |
| 207 else if ( strcmp ( field, "from" ) == 0 ) | 225 else if ( strcmp ( field, "from" ) == 0 ) |
| 208 { | 226 { |
| 227 if ( !continuation && fromFound ) | |
| 228 { | |
| 229 Log_err( "Duplicate From: header" ); | |
| 230 return FALSE; | |
| 231 } | |
| 209 Utl_catStr( article.over.from, value ); | 232 Utl_catStr( article.over.from, value ); |
| 210 DynStr_appLn( s, line ); | 233 DynStr_appLn( s, line ); |
| 234 fromFound = TRUE; | |
| 211 } | 235 } |
| 212 else if ( strcmp ( field, "date" ) == 0 ) | 236 else if ( strcmp ( field, "date" ) == 0 ) |
| 237 { | |
| 238 if ( !continuation && dateFound ) | |
| 239 { | |
| 240 Log_err( "Duplicate Date: header" ); | |
| 241 return FALSE; | |
| 242 } | |
| 213 Utl_catStr( article.over.date, value ); | 243 Utl_catStr( article.over.date, value ); |
| 244 dateFound = TRUE; | |
| 245 } | |
| 214 else if ( strcmp ( field, "references" ) == 0 ) | 246 else if ( strcmp ( field, "references" ) == 0 ) |
| 215 { | 247 { |
| 216 Utl_catStr( article.over.ref, value ); | 248 Utl_catStr( article.over.ref, value ); |
| 217 DynStr_appLn( s, line ); | 249 DynStr_appLn( s, line ); |
| 218 } | 250 } |
| 219 else if ( strcmp ( field, "message-id" ) == 0 ) | 251 else if ( strcmp ( field, "message-id" ) == 0 ) |
| 220 /* Utl_catStr( article.over.msgId, value ); */ | 252 { |
| 221 Utl_cpyStr( article.over.msgId, value ); | 253 if ( !continuation && msgIdFound ) |
| 254 { | |
| 255 Log_err( "Duplicate Message-Id: header" ); | |
| 256 return FALSE; | |
| 257 } | |
| 258 Utl_catStr( article.over.msgId, value ); | |
| 259 msgIdFound = TRUE; | |
| 260 } | |
| 222 else if ( strcmp ( field, "newsgroups" ) == 0 ) | 261 else if ( strcmp ( field, "newsgroups" ) == 0 ) |
| 223 { | 262 { |
| 263 if ( !continuation && newsgroupsFound ) | |
| 264 { | |
| 265 Log_err( "Duplicate Newsgroups: header" ); | |
| 266 return FALSE; | |
| 267 } | |
| 224 article.newsgroups = new_Itl( value, " ,\n\t" ); | 268 article.newsgroups = new_Itl( value, " ,\n\t" ); |
| 225 DynStr_appLn( s, line ); | 269 DynStr_appLn( s, line ); |
| 270 newsgroupsFound = TRUE; | |
| 226 } | 271 } |
| 227 else if ( strcmp ( field, "control" ) == 0 ) | 272 else if ( strcmp ( field, "control" ) == 0 ) |
| 228 { | 273 { |
| 229 article.control = new_Itl( value, " " ); | 274 article.control = new_Itl( value, " " ); |
| 230 DynStr_appLn( s, line ); | 275 DynStr_appLn( s, line ); |
| 239 article.approved = TRUE; | 284 article.approved = TRUE; |
| 240 DynStr_appLn( s, line ); | 285 DynStr_appLn( s, line ); |
| 241 } | 286 } |
| 242 else if ( strcmp ( field, "path" ) == 0 ) | 287 else if ( strcmp ( field, "path" ) == 0 ) |
| 243 { | 288 { |
| 289 if ( !continuation && pathFound ) | |
| 290 { | |
| 291 Log_err( "Duplicate Path: header" ); | |
| 292 return FALSE; | |
| 293 } | |
| 244 pathFound = TRUE; | 294 pathFound = TRUE; |
| 245 DynStr_appLn( s, line ); | 295 DynStr_appLn( s, line ); |
| 246 } | 296 } |
| 247 else if ( strcmp ( field, "organization" ) == 0 ) | 297 else if ( strcmp ( field, "organization" ) == 0 ) |
| 248 { | 298 { |
| 278 { | 328 { |
| 279 Log_err( "Posted message has no From field" ); | 329 Log_err( "Posted message has no From field" ); |
| 280 return FALSE; | 330 return FALSE; |
| 281 } | 331 } |
| 282 } | 332 } |
| 283 if ( article.over.subject[ 0 ] == '\0' ) | 333 if ( ! subjectFound ) |
| 284 { | 334 { |
| 285 Log_err( "Posted message has no Subject field" ); | 335 Log_err( "Posted message has no Subject field" ); |
| 286 return FALSE; | 336 return FALSE; |
| 287 } | 337 } |
| 288 if ( article.newsgroups == NULL || Itl_count( article.newsgroups) == 0 ) | 338 if ( article.newsgroups == NULL || Itl_count( article.newsgroups) == 0 ) |
| 541 * Only post locally to external group if that group's post | 591 * Only post locally to external group if that group's post |
| 542 * status is 'y'. Otherwise retrieve from upstream server - | 592 * status is 'y'. Otherwise retrieve from upstream server - |
| 543 * for example, we don't want to immediately post locally articles | 593 * for example, we don't want to immediately post locally articles |
| 544 * destined for the moderator of a moderated group. | 594 * destined for the moderator of a moderated group. |
| 545 */ | 595 */ |
| 546 if ( ! local && ( ! postLocal || Grp_postAllow( grp ) != 'y' ) ) | 596 if ( local || ( postLocal && Grp_postAllow( grp ) == 'y' ) ) |
| 547 continue; | 597 err = addToGroup( grp ) && err; |
| 548 err = addToGroup( grp ) && err; | |
| 549 } | 598 } |
| 550 | 599 |
| 551 return postExternal() && err; | 600 return postExternal() && err; |
| 552 } | 601 } |
| 553 | 602 |
