[Mixmaster-devel] r850 - branches/Mix-stats/Src
Brought to you by:
weaselp
|
From: <co...@so...> - 2004-05-13 10:50:10
|
Author: colin
Date: 2004-05-13 12:49:58 +0200 (Thu, 13 May 2004)
New Revision: 850
Modified:
branches/Mix-stats/Src/main.c
Log:
Fix white space
Add logging for stats/pinger stuff
Fix verbose mode
Modified: branches/Mix-stats/Src/main.c
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D
--- branches/Mix-stats/Src/main.c 2004-05-13 06:44:00 UTC (rev 849)
+++ branches/Mix-stats/Src/main.c 2004-05-13 10:49:58 UTC (rev 850)
@@ -40,10 +40,10 @@
#endif /* WIN32SERVICE */
{
int error =3D 0, deflt =3D 1, help =3D 0, readmail =3D 0, send =3D -1,=
sendpool =3D 0,
- header =3D 1, maint =3D 0, keygen =3D 0, verbose =3D 2, sign =3D 0, en=
crypt =3D 0,
+ header =3D 1, maint =3D 0, keygen =3D 0, verbose =3D 0, sign =3D 0, en=
crypt =3D 0,
redirect_mail =3D 0, about=3D0, version=3D0;
int daemon =3D 0, type_list =3D 0, nodetach =3D 0;
- int update_stats =3D 0, update_pingerlist =3D 0;
+ int update_stats =3D 0, update_pingerlist =3D 0;
=20
#ifdef USE_SOCK
int pop3 =3D 0;
@@ -73,7 +73,7 @@
attachments =3D buf_new();
field =3D buf_new();
content =3D buf_new();
- statssrc =3D buf_new();
+ statssrc =3D buf_new();
=20
#ifdef USE_NCURSES
if (argc =3D=3D 1) {
@@ -86,27 +86,27 @@
#endif /* USE_NCURSES */
if (argc > 1 && strleft(argv[1], "-f")) {
menu_folder(strlen(argv[1]) > 2 ? argv[1][2] : 0,
- argc < 3 ? NULL : argv[2]);
+ argc < 3 ? NULL : argv[2]);
goto clientpool;
}
for (i =3D 1; i < argc; i++) {
p =3D argv[i];
if (p[0] =3D=3D '-' && p[1] !=3D '\0') {
if (p[1] =3D=3D '-') {
- p +=3D 2;
- if (strieq(p, "help"))
- help =3D 1, deflt =3D 0;
+ p +=3D 2;
+ if (strieq(p, "help"))
+ help =3D 1, deflt =3D 0;
else if (streq(p, "version"))
version =3D 1, deflt =3D 0;
else if (streq(p, "about"))
about =3D 1, deflt =3D 0;
- else if (streq(p, "verbose"))
- verbose =3D 1;
- else if (streq(p, "type-list"))
- type_list =3D 1;
- else if (streq(p, "dummy"))
- send =3D MSG_NULL, deflt =3D 0;
- else if (streq(p, "remailer"))
+ else if (streq(p, "verbose"))
+ verbose =3D 1;
+ else if (streq(p, "type-list"))
+ type_list =3D 1;
+ else if (streq(p, "dummy"))
+ send =3D MSG_NULL, deflt =3D 0;
+ else if (streq(p, "remailer"))
maint =3D 1, deflt =3D 0;
else if (streq(p, "generate-key"))
keygen =3D 2, deflt =3D 0;
@@ -138,36 +138,40 @@
encrypt =3D 1;
else if (streq(p, "update-pinger-list"))
update_pingerlist =3D 1;
- else if (streq(p, "update-stats")) {
- buf_clear(statssrc);
- f =3D mix_openfile(STATSSRC, "r");
- if (f !=3D NULL) {
- buf_read(statssrc, f);
- fclose(f);
- }
- if (statssrc->length > 0) {
- update_stats =3D 1;
- } else {
- deflt =3D 0;
- fprintf(stderr, "%s: No current stats source --%s\n", argv[0], p);
- }
+ else if (streq(p, "update-stats")) {
+ buf_clear(statssrc);
+ f =3D mix_openfile(STATSSRC, "r");
+ if (f !=3D NULL) {
+ buf_read(statssrc, f);
+ fclose(f);
+ }
+ if (statssrc->length > 0) {
+ update_stats =3D 1;
+ }
+ else {
+ deflt =3D 0;
+ fprintf(stderr, "%s: No current stats source --%s\n", argv[0], p);
+ }
}
- else if (strleft(p, "update-stats") && p[strlen("update-stats")] =3D=3D=
'=3D') {
- buf_clear(statssrc);
- buf_appendf(statssrc, "%s", (p + strlen("update-stats") + 1));
- if (statssrc->length > 0) {
- update_stats =3D 1;
- } else {
- fprintf(stderr, "%s: No stats source specified --%s\n", argv[0], p=
);
- }
- }
+ else if (strleft(p, "update-stats") && p[strlen("update-stats")] =3D=3D=
'=3D') {
+ buf_clear(statssrc);
+ buf_appendf(statssrc, "%s", (p + strlen("update-stats") + 1));
+ if (statssrc->length > 0) {
+ update_stats =3D 1;
+ }
+ else {
+ fprintf(stderr, "%s: No stats source specified --%s\n", argv[0], p)=
;
+ }
+ }
else if ((q =3D largopt(p, "to", argv[0], &error)) !=3D NULL) {
header =3D 0;
buf_appendf(msg, "To: %s\n", q);
- } else if ((q =3D largopt(p, "post-to", argv[0], &error)) !=3D NULL) {
+ }
+ else if ((q =3D largopt(p, "post-to", argv[0], &error)) !=3D NULL) {
send =3D MSG_POST, header =3D 0;
buf_appendf(msg, "Newsgroups: %s\n", q);
- } else if ((q =3D largopt(p, "subject", argv[0], &error)) !=3D NULL) {
+ }
+ else if ((q =3D largopt(p, "subject", argv[0], &error)) !=3D NULL) {
buf_appendf(msg, "Subject: %s\n", q);
} else if ((q =3D largopt(p, "header", argv[0], &error)) !=3D NULL) {
buf_appendf(msg, "%s\n", q);
@@ -372,34 +376,42 @@
}
if (update_pingerlist) {
mixfile(pingpath, ALLPINGERSFILE);
- printf ("downloading %s...\n", ALLPINGERSURL);
- if (url_download(ALLPINGERSURL, pingpath) < 0)
+ if (verbose) printf ("downloading %s...\n", ALLPINGERSURL);
+ if (url_download(ALLPINGERSURL, pingpath) < 0) {
printf(" Download failed... Try again later.\n");
- else
- printf(" Done.\n");
+ errlog(ERRORMSG, "All Pingers File Download failed.\n");
+ }
+ else {
+ if (verbose) printf(" Done.\n");
+ errlog(LOG, "All Pingers File Downloaded OK.\n");
+ }
ret =3D 0;
goto end;
}
- if (update_stats) {
- BUFFER *inifile;
- inifile =3D buf_new();
- read_allpingers(inifile);
- if (good_stats_source(inifile, statssrc->data) =3D=3D 1) {
+ if (update_stats) {
+ BUFFER *inifile;
+ inifile =3D buf_new();
+ read_allpingers(inifile);
+ if (good_stats_source(inifile, statssrc->data) =3D=3D 1) {
if (stats_download(inifile, statssrc->data, 0) =3D=3D 0) {
f =3D mix_openfile(STATSSRC, "w+");
if (f !=3D NULL) {
fprintf(f, "%s", statssrc->data);
fclose(f);
- } else
+ } else {
fprintf(stderr, "Could not open stats source file for writing\=
n");
+ errlog(ERRORMSG, "Could not open stats source file for writing.\n");
+ }
}
- }
- else
- printf("Stats source does not include all required files.\n");
- ret =3D 0;
- buf_free(inifile);
- goto end;
- }
+ }
+ else {
+ fprintf(stderr, "Stats source does not include all required files.=
\n");
+ errlog(ERRORMSG, "Stats source does not include all required files=
.\n");
+ }
+ ret =3D 0;
+ buf_free(inifile);
+ goto end;
+ }
if (help ||about ||(isatty(fileno(stdin)) && isatty(fileno(stdout))))
fprintf(stderr, "Mixmaster %s\n", VERSION);
if (help ||about)
@@ -629,12 +641,12 @@
if (mix_encrypt(MSG_NULL, NULL, chain, numcopies, chainlist) =3D=3D =
-1) {
ret =3D 2;
if (chainlist->length)
- fprintf(stderr, "%s\n", chainlist->data);
+ printf("%s\n", chainlist->data);
else
fprintf(stderr, "Failed!\n");
} else if (verbose) {
- fprintf(stderr, "Chain: ");
- buf_write(chainlist, stderr);
+ printf("Chain: ");
+ buf_write(chainlist, stdout);
}
}
#ifdef USE_PGP
@@ -713,20 +725,20 @@
/* Detach as suggested by the Unix Programming FAQ */
pid =3D fork();
if (pid > 0)
- exit(0);
+ exit(0);
if (setsid() < 0) {
- /* This should never happen. */
- fprintf(stderr, "setsid() failed.\n");
- exit(1);
+ /* This should never happen. */
+ fprintf(stderr, "setsid() failed.\n");
+ exit(1);
};
pid =3D fork();
if (pid > 0)
- exit(0);
+ exit(0);
};
if (chdir(MIXDIR) < 0) {
if (chdir("/") < 0) {
- fprintf(stderr, "Cannot chdir to mixdir or /.\n");
- exit(1);
+ fprintf(stderr, "Cannot chdir to mixdir or /.\n");
+ exit(1);
};
};
if (write_pidfile(PIDFILE)) {
@@ -741,7 +753,7 @@
#endif /* UNIX */
mix_daemon();
#ifdef UNIX
-/* ifdef this one to, so that we do not need to export it from windows d=
ll */
+/* ifdef this one too, so that we do not need to export it from windows =
dll */
clear_pidfile(PIDFILE);
#endif /* UNIX */
}
|