/[projects]/smsdaemon/plugins/SpamPlugin.cpp
ViewVC logotype

Contents of /smsdaemon/plugins/SpamPlugin.cpp

Parent Directory Parent Directory | Revision Log Revision Log


Revision 142 - (show annotations) (download)
Sun Dec 7 15:51:02 2008 UTC (15 years, 5 months ago) by torben
File size: 1079 byte(s)
Refacerored SMS class

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

  ViewVC Help
Powered by ViewVC 1.1.20