00001
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00319 #include "init.h"
00320
00321 #include <rd/log.h>
00322 #include <rd/conf.h>
00323 #include <rd/email.h>
00324 #include <rd/timer.h>
00325 #include <rd/daemon.h>
00326
00327 void VF__send_report(veldfire *v, struct rdtimer *t);
00328
00337 int main(int argc, char *argv[]) {
00338 veldfire *v = NULL;
00339 struct rdtimer t;
00340 int rc = 0;
00341
00342 if ( (v = VF__init(argc, argv)) == NULL) {
00343 return -1;
00344 }
00345
00346 if ( (v->msg = VF__get_msg(v)) == NULL) {
00347 VF__cleanup(v);
00348 return -1;
00349 }
00350
00351 if (v->debug == 0 && v->foreground == 0) {
00352 RD__daemon(1, v->printlog ? 1 : 0);
00353 }
00354
00355 RD__timer_start(&t);
00356 rc = RD__email(v->host, v->port, v->from, v->to,
00357 v->subject, v->msg, v->files, v->headers,
00358 v->sendtimeout, v->recvtimeout,
00359 v->maxconnection, v->log, &v->sent, &v->fail);
00360 RD__timer_stop(&t);
00361
00362 VF__send_report(v, &t);
00363 VF__cleanup(v);
00364
00365 return rc;
00366 }
00367
00374 void
00375 VF__send_report(veldfire *v, struct rdtimer *t)
00376 {
00377 char msg[256];
00378 char *p = RD__error();
00379 char *subj = "[veldfire] Email results";
00380
00381 if (v == NULL || v->report == NULL || t == NULL) {
00382 return;
00383 }
00384
00385 RD__log(v->log, 3, "%s Sent: %d Fail: %d", t->time, v->sent, v->fail);
00386
00387 snprintf(msg, sizeof(msg),
00388 "Mail results\n------------\n\n%d Sent, %d Fail\nTime: %s\n%s%s\n",
00389 v->sent, v->fail, t->time,
00390 p && strlen(p) ? "Last error: " : "",
00391 p && strlen(p) ? p : "");
00392
00393 RD__email_simple(v->host, v->from, v->report, subj, msg);
00394 }
00395