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

Contents of /smsdaemon/plugins/SpamPlugin.cpp

Parent Directory Parent Directory | Revision Log Revision Log


Revision 678 - (show annotations) (download)
Tue Apr 27 21:06:53 2010 UTC (14 years ago) by torben
File size: 1483 byte(s)
undo previous unintentional commit
1 #include "SpamPlugin.h"
2 #include "ISmsTransceiver.h"
3 #include "Sms.h"
4
5 #include "tasks/SpamTask.h"
6 #include "TaskManager.h"
7
8 #include "Common.h"
9 #include "Logger.h"
10 #include "Util.h"
11
12 #include <stdlib.h>
13
14 #include <sstream>
15 #include <string>
16 #include <vector>
17
18 using namespace std;
19
20 const string USAGE = "Usage: spam <recipient> <nr> <interval> <message>";
21
22 SpamPlugin::SpamPlugin()
23 : Plugin("spam", "Sends a number of messages to a given phone nr")
24 {
25 }
26
27 void SpamPlugin::Execute(ISmsTransceiver& modem, SMS& sms)
28 {
29
30 string cmd = sms.ExtractParameters();
31
32
33 if (cmd == "")
34 {
35 modem.SendSms(sms.GetSender(), USAGE, false);
36 return;
37 }
38
39 vector<string> parts = Util::str_split(cmd," ");
40
41
42 if (parts.size() < 4 )
43 {
44 modem.SendSms(sms.GetSender(), USAGE, false);
45 return;
46 }
47
48 string nr = parts[0];
49 unsigned int count = atoi( parts[1].c_str() );
50 unsigned int interval = atoi( parts[2].c_str() );
51 if (count > 25)
52 count = 25;
53
54 string message;
55 for (unsigned i=3; i<parts.size(); ++i)
56 {
57 if (message.length() > 0)
58 message += " ";
59 message += parts[i];
60 }
61
62 ostringstream os;
63 os << "Spamming " << nr << ", " << count << " times, with an interval on " << interval << " minutes";
64 modem.SendSms(sms.GetSender(), os.str(), false);
65
66 Logger::logMessage(os.str());
67
68 SpamTask* task = new SpamTask();
69 task->SetDestination( nr );
70 task->SetNumber( count );
71 task->SetInterval( interval );
72 task->SetMessage( message );
73
74 task->RegisterTask();//register with taskmanager
75
76 }

  ViewVC Help
Powered by ViewVC 1.1.20