Skip to content

Commit

Permalink
zz
Browse files Browse the repository at this point in the history
  • Loading branch information
cora32 committed Dec 11, 2015
1 parent 90d94b8 commit 4cf3b15
Show file tree
Hide file tree
Showing 4 changed files with 265 additions and 42 deletions.
124 changes: 107 additions & 17 deletions Connector.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -211,6 +211,18 @@ int Connector::nConnect(const char* ip, const int port, std::string *buffer,
|| res == CURLE_SEND_ERROR
|| res == CURLE_RECV_ERROR
) {
if (gNegDebugMode)
{
stt->doEmitionDebugFoundData("NConnect failed (curl_code: " + QString::number(res) + ") [<a href=\"" + QString(ip) + ":" + QString::number(port) +
"/\"><font color=\"#0084ff\">" + QString(ip) + ":" + QString::number(port) + "</font></a>]");
}
SOCKET eNobuffSocket = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP);
shutdown(eNobuffSocket, SD_BOTH);
closesocket(eNobuffSocket);
if (ENOBUFS == eNobuffSocket || ENOMEM == eNobuffSocket) {
stt->doEmitionRedFoundData("Insufficient buffer/memory space. Sleeping for 10 sec...");
Sleep(10000);
}
return -1;
}
else {
Expand Down Expand Up @@ -259,26 +271,104 @@ int Connector::nConnect(const char* ip, const int port, std::string *buffer,
}

bool portCheck(const char * sDVRIP, int wDVRPort) {
CURL *curl = curl_easy_init();
if (curl != NULL) {
curl_easy_setopt(curl, CURLOPT_NOSIGNAL, 1L);
curl_easy_setopt(curl, CURLOPT_URL, sDVRIP);
curl_easy_setopt(curl, CURLOPT_PORT, wDVRPort);
int proxyPort = std::atoi(gProxyPort);
if (proxyPort > 0 && proxyPort < 65535) curl_easy_setopt(curl, CURLOPT_PROXYPORT, proxyPort);
curl_easy_setopt(curl, CURLOPT_PROXY, gProxyIP);
curl_easy_setopt(curl, CURLOPT_CONNECTTIMEOUT, gTimeOut);
curl_easy_setopt(curl, CURLOPT_TIMEOUT, gTimeOut);
curl_easy_setopt(curl, CURLOPT_CONNECT_ONLY, 1L);
sockaddr_in sa;
sa.sin_family = AF_INET;
sa.sin_port = htons(wDVRPort);

int res = curl_easy_perform(curl);
curl_easy_cleanup(curl);
if (res != CURLE_OK) {
return false;
hostent *host = NULL;
#if defined(WIN32)
if (inet_addr(sDVRIP) != INADDR_NONE) sa.sin_addr.S_un.S_addr = inet_addr(sDVRIP);
else if (host = gethostbyname(sDVRIP)) ((unsigned long*)&sa.sin_addr)[0] = ((unsigned long**)host->h_addr_list)[0][0];
#else
if (inet_addr(sDVRIP) != INADDR_NONE) sa.sin_addr.s_addr = inet_addr(sDVRIP);
else if (host = gethostbyname(sDVRIP)) ((unsigned long*)&sa.sin_addr)[0] = ((unsigned long**)host->h_addr_list)[0][0];
#endif
else return false;

SOCKET sock = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP);
if (sock == INVALID_SOCKET) return -1;
else if (ENOBUFS == sock || ENOMEM == sock) {
stt->doEmitionRedFoundData("Insufficient buffer/memory space. Sleeping for 10 sec...");
return -1;
}

struct linger linger = { 1, gTimeOut };
setsockopt(sock, SOL_SOCKET, SO_LINGER, (const char *)&linger, sizeof(linger));

int res = connect(sock, (sockaddr*)&sa, sizeof(sa));

shutdown(sock, SD_BOTH);
closesocket(sock);

if (res == SOCKET_ERROR) {
if (gNegDebugMode)
{
stt->doEmitionDebugFoundData("Port check failed - SOCKET_ERROR. [<a href=\"" + QString(sDVRIP) + ":" + QString::number(wDVRPort) +
"/\"><font color=\"#0084ff\">" + QString(sDVRIP) + ":" + QString::number(wDVRPort) + "</font></a>]");
}
else return true;
return false;
}
else return false;
else {
if (gNegDebugMode)
{
stt->doEmitionDebugFoundData("Port check succeeded (curl_code: " + QString::number(res) + ") [<a href=\"" + QString(sDVRIP) + ":" + QString::number(wDVRPort) +
"/\"><font color=\"#0084ff\">" + QString(sDVRIP) + ":" + QString::number(wDVRPort) + "</font></a>]");
}
return true;
}

if (gNegDebugMode)
{
stt->doEmitionDebugFoundData("Port check failed - unknown socket error. [<a href=\"" + QString(sDVRIP) + ":" + QString::number(wDVRPort) +
"/\"><font color=\"#0084ff\">" + QString(sDVRIP) + ":" + QString::number(wDVRPort) + "</font></a>]");
}
return false;

//CURL *curl = curl_easy_init();
//if (curl != NULL) {
// curl_easy_setopt(curl, CURLOPT_NOSIGNAL, 1L);
// curl_easy_setopt(curl, CURLOPT_URL, sDVRIP);
// curl_easy_setopt(curl, CURLOPT_PORT, wDVRPort);
// int proxyPort = std::atoi(gProxyPort);
// if (proxyPort > 0 && proxyPort < 65535) curl_easy_setopt(curl, CURLOPT_PROXYPORT, proxyPort);
// curl_easy_setopt(curl, CURLOPT_PROXY, gProxyIP);
// curl_easy_setopt(curl, CURLOPT_CONNECTTIMEOUT, gTimeOut);
// curl_easy_setopt(curl, CURLOPT_TIMEOUT, gTimeOut);
// //curl_easy_setopt(curl, CURLOPT_CONNECT_ONLY, 1L); //DO_NOT_USE. Windows XP - returns CURLE_OK even if port is closed.
// int res = curl_easy_perform(curl);
// curl_easy_cleanup(curl);
// if (res != CURLE_OK) {
// if (gNegDebugMode)
// {
// stt->doEmitionDebugFoundData("Port check failed (curl_code: " + QString::number(res) + ") [<a href=\"" + QString(sDVRIP) + ":" + QString::number(wDVRPort) +
// "/\"><font color=\"#0084ff\">" + QString(sDVRIP) + ":" + QString::number(wDVRPort) + "</font></a>]");
// }
// SOCKET eNobuffSocket = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP);
// shutdown(eNobuffSocket, SD_BOTH);
// closesocket(eNobuffSocket);
// if (ENOBUFS == eNobuffSocket || ENOMEM == eNobuffSocket) {
// stt->doEmitionRedFoundData("Insufficient buffer/memory space. Sleeping for 10 sec...");
// Sleep(10000);
// }
// return false;
// }
// else {
// if (gNegDebugMode)
// {
// stt->doEmitionDebugFoundData("Port check succeeded (curl_code: " + QString::number(res) + ") [<a href=\"" + QString(sDVRIP) + ":" + QString::number(wDVRPort) +
// "/\"><font color=\"#0084ff\">" + QString(sDVRIP) + ":" + QString::number(wDVRPort) + "</font></a>]");
// }
// return true;
// }
//}
//else {
// if (gNegDebugMode)
// {
// stt->doEmitionDebugFoundData("Port check failed - curl_easy_init() error. [<a href=\"" + QString(sDVRIP) + ":" + QString::number(wDVRPort) +
// "/\"><font color=\"#0084ff\">" + QString(sDVRIP) + ":" + QString::number(wDVRPort) + "</font></a>]");
// }
// return false;
//}
}
int Connector::connectToPort(char* ip, int port)
{
Expand Down
130 changes: 117 additions & 13 deletions HikvisionLogin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -80,10 +80,24 @@ bool HikVis::checkHikk(const char * sDVRIP, int port) {
if (inet_addr(sDVRIP) != INADDR_NONE) sa.sin_addr.s_addr = inet_addr(sDVRIP);
else if (host = gethostbyname(sDVRIP)) ((unsigned long*)&sa.sin_addr)[0] = ((unsigned long**)host->h_addr_list)[0][0];
#endif
else return false;
else {
if (gNegDebugMode)
{
stt->doEmitionDebugFoundData("inet_addr error - iVMS check failed [<a href=\"" + QString(sDVRIP) + ":" + QString::number(port) +
"/\"><font color=\"#0084ff\">" + QString(sDVRIP) + ":" + QString::number(port) + "</font></a>]");
}
return false;
}

SOCKET sock = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP);
if (sock == INVALID_SOCKET) return false;
if (sock == INVALID_SOCKET) {
if (gNegDebugMode)
{
stt->doEmitionDebugFoundData("Socket error - iVMS check failed [<a href=\"" + QString(sDVRIP) + ":" + QString::number(port) +
"/\"><font color=\"#0084ff\">" + QString(sDVRIP) + ":" + QString::number(port) + "</font></a>]");
}
return false;
}

struct linger linger = { 1, gTimeOut };
setsockopt(sock, SOL_SOCKET, SO_LINGER, (const char *)&linger, sizeof(linger));
Expand All @@ -104,12 +118,31 @@ bool HikVis::checkHikk(const char * sDVRIP, int port) {
shutdown(sock, SD_BOTH);
closesocket(sock);

if (buff[3] == 0x10) return true;
else return false;
if (buff[3] == 0x10) {
if (gNegDebugMode)
{
stt->doEmitionDebugFoundData("iVMS check succeeded [<a href=\"" + QString(sDVRIP) + ":" + QString::number(port) +
"/\"><font color=\"#0084ff\">" + QString(sDVRIP) + ":" + QString::number(port) + "</font></a>]");
}
return true;
}
else {
if (gNegDebugMode)
{
stt->doEmitionDebugFoundData("iVMS check failed [<a href=\"" + QString(sDVRIP) + ":" + QString::number(port) +
"/\"><font color=\"#0084ff\">" + QString(sDVRIP) + ":" + QString::number(port) + "</font></a>]");
}
return false;
}
}

shutdown(sock, SD_BOTH);
closesocket(sock);
closesocket(sock);
if (gNegDebugMode)
{
stt->doEmitionDebugFoundData("Unknown error - iVMS check failed [<a href=\"" + QString(sDVRIP) + ":" + QString::number(port) +
"/\"><font color=\"#0084ff\">" + QString(sDVRIP) + ":" + QString::number(port) + "</font></a>]");
}
return false;
}

Expand All @@ -126,10 +159,24 @@ bool HikVis::checkRVI(const char * sDVRIP, int port) {
if (inet_addr(sDVRIP) != INADDR_NONE) sa.sin_addr.s_addr = inet_addr(sDVRIP);
else if (host = gethostbyname(sDVRIP)) ((unsigned long*)&sa.sin_addr)[0] = ((unsigned long**)host->h_addr_list)[0][0];
#endif
else return false;
else {
if (gNegDebugMode)
{
stt->doEmitionDebugFoundData("inet_addr error - RVI check failed [<a href=\"" + QString(sDVRIP) + ":" + QString::number(port) +
"/\"><font color=\"#0084ff\">" + QString(sDVRIP) + ":" + QString::number(port) + "</font></a>]");
}
return false;
}

SOCKET sock = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP);
if (sock == INVALID_SOCKET) return false;
if (sock == INVALID_SOCKET) {
if (gNegDebugMode)
{
stt->doEmitionDebugFoundData("Socket error - RVI check failed [<a href=\"" + QString(sDVRIP) + ":" + QString::number(port) +
"/\"><font color=\"#0084ff\">" + QString(sDVRIP) + ":" + QString::number(port) + "</font></a>]");
}
return false;
}

struct linger linger = { 1, gTimeOut };
setsockopt(sock, SOL_SOCKET, SO_LINGER, (const char *)&linger, sizeof(linger));
Expand All @@ -150,12 +197,31 @@ bool HikVis::checkRVI(const char * sDVRIP, int port) {
shutdown(sock, SD_BOTH);
closesocket(sock);

if (buff[0] == -80) return true;
else return false;
if (buff[0] == -80) {
if (gNegDebugMode)
{
stt->doEmitionDebugFoundData("RVI check succeeded [<a href=\"" + QString(sDVRIP) + ":" + QString::number(port) +
"/\"><font color=\"#0084ff\">" + QString(sDVRIP) + ":" + QString::number(port) + "</font></a>]");
}
return true;
}
else {
if (gNegDebugMode)
{
stt->doEmitionDebugFoundData("RVI check failed [<a href=\"" + QString(sDVRIP) + ":" + QString::number(port) +
"/\"><font color=\"#0084ff\">" + QString(sDVRIP) + ":" + QString::number(port) + "</font></a>]");
}
return false;
}
}

shutdown(sock, SD_BOTH);
closesocket(sock);
if (gNegDebugMode)
{
stt->doEmitionDebugFoundData("Unknown error - RVI check failed [<a href=\"" + QString(sDVRIP) + ":" + QString::number(port) +
"/\"><font color=\"#0084ff\">" + QString(sDVRIP) + ":" + QString::number(port) + "</font></a>]");
}
return false;
}

Expand All @@ -172,10 +238,24 @@ bool HikVis::checkSAFARI(const char * sDVRIP, int port) {
if (inet_addr(sDVRIP) != INADDR_NONE) sa.sin_addr.s_addr = inet_addr(sDVRIP);
else if (host = gethostbyname(sDVRIP)) ((unsigned long*)&sa.sin_addr)[0] = ((unsigned long**)host->h_addr_list)[0][0];
#endif
else return false;
else {
if (gNegDebugMode)
{
stt->doEmitionDebugFoundData("inet_addr error - SAFARI check failed [<a href=\"" + QString(sDVRIP) + ":" + QString::number(port) +
"/\"><font color=\"#0084ff\">" + QString(sDVRIP) + ":" + QString::number(port) + "</font></a>]");
}
return false;
}

SOCKET sock = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP);
if (sock == INVALID_SOCKET) return false;
if (sock == INVALID_SOCKET) {
if (gNegDebugMode)
{
stt->doEmitionDebugFoundData("Socket error - SAFARI check failed [<a href=\"" + QString(sDVRIP) + ":" + QString::number(port) +
"/\"><font color=\"#0084ff\">" + QString(sDVRIP) + ":" + QString::number(port) + "</font></a>]");
}
return false;
}

struct linger linger = { 1, gTimeOut };
setsockopt(sock, SOL_SOCKET, SO_LINGER, (const char *)&linger, sizeof(linger));
Expand All @@ -197,15 +277,39 @@ bool HikVis::checkSAFARI(const char * sDVRIP, int port) {
closesocket(sock);

if (buff[0] != '\0') {
if (gNegDebugMode)
{
stt->doEmitionDebugFoundData("SAFARI check succeeded [<a href=\"" + QString(sDVRIP) + ":" + QString::number(port) +
"/\"><font color=\"#0084ff\">" + QString(sDVRIP) + ":" + QString::number(port) + "</font></a>]");
}
return true;
}

if (buff[0] == 8) return true;
else return false;
if (buff[0] == 8) {
if (gNegDebugMode)
{
stt->doEmitionDebugFoundData("SAFARI check succeeded [<a href=\"" + QString(sDVRIP) + ":" + QString::number(port) +
"/\"><font color=\"#0084ff\">" + QString(sDVRIP) + ":" + QString::number(port) + "</font></a>]");
}
return true;
}
else {
if (gNegDebugMode)
{
stt->doEmitionDebugFoundData("SAFARI check failed [<a href=\"" + QString(sDVRIP) + ":" + QString::number(port) +
"/\"><font color=\"#0084ff\">" + QString(sDVRIP) + ":" + QString::number(port) + "</font></a>]");
}
return false;
}
}

shutdown(sock, SD_BOTH);
closesocket(sock);
if (gNegDebugMode)
{
stt->doEmitionDebugFoundData("Unknown error - SAFARI check failed [<a href=\"" + QString(sDVRIP) + ":" + QString::number(port) +
"/\"><font color=\"#0084ff\">" + QString(sDVRIP) + ":" + QString::number(port) + "</font></a>]");
}
return false;
}

Expand Down
8 changes: 4 additions & 4 deletions MainStarter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1381,10 +1381,10 @@ void MainStarter::runAuxiliaryThreads() {
std::thread lpThread(FileUpdater::updateLists);
lpThread.detach();
}
if (!trackerRunning) {
std::thread trackerThread(_tracker);
trackerThread.detach();
}
//if (!trackerRunning) {
// std::thread trackerThread(_tracker);
// trackerThread.detach();
//}
if (!ipPerSecTimer) {
std::thread timerThread(_IPPerSecTimer);
timerThread.detach();
Expand Down
Loading

0 comments on commit 4cf3b15

Please sign in to comment.