Mercurial > noffle
comparison src/post.c @ 43:2842f50feb55 noffle
[svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
control.c, control.h, database.c, database.h, dynamicstring.c,
dynamicstring.h, fetch.c, fetch.h, fetchlist.c, fetchlist.h, group.c,
group.h, itemlist.c, itemlist.h, lock.c, lock.h, log.c, log.h, noffle.c,
online.c, online.h, outgoing.c, outgoing.h, over.c, over.h, post.c, post.h,
protocol.c, protocol.h, pseudo.c, pseudo.h, request.c, request.h, server.c,
server.h, util.c, util.h, wildmat.c, wildmat.h: Moved files to the
subdirectory src/
* Makefile.am, acconfig.h, configure.in, docs/Makefile.am, src/Makefile.am,
Makefile.in, aclocal.m4, config.h.in, configure, install-sh, missing,
mkinstalldirs, stamp-h.in, docs/Makefile.in, src/Makefile.in: Added files.
They are used by aclocal, autoheader, autoconf and automake.
* src/config.c, src/config.h: Renamed to configfile.c and configfile.h,
because configure will generate a config.h file itself.
* src/client.c, src/content.c, src/database.c, src/fetch.c, src/fetchlist.c,
src/group.c, src/lock.c, src/noffle.c, src/online.c, src/outgoing.c,
src/over.c, src/pseudo.c, src/request.c, src/server.c, src/util.c:
Changed '#include "config.h"' to '#include "configfile.h"'.
* src/client.c, src/content.c, src/database.c, src/fetch.c, src/fetchlist.c,
src/group.c, src/lock.c, src/online.c, src/outgoing.c, src/post.c,
src/protocol.c, src/request.c, src/server.c: Files now #include <config.h>.
Added missing <stdio.h>. This removes the warnings about snprintf() not
being declared.
* Makefile: Removed. This is now generated by configure.
author | uh1763 |
---|---|
date | Fri, 05 May 2000 22:45:56 +0100 |
parents | |
children | 125d79c9e586 |
comparison
equal
deleted
inserted
replaced
42:2467ff423c15 | 43:2842f50feb55 |
---|---|
1 /* | |
2 post.c | |
3 | |
4 $Id: post.c 49 2000-05-05 21:45:56Z uh1763 $ | |
5 */ | |
6 | |
7 #if HAVE_CONFIG_H | |
8 #include <config.h> | |
9 #endif | |
10 | |
11 #include <stdio.h> | |
12 #include "post.h" | |
13 #include <string.h> | |
14 #include "common.h" | |
15 #include "content.h" | |
16 #include "database.h" | |
17 #include "group.h" | |
18 #include "log.h" | |
19 #include "over.h" | |
20 #include "protocol.h" | |
21 #include "util.h" | |
22 | |
23 struct OverInfo | |
24 { | |
25 Str subject; | |
26 Str from; | |
27 Str date; | |
28 Str msgId; | |
29 Str ref; | |
30 size_t bytes; | |
31 size_t lines; | |
32 }; | |
33 | |
34 struct Article | |
35 { | |
36 const char * text; | |
37 Bool posted; | |
38 struct OverInfo over; | |
39 }; | |
40 | |
41 static struct Article article = { NULL, FALSE }; | |
42 | |
43 static void | |
44 getOverInfo( struct OverInfo * o ) | |
45 { | |
46 const char *p = article.text; | |
47 Str line, field, value; | |
48 | |
49 o->bytes = strlen( p ); | |
50 | |
51 while( p != NULL ) | |
52 { | |
53 p = Utl_getHeaderLn( line, p ); | |
54 if ( line[ 0 ] == '\0' ) | |
55 break; | |
56 | |
57 /* Look for headers we need to stash. */ | |
58 if ( Prt_getField( field, value, line ) ) | |
59 { | |
60 if ( strcmp( field, "subject" ) == 0 ) | |
61 Utl_cpyStr( o->subject, value ); | |
62 else if ( strcmp ( field, "from" ) == 0 ) | |
63 Utl_cpyStr( o->from, value ); | |
64 else if ( strcmp ( field, "date" ) == 0 ) | |
65 Utl_cpyStr( o->date, value ); | |
66 else if ( strcmp ( field, "references" ) == 0 ) | |
67 Utl_cpyStr( o->ref, value ); | |
68 else if ( strcmp ( field, "message-id" ) == 0 ) | |
69 Utl_cpyStr( o->msgId, value ); | |
70 } | |
71 } | |
72 | |
73 /* Move to start of body and count lines. */ | |
74 for ( p++, o->lines = 0; *p != '\0'; p++ ) | |
75 if ( *p == '\n' ) | |
76 o->lines++; | |
77 } | |
78 | |
79 /* Register an article for posting. */ | |
80 Bool | |
81 Post_open( const char * text ) | |
82 { | |
83 if ( article.text != NULL ) | |
84 { | |
85 Log_err( "Busy article in Post_open." ); | |
86 return FALSE; | |
87 } | |
88 | |
89 memset( &article.over, 0, sizeof( article.over ) ); | |
90 article.text = text; | |
91 getOverInfo( &article.over ); | |
92 | |
93 if ( Db_contains( article.over.msgId ) ) | |
94 { | |
95 Log_err( "Duplicate article %s.", article.over.msgId ); | |
96 return FALSE; | |
97 } | |
98 | |
99 return TRUE; | |
100 } | |
101 | |
102 | |
103 /* Add the article to a group. */ | |
104 Bool | |
105 Post_add ( const char * grp ) | |
106 { | |
107 Over * over; | |
108 const char *msgId; | |
109 | |
110 over = new_Over( article.over.subject, | |
111 article.over.from, | |
112 article.over.date, | |
113 article.over.msgId, | |
114 article.over.ref, | |
115 article.over.bytes, | |
116 article.over.lines ); | |
117 | |
118 msgId = article.over.msgId; | |
119 | |
120 Cont_read( grp ); | |
121 Cont_app( over ); | |
122 Log_dbg( "Added message '%s' to group '%s'.", msgId, grp ); | |
123 | |
124 if ( !article.posted ) | |
125 { | |
126 Log_inf( "Added '%s' to database.", msgId ); | |
127 if ( ! Db_prepareEntry( over, Cont_grp(), Cont_last() ) | |
128 || ! Db_storeArt ( msgId, article.text ) ) | |
129 return FALSE; | |
130 article.posted = TRUE; | |
131 } | |
132 else | |
133 { | |
134 Str t; | |
135 const char *xref; | |
136 | |
137 xref = Db_xref( msgId ); | |
138 Log_dbg( "Adding '%s' to Xref of '%s'", grp, msgId ); | |
139 snprintf( t, MAXCHAR, "%s %s:%i", xref, grp, Ov_numb( over ) ); | |
140 Db_setXref( msgId, t ); | |
141 } | |
142 | |
143 Cont_write(); | |
144 Grp_setFirstLast( Cont_grp(), Cont_first(), Cont_last() ); | |
145 return TRUE; | |
146 } | |
147 | |
148 /* Done with article - tidy up. */ | |
149 void | |
150 Post_close( void ) | |
151 { | |
152 article.text = NULL; | |
153 article.posted = FALSE; | |
154 } | |
155 |