1 |
#include "SpamPlugin.h" |
#include "SpamPlugin.h" |
2 |
#include "GsmModem.h" |
#include "ISmsTransceiver.h" |
3 |
|
#include "Sms.h" |
4 |
|
|
5 |
#include "util.h" |
#include "Util.h" |
6 |
#include "common.h" |
#include "Logger.h" |
7 |
#include <sstream> |
#include <sstream> |
8 |
|
#include <stdlib.h> |
9 |
|
|
10 |
|
|
11 |
using namespace std; |
using namespace std; |
12 |
|
|
13 |
|
|
14 |
SpamPlugin::SpamPlugin() |
SpamPlugin::SpamPlugin() |
15 |
: Plugin("spam", "Sends a number of messages to a given phone nr") |
: Plugin("spam", "Sends a number of messages to a given phone nr") |
16 |
{ |
{ |
17 |
} |
} |
18 |
|
|
19 |
const string USAGE = "Usage: spam <recipient> <nr> message"; |
const string USAGE = "Usage: spam <recipient> <nr> message"; |
20 |
|
|
21 |
void SpamPlugin::Execute(IGsmModem& modem, SMS& sms) |
void SpamPlugin::Execute(ISmsTransceiver& modem, SMS& sms) |
22 |
{ |
{ |
23 |
string cmd = GetSmsData(sms); |
string cmd = sms.ExtractParameters(); |
24 |
|
|
25 |
|
|
26 |
if (cmd == "") |
if (cmd == "") |
27 |
{ |
{ |
28 |
modem.SendSms(sms.sender, USAGE, false); |
modem.SendSms(sms.GetSender(), USAGE, false); |
29 |
return; |
return; |
30 |
} |
} |
31 |
|
|
32 |
vector<string> parts = Util::str_split(cmd," "); |
vector<string> parts = Util::str_split(cmd," "); |
33 |
|
|
34 |
|
|
35 |
if (parts.size() < 2 ) |
if (parts.size() < 2 ) |
36 |
{ |
{ |
37 |
modem.SendSms(sms.sender, USAGE, false); |
modem.SendSms(sms.GetSender(), USAGE, false); |
38 |
return; |
return; |
39 |
} |
} |
40 |
|
|
42 |
unsigned int count = atoi(parts[1].c_str()); |
unsigned int count = atoi(parts[1].c_str()); |
43 |
if (count > 25) |
if (count > 25) |
44 |
count = 25; |
count = 25; |
45 |
|
|
46 |
ostringstream os; |
ostringstream os; |
47 |
os << "Spamming " << nr << " " << count << " times."; |
os << "Spamming " << nr << " " << count << " times."; |
48 |
Common::instance()->logMessage(os.str()); |
modem.SendSms(sms.GetSender(), os.str(), false); |
49 |
|
|
50 |
|
Logger::logMessage(os.str()); |
51 |
|
|
52 |
string message; |
string message; |
53 |
for (unsigned i=2; i<parts.size(); ++i) |
for (unsigned i=2; i<parts.size(); ++i) |