nesca/msgcheckerthread.cpp

48 lines
1.3 KiB
C++
Raw Normal View History

2015-02-24 14:00:19 +00:00
#include "msgcheckerthread.h"
#include "externData.h"
#include "mainResources.h"
2015-03-05 14:29:05 +00:00
#include <Utils.h>
#include <Connector.h>
2015-02-24 14:00:19 +00:00
void MSGCheckerThread::doEmitionShowNewMsg(QString str)
{
emit mct->showNewMsg(str);
2015-03-06 14:32:36 +00:00
}
2015-02-24 14:00:19 +00:00
void _getNewMsg()
{
2015-03-05 14:29:05 +00:00
char request[256] = {0};
sprintf(request, "http://nesca.d3w.org/mailbox?key=%s", trcPersKey);
2015-02-24 14:00:19 +00:00
2015-03-05 14:29:05 +00:00
std::string buffer;
std::vector<std::string> headerVector {"X-Nescav3: True"};
Connector::nConnect(request, 80, &buffer, NULL, &headerVector);
char *ptr1 = NULL;
if(buffer.size() > 0)
2015-02-24 14:00:19 +00:00
{
2015-03-05 14:29:05 +00:00
if(Utils::ci_find_substr(buffer, std::string("\r\n\r\n")) != -1
2015-03-16 14:29:34 +00:00
&& Utils::ci_find_substr(buffer, std::string("404 Not Found")) == -1
&& Utils::ci_find_substr(buffer, std::string("502 Bad Gateway")) == -1
&& Utils::ci_find_substr(buffer, std::string("400 Bad Request")) == -1
2015-03-05 14:29:05 +00:00
&& Utils::ci_find_substr(buffer, std::string("\r\n\r\nEmpty")) == -1
)
{
ptr1 = strstr((char*)buffer.c_str(), "\r\n\r\n");
if(strlen(ptr1 + 4) != 0)
{
mct->doEmitionShowNewMsg(QString(ptr1 + 4));
};
}
2015-02-24 14:00:19 +00:00
};
2015-03-05 14:29:05 +00:00
}
2015-02-24 14:00:19 +00:00
void MSGCheckerThread::run()
{
for(;;)
{
2015-03-16 14:29:34 +00:00
Sleep(60000);
if(strlen(trcPersKey) != 0) _getNewMsg();
2015-02-24 14:00:19 +00:00
};
2015-03-05 14:29:05 +00:00
}