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

Annotation of /smsdaemon/plugins/SpamPlugin.cpp

Parent Directory Parent Directory | Revision Log Revision Log


Revision 522 - (hide annotations) (download)
Sun Dec 27 18:37:23 2009 UTC (14 years, 5 months ago) by torben
File size: 1483 byte(s)
Small fixes

1 torben 521 #include "SpamPlugin.h"
2 torben 520 #include "ISmsTransceiver.h"
3     #include "Sms.h"
4    
5 torben 521 #include "tasks/SpamTask.h"
6 torben 520 #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 torben 522 const string USAGE = "Usage: spam <recipient> <nr> <interval> <message>";
21 torben 520
22 torben 521 SpamPlugin::SpamPlugin()
23 torben 522 : Plugin("spam", "Sends a number of messages to a given phone nr")
24 torben 520 {
25     }
26    
27 torben 521 void SpamPlugin::Execute(ISmsTransceiver& modem, SMS& sms)
28 torben 520 {
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 torben 522 if (parts.size() < 4 )
43 torben 520 {
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 torben 521 SpamTask* task = new SpamTask();
69 torben 520 task->SetDestination( nr );
70     task->SetNumber( count );
71     task->SetInterval( interval );
72     task->SetMessage( message );
73    
74     task->RegisterTask();//register with taskmanager
75    
76     }

Properties

Name Value
svn:mergeinfo

  ViewVC Help
Powered by ViewVC 1.1.20