leafnode  1.12.0
About: Leafnode is a store & forward NNTP proxy for small (dialup) sites.
  Fossies Dox: leafnode-1.12.0.tar.xz  ("unofficial" and yet experimental doxygen-generated source code documentation)  

newsq.c
Go to the documentation of this file.
1/*
2 * find out what is in your out.going or failed.postings directory
3 *
4 * Written by Cornelius Krasel <krasel@wpxx02.toxi.uni-wuerzburg.de>.
5 * Copyright 1999.
6 * Enhanced by Matthias Andree <matthias.andree@gmx.de>
7 * Copyright 2002 - 2004
8 *
9 * See file COPYING for restrictions on the use of this software.
10 */
11
12#include "leafnode.h"
13#include "mastring.h"
14
15#include <sys/types.h>
16#include <sys/stat.h>
17#include "system.h"
18#include <stdio.h>
19#include <stdlib.h>
20#include <string.h>
21#include <unistd.h>
22
23int verbose = 0;
24int debug = 0;
25
26/* in-situ LF remover, returns pointer to modified string */
27static char *droplf(char *t) {
28 char *i, *j;
29
30 if (t) {
31 for (i = j = t; *i; i++) {
32 if (*i != '\n') *(j++) = *i;
33 }
34 *j = '\0';
35 }
36 return t;
37}
38
39/* in-situ NULL -> "(null)" mapper for strings */
40static const char *catch0(const char *i) {
41 return i ? i : "(null)";
42}
43
44int
45main(const int argc, char **argv)
46{
47 FILE *f;
48 DIR *d;
49 struct dirent *de;
50 struct stat st;
51 unsigned long filesize;
52 mastr *dirname = mastr_new(PATH_MAX);
53 const char *s = mastr_str(dirname);
54 int empty = 1;
55
56 if (argc > 1 && argv[1] && 0 == strcasecmp(argv[1], "-f"))
57 mastr_vcat(dirname, spooldir, "/failed.postings", NULL);
58 else
59 mastr_vcat(dirname, spooldir, "/out.going", NULL);
60
61 if (chdir(s) < 0) {
62 fprintf(stderr, "Cannot change to %s -- aborting.\n", s);
63 exit(1);
64 }
65 d = opendir(".");
66 if (!d) {
67 fprintf(stderr, "Cannot open directory %s -- aborting.\n", s);
68 exit(1);
69 }
70
71 printf("Contents of queue in directory %s:\n", s);
72 while ((de = readdir(d))) {
73 if (stat(de->d_name, &st)) {
74 fprintf(stderr, "Cannot stat %s\n", de->d_name);
75 } else if (S_ISREG(st.st_mode)) {
76 f = fopen(de->d_name, "r");
77 if (f) {
78 char *t1, *t2, *t3, *t4;
79
80 empty = 0;
81 filesize = st.st_size;
82 printf("%s: %s %8lu bytes, spooled %s"
83 "\tFrom: %-.66s\n"
84 "\tNewsgroups: %-.66s\n"
85 "\tSubject: %-.66s\n"
86 "\tMessage-ID: %-.66s\n",
87 de->d_name,
88 st.st_mode & S_IRUSR ? "complete " : "INCOMPLETE",
89 filesize, ctime(&st.st_mtime),
90 catch0(droplf(t1 = fgetheader(f, "From:"))),
91 catch0(droplf(t2 = fgetheader(f, "Newsgroups:"))),
92 catch0(droplf(t3 = fgetheader(f, "Subject:"))),
93 catch0(droplf(t4 = fgetheader(f, "Message-ID:"))));
94 if (t1) free(t1);
95 if (t2) free(t2);
96 if (t3) free(t3);
97 if (t4) free(t4);
98 fclose(f);
99 } else
100 fprintf(stderr, "Cannot open %s\n", de->d_name);
101 }
102 }
103 closedir(d);
104 if (empty) puts("The queue is empty.");
105 mastr_delete(dirname);
106 exit(0);
107}
char * fgetheader(FILE *f, const char *header)
Definition: artutil.c:27
const char * spooldir
#define PATH_MAX
Definition: leafnode.h:43
void mastr_delete(mastr *m)
Definition: mastring.c:223
mastr * mastr_new(size_t size)
Definition: mastring.c:62
int mastr_vcat(mastr *m,...)
Definition: mastring.c:147
#define mastr_str(m)
Definition: mastring.h:57
int verbose
Definition: newsq.c:23
static char * droplf(char *t)
Definition: newsq.c:27
static const char * catch0(const char *i)
Definition: newsq.c:40
int main(const int argc, char **argv)
Definition: newsq.c:45
int debug
Definition: newsq.c:24
Definition: mastring.h:28
#define dirent
Definition: system.h:21