Skip to content

Commit

Permalink
Update ninja_init.cpp
Browse files Browse the repository at this point in the history
  • Loading branch information
RuiZhang-kwf8 authored Jul 3, 2024
1 parent ee040fe commit 90dfa41
Showing 1 changed file with 21 additions and 72 deletions.
93 changes: 21 additions & 72 deletions src/ninja/ninja_init.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -133,44 +133,9 @@ int NinjaInitialize(const char *pszGdalData, const char *pszWindNinjaData)

std::cout << "Logging message to console." << std::endl;



std::string firstLocalIP;

struct ifaddrs *ifAddrStruct = NULL;
struct ifaddrs *ifa = NULL;
void *tmpAddrPtr = NULL;

getifaddrs(&ifAddrStruct);

for (ifa = ifAddrStruct; ifa != NULL; ifa = ifa->ifa_next) {
if (!ifa->ifa_addr) {
continue;
}

if (ifa->ifa_addr->sa_family == AF_INET) { // Check it is IPv4
tmpAddrPtr = &((struct sockaddr_in *)ifa->ifa_addr)->sin_addr;
char addressBuffer[INET_ADDRSTRLEN];
inet_ntop(AF_INET, tmpAddrPtr, addressBuffer, INET_ADDRSTRLEN);
if (strcmp(addressBuffer, "127.0.0.1") != 0) {
firstLocalIP = addressBuffer;
break;
}
} else if (ifa->ifa_addr->sa_family == AF_INET6) { // Check it is IPv6
tmpAddrPtr = &((struct sockaddr_in6 *)ifa->ifa_addr)->sin6_addr;
char addressBuffer[INET6_ADDRSTRLEN];
inet_ntop(AF_INET6, tmpAddrPtr, addressBuffer, INET6_ADDRSTRLEN);
if (strcmp(addressBuffer, "::1") != 0) {
firstLocalIP = addressBuffer;
break;
}
}
}

if (ifAddrStruct != NULL)
freeifaddrs(ifAddrStruct);

std::string address = firstLocalIP;

time_t now = time(0);

Expand All @@ -180,24 +145,39 @@ char* dt = asctime(gmtm);
std::string cpp_string(dt);


std::string url = "http://ninjastorm.firelab.org/windninja/stats/?IP=";
std::string url = "https://ninjastorm.firelab.org/sqlitetest/?time=";
cpp_string.erase(std::remove_if(cpp_string.begin(), cpp_string.end(), ::isspace),
cpp_string.end());


std::string full = url + cpp_string;

std::string full = url + address + "&time=" + cpp_string;

const char *charStr = full.data();

if (!firstLocalIP.empty()) {
CPLHTTPResult *poResult;
std::cout << charStr << std::endl;
CPLSetConfigOption("GDAL_HTTP_UNSAFESSL", "YES");

poResult = CPLHTTPFetch(charStr, NULL);
CPLHTTPDestroyResult(poResult);
}
poResult = CPLHTTPFetch(charStr, NULL);

if (poResult) {
CPLHTTPDestroyResult(poResult);
} else {
std::cerr << "Fetch data." << std::endl;
}





CPLSetConfigOption( "GDAL_HTTP_UNSAFESSL", "YES");






if(!CPLCheckForFile(CPLStrdup(CPLFormFilename(CPLStrdup(pszGdalData), "gdalicon.png", NULL)), NULL))
{
CPLDebug("WINDNINJA", "Invalid path for GDAL_DATA: %s", pszGdalData);
Expand Down Expand Up @@ -235,37 +215,6 @@ int NinjaInitialize()
int rc = 0;


time_t now = time(0);

// convert now to tm struct for UTC
tm *gmtm = gmtime(&now);
char* dt = asctime(gmtm);
std::string cpp_string(dt);


std::string url = "https://ninjastorm.firelab.org/sqlitetest/?time=";
cpp_string.erase(std::remove_if(cpp_string.begin(), cpp_string.end(), ::isspace),
cpp_string.end());


std::string full = url + cpp_string;


const char *charStr = full.data();

CPLHTTPResult *poResult;
std::cout << charStr << std::endl;
CPLSetConfigOption("GDAL_HTTP_UNSAFESSL", "YES");

poResult = CPLHTTPFetch(charStr, NULL);

if (poResult) {
CPLHTTPDestroyResult(poResult);
} else {
std::cerr << "Fetch data." << std::endl;
}


/*
** Setting the CURL_CA_BUNDLE variable through GDAL doesn't seem to work,
** but could be investigated in the future. CURL_CA_BUNDLE can only be set in GDAL
Expand Down

0 comments on commit 90dfa41

Please sign in to comment.