|
|
@ -29,7 +29,7 @@ static int SockOptCallback(void *clientp, curl_socket_t curlfd, curlsocktype pur
|
|
|
|
return res == 0 ? CURL_SOCKOPT_OK : CURL_SOCKOPT_ERROR;
|
|
|
|
return res == 0 ? CURL_SOCKOPT_OK : CURL_SOCKOPT_ERROR;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
int DoGetRequest(const char* url, const char* userName, const char* password, net_handle_t netHandle, std::vector<uint8_t>& data)
|
|
|
|
int DoGetRequest(const char* url, int authType, const char* userName, const char* password, net_handle_t netHandle, std::vector<uint8_t>& data)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
CURLcode nRet;
|
|
|
|
CURLcode nRet;
|
|
|
|
std::string auth;
|
|
|
|
std::string auth;
|
|
|
@ -37,14 +37,24 @@ int DoGetRequest(const char* url, const char* userName, const char* password, ne
|
|
|
|
CURL *curl = curl_easy_init();
|
|
|
|
CURL *curl = curl_easy_init();
|
|
|
|
curl_easy_setopt(curl, CURLOPT_CUSTOMREQUEST, "GET");
|
|
|
|
curl_easy_setopt(curl, CURLOPT_CUSTOMREQUEST, "GET");
|
|
|
|
curl_easy_setopt(curl, CURLOPT_URL, url);
|
|
|
|
curl_easy_setopt(curl, CURLOPT_URL, url);
|
|
|
|
if (userName != NULL && password != NULL && strlen(userName) > 0)
|
|
|
|
if (authType != HTTP_AUTH_TYPE_NONE)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
auth = userName;
|
|
|
|
if (userName != NULL && password != NULL && strlen(userName) > 0)
|
|
|
|
auth += ":";
|
|
|
|
{
|
|
|
|
auth += password;
|
|
|
|
auth = userName;
|
|
|
|
curl_easy_setopt(curl, CURLOPT_USERPWD, auth.c_str());
|
|
|
|
auth += ":";
|
|
|
|
// DIGEST Auth
|
|
|
|
auth += password;
|
|
|
|
curl_easy_setopt(curl, CURLOPT_HTTPAUTH, CURLAUTH_DIGEST);
|
|
|
|
curl_easy_setopt(curl, CURLOPT_USERPWD, auth.c_str());
|
|
|
|
|
|
|
|
// DIGEST Auth
|
|
|
|
|
|
|
|
if (authType == HTTP_AUTH_TYPE_BASIC)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
curl_easy_setopt(curl, CURLOPT_HTTPAUTH, CURLAUTH_BASIC);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
else if (authType == HTTP_AUTH_TYPE_DIGEST)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
curl_easy_setopt(curl, CURLOPT_HTTPAUTH, CURLAUTH_DIGEST);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if (netHandle != NETWORK_UNSPECIFIED)
|
|
|
|
if (netHandle != NETWORK_UNSPECIFIED)
|
|
|
@ -69,30 +79,56 @@ int DoGetRequest(const char* url, const char* userName, const char* password, ne
|
|
|
|
curl_easy_setopt(curl, CURLOPT_CONNECTTIMEOUT, 10);
|
|
|
|
curl_easy_setopt(curl, CURLOPT_CONNECTTIMEOUT, 10);
|
|
|
|
|
|
|
|
|
|
|
|
nRet = curl_easy_perform(curl);
|
|
|
|
nRet = curl_easy_perform(curl);
|
|
|
|
if (CURLE_OK != nRet)
|
|
|
|
|
|
|
|
|
|
|
|
long responseCode = 0;
|
|
|
|
|
|
|
|
if (CURLE_OK == nRet)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
curl_easy_getinfo(curl, CURLINFO_RESPONSE_CODE, &responseCode);
|
|
|
|
|
|
|
|
if (responseCode != 200)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
#ifdef _DEBUG
|
|
|
|
|
|
|
|
char * log = new char[data.size() + 1];
|
|
|
|
|
|
|
|
log[data.size()] = 0;
|
|
|
|
|
|
|
|
memcpy(log, &data[0], data.size());
|
|
|
|
|
|
|
|
printf(log);
|
|
|
|
|
|
|
|
delete[] log;
|
|
|
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
else
|
|
|
|
{
|
|
|
|
{
|
|
|
|
printf("GET err=%d", nRet);
|
|
|
|
printf("GET err=%d", nRet);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
curl_easy_cleanup(curl);
|
|
|
|
curl_easy_cleanup(curl);
|
|
|
|
|
|
|
|
|
|
|
|
return (0 == nRet) ? 0 : 1;
|
|
|
|
return ((0 == nRet) && (responseCode == 200)) ? 0 : 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
int DoPutRequest(const char* url, const char* userName, const char* password, net_handle_t netHandle, const char* contents, std::vector<uint8_t>& data)
|
|
|
|
int DoPutRequest(const char* url, int authType, const char* userName, const char* password, net_handle_t netHandle, const char* contents, std::vector<uint8_t>& data)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
std::string auth;
|
|
|
|
std::string auth;
|
|
|
|
|
|
|
|
|
|
|
|
CURL *curl = curl_easy_init();
|
|
|
|
CURL *curl = curl_easy_init();
|
|
|
|
curl_easy_setopt(curl, CURLOPT_CUSTOMREQUEST, "PUT");
|
|
|
|
curl_easy_setopt(curl, CURLOPT_CUSTOMREQUEST, "PUT");
|
|
|
|
curl_easy_setopt(curl, CURLOPT_URL, url);
|
|
|
|
curl_easy_setopt(curl, CURLOPT_URL, url);
|
|
|
|
if (userName != NULL && password != NULL && strlen(userName) > 0)
|
|
|
|
if (authType != HTTP_AUTH_TYPE_NONE)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
auth = userName;
|
|
|
|
if (userName != NULL && password != NULL && strlen(userName) > 0)
|
|
|
|
auth += ":";
|
|
|
|
{
|
|
|
|
auth += password;
|
|
|
|
auth = userName;
|
|
|
|
curl_easy_setopt(curl, CURLOPT_USERPWD, auth.c_str());
|
|
|
|
auth += ":";
|
|
|
|
// DIGEST Auth
|
|
|
|
auth += password;
|
|
|
|
curl_easy_setopt(curl, CURLOPT_HTTPAUTH, CURLAUTH_DIGEST);
|
|
|
|
curl_easy_setopt(curl, CURLOPT_USERPWD, auth.c_str());
|
|
|
|
|
|
|
|
// DIGEST Auth
|
|
|
|
|
|
|
|
if (authType == HTTP_AUTH_TYPE_BASIC)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
curl_easy_setopt(curl, CURLOPT_HTTPAUTH, CURLAUTH_BASIC);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
else if (authType == HTTP_AUTH_TYPE_DIGEST)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
curl_easy_setopt(curl, CURLOPT_HTTPAUTH, CURLAUTH_DIGEST);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if (netHandle != NETWORK_UNSPECIFIED)
|
|
|
|
if (netHandle != NETWORK_UNSPECIFIED)
|
|
|
@ -137,7 +173,7 @@ bool requestCapture(uint8_t channel, uint8_t preset, const NET_PHOTO_INFO& photo
|
|
|
|
url += photoInfo.ip;
|
|
|
|
url += photoInfo.ip;
|
|
|
|
url += photoInfo.url;
|
|
|
|
url += photoInfo.url;
|
|
|
|
|
|
|
|
|
|
|
|
int nRet = DoGetRequest(url.c_str(), userName, password, photoInfo.netHandle, data);
|
|
|
|
int nRet = DoGetRequest(url.c_str(), photoInfo.authType, userName, password, photoInfo.netHandle, data);
|
|
|
|
if (0 == nRet)
|
|
|
|
if (0 == nRet)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
if (!data.empty())
|
|
|
|
if (!data.empty())
|
|
|
@ -170,7 +206,7 @@ bool requestCapture(uint8_t channel, uint8_t preset, const NET_PHOTO_INFO& photo
|
|
|
|
url += photoInfo.ip;
|
|
|
|
url += photoInfo.ip;
|
|
|
|
url += photoInfo.url;
|
|
|
|
url += photoInfo.url;
|
|
|
|
|
|
|
|
|
|
|
|
int nRet = DoGetRequest(url.c_str(), userName, password, photoInfo.netHandle, img);
|
|
|
|
int nRet = DoGetRequest(url.c_str(), photoInfo.authType, userName, password, photoInfo.netHandle, img);
|
|
|
|
return (0 == nRet);
|
|
|
|
return (0 == nRet);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
@ -191,7 +227,7 @@ namespace nc_hk
|
|
|
|
url += photoInfo.ip;
|
|
|
|
url += photoInfo.ip;
|
|
|
|
url += photoInfo.url;
|
|
|
|
url += photoInfo.url;
|
|
|
|
|
|
|
|
|
|
|
|
int nRet = DoGetRequest(url.c_str(), userName, password, photoInfo.netHandle, img);
|
|
|
|
int nRet = DoGetRequest(url.c_str(), photoInfo.authType, userName, password, photoInfo.netHandle, img);
|
|
|
|
#ifdef _DEBUG
|
|
|
|
#ifdef _DEBUG
|
|
|
|
if (0 == nRet)
|
|
|
|
if (0 == nRet)
|
|
|
|
{
|
|
|
|
{
|
|
|
@ -225,7 +261,7 @@ namespace nc_ys
|
|
|
|
url += photoInfo.ip;
|
|
|
|
url += photoInfo.ip;
|
|
|
|
url += photoInfo.url;
|
|
|
|
url += photoInfo.url;
|
|
|
|
|
|
|
|
|
|
|
|
int nRet = DoGetRequest(url.c_str(), userName, password, photoInfo.netHandle, img);
|
|
|
|
int nRet = DoGetRequest(url.c_str(), photoInfo.authType, userName, password, photoInfo.netHandle, img);
|
|
|
|
#ifdef _DEBUG
|
|
|
|
#ifdef _DEBUG
|
|
|
|
if (0 == nRet)
|
|
|
|
if (0 == nRet)
|
|
|
|
{
|
|
|
|
{
|
|
|
|