QString instead of std::string. added socket error handle, still not completed the handling

This commit is contained in:
liranbg 2014-09-17 04:08:38 +03:00
parent 582a959fb3
commit 03a75ab737
29 changed files with 813 additions and 547 deletions

8
.gitignore vendored
View file

@ -1,4 +1,4 @@
jceGrade.pro.user*
.sass-cache/
_site/
jceGrade.pro.user*
.sass-cache/
_site/

View file

@ -6,7 +6,7 @@ CalendarManager::CalendarManager(calendarSchedule *ptr)
caliDialog = new CalendarDialog();
}
void CalendarManager::setCalendar(std::string html)
void CalendarManager::setCalendar(QString html)
{
caliSchedPtr->setPage(html);
}

View file

@ -18,7 +18,7 @@ public:
delete caliDialog;
}
bool exportCalendarCSV();
void setCalendar(std::string html);
void setCalendar(QString html);
void resetTable() { if (caliSchedPtr != NULL) caliSchedPtr->clearTableItems(); }
private:

View file

@ -46,7 +46,7 @@ void coursesTableManager::insertJceCoursesIntoTable()
* @brief coursesTableManager::setCoursesList creating courses list with given html page
* @param html
*/
void coursesTableManager::setCoursesList(std::string &html)
void coursesTableManager::setCoursesList(QString &html)
{
gp = new GradePage(html);
}
@ -70,10 +70,10 @@ bool coursesTableManager::changes(QString change, int row, int col)
switch (col)
{
case (gradeCourse::CourseScheme::NAME):
c->setName(change.toStdString());
c->setName(change);
break;
case (gradeCourse::CourseScheme::TYPE):
c->setType(change.toStdString());
c->setType(change);
break;
case (gradeCourse::CourseScheme::POINTS):
{
@ -117,7 +117,7 @@ bool coursesTableManager::changes(QString change, int row, int col)
break;
}
case (gradeCourse::CourseScheme::ADDITION):
c->setAdditions(change.toStdString());
c->setAdditions(change);
break;
}
break;
@ -150,11 +150,11 @@ void coursesTableManager::addRow(const gradeCourse *courseToAdd)
hours = new QTableWidgetItem(QString::number(c->getHours()));
hours->setFlags(serial->flags() & ~Qt::ItemIsEditable);
grade = new QTableWidgetItem(QString::number(c->getGrade()));
name = new QTableWidgetItem(QString::fromStdString(c->getName()));
name = new QTableWidgetItem(c->getName());
name->setFlags(serial->flags() & ~Qt::ItemIsEditable);
type = new QTableWidgetItem(QString::fromStdString(c->getType()));
type = new QTableWidgetItem(c->getType());
type->setFlags(serial->flags() & ~Qt::ItemIsEditable);
addition = new QTableWidgetItem(QString::fromStdString(c->getAddidtions()));
addition = new QTableWidgetItem(c->getAddidtions());
courseTBL->setItem(i,j++,serial);
courseTBL->setItem(i,j++,name);
@ -212,7 +212,7 @@ void coursesTableManager::clearTable()
int i = 0; //starting point
while (courseTBL->rowCount() > i)
{
gp->removeCourse(courseTBL->item(i,gradeCourse::CourseScheme::SERIAL)->text().toStdString());
gp->removeCourse(courseTBL->item(i,gradeCourse::CourseScheme::SERIAL)->text());
courseTBL->removeRow(i);
}
gp = NULL;

View file

@ -22,7 +22,7 @@ public:
coursesTableManager(QTableWidget *, user *usrPtr);
~coursesTableManager();
void insertJceCoursesIntoTable();
void setCoursesList(std::string &htmlPage);
void setCoursesList(QString &htmlPage);
bool changes(QString change, int row, int col);
void addRow(const gradeCourse * courseToAdd = 0);
double getAvg();

View file

@ -2,142 +2,142 @@
loginHandler::loginHandler(user *ptr): logggedInFlag(false)
{
this->jceLog = new jceLogin(ptr);
this->jceLog = new jceLogin(ptr);
}
void loginHandler::setPointers(QLabel *statusLabelPtr,QLineEdit *pswdEditPtr,QLineEdit *usrnmEditPtr)
{
this->statusLabelPtr = statusLabelPtr;
this->pswdEditPtr = pswdEditPtr;
this->usrnmEditPtr = usrnmEditPtr;
this->statusLabelPtr = statusLabelPtr;
this->pswdEditPtr = pswdEditPtr;
this->usrnmEditPtr = usrnmEditPtr;
}
bool loginHandler::makeConnection()
{
if (this->jceLog == NULL)
return false;
if (this->jceLog == NULL)
return false;
try
{
jceLog->makeConnection();
}
catch (jceLogin::jceStatus &a)
{
int status = (int)a;
switch (status)
try
{
jceLog->makeConnection();
}
catch (jceLogin::jceStatus &a)
{
int status = (int)a;
switch (status)
{
case jceLogin::JCE_YOU_ARE_IN:
{
case jceLogin::JCE_YOU_ARE_IN:
{
logggedInFlag = true;
return logggedInFlag;
break;
logggedInFlag = true;
return logggedInFlag;
break;
}
case jceLogin::ERROR_ON_VALIDATION:
case jceLogin::ERROR_ON_VALIDATION:
{
popMessage(QObject::tr("Please Check Your Username & Password"),false);
popMessage(QObject::tr("Please Check Your Username & Password"),false);
usrnmEditPtr->setDisabled(false);
pswdEditPtr->setDisabled(false);
usrnmEditPtr->setDisabled(false);
pswdEditPtr->setDisabled(false);
pswdEditPtr->selectAll();
pswdEditPtr->setFocus();
return false;
pswdEditPtr->selectAll();
pswdEditPtr->setFocus();
return false;
}
case jceLogin::ERROR_ON_VALIDATION_USER_BLOCKED:
case jceLogin::ERROR_ON_VALIDATION_USER_BLOCKED:
{
popMessage(QObject::tr("You have been blocked by JCE, please try in a couple of minutes."));
jceLog->closeAll();
return false;
popMessage(QObject::tr("You have been blocked by JCE, please try in a couple of minutes."));
jceLog->closeAll();
return false;
}
case jceLogin::ERROR_ON_OPEN_SOCKET:
case jceLogin::ERROR_ON_OPEN_SOCKET:
{
popMessage(QObject::tr("Please Check Your Internet Connection."));
jceLog->closeAll();
return false;
popMessage(QObject::tr("Please Check Your Internet Connection."));
jceLog->closeAll();
return false;
}
case jceLogin::JCE_NOT_CONNECTED:
case jceLogin::JCE_NOT_CONNECTED:
{
jceLog->reConnect();
/*
jceLog->reConnect();
/*
* Fix: need to add a prompte window to ask user whether he wants to reconnect or not
*/
break;
break;
}
case jceLogin::ERROR_ON_GETTING_INFO:
case jceLogin::ERROR_ON_GETTING_INFO:
{
popMessage(QObject::tr("Receive Request Timeout."));
jceLog->closeAll();
return false;
break;
popMessage(QObject::tr("Receive Request Timeout."));
jceLog->closeAll();
return false;
break;
}
case jceLogin::ERROR_ON_SEND_REQUEST:
case jceLogin::ERROR_ON_SEND_REQUEST:
{
popMessage(QObject::tr("Send Request Timeout."));
jceLog->closeAll();
return false;
break;
popMessage(QObject::tr("Send Request Timeout."));
jceLog->closeAll();
return false;
break;
}
}
}
return false;
}
}
return false;
}
bool loginHandler::isLoggedInFlag()
{
if (jceLog->isLoginFlag()) //checking connection and then if logged in
return this->logggedInFlag;
else
this->setLoginFlag(false);
return false;
if (jceLog->isLoginFlag()) //checking connection and then if logged in
return this->logggedInFlag;
else
this->setLoginFlag(false);
return false;
}
void loginHandler::setLoginFlag(bool flag)
{
this->logggedInFlag = flag;
this->logggedInFlag = flag;
}
QString loginHandler::getCurrentPageContect()
{
QTextEdit phrase;
if (isLoggedInFlag())
phrase.setText(QString::fromStdString(jceLog->getPage()));
else
throw jceLogin::ERROR_ON_GETTING_INFO;
QTextEdit phrase;
if (isLoggedInFlag())
phrase.setText(jceLog->getPage());
else
throw jceLogin::ERROR_ON_GETTING_INFO;
return phrase.toPlainText();
return phrase.toPlainText();
}
void loginHandler::makeDisconnectionRequest()
{
jceLog->closeAll();
this->logggedInFlag = false;
jceLog->closeAll();
this->logggedInFlag = false;
}
int loginHandler::makeGradeRequest(int fromYear, int toYear, int fromSemester, int toSemester)
{
if (isLoggedInFlag())
return jceLog->getGrades(fromYear, toYear, fromSemester, toSemester);
else
return jceLogin::JCE_NOT_CONNECTED;
if (isLoggedInFlag())
return jceLog->getGrades(fromYear, toYear, fromSemester, toSemester);
else
return jceLogin::JCE_NOT_CONNECTED;
}
int loginHandler::makeCalendarRequest(int year, int semester)
{
if (isLoggedInFlag())
return jceLog->getCalendar(year,semester);
else
return jceLogin::JCE_NOT_CONNECTED;
if (isLoggedInFlag())
return jceLog->getCalendar(year,semester);
else
return jceLogin::JCE_NOT_CONNECTED;
}
void loginHandler::popMessage(QString message,bool addInfo)
{
if (addInfo)
message.append(QObject::tr("\nIf this message appear without reason, please contact me at liranbg@gmail.com"));
if (addInfo)
message.append(QObject::tr("\nIf this message appear without reason, please contact me at liranbg@gmail.com"));
QMessageBox msgBox;
msgBox.setWindowTitle(QObject::tr("Error"));
msgBox.setText(message);
msgBox.exec();
msgBox.setFocus();
QMessageBox msgBox;
msgBox.setWindowTitle(QObject::tr("Error"));
msgBox.setText(message);
msgBox.exec();
msgBox.setFocus();
}

View file

@ -20,7 +20,7 @@ MainScreen::MainScreen(QWidget *parent) :QMainWindow(parent), ui(new Ui::MainScr
ui->statusBar->setStyleSheet("QStatusBar::item { border: 0px solid black };");
ButtomStatusLabel = new QLabel(this);
statusLabel = new QLabel(this);
ui->statusBar->setMaximumSize(this->geometry().width(),StatusIconHeight);
ui->statusBar->setMaximumSize(this->geometry().width(),STATUS_ICON_HEIGH);
ui->statusBar->addPermanentWidget(ButtomStatusLabel,0);
ui->statusBar->addPermanentWidget(statusLabel,1);
setLabelConnectionStatus(jceLogin::jceStatus::JCE_NOT_CONNECTED);
@ -50,6 +50,7 @@ MainScreen::MainScreen(QWidget *parent) :QMainWindow(parent), ui(new Ui::MainScr
checkLocale();
}
MainScreen::~MainScreen()
@ -125,8 +126,8 @@ void MainScreen::uiSetDisconnectMode()
}
void MainScreen::uiSetConnectMode()
{
string username;
string password;
QString username;
QString password;
if ((ui->usrnmLineEdit->text().isEmpty()) || (ui->pswdLineEdit->text().isEmpty()))
{
if (ui->usrnmLineEdit->text().isEmpty())
@ -152,8 +153,8 @@ void MainScreen::uiSetConnectMode()
}
setLabelConnectionStatus(jceLogin::jceStatus::JCE_START_VALIDATING_PROGRESS);
username = ui->usrnmLineEdit->text().toStdString();
password = ui->pswdLineEdit->text().toStdString();
username = ui->usrnmLineEdit->text();
password = ui->pswdLineEdit->text();
ui->usrnmLineEdit->setDisabled(true);
ui->pswdLineEdit->setDisabled(true);
@ -180,13 +181,13 @@ void MainScreen::uiSetConnectMode()
//EVENTS ON GPA TAB
void MainScreen::on_ratesButton_clicked()
{
std::string pageString;
QString pageString;
int status = 0;
if (loginHandel->isLoggedInFlag())
{
if ((status = loginHandel->makeGradeRequest(ui->spinBoxCoursesFromYear->value(),ui->spinBoxCoursesToYear->value(),ui->spinBoxCoursesFromSemester->value(),ui->spinBoxCoursesToSemester->value())) == jceLogin::JCE_GRADE_PAGE_PASSED)
{
pageString = loginHandel->getCurrentPageContect().toStdString();
pageString = loginHandel->getCurrentPageContect();
courseTableMgr->setCoursesList(pageString);
courseTableMgr->insertJceCoursesIntoTable();
}
@ -264,7 +265,7 @@ void MainScreen::on_getCalendarBtn_clicked()
//Use it for debug. add plain text and change the object name to 'plainTextEdit' so you will get the html request
//ui->plainTextEdit->setPlainText(loginHandel->getCurrentPageContect());
calendar->resetTable();
calendar->setCalendar(loginHandel->getCurrentPageContect().toStdString());
calendar->setCalendar(loginHandel->getCurrentPageContect());
}
else if (status == jceLogin::JCE_NOT_CONNECTED)

View file

@ -15,7 +15,7 @@
#include "./CalendarTab/CalendarManager.h"
#define StatusIconHeight 35
#define STATUS_ICON_HEIGH 35
namespace Ui {
class MainScreen;
}

View file

@ -1,58 +1,126 @@
#include "jcesslclient.h"
/**
* @brief jceSSLClient::jceSSLClient Constructer, setting the signals
*/
jceSSLClient::jceSSLClient() : flag(false), packet("")
{
//setting signals
connect(this,SIGNAL(error(QAbstractSocket::SocketError)),this,SLOT(checkErrors(QAbstractSocket::SocketError)));
connect(this,SIGNAL(connected()),this,SLOT(setConnected()));
connect(this,SIGNAL(encrypted()),this,SLOT(setEncrypted()));
connect(this,SIGNAL(disconnected()),this,SLOT(setDisconnected()));
//loop event will connect the server, and when it is connected, it will quit - but connection will be open
connect(this, SIGNAL(encrypted()), &loop, SLOT(quit()));
connect(this,SIGNAL(error(QAbstractSocket::SocketError)),&loop,SLOT(quit()));
}
bool jceSSLClient::makeConnect(std::string server, int port)
/**
* @brief jceSSLClient::makeConnect connecting to server with given port. using eventloop to assure it wont stuck the application.
* @param server - server to connect to
* @param port - the using port
* @return - true if connected, false otherwise
*/
bool jceSSLClient::makeConnect(QString server, int port)
{
QEventLoop loop;
QObject::connect(this, SIGNAL(encrypted()), &loop, SLOT(quit()));
qDebug() << "jceSSLClient::makeConnect; Making connection";
if (isConnected())
abort();
{
qWarning() << "jceSSLClient::makeConnect; Was already connected. Aborting.";
makeDiconnect();
}
if (isOpen())
abort();
{
qWarning() << "jceSSLClient::makeConnect; IsO pen. Aborting.";
makeDiconnect();
}
connectToHostEncrypted(server.c_str(), port);
loop.exec();
qDebug() << "jceSSLClient::makeConnect; Connection to: " << server << "On Port: " << port;
connectToHostEncrypted(server.toStdString().c_str(), port);
loop.exec(); //starting connection, waiting to encryption and then it ends
qDebug() << "jceSSLClient::makeConnect; returning the connection status: " << isConnected();
return isConnected();
}
/**
* @brief jceSSLClient::makeDiconnect from current server
* @return the flag of connection status
*/
bool jceSSLClient::makeDiconnect()
{
abort();
if (state() == QAbstractSocket::SocketState::ConnectedState)
qDebug() << "jceSSLClient::makeDiconnect;";
if (loop.isRunning())
{
qWarning() << "jceSSLClient::makeDiconnect; Killing connection thread";
loop.exit();
}
if (state() == QAbstractSocket::SocketState::UnconnectedState)
{
qDebug() << "jceSSLClient::makeDiconnect; Disconnected with [UnconnectedState]";
flag = false;
}
else if (state() == QAbstractSocket::SocketState::ConnectedState)
{
qWarning() << "jceSSLClient::makeDiconnect; Disconnecting with [ConnectedState] ";
abort();
if (state() != QAbstractSocket::SocketState::UnconnectedState)
{
qWarning() << "jceSSLClient::makeDiconnect; still open! recursion call to disconnect";
abort();//still connected? ensure the disconnection
flag = makeDiconnect(); //recursion call!
}
flag = false;
}
else
flag = true;
{
qWarning() << "jceSSLClient::makeDiconnect; Disconnecting [else] ";
abort(); //ensure the disconnection
flag = false;
}
qDebug() << "jceSSLClient::makeDiconnect; disconnect return with " << flag;
return flag;
}
/**
* @brief jceSSLClient::isConnected connection checking
* @return regardless to state, it checks if there's a connection
*/
bool jceSSLClient::isConnected()
{
//checking state before returning flag!
if (state() == QAbstractSocket::SocketState::UnconnectedState)
{
flag = false;
}
else if (state() == QAbstractSocket::SocketState::ClosingState)
{
flag = false;
}
else if (state() == QAbstractSocket::SocketState::ConnectedState)
{
flag = true;
}
return flag;
}
bool jceSSLClient::sendData(std::string str)
/**
* @brief jceSSLClient::sendData - given string, send it to server
* @param str - string to send
* @return true if succeed and byte were written
*/
bool jceSSLClient::sendData(QString str)
{
bool sendDataFlag = false;
if (isConnected()) //if connected
{
write(str.c_str(),str.length());
while (waitForBytesWritten());
return true;
write(str.toStdString().c_str(),str.length());
if (waitForBytesWritten())
sendDataFlag = true;
}
return false;
qDebug() << "jceSSLClient::sendData; Sending Data status is: " << sendDataFlag;
return sendDataFlag;
}
/**
* @brief jceSSLClient::recieveData
@ -60,13 +128,15 @@ bool jceSSLClient::sendData(std::string str)
* @param fast true for LOGIN ONLY, false to retrieve all data
* @return true if recieved data bigger than zero
*/
bool jceSSLClient::recieveData(std::string &str, bool fast)
bool jceSSLClient::recieveData(QString &str, bool fast)
{
qDebug() << "jceSSLClient::recieveData Data receiving!";
packet = "";
bool sflag = false;
if (fast) //fast connection, good for login only!!
if (fast) //fast mode connection, good only for login step!!!!
{
qDebug() << "jceSSLClient::recieveData login step receiving";
QEventLoop loop;
connect(this, SIGNAL(readyRead()), &loop, SLOT(quit()));
connect(this, SIGNAL(readyRead()), this, SLOT(readIt()));
@ -76,6 +146,7 @@ bool jceSSLClient::recieveData(std::string &str, bool fast)
}
else
{
qDebug() << "jceSSLClient::recieveData normal receiving";
QString p;
while (waitForReadyRead(milisTimeOut))
{
@ -86,14 +157,17 @@ bool jceSSLClient::recieveData(std::string &str, bool fast)
}while (p.size() > 0);
}
}
str = packet.toStdString();
if (str.size() > 0)
str = packet;
qDebug() << "jceSSLClient::recieveData received bytes: " << str.length() ;
if (str.length() > 0)
sflag = true;
qDebug() << "jceSSLClient::recieveData return with flag: " << sflag;
return sflag;
}
/**
* @brief jceSSLClient::readIt function to read for fast mode in recieved data
*/
void jceSSLClient::readIt()
{
QString p;
@ -103,30 +177,146 @@ void jceSSLClient::readIt()
packet.append(p);
}while (p.size() > 0);
}
/**
* @brief jceSSLClient::setConnected called when signaled with connected, calling the encryption function
*/
void jceSSLClient::setConnected()
{
waitForEncrypted();
}
/**
* @brief jceSSLClient::setDisconnected called when signaled with disconnected, setting flag to false
*/
void jceSSLClient::setDisconnected()
{
flag = false;
}
/**
* @brief jceSSLClient::setEncrypted called when signaled with encrypted. setting the buffer size and keeping alive.
*/
void jceSSLClient::setEncrypted()
{
setReadBufferSize(10000);
setSocketOption(QAbstractSocket::KeepAliveOption,1);
flag = true;
if (state() == QAbstractSocket::SocketState::ConnectedState)
flag = true;
else
{
qWarning() << "jceSSLClient::setEncrypted(); Connection status didnt change!";
flag = false;
}
}
void jceSSLClient::setDisconnected()
/**
* @brief jceSSLClient::showIfErrorMsg message box to show the error occured according to socket
* if relevant, we will prompt a message box to informate the user
* otherwise, we will handle the error or ignore it.
*/
void jceSSLClient::showIfErrorMsg()
{
abort();
flag = false;
QMessageBox msgBox;
SocketError enumError = error();
QString errorString;
bool relevantError = false;
switch (enumError)
{
case QAbstractSocket::SocketError::ConnectionRefusedError:
errorString = QObject::tr("ConnectionRefusedError");
relevantError = true;
break;
case QAbstractSocket::SocketError::RemoteHostClosedError:
errorString = QObject::tr("RemoteHostClosedError");
relevantError = true;
break;
case QAbstractSocket::SocketError::HostNotFoundError:
errorString = QObject::tr("HostNotFoundError");
relevantError = true;
break;
case QAbstractSocket::SocketError::SocketAccessError:
errorString = QObject::tr("SocketAccessError");
break;
case QAbstractSocket::SocketError::SocketResourceError:
errorString = QObject::tr("SocketResourceError");
break;
case QAbstractSocket::SocketError::SocketTimeoutError:
errorString = QObject::tr("SocketTimeoutError");
if (isConnected())
relevantError = true;
break;
case QAbstractSocket::SocketError::DatagramTooLargeError:
errorString = QObject::tr("DatagramTooLargeError");
break;
case QAbstractSocket::SocketError::NetworkError:
errorString = QObject::tr("NetworkError");
relevantError = true;
break;
case QAbstractSocket::SocketError::AddressInUseError:
errorString = QObject::tr("AddressInUseError");
break;
case QAbstractSocket::SocketError::SocketAddressNotAvailableError:
errorString = QObject::tr("SocketAddressNotAvailableError");
break;
case QAbstractSocket::SocketError::UnsupportedSocketOperationError:
errorString = QObject::tr("UnsupportedSocketOperationError");
break;
case QAbstractSocket::SocketError::ProxyAuthenticationRequiredError:
errorString = QObject::tr("ProxyAuthenticationRequiredError");
break;
case QAbstractSocket::SocketError::SslHandshakeFailedError:
errorString = QObject::tr("SslHandshakeFailedError");
break;
case QAbstractSocket::SocketError::ProxyConnectionRefusedError:
errorString = QObject::tr("ProxyConnectionRefusedError");
break;
case QAbstractSocket::SocketError::UnfinishedSocketOperationError:
errorString = QObject::tr("UnfinishedSocketOperationError");
break;
case QAbstractSocket::SocketError::ProxyConnectionClosedError:
errorString = QObject::tr("ProxyConnectionClosedError");
break;
case QAbstractSocket::SocketError::ProxyConnectionTimeoutError:
errorString = QObject::tr("ProxyConnectionTimeoutError");
break;
case QAbstractSocket::SocketError::ProxyNotFoundError:
errorString = QObject::tr("ProxyNotFoundError");
break;
case QAbstractSocket::SocketError::ProxyProtocolError:
errorString = QObject::tr("ProxyProtocolError");
break;
case QAbstractSocket::SocketError::OperationError:
errorString = QObject::tr("OperationError");
break;
case QAbstractSocket::SocketError::SslInternalError:
errorString = QObject::tr("SslInternalError");
break;
case QAbstractSocket::SocketError::SslInvalidUserDataError:
errorString = QObject::tr("SslInvalidUserDataError");
break;
case QAbstractSocket::SocketError::TemporaryError:
errorString = QObject::tr("TemporaryError");
break;
case QAbstractSocket::SocketError::UnknownSocketError:
errorString = QObject::tr("UnknownSocketError");
relevantError = true;
break;
}
if (relevantError) //informative string to be shown
{
qDebug() << "jceSSLClient::showIfErrorMsg(); relevant error. msgbox popped";
msgBox.setIcon(QMessageBox::Warning);
msgBox.setText(errorString);
msgBox.exec();
}
}
void jceSSLClient::checkErrors(QAbstractSocket::SocketError)
/**
* @brief jceSSLClient::checkErrors this function exctuing when socket error has occured
* @param a includes the error enum from QAbstractSocket::SocketError enum list
*/
void jceSSLClient::checkErrors(QAbstractSocket::SocketError a)
{
qWarning() << "jceSSLClient::checkErrors; Var Error: " << a;
qWarning() << "jceSSLClient::checkErrors; Error: " << this->errorString();
showIfErrorMsg();
}

View file

@ -5,6 +5,7 @@
#include <QSslSocket>
#include <QThread>
#include <QEventLoop>
#include <QMessageBox>
#include <iostream>
#include <string>
@ -16,14 +17,15 @@ class jceSSLClient : QSslSocket
public:
jceSSLClient();
bool makeConnect(std::string server,int port);
bool makeConnect(QString server, int port);
bool isConnected();
bool sendData(std::string str);
bool recieveData(std::string &str, bool fast);
bool sendData(QString str);
bool recieveData(QString &str, bool fast);
bool makeDiconnect();
void showIfErrorMsg();
private slots:
void checkErrors(QAbstractSocket::SocketError);
void checkErrors(QAbstractSocket::SocketError a);
void setConnected();
void setEncrypted();
void setDisconnected();
@ -33,6 +35,7 @@ private:
bool flag;
QString packet;
QEventLoop loop; //handle the connection as thread
};

View file

@ -36,10 +36,10 @@ bool CSV_Exporter::exportCalendar(calendarSchedule *calSched, CalendarDialog *ca
int startM = coursePtr->getMinutesBegin();
int endH = coursePtr->getHourEnd();
int endM = coursePtr->getMinutesEnd();
QString lecturer = QString(coursePtr->getLecturer().c_str()); //WHY YOU USED STD STRING?!
QString type = QString(coursePtr->getType().c_str());
QString name = QString(coursePtr->getName().c_str());
QString room = QString(coursePtr->getRoom().c_str());
QString lecturer = coursePtr->getLecturer();
QString type = coursePtr->getType();
QString name = coursePtr->getName();
QString room = coursePtr->getRoom();
QDate currentDate = cal->getStartDate();

View file

@ -1,8 +1,8 @@
#include "calendarCourse.h"
calendarCourse::calendarCourse(int serial, std::string name, std::string type, std::string lecturer, double points,
double semesterHours, std::string dayAndHour,
std::string room) : Course(serial,name, type,points)
calendarCourse::calendarCourse(int serial, QString name, QString type, QString lecturer, double points,
double semesterHours, QString dayAndHour,
QString room) : Course(serial,name, type,points)
{
this->lecturer = lecturer;
this->semesterHours = semesterHours;
@ -10,13 +10,13 @@ calendarCourse::calendarCourse(int serial, std::string name, std::string type, s
setDayAndHour(dayAndHour);
}
void calendarCourse::setDayAndHour(std::string phrase)
void calendarCourse::setDayAndHour(QString phrase)
{
int ctr = 0;
std::string temp = "";
QString temp = "";
QTime timetemp;
char *tok;
char* textToTok = strdup(phrase.c_str());
char* textToTok = strdup(phrase.toStdString().c_str());
tok = strtok(textToTok, " -");
while(tok != NULL)
{
@ -27,12 +27,12 @@ void calendarCourse::setDayAndHour(std::string phrase)
setDay(temp);
break;
case 1:
timetemp = QTime::fromString(QString::fromStdString(temp),"hh:mm");
timetemp = QTime::fromString(temp,"hh:mm");
setHourBegin(timetemp.hour());
setMinutesBegin(timetemp.minute());
break;
case 2:
timetemp = QTime::fromString(QString::fromStdString(temp),"hh:mm");
timetemp = QTime::fromString(temp,"hh:mm");
setHourEnd(timetemp.hour());
setMinutesEnd(timetemp.minute());
break;
@ -43,12 +43,12 @@ void calendarCourse::setDayAndHour(std::string phrase)
}
}
std::string calendarCourse::getLecturer() const
QString calendarCourse::getLecturer() const
{
return lecturer;
}
void calendarCourse::setLecturer(const std::string &value)
void calendarCourse::setLecturer(const QString &value)
{
lecturer = value;
}
@ -98,17 +98,17 @@ void calendarCourse::setMinutesEnd(int value)
minutesEnd = value;
}
std::string calendarCourse::courseToString()
QString calendarCourse::courseToString()
{
std::string courseText = "";
courseText += " " + std::to_string(this->getSerialNum());
QString courseText = "";
courseText += " " + QString::number(this->getSerialNum());
courseText += " " + this->getName();
courseText += " " + this->getType();
courseText += " " + this->lecturer;
courseText += " " + std::to_string(this->getPoints());
courseText += " " + std::to_string(this->semesterHours);
courseText += " " + std::to_string(this->day);
courseText += " " + std::to_string(this->hourBegin) + ":" + std::to_string(this->minutesBegin) + "-" + std::to_string(this->hourEnd) + ":" + std::to_string(this->minutesEnd);
courseText += " " + QString::number(this->getPoints());
courseText += " " + QString::number(this->semesterHours);
courseText += " " + QString::number(this->day);
courseText += " " + QString::number(this->hourBegin) + ":" + QString::number(this->minutesBegin) + "-" + QString::number(this->hourEnd) + ":" + QString::number(this->minutesEnd);
courseText += " " + this->room;
courseText += "\n";
return courseText;
@ -119,9 +119,9 @@ int calendarCourse::getDay() const
return day;
}
void calendarCourse::setDay(const std::string &value)
void calendarCourse::setDay(const QString &value)
{
std::string dayTemp = value.substr(0,2);
std::string dayTemp = value.toStdString().substr(0,2); //recieving two characters respresting days
if (dayTemp.compare("\u05D0") == 0) //alef
day = 1;
else if (dayTemp.compare("\u05D1") == 0) //bet
@ -138,12 +138,12 @@ void calendarCourse::setDay(const std::string &value)
day= -1;
}
std::string calendarCourse::getRoom() const
QString calendarCourse::getRoom() const
{
return room;
}
void calendarCourse::setRoom(const std::string &value)
void calendarCourse::setRoom(const QString &value)
{
room = value;
}

View file

@ -24,43 +24,43 @@ public:
DAY_AND_HOURS,
ROOM
};
calendarCourse(int serial, std::string name, std::string type, std::string lecturer,
double points, double semesterHours, std::string dayAndHour, std::string room);
calendarCourse(int serial, QString name, QString type, QString lecturer,
double points, double semesterHours, QString dayAndHour, QString room);
~calendarCourse(){}
int getDay() const;
std::string getLecturer() const;
std::string getRoom() const;
QString getLecturer() const;
QString getRoom() const;
double getSemesterHours() const;
int getHourBegin() const;
int getMinutesBegin() const;
int getHourEnd() const;
int getMinutesEnd() const;
void setDay(const std::string &value);
void setLecturer(const std::string &value);
void setRoom(const std::string &value);
void setDay(const QString &value);
void setLecturer(const QString &value);
void setRoom(const QString &value);
void setSemesterHours(double value);
void setHourBegin(int value);
void setMinutesBegin(int value);
void setHourEnd(int value);
void setMinutesEnd(int value);
std::string courseToString();
QString courseToString();
private:
void setDayAndHour(std::string phrase);
void setDayAndHour(QString phrase);
std::string lecturer;
QString lecturer;
double semesterHours;
int day;
int hourBegin;
int minutesBegin;
int hourEnd;
int minutesEnd;
std::string room;
QString room;
};

View file

@ -1,11 +1,11 @@
#include "calendarPage.h"
std::string CalendarPage::htmlToString()
QString CalendarPage::htmlToString()
{
return tempHtml;
}
void CalendarPage::setPage(std::string html)
void CalendarPage::setPage(QString html)
{
courses = new std::list<calendarCourse*>();
@ -15,12 +15,12 @@ void CalendarPage::setPage(std::string html)
}
std::string CalendarPage::tokenToLines(std::string &textToPhrase)
QString CalendarPage::tokenToLines(QString &textToParse)
{
int ctr = 0;
std::string temp = "";
QString temp = "";
char *tok;
char* textToTok = strdup(textToPhrase.c_str());
char* textToTok = strdup(textToParse.toStdString().c_str());
tok = strtok(textToTok, "\n");
while(tok != NULL)
{
@ -36,13 +36,13 @@ std::string CalendarPage::tokenToLines(std::string &textToPhrase)
return temp;
}
void CalendarPage::calendarListInit(std::string &linesTokinzedString)
void CalendarPage::calendarListInit(QString &linesTokinzedString)
{
std::list<std::string> stringHolder;
std::string temp;
std::list<QString> stringHolder;
QString temp;
calendarCourse * cTemp = NULL;
char* tok;
char* textToTok = strdup(linesTokinzedString.c_str());
char* textToTok = strdup(linesTokinzedString.toStdString().c_str());
tok = strtok(textToTok,"\n");
while (tok != NULL)
{
@ -50,7 +50,7 @@ void CalendarPage::calendarListInit(std::string &linesTokinzedString)
stringHolder.push_back(temp);
tok = strtok(NULL, "\n");
}
for(std::string temp: stringHolder)
for (QString temp: stringHolder)
{
cTemp = lineToCourse(temp);
if (cTemp != NULL)
@ -58,24 +58,23 @@ void CalendarPage::calendarListInit(std::string &linesTokinzedString)
}
}
calendarCourse *CalendarPage::lineToCourse(std::string line)
calendarCourse *CalendarPage::lineToCourse(QString line)
{
calendarCourse *tempC = NULL;
std::string templinearray[CALENDAR_COURSE_FIELDS];//[serial,name,type,lecturer,points,semesterhours,dayandhours,room]
QString templinearray[CALENDAR_COURSE_FIELDS];//[serial,name,type,lecturer,points,semesterhours,dayandhours,room]
int serial;
double points,semesterHours;
std::string name,type, lecturer,dayAndHour,room;
std::string tempS = "";
std::string emptyTab = " ";
QString name,type, lecturer,dayAndHour,room;
QString tempS = "";
int i = 0;
char* tok;
char* cLine = strdup(line.c_str());
char* cLine = strdup(line.toStdString().c_str());
tok = strtok(cLine, "\t");
while(tok != NULL)
{
tempS = tok;
tempS = QString(tok);
if (i>=1)
templinearray[i-1] = tempS;
i++;
@ -83,19 +82,19 @@ calendarCourse *CalendarPage::lineToCourse(std::string line)
break;
tok=strtok(NULL, "\t");
}
if (templinearray[0] == "") //empty phrasing
if (templinearray[0] == "") //empty parsing
return NULL;
serial = stoi(templinearray[calendarCourse::CourseScheme::SERIAL]);
serial = templinearray[calendarCourse::CourseScheme::SERIAL].toInt();
name = templinearray[calendarCourse::CourseScheme::NAME];
type = templinearray[calendarCourse::CourseScheme::TYPE];
lecturer = templinearray[calendarCourse::CourseScheme::LECTURER];
if (templinearray[calendarCourse::CourseScheme::POINTS].compare(" ") == 0)
points = stod(templinearray[calendarCourse::CourseScheme::POINTS]);
points = templinearray[calendarCourse::CourseScheme::POINTS].toDouble();
else
points = 0;
if (templinearray[calendarCourse::CourseScheme::SEM_HOURS].compare(" ") == 0)
semesterHours = stod(templinearray[calendarCourse::CourseScheme::SEM_HOURS]);
semesterHours = templinearray[calendarCourse::CourseScheme::SEM_HOURS].toDouble();
else
semesterHours = 0;
dayAndHour = templinearray[calendarCourse::CourseScheme::DAY_AND_HOURS];

View file

@ -4,28 +4,28 @@
#include "../page.h"
#include "calendarCourse.h"
#include <list>
#include <string.h> //strlen and strtok to phrase the html file
#include <ctype.h> //checks if character is numeric
//#include <string.h> //strlen and strtok to phrase the html file
//#include <ctype.h> //checks if character is numeric
class CalendarPage : public Page
{
public:
std::string htmlToString();
QString htmlToString();
std::list<calendarCourse*>* getCourses() { return courses; }
protected:
virtual void setPage(std::string html);
CalendarPage() { }
virtual void setPage(QString html);
CalendarPage() { }
private:
std::string tokenToLines(std::string& textToPhrase);
void calendarListInit(std::string& linesTokinzedString);
calendarCourse* lineToCourse(std::string line);
QString tokenToLines(QString &textToParse);
void calendarListInit(QString &linesTokinzedString);
calendarCourse* lineToCourse(QString line);
std::string tempHtml;
QString tempHtml;
std::list<calendarCourse*>* courses;

View file

@ -34,7 +34,7 @@ calendarSchedule::calendarSchedule()
}
void calendarSchedule::setPage(std::string html)
void calendarSchedule::setPage(QString html)
{
CalendarPage::setPage(html);
@ -69,7 +69,7 @@ void calendarSchedule::insertCourseIntoTable()
{
row = currentHour % HOURS_BEGIN;
col = currentDay-1;
courseString = (QString::fromStdString(coursePtr->getName() + " \n" + coursePtr->getLecturer() + " \n" + coursePtr->getRoom()));
courseString = (QString(coursePtr->getName() + " \n" + coursePtr->getLecturer() + " \n" + coursePtr->getRoom()));
item = new QTableWidgetItem(courseString);
if (this->takeItem(row,col) != NULL)
delete this->takeItem(row,col);

View file

@ -19,7 +19,7 @@ class calendarSchedule : public QTableWidget, public CalendarPage
public:
calendarSchedule();
~calendarSchedule() { clearTableItems(); }
void setPage(std::string html);
void setPage(QString html);
void clearTableItems();
signals:

View file

@ -1,6 +1,6 @@
#include "gradeCourse.h"
gradeCourse::gradeCourse(int serial,std::string name, std::string type, double points, double hours, double grade, std::string additions) : Course(serial,name,type,points)
gradeCourse::gradeCourse(int serial, QString name, QString type, double points, double hours, double grade, QString additions) : Course(serial,name,type,points)
{
this->hours = hours;
this->grade = grade;
@ -30,7 +30,7 @@ void gradeCourse::setGrade(double grade)
this->grade = grade;
}
void gradeCourse::setAdditions(std::string additions)
void gradeCourse::setAdditions(QString additions)
{
this->additions = additions;
}

View file

@ -30,22 +30,22 @@ public:
ADDITION
};
gradeCourse(int serial, std::string name, std::string type, double points,double hours, double grade, std::string additions);
gradeCourse(int serial, QString name, QString type, double points,double hours, double grade, QString additions);
~gradeCourse();
double getHours() const {return this->hours;}
double getGrade() const ;
std::string getAddidtions() const {return this->additions;}
QString getAddidtions() const {return this->additions;}
void setHours(double hours);
void setGrade(double grade);
void setAdditions(std::string additions);
void setAdditions(QString additions);
private:
double hours;
double grade;
std::string additions;
QString additions;
};

View file

@ -1,11 +1,11 @@
#include "gradePage.h"
GradePage::GradePage(std::string html) : Page()
GradePage::GradePage(QString html) : Page()
{
this->courses = new std::list<gradeCourse*>();
this->tempHtml = getString(html);
this->tempHtml = tokenToLines(this->tempHtml);
coursesListInit(this->tempHtml);
courses = new std::list<gradeCourse*>();
tempHtml = getString(html);
tempHtml = tokenToLines(tempHtml);
coursesListInit(tempHtml);
}
GradePage::~GradePage()
@ -15,17 +15,11 @@ GradePage::~GradePage()
delete courses;
}
void GradePage::addCourse(gradeCourse *a)
{
GradePage::courses->push_back(a);
return;
}
void GradePage::removeCourse(std::string courseSerialID)
void GradePage::removeCourse(QString courseSerialID)
{
for(gradeCourse* c : *courses)
{
if (c->getSerialNum() == stoi(courseSerialID))
if (c->getSerialNum() == courseSerialID.toInt())
{
courses->remove(c);
delete c;
@ -34,13 +28,13 @@ void GradePage::removeCourse(std::string courseSerialID)
}
}
void GradePage::coursesListInit(std::string& linesTokinzedString)
void GradePage::coursesListInit(QString &linesTokinzedString)
{
std::list<std::string> stringHolder;
std::string temp;
std::list<QString> stringHolder;
QString temp;
gradeCourse* cTemp = NULL;
char* tok;
char* textToTok = strdup(linesTokinzedString.c_str());
char* textToTok = strdup(linesTokinzedString.toStdString().c_str());
tok = strtok(textToTok,"\n");
while (tok != NULL)
{
@ -48,20 +42,20 @@ void GradePage::coursesListInit(std::string& linesTokinzedString)
stringHolder.push_back(temp);
tok = strtok(NULL, "\n");
}
for(std::string temp: stringHolder)
for(QString temp: stringHolder)
{
cTemp = lineToCourse(temp);
if (cTemp != NULL)
addCourse(cTemp);
courses->push_back(cTemp);
}
}
std::string GradePage::tokenToLines(std::string& textToPhrase)
QString GradePage::tokenToLines(QString &textToPhrase)
{
int ctr = 0;
std::string temp = "";
QString temp = "";
char *tok;
char* textToTok = strdup(textToPhrase.c_str());
char* textToTok = strdup(textToPhrase.toStdString().c_str());
tok = strtok(textToTok, "\n");
while(tok != NULL)
{
@ -77,17 +71,17 @@ std::string GradePage::tokenToLines(std::string& textToPhrase)
return temp;
}
gradeCourse* GradePage::lineToCourse(std::string line)
gradeCourse* GradePage::lineToCourse(QString line)
{
gradeCourse *tempC = NULL;
std::string templinearray[COURSE_FIELDS];//[serial,name,type,points,hours,grade,additions]
QString templinearray[COURSE_FIELDS];//[serial,name,type,points,hours,grade,additions]
int serial;
double points,hours,grade;
std::string name,type, additions;
std::string tempS = "";
QString name,type, additions;
QString tempS = "";
int i = 0;
char* tok;
char* cLine = strdup(line.c_str());
char* cLine = strdup(line.toStdString().c_str());
tok = strtok(cLine, "\t");
while(tok != NULL)
{
@ -98,37 +92,38 @@ gradeCourse* GradePage::lineToCourse(std::string line)
tempS = "";
char *tokTemp;
tokTemp = tok;
while (!(isdigit((int)*tokTemp)))
tokTemp++;
while (isdigit((int)*tokTemp))
{
tempS += *tokTemp;
tempS += QString(*tokTemp);
tokTemp++;
}
templinearray[i-1] = tempS;
templinearray[i] = tokTemp;
templinearray[i] = QString(tokTemp);
}
else if (i > 1)
{
templinearray[i] = tempS;
}
i++;
tok=strtok(NULL, "\t");
}
if (templinearray[0] == "") //empty phrasing
return NULL;
serial = stoi(templinearray[gradeCourse::CourseScheme::SERIAL]);
serial = templinearray[gradeCourse::CourseScheme::SERIAL].toInt();
name = templinearray[gradeCourse::CourseScheme::NAME];
type = templinearray[gradeCourse::CourseScheme::TYPE];
points = stod(templinearray[gradeCourse::CourseScheme::POINTS]);
hours = stod(templinearray[gradeCourse::CourseScheme::HOURS]);
points = templinearray[gradeCourse::CourseScheme::POINTS].toDouble();
hours = templinearray[gradeCourse::CourseScheme::HOURS].toDouble();
if (isGradedYet(templinearray[gradeCourse::CourseScheme::GRADE]))
grade = stod(templinearray[gradeCourse::CourseScheme::GRADE]);
grade = templinearray[gradeCourse::CourseScheme::GRADE].toDouble();
else
grade = NO_GRADE_YET;
@ -139,12 +134,12 @@ gradeCourse* GradePage::lineToCourse(std::string line)
}
//checking if one of the chars inside grade is not a number
bool GradePage::isGradedYet(std::string grade)
bool GradePage::isGradedYet(QString grade)
{
if (strlen(grade.c_str()) <= 1)
if (strlen(grade.toStdString().c_str()) <= 1)
return false;
for (char c: grade)
for (char c: grade.toStdString())
{
if (c == '\0')
break;

View file

@ -4,7 +4,7 @@
/* This Code Made By Sagi Dayan
* SagiDayan@gmail.com
*
* Minor changes has been made by Liran Ben Gida
* Changes has been made by Liran Ben Gida
* LiranBG@gmail.com
*/
@ -12,32 +12,29 @@
#include "../Grades/gradeCourse.h"
#include <list>
#include <string.h> //strlen and strtok to phrase the html file
#include <ctype.h> //checks if character is numeric
class GradePage : public Page
{
public:
GradePage(std::string html);
GradePage(QString html);
~GradePage();
void addCourse(gradeCourse *);
void removeCourse(std::string courseSerialID);
void removeCourse(QString courseSerialID);
double getAvg();
std::list<gradeCourse*>* getCourses() { return courses; }
private:
std::string tokenToLines(std::string& textToPhrase);
void coursesListInit(std::string& linesTokinzedString);
gradeCourse* lineToCourse(std::string line);
QString tokenToLines(QString &textToPhrase);
void coursesListInit(QString &linesTokinzedString);
gradeCourse* lineToCourse(QString line);
bool isGradedYet(std::string grade);
bool isGradedYet(QString grade);
std::list<gradeCourse*>* courses;
std::string tempHtml;
QString tempHtml;
};

View file

@ -8,8 +8,7 @@
* LiranBG@gmail.com
*/
#include <string>
#include <iostream>
#include <QString>
#include <list>
@ -17,7 +16,7 @@ class Course {
public:
Course(int serial,std::string name, std::string type, double points) {
Course(int serial,QString name, QString type, double points) {
this->serialNum = serial;
this->name = name;
this->type = type;
@ -26,20 +25,20 @@ public:
virtual ~Course() { }
int getSerialNum() const {return this->serialNum;}
virtual std::string getName() const {return this->name;}
virtual std::string getType() const {return this->type;}
virtual QString getName() const {return this->name;}
virtual QString getType() const {return this->type;}
virtual double getPoints() const {return this->points;}
virtual void setName(std::string name) { this->name = name;}
virtual void setType(std::string type){ this->type = type;}
virtual void setName(QString name) { this->name = name;}
virtual void setType(QString type){ this->type = type;}
virtual void setPoints(double points){ this->points = points;}
private:
int serialNum;
std::string name;
std::string type;
QString name;
QString type;
double points;
};

View file

@ -1,56 +1,51 @@
#include "page.h"
Page::Page()
Page::Page() {}
/**
* @brief Page::getString
* @param htmlToPhrased
* @return
*/
QString Page::getString(QString &htmlToParse)
{
}
std::string Page::getString(std::string& htmlToPhrased)
{
makeText(htmlToPhrased);
makeText(htmlToParse);
return this->text;
}
void Page::makeText(std::string& html)
void Page::makeText(QString &html)
{
int index = 0;
index = runToActualText(html, index); //set index into the actual place where the data is
index = html.indexOf("<tbody>",0); //set index into the place where the data is
manageTableContent(html, index);
qDebug() << "page after parsing " << text;
}
int Page::runToActualText(std::string& from, int index)
/**
* @brief Page::manageTableContent strip html, make it string
* @param html html to parse
* @param index index to start looking for data
*/
void Page::manageTableContent(QString &html, int index)
{
while (index < (int)from.length())
if (index == -1)
return;
QString temp;
for (int i = index; i < html.length(); i++)
{
if (from[index] == '<')
{
if (from.substr(index,7) == "<tbody>")
return index+7;
}
index++;
}
return -1;
}
void Page::manageTableContent(std::string& html, int index)
{
std::string temp;
for (int i = index; i < (int)html.length(); i++)
{
if(html[i] == '<')
if(html.at(i) == '<')
{
//<tr> / <td> / <th>
std::string endofTable = "</tbody>";
std::string tableTag = html.substr(i, 4); //legth of "tr/td"
if(tableTag == "<tr>")
QString endofTable = "</tbody>";
QString tableTag = html.mid(i, 4); //legth of "tr/td"
if (tableTag == "<tr>")
{
temp += "\n"; //new row -> new line
i = stitchText(html, temp, i+4);
if(i == -1) //EOF
break;
}
else if(tableTag == "<td>" || tableTag == "<th>")
else if (tableTag == "<td>" || tableTag == "<th>")
{
temp += "\t"; // new cell -> tab between data
if (html.substr(i, 6) == "<td><a") //link to lecturer portal, need to be deleted
if (html.mid(i, 6) == "<td><a") //link to lecturer portal, need to be deleted
{
i += 6;
while (html.at(++i) != '>');
@ -64,11 +59,11 @@ void Page::manageTableContent(std::string& html, int index)
else if(tableTag == "<td ") // a Year title (in grades table)
{
temp += "\t";
while(html[i] != '>')
while(html.at(i) != '>')
i++;
i = stitchText(html, temp, i+1);
}
else if (html.substr(i,(endofTable).length()) == endofTable) //is end of table
else if (html.mid(i,(endofTable).length()) == endofTable) //is end of table
{
break;
}
@ -79,26 +74,26 @@ void Page::manageTableContent(std::string& html, int index)
this->text = temp;
}
int Page::stitchText(std::string& from, std::string& to, int index)
int Page::stitchText(QString &from, QString &to, int index)
{
if (from[index] == '<')
if (from.at(index) == '<')
{
std::string bTag = from.substr(index, 3);
QString bTag = from.mid(index, 3);
if (bTag != "<b>")
return index-1; //go back one step - for the main function to inc i
index += 3;
}
while (from[index] != '<' && index < (int)from.length())
while (from.at(index) != '<' && index < (int)from.length())
{
if (from[index] == '&')
{
//&nbsp;
std::string nbspChr = from.substr(index, 6);
QString nbspChr = from.mid(index, 6);
if (nbspChr == "&nbsp;")
{
index += 5;
from.at(index) = ' ';
from.replace(index,1,' ');
}
}
@ -106,11 +101,11 @@ int Page::stitchText(std::string& from, std::string& to, int index)
if (endOfString(index,(int) from.length()))
return -1; //EOF
else if (from[index] == '<')
else if (from.at(index) == '<')
return index - 1; //go back one step - for the main function to inc i
if (from[index] != '\n') //check the actuall data before continue
to += from[index];
if (from.at(index) != '\n') //check the actuall data before continue
to += from.at(index);
index++;
}

View file

@ -4,35 +4,36 @@
/* This Code Made By Sagi Dayan
* SagiDayan@gmail.com
*
* Minor changes has been made by Liran Ben Gida
* Changes has been made by Liran Ben Gida
* LiranBG@gmail.com
*/
#include <QDebug>
#include <QString>
#include <iostream>
#include <string>
/**
* @brief The Page class
* parsing given page - strip and clean html tags
* use only with JCE
*/
class Page
{
public:
~Page() {}
protected:
Page();
std::string getString(std::string& htmlToPhrased);
void makeText(std::string& html);
QString getString(QString &htmlToParse);
void makeText(QString &html);
private:
int runToActualText(std::string& from, int index);
void manageTableContent(std::string& html, int index);
int stitchText(std::string& from, std::string& to, int index);
void manageTableContent(QString &html, int index);
int stitchText(QString &from, QString &to, int index);
bool endOfString(int index, int length);
std::string text;
std::string title;
QString text;
QString title;
};

View file

@ -1,12 +1,16 @@
#ifndef JCELOGINHTMLSCRIPTS_H
#define JCELOGINHTMLSCRIPTS_H
#include <string>
#include "./src/jceSettings/user.h"
#define dst_host "yedion.jce.ac.il"
#define dst_port 443
#include "./src/jceSettings/user.h"
/**
* @brief The jceLoginHtmlScripts class
* this class gets parameters and making the httml request string to be sent
* the headers of the http request were written according to JCE's student portal login page
*/
class jceLoginHtmlScripts
{
@ -17,13 +21,13 @@ private:
public:
static std::string makeRequest(std::string parameters)
static QString makeRequest(QString parameters)
{
std::string msg;
QString msg;
msg = "POST /yedion/fireflyweb.aspx HTTP/1.1\r\n";
msg += "Host: " + std::string(dst_host) + "\r\n";
msg += "Host: " + QString(dst_host) + "\r\n";
msg += "Content-Type: application/x-www-form-urlencoded\r\n";
msg += "Content-Length: " + to_string(parameters.length()) + "\r\n";
msg += "Content-Length: " + QString::number(parameters.length()) + "\r\n";
msg += "Proxy-Connection: Keep-Alive\r\n";
msg += "Accept-Charset: UTF-8";
msg += "Accept: text/plain\r\n";
@ -33,18 +37,18 @@ public:
return msg;
}
const static std::string getFirstValidationStep(const user &usr)
const static QString getFirstValidationStep(const user &usr)
{
std::string parameters = "?appname=BSHITA&prgname=LoginValidation&arguments=-N";
QString parameters = "?appname=BSHITA&prgname=LoginValidation&arguments=-N";
parameters += usr.getUsername();
parameters += ",-N";
parameters += usr.getPassword();
return parameters;
}
const static std::string getSecondValidationStep(const user &usr)
const static QString getSecondValidationStep(const user &usr)
{
std::string parameters;
QString parameters;
parameters = "prgname=LoginValidtion1&Arguments=-N";
parameters += usr.getUserID();
parameters += ",-A,-N";
@ -52,32 +56,32 @@ public:
parameters += ",-A,-A";
return parameters;
}
const static std::string getGradesPath(const user &usr,
const static QString getGradesPath(const user &usr,
int fromYear,
int toYear,
int fromSemester,
int toSemester)
{
std::string parameters;
QString parameters;
parameters = "PRGNAME=HADPASAT_MISMAHIM_LETALMID&ARGUMENTS=TZ,-N4,R1C2,R1C4,R1C1,R1C3,-A,-A,R1C5,-A,UNIQ&";
parameters += "TZ=" + usr.getUserID() + "&";
parameters += "UNIQ=" + usr.getHashedPassword() + "&";
parameters += "R1C2=" + std::to_string(fromYear) + "&";
parameters += "R1C1=" + std::to_string(toYear) + "&";
parameters += "R1C3=" + std::to_string(toSemester) + "&";
parameters += "R1C4=" + std::to_string(fromSemester) + "&";
parameters += "R1C2=" + QString::number(fromYear) + "&";
parameters += "R1C1=" + QString::number(toYear) + "&";
parameters += "R1C3=" + QString::number(toSemester) + "&";
parameters += "R1C4=" + QString::number(fromSemester) + "&";
parameters += "R1C5=0";
return parameters;
}
const static std::string getCalendar(const user &usr,int year, int semester)
const static QString getCalendar(const user &usr,int year, int semester)
{
std::string parameters;
QString parameters;
parameters = "PRGNAME=Bitsua_maarechet_shaot&ARGUMENTS=TZ,UNIQ,MisparSheilta,R1C1,R1C2&";
parameters += "TZ=" + usr.getUserID() + "&";
parameters += "UNIQ=" + usr.getHashedPassword() + "&";
parameters += "MisparSheilta=3&";
parameters += "R1C1=" + std::to_string(year) + "&";
parameters += "R1C2=" + std::to_string(semester) + "&";
parameters += "R1C1=" + QString::number(year) + "&";
parameters += "R1C2=" + QString::number(semester) + "&";
return parameters;
}

View file

@ -1,19 +1,23 @@
#include "jcelogin.h"
/**
* @brief jceLogin::jceLogin
* @param username pointer to allocated user settings
*/
jceLogin::jceLogin(user * username)
{
this->recieverPage = new std::string();
this->jceA = username;
this->JceConnector = new jceSSLClient();
this->recieverPage = new QString();
this->jceA = username;
this->JceConnector = new jceSSLClient();
}
jceLogin::~jceLogin()
{
this->jceA = NULL;
delete recieverPage;
delete JceConnector;
JceConnector = NULL;
recieverPage = NULL;
this->jceA = NULL;
delete recieverPage;
delete JceConnector;
JceConnector = NULL;
recieverPage = NULL;
}
/**
* @brief jceLogin::makeConnection Connecting to JCE student web site with JceA (username object) and validate it.
@ -21,212 +25,266 @@ jceLogin::~jceLogin()
*/
void jceLogin::makeConnection() throw (jceStatus)
{
if (this->recieverPage == NULL)
this->recieverPage = new std::string();
qDebug() << "jceLogin::makeConnection(); connection to be make";
if (JceConnector->makeConnect(dst_host,dst_port) == false)
throw jceStatus::ERROR_ON_OPEN_SOCKET;
if (this->recieverPage == NULL)
this->recieverPage = new QString();
int returnMode;
jceStatus status = jceStatus::JCE_NOT_CONNECTED;
if (JceConnector->makeConnect(dst_host,dst_port) == false) //couldnt make a connection
throw jceStatus::ERROR_ON_OPEN_SOCKET;
returnMode = checkConnection();
if (returnMode == true) //connected to host
int returnMode; //gets status according to called function of validation step
jceStatus status = jceStatus::JCE_NOT_CONNECTED;
returnMode = checkConnection(); //checking socket status. is connected?
if (returnMode == true) //connected to host
{
returnMode = makeFirstVisit();
if (returnMode == true) //requst and send first validation
returnMode = makeFirstVisit();
if (returnMode == true) //requst and send first validation
{
status = jceStatus::JCE_START_VALIDATING_PROGRESS;
returnMode = checkValidation();
if (returnMode == true) //check if username and password are matching
status = jceStatus::JCE_START_VALIDATING_PROGRESS;
returnMode = checkValidation();
if (returnMode == true) //check if username and password are matching
{
status = jceStatus::JCE_VALIDATION_PASSED;
returnMode = makeSecondVisit();
if (returnMode == true) //siging in the website
status = jceStatus::JCE_VALIDATION_PASSED;
returnMode = makeSecondVisit();
if (returnMode == true) //siging in the website
{
status = jceStatus::JCE_YOU_ARE_IN;
setLoginFlag(true);
qDebug() << "jceLogin::makeConnection(); Signed in succeesfully";
status = jceStatus::JCE_YOU_ARE_IN;
setLoginFlag(true);
}
else if (returnMode == jceLogin::ERROR_ON_GETTING_INFO)
else if (returnMode == jceLogin::ERROR_ON_GETTING_INFO)
{
status = jceLogin::ERROR_ON_GETTING_INFO;
status = jceLogin::ERROR_ON_GETTING_INFO;
}
else if (returnMode == jceLogin::ERROR_ON_SEND_REQUEST)
else if (returnMode == jceLogin::ERROR_ON_SEND_REQUEST)
{
status = jceLogin::ERROR_ON_SEND_REQUEST;
status = jceLogin::ERROR_ON_SEND_REQUEST;
}
else
status = jceStatus::ERROR_ON_VALIDATION;
}
else
else
status = jceStatus::ERROR_ON_VALIDATION;
}
else
status = jceStatus::ERROR_ON_VALIDATION;
}
else if (returnMode == jceLogin::ERROR_ON_GETTING_INFO)
else if (returnMode == jceLogin::ERROR_ON_GETTING_INFO)
{
status = jceLogin::ERROR_ON_GETTING_INFO;
status = jceLogin::ERROR_ON_GETTING_INFO;
}
else if (returnMode == jceLogin::ERROR_ON_SEND_REQUEST)
else if (returnMode == jceLogin::ERROR_ON_SEND_REQUEST)
{
status = jceLogin::ERROR_ON_SEND_REQUEST;
status = jceLogin::ERROR_ON_SEND_REQUEST;
}
else
status = jceStatus::ERROR_ON_VALIDATION_USER_BLOCKED;
else
status = jceStatus::ERROR_ON_VALIDATION_USER_BLOCKED;
}
else
status = jceStatus::JCE_NOT_CONNECTED;
else
status = jceStatus::JCE_NOT_CONNECTED;
//we throw status even if we are IN!
throw status;
//we throw status even if we are IN!
qDebug() << "jceLogin::makeConnection(); throw status: " << status;
throw status;
}
/**
* @brief jceLogin::checkConnection
* @return if connected true, otherwise false
*/
bool jceLogin::checkConnection() const
{
if (JceConnector->isConnected())
return true;
if (JceConnector->isConnected())
return true;
return false;
return false;
}
/**
* @brief jceLogin::reConnect
* closing connection and deleting pointers.
* calling class's makeConnection function and throw the exception of it.
*/
void jceLogin::reConnect() throw (jceStatus)
{
closeAll();
if (this->JceConnector != NULL)
delete JceConnector;
this->recieverPage = new std::string();
this->JceConnector = new jceSSLClient();
try
{
closeAll();
if (this->JceConnector != NULL)
delete JceConnector;
this->recieverPage = new QString();
this->JceConnector = new jceSSLClient();
makeConnection();
}
catch (jceLogin::jceStatus &a)
{
throw a;
}
try
{
makeConnection();
}
catch (jceLogin::jceStatus &a)
{
throw a;
}
}
/**
* @brief jceLogin::closeAll
*/
void jceLogin::closeAll()
{
JceConnector->makeDiconnect();
delete recieverPage;
recieverPage = NULL;
loginFlag = false;
JceConnector->makeDiconnect();
delete recieverPage;
recieverPage = NULL;
}
/**
* @brief jceLogin::makeFirstVisit making the first validation step of jce student portal login
* @return jceLogin enum list on error, true if valid
*/
int jceLogin::makeFirstVisit()
{
std::string usr = jceA->getUsername();
std::string psw = jceA->getPassword();
if (JceConnector->sendData(jceLoginHtmlScripts::makeRequest(jceLoginHtmlScripts::getFirstValidationStep(*jceA))))
QString usr = jceA->getUsername();
QString psw = jceA->getPassword();
if (JceConnector->sendData(jceLoginHtmlScripts::makeRequest(jceLoginHtmlScripts::getFirstValidationStep(*jceA))))
{
if (!JceConnector->recieveData(*recieverPage,true))
return jceLogin::ERROR_ON_GETTING_INFO;
if (!JceConnector->recieveData(*recieverPage,true))
return jceLogin::ERROR_ON_GETTING_INFO;
}
else
return jceLogin::ERROR_ON_SEND_REQUEST;
else
return jceLogin::ERROR_ON_SEND_REQUEST;
return true;
return true;
}
/**
* @brief jceLogin::makeSecondVisit making the second validation step of jce student portal login
* @return jceLogin enum list on error, true if valid
*/
int jceLogin::makeSecondVisit()
{
std::string usrid=jceA->getUserID();
std::string pswid=jceA->getHashedPassword();
if ((JceConnector->sendData(jceLoginHtmlScripts::makeRequest(jceLoginHtmlScripts::getSecondValidationStep(*jceA)))))
QString usrid=jceA->getUserID();
QString pswid=jceA->getHashedPassword();
if ((JceConnector->sendData(jceLoginHtmlScripts::makeRequest(jceLoginHtmlScripts::getSecondValidationStep(*jceA)))))
{
if (!(JceConnector->recieveData(*recieverPage,true)))
return jceLogin::ERROR_ON_GETTING_INFO;
if (!(JceConnector->recieveData(*recieverPage,true)))
return jceLogin::ERROR_ON_GETTING_INFO;
return true;
return true;
}
else
return jceLogin::ERROR_ON_SEND_REQUEST;
else
return jceLogin::ERROR_ON_SEND_REQUEST;
return true;
return true;
}
/**
* @brief jceLogin::getCalendar according to parameters, we make an HTML request and send it over socket to server
* @param year - selected year
* @param semester - selected semester
* @return true if ok, jceLogin enum on error (recieverPage has html to parse if true)
*/
int jceLogin::getCalendar(int year, int semester)
{
if ((JceConnector->sendData(jceLoginHtmlScripts::makeRequest(jceLoginHtmlScripts::getCalendar(*jceA,year,semester)))))
if ((JceConnector->sendData(jceLoginHtmlScripts::makeRequest(jceLoginHtmlScripts::getCalendar(*jceA,year,semester)))))
{
if (!(JceConnector->recieveData(*recieverPage,false)))
return jceLogin::ERROR_ON_GETTING_GRADES;
else
return jceLogin::JCE_GRADE_PAGE_PASSED;
if (!(JceConnector->recieveData(*recieverPage,false)))
return jceLogin::ERROR_ON_GETTING_GRADES;
else
return jceLogin::JCE_GRADE_PAGE_PASSED;
}
else
return jceLogin::ERROR_ON_SEND_REQUEST;
else
return jceLogin::ERROR_ON_SEND_REQUEST;
return true;
return true;
}
/**
* @brief jceLogin::getGrades according to parameters, we make an HTML request and send it over socket to server
* @param fromYear - from year
* @param toYear - to year
* @param fromSemester - from semester
* @param toSemester - to semester
* @return true if ok, jceLogin enum on error (recieverPage has html to parse if true)
*/
int jceLogin::getGrades(int fromYear, int toYear, int fromSemester, int toSemester)
{
std::cout << fromYear << " " << toYear << " " << fromSemester << " " << toSemester << std::endl;
if ((JceConnector->sendData(jceLoginHtmlScripts::makeRequest(jceLoginHtmlScripts::getGradesPath(*jceA,fromYear, toYear, fromSemester, toSemester)))))
std::cout << fromYear << " " << toYear << " " << fromSemester << " " << toSemester << std::endl;
if ((JceConnector->sendData(jceLoginHtmlScripts::makeRequest(jceLoginHtmlScripts::getGradesPath(*jceA,fromYear, toYear, fromSemester, toSemester)))))
{
if (!(JceConnector->recieveData(*recieverPage,false)))
return jceLogin::ERROR_ON_GETTING_GRADES;
else
return jceLogin::JCE_GRADE_PAGE_PASSED;
if (!(JceConnector->recieveData(*recieverPage,false)))
return jceLogin::ERROR_ON_GETTING_GRADES;
else
return jceLogin::JCE_GRADE_PAGE_PASSED;
}
else
return jceLogin::ERROR_ON_SEND_REQUEST;
else
return jceLogin::ERROR_ON_SEND_REQUEST;
return true;
return true;
}
void jceLogin::setLoginFlag(bool x)
{
this->loginFlag = x;
}
bool jceLogin::isLoginFlag() const
{
if (checkConnection())
return this->loginFlag;
return false;
}
std::string jceLogin::getPage()
{
return *recieverPage;
}
/**
* @brief jceLogin::checkValidation Made by Nadav Luzzato
* @return true if second validation step is right
*/
bool jceLogin::checkValidation()
{
//finds the hashed password
std::size_t hasspass_position1,hasspass_position2;
if ((hasspass_position1 = recieverPage->find("-A,-N")) == string::npos)
return false;
hasspass_position1 += 5;
if ((hasspass_position2 = recieverPage->find(",-A,-A", hasspass_position1)) == string::npos)
return false;
//finds the hashed password
QString constUserID_TAG = "value=\"-N";
QString constHassID_TAG = "-A,-N";
QString hasspass,hassid;
std::size_t hasspass_position1,hasspass_position2;
std::size_t id_position1,id_position2;
std::string hasspass = recieverPage->substr(hasspass_position1,hasspass_position2-hasspass_position1);
jceA->setHashedPassword(hasspass);
hasspass_position1 = this->recieverPage->toStdString().find(constHassID_TAG.toStdString()); //looking for hasspass index
if (hasspass_position1 == std::string::npos) //didnt find the tag
return false;
else
hasspass_position1 += constHassID_TAG.length(); //skip the index of tag
hasspass_position2 = this->recieverPage->toStdString().find(",-A,-A", hasspass_position1);
//finds the hass pass
if (hasspass_position2 != std::string::npos) //found the hasspass! storing it
hasspass = recieverPage->mid(hasspass_position1,hasspass_position2-hasspass_position1);
else
return false;
//finds the user id
id_position1 = this->recieverPage->toStdString().find(constUserID_TAG.toStdString(), 0); //looking for hassid index
if (id_position1 == std::string::npos) //didnt find the tag
return false;
else
id_position1 += constUserID_TAG.length(); //skip the index of tag
id_position2 = this->recieverPage->toStdString().find(",-A", id_position1);
if (id_position2 != std::string::npos) //found the hassid! storing it
hassid = recieverPage->mid(id_position1,id_position2-id_position1);
else
return false;
//finds the user id
std::size_t id_position1 = recieverPage->find("value=\"-N", 0);
id_position1 += 9;
std::size_t id_position2 = recieverPage->find(",-A", id_position1);
if ((id_position2 != std::string::npos) && (id_position1 != std::string::npos))
{
std::string hassid = recieverPage->substr(id_position1,id_position2-id_position1);
jceA->setUserID(hassid);
}
if (((jceA->getUserID()).empty()) || ((jceA->getHashedPassword()).empty()))
return false;
//setting user information with given data hassid and hasspass
jceA->setHashedPassword(hasspass);
jceA->setUserID(hassid);
return true;
qDebug() << "jceLogin::checkValidation(); Found Hashed: " << hasspass << "And ID: " << hassid;
return true;
}
/**
* @brief jceLogin::setLoginFlag
* @param x
*/
void jceLogin::setLoginFlag(bool x)
{
this->loginFlag = x;
}
/**
* @brief jceLogin::isLoginFlag checking if there is a connection, if true - > return if we signed in. otherwise, return not (not connected dough)
* @return
*/
bool jceLogin::isLoginFlag() const
{
if (checkConnection())
return this->loginFlag;
return false;
}
/**
* @brief jceLogin::getPage
* @return html page
*/
QString jceLogin::getPage()
{
return *recieverPage;
}

View file

@ -1,13 +1,12 @@
#ifndef JCELOGIN_H
#define JCELOGIN_H
#include <string>
#include <fstream>
#include "./src/jceConnection/jcesslclient.h"
#include "./src/jceSettings/user.h"
#include "jceLoginHtmlScripts.h"
#include <QString>
class jceLogin
{
public:
@ -29,28 +28,28 @@ public:
jceLogin(user* username);
~jceLogin();
void makeConnection() throw (jceStatus);
bool checkConnection() const;
void reConnect() throw (jceStatus);
void closeAll();
int getCalendar(int year, int semester);
int getGrades(int fromYear, int toYear, int fromSemester, int toSemester);
bool checkConnection() const;
bool isLoginFlag() const;
std::string getPage();
int getCalendar(int year, int semester);
int getGrades(int fromYear, int toYear, int fromSemester, int toSemester);
QString getPage();
private:
int makeFirstVisit();
bool checkValidation();
int makeSecondVisit();
bool checkValidation();
void setLoginFlag(bool x);
bool loginFlag;
std::string * recieverPage;
QString * recieverPage;
user * jceA;
jceSSLClient * JceConnector;

View file

@ -1,45 +1,73 @@
#include "user.h"
user::user(string username,string password) : hashedPassword(""),userID(""), influenceCourseOnly(false)
/**
* @brief user::user Constructor
* @param username user name
* @param password password
*/
user::user(QString username,QString password) : hashedPassword(""),userID(""), influenceCourseOnly(false)
{
this->username = username;
this->password = password;
}
user::~user()
{
}
/**
* @brief user::setInfluenceCourseOnly
* @param status show only courses with influnce?
*/
void user::setInfluenceCourseOnly(bool status)
{
this->influenceCourseOnly = status;
}
/**
* @brief user::getInfluenceCourseOnly
* @return if user wants to show only influence courses
*/
bool user::getInfluenceCourseOnly() const
{
return this->influenceCourseOnly;
}
void user::setUsername(string& username) {
this->username=username;
/**
* @brief user::setUsername
* @param username given username to change to
*/
void user::setUsername(QString& username)
{
this->username = username;
}
void user::setPassword(string& password) {
this->password=password;
/**
* @brief user::setPassword
* @param password given password to change to
*/
void user::setPassword(QString& password)
{
this->password = password;
}
void user::setUserID(string& ID)
/**
* @brief user::setUserID
* @param ID given ID from html
*/
void user::setUserID(QString& ID)
{
this->userID = ID;
}
void user::setHashedPassword(string& hashpass)
/**
* @brief user::setHashedPassword
* @param hashpass given hashed password given from html
*/
void user::setHashedPassword(QString& hashpass)
{
this->hashedPassword = hashpass;
}
string user::getPassword() const { return password; }
string user::getUsername() const { return username; }
string user::getUserID() const { return userID; }
string user::getHashedPassword() const { return hashedPassword; }
/**
* @brief user::get*
* @return getters
*/
QString user::getPassword() const { return password; }
QString user::getUsername() const { return username; }
QString user::getUserID() const { return userID; }
QString user::getHashedPassword() const { return hashedPassword; }

View file

@ -1,42 +1,39 @@
#ifndef user_H
#define user_H
#include <string>
#include <iostream>
#include <QString>
using namespace std;
class user
{
public:
user(string username,string password);
user(QString username,QString password);
~user();
void setUsername(string& username);
void setPassword(string& password);
void setUsername(QString& username);
void setPassword(QString& password);
string getPassword() const;
string getUsername() const;
QString getPassword() const;
QString getUsername() const;
void setUserID(string& ID);
void setHashedPassword(string& hashpass);
void setUserID(QString& ID);
void setHashedPassword(QString& hashpass);
string getUserID() const;
string getHashedPassword() const;
QString getUserID() const;
QString getHashedPassword() const;
void setInfluenceCourseOnly(bool status);
bool getInfluenceCourseOnly() const;
private:
string username;
string password;
QString username;
QString password;
string hashedPassword;
string userID;
QString hashedPassword;
QString userID;
bool influenceCourseOnly;
};
#endif