| Server IP : 209.209.40.120 / Your IP : 216.73.217.112 Web Server : Microsoft-IIS/10.0 System : Windows NT NEWWWW 10.0 build 17763 (Windows Server 2019) i586 User : NEWWWW$ ( 0) PHP Version : 8.3.30 Disable Function : NONE MySQL : OFF | cURL : ON | WGET : OFF | Perl : OFF | Python : OFF | Sudo : OFF | Pkexec : OFF Directory : /software/Services/MessageStatusCPP/MessageStatusCPP/MessageStatusCPP/ |
Upload File : |
// MessageStatusCPP.cpp : Defines the entry point for the console application.
//
#include "stdafx.h"
#include <stdlib.h>
#include <iostream>
#include <sstream>
#include <stdexcept>
#include <string>
#include <time.h>
#include <iomanip>
#include <math.h>
#include <algorithm>
#include <vector>
#include <thread>
#include <chrono>
#include <regex>
/* uncomment for applications that use vectors */
/*#include <vector>*/
#include "mysql_connection.h"
#include <cppconn/driver.h>
#include <cppconn/exception.h>
#include <cppconn/resultset.h>
#include <cppconn/statement.h>
#include <cppconn/prepared_statement.h>
#define EXAMPLE_HOST "localhost"
#define EXAMPLE_USER "smsEngine"
#define EXAMPLE_PASS "guEnaR28T"
#define EXAMPLE_DB "smartsmsrouter"
using namespace std;
string datetime()
{
time_t rawtime;
tm * timeinfo;
char buffer[80];
time(&rawtime);
timeinfo = localtime(&rawtime);
//2014 - 10 - 17 00:00 : 00
strftime(buffer, 80, "%Y-%m-%d %H:%M:%S", timeinfo);
std::string retVal = buffer;
return(retVal);
}
string date()
{
time_t rawtime;
tm * timeinfo;
char buffer[80];
time(&rawtime);
timeinfo = localtime(&rawtime);
//2014 - 10 - 17 00:00 : 00
strftime(buffer, 80, "%Y-%m-%d %H:%M:%S", timeinfo);
std::string retVal = buffer;
return(retVal);
}
string date(int n)
{
time_t rawtime;
tm * timeinfo;
char buffer[80];
time(&rawtime);
rawtime = rawtime - (24 * 60 * 60 * n);
timeinfo = localtime(&rawtime);
//2014 - 10 - 17 00:00 : 00
strftime(buffer, 80, "%Y-%m-%d", timeinfo);
std::string retVal = buffer;
return(retVal);
}
string mytime()
{
time_t rawtime;
tm * timeinfo;
char buffer[80];
time(&rawtime);
timeinfo = localtime(&rawtime);
//2014 - 10 - 17 00:00 : 00
strftime(buffer, 80, "%H:%M", timeinfo);
std::string retVal = buffer;
return(retVal);
}
string getQuery(string myquery)
{
string response = "#";
try {
sql::Driver *driver;
sql::Connection *con;
sql::Statement *stmt;
sql::ResultSet *res;
/* Create a connection */
driver = get_driver_instance();
con = driver->connect("tcp://127.0.0.1:3306", "smsEngine", "guEnaR28T");
/* Connect to the MySQL test database */
con->setSchema("smartsmsrouter");
stmt = con->createStatement();
res = stmt->executeQuery(myquery);
while (res->next()) {
response = res->getString(1);
}
delete res;
delete stmt;
delete con;
}
catch (sql::SQLException &e) {
cout << "# ERR: SQLException in " << __FILE__;
cout << "(" << __FUNCTION__ << ") on line " << __LINE__ << endl;
cout << "# ERR: " << e.what();
cout << " (MySQL error code: " << e.getErrorCode();
cout << ", SQLState: " << e.getSQLState() << " )" << endl;
}
return response;
}//end of getQuery
int _tmain(int argc, _TCHAR* argv[])
{
string snstatus = "";
string stateID = "";
string networkID = "";
string snmessagesent = "";
string response = "";
string stateResult = "";
string networkResult = "";
string query = "";
string phonenumber = "";
string mccmnc = "";
string route = "";
int cnt7 = 0;
while (1)
{
string url(argc >= 2 ? argv[1] : EXAMPLE_HOST);
const string user(argc >= 3 ? argv[2] : EXAMPLE_USER);
const string pass(argc >= 4 ? argv[3] : EXAMPLE_PASS);
const string database(argc >= 5 ? argv[4] : EXAMPLE_DB);
try {
sql::Driver * driver = get_driver_instance();
std::unique_ptr< sql::Connection > con(driver->connect(url, user, pass));
con->setSchema(database);
std::unique_ptr< sql::Statement > stmt(con->createStatement());
std::unique_ptr< sql::PreparedStatement > pstmt;
std::unique_ptr< sql::ResultSet > res;
std::unique_ptr< sql::PreparedStatement > pstmt2;
std::unique_ptr< sql::ResultSet > res2;
// pstmt.reset(con->prepareStatement("CALL get_pop_continent(?,@pop)"));
// res.reset(stmt->executeQuery("SELECT @pop AS _population"));
pstmt.reset(con->prepareStatement("select a.sn,b.sn,messagestate,networkerror,b.phonenumber,b.mccmnc,b.route from messagestatus as a,messagesent as b where a.status = '0' and a.messageid=b.messageid and billcode ='1';"));
res.reset(pstmt->executeQuery());
while (res->next())
{
cout << "Working..." << endl;
cout << endl;
//cout << "\t... MySQL counts: " << SMSCID << endl;
snstatus = res->getString(1);
snmessagesent = res->getString(2);
stateID = res->getString(3);
networkID = res->getString(4);
phonenumber = res->getString(5);
mccmnc = res->getString(6);
route = res->getString(7);
cnt7 = 0;
cout << stateID << endl;
//call get StatusCode
query = "select description from messagestate where code ='" + stateID + "'";
response = getQuery(query);
if (response == "#")
stateResult = "Unknown Error";
else
stateResult = response;
cout << "StateResult " << stateResult << endl;
//call NetworkCode
query = "select description from status where code ='" + networkID + "'";
response = getQuery(query);
if (response == "#")
networkResult = "Unknown Error";
else
networkResult = response;
cout << "networkResult " << networkResult << endl;
if (networkID == "2050") {
//check if already in dnd list
query = "select phonenumber from dnd where phonenumber ='" + phonenumber + "'";
response = getQuery(query);
if (response == "#"){
//not in dnd
query = "insert into dnd (phonenumber,datesent) values ('"+phonenumber+"','"+date()+"')";
pstmt2.reset(con->prepareStatement(query));
pstmt2->execute();
cout << "Included in dnd " << phonenumber << endl;
}
//update Messagesent
query = "Update messagesent set sentcode ='1', route = '1', track = '0' where sn =" + snmessagesent;
pstmt2.reset(con->prepareStatement(query));
pstmt2->execute();
cout << "rerouting dnd: messagesent serial " << snmessagesent << endl;
cnt7 = 1;
}
//if (stateID == "8" && mccmnc == "62130" && route =="4"){
// //update Messagesent
// query = "Update messagesent set sentcode ='1', route = '1', track = '0' where sn =" + snmessagesent;
// pstmt2.reset(con->prepareStatement(query));
// pstmt2->execute();
// cout << "rerouting rejected message: messagesent serial " << snmessagesent << endl;
// cnt7 = 1;
//}
if ( cnt7 ==0)
{
//update Messagesent
query = "Update messagesent set status ='" + stateResult + "', failurereason = '" + networkResult + "', track = '2' where sn =" + snmessagesent;
pstmt2.reset(con->prepareStatement(query));
pstmt2->execute();
}
//update Messagestatus
query = "UPDATE messagestatus set status = '1' where sn = " + snstatus;
pstmt2.reset(con->prepareStatement(query));
pstmt2->execute();
}//end of while loop
}
catch (sql::SQLException &e) {
cout << "# ERR: SQLException in " << __FILE__;
cout << "(" << __FUNCTION__ << ") on line " << __LINE__ << endl;
/* what() (derived from std::runtime_error) fetches error message */
cout << "# ERR: " << e.what();
cout << " (MySQL error code: " << e.getErrorCode();
cout << ", SQLState: " << e.getSQLState() << " )" << endl;
return EXIT_FAILURE;
}
cout << "Sleeping " << date() << endl;
this_thread::sleep_for(chrono::seconds(5));
}//end of while
return EXIT_SUCCESS;
}