File: rabid.cpp

package info (click to toggle)
postal 0.62.1
  • links: PTS
  • area: main
  • in suites: etch, etch-m68k, sarge
  • size: 476 kB
  • ctags: 445
  • sloc: cpp: 2,902; sh: 289; ansic: 258; makefile: 86
file content (140 lines) | stat: -rw-r--r-- 3,241 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
#ifndef _GNU_SOURCE
#define _GNU_SOURCE
#endif

#include "userlist.h"
#include "client.h"
#include <unistd.h>
#include <sys/wait.h>
#include <signal.h>
#include <stdio.h>
#include "postal.h"
#include "logit.h"

void usage()
{
  printf("Usage: rabid [-r max-connections-per-minute] [-p processes] [-l local-address]\n"
         "             [-c messages-per-connection] [-a] [-i imap-percentage]\n"
#ifdef USE_SSL
         "             [-s ssl-percentage] [-d download-percentage[:delete-percentage]]\n"
#endif
         "             [-[z|Z] debug-file]\n"
         "             pop-server user-list-filename conversion-filename\n"
         "\n"
         "Rabid Version: " VER_STR "\n");
  exit(eParam);
}

int main(int argc, char **argv)
{

  int processes = 1;
  int connectionsPerMinute = 0;
  int msgsPerConnection = -1;
  const char *ourAddr = NULL;
  bool logAll = false;
#ifdef USE_SSL
  int ssl = 0;
#endif
  int imap = 0;
  int downloadPercent = 100, deletePercent = 100;
  TRISTATE qmail_pop = eNONE;
  PCCHAR debugName = NULL;
  bool debugMultipleFiles = false;

  int c;
  while(-1 != (c = getopt(argc, argv, "ab:d:c:i:l:p:r:s:z:Z:")) )
  {
    switch(char(c))
    {
      case '?':
      case ':':
        usage();
      break;
      case 'a':
        logAll = true;
      break;
      case 'b':
        if(!strcasecmp(optarg, "qmail-pop"))
          qmail_pop = eWONT;
      break;
      case 'c':
        msgsPerConnection = atoi(optarg);
      break;
      case 'd':
        if(sscanf(optarg, "%d:%d", &downloadPercent, &deletePercent) < 2)
          deletePercent = 100;
      break;
      case 'i':
        imap = atoi(optarg);
      break;
      case 'l':
        ourAddr = optarg;
      break;
      case 'p':
        processes = atoi(optarg);
      break;
      case 'r':
        connectionsPerMinute = atoi(optarg);
      break;
      case 's':
#ifdef USE_SSL
        ssl = atoi(optarg);
#else
        usage();
#endif
      break;
      case 'Z':
        debugMultipleFiles = true;
      case 'z':
        debugName = optarg;
      break;
    }
  }
  if(processes < 1 || processes > MAX_PROCESSES || connectionsPerMinute < 0)
    usage();
#ifdef USE_SSL
  if(ssl < 0 || ssl > 100)
    usage();
#endif
  if(imap < 0 || imap > 100)
    usage();
  if(downloadPercent < 0 || downloadPercent > 100)
    usage();
  if(deletePercent < 0 || deletePercent > 100)
    usage();
  if(optind + 3 != argc)
    usage();

  UserList ul(argv[optind + 1]
            , argv[optind + 2]
            , true);

  struct sigaction sa;
  sa.sa_handler = SIG_IGN;
  sa.sa_sigaction = NULL;
  sa.sa_flags = 0;
  if(sigaction(SIGPIPE, &sa, NULL))
  {
    printf("Can't block SIGPIPE.\n");
    return eSystem;
  }
  printf("time,messages,data(K),errors,connections"
#ifdef USE_SSL
         ",SSL connections,"
#endif
         "IMAP connections\n");
  Logit log("rabid.log", logAll, false, 0);
  Logit *debug = NULL;
 
  if(debugName)
    debug = new Logit(debugName, false, debugMultipleFiles, 0);
  client popper(argv[optind], ourAddr, ul, processes, msgsPerConnection, &log
#ifdef USE_SSL
              , ssl
#endif
              , qmail_pop, imap, downloadPercent, deletePercent, debug);

  return popper.doAllWork(connectionsPerMinute);
}