XI.CHEN 6 months ago
commit cd1e7b8a8c

@ -47,7 +47,7 @@ add_definitions(-DUSING_EXEC_HDRP=1)
set(USING_EXEC_HDRP 1)
add_definitions(-DUSING_PLZ)
# add_definitions(-DUSING_PLZ)
if(ANDROID_ABI STREQUAL "armeabi-v7a")
add_definitions(-DUSING_N938)

@ -1679,6 +1679,7 @@ bool CPhoneDevice::TakePhoto(const IDevice::PHOTO_INFO& photoInfo, const vector<
if (localPhotoInfo.vendor == 1)
{
// Hai Kang
netPhotoInfo.authType = HTTP_AUTH_TYPE_DIGEST;
snprintf(netPhotoInfo.url, sizeof(netPhotoInfo.url), "/ISAPI/Streaming/channels/%u/picture", (uint32_t)localPhotoInfo.channel);
}
else if (localPhotoInfo.vendor == 2)
@ -1689,15 +1690,18 @@ bool CPhoneDevice::TakePhoto(const IDevice::PHOTO_INFO& photoInfo, const vector<
else if (localPhotoInfo.vendor == 3)
{
// Yu Shi
netPhotoInfo.authType = HTTP_AUTH_TYPE_DIGEST;
int streamSid = 0; // should put into config
snprintf(netPhotoInfo.url, sizeof(netPhotoInfo.url), "/LAPI/V1.0/Channels/%u/Media/Video/Streams/%d/Snapshot", (uint32_t)localPhotoInfo.channel, streamSid);
}
else if (localPhotoInfo.vendor == 5)
{
// Hang Yu - New
netPhotoInfo.authType = HTTP_AUTH_TYPE_BASIC;
// http://192.168.1.46/Snapshot/%u/RemoteImageCapture?ImageFormat=2&HorizontalPixel=1920&VerticalPixel=1080
snprintf(netPhotoInfo.url, sizeof(netPhotoInfo.url), "/Snapshot/%u/RemoteImageCapture?ImageFormat=2&HorizontalPixel=%u&VerticalPixel=%u",
(uint32_t)localPhotoInfo.channel, (uint32_t)localPhotoInfo.width, (uint32_t)localPhotoInfo.height);
// http://192.168.1.101/Snapshot/1/2/RemoteImageCaptureV2?ImageFormat=jpg
// http://192.168.1.101/Snapshot/1/1/RemoteImageCaptureV2?ImageFormat=jpg
snprintf(netPhotoInfo.url, sizeof(netPhotoInfo.url), "/Snapshot/%u/1/RemoteImageCaptureV2?ImageFormat=jpg", (uint32_t)localPhotoInfo.channel);
}
else
{

@ -29,7 +29,7 @@ static int SockOptCallback(void *clientp, curl_socket_t curlfd, curlsocktype pur
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;
std::string auth;
@ -37,6 +37,8 @@ int DoGetRequest(const char* url, const char* userName, const char* password, ne
CURL *curl = curl_easy_init();
curl_easy_setopt(curl, CURLOPT_CUSTOMREQUEST, "GET");
curl_easy_setopt(curl, CURLOPT_URL, url);
if (authType != HTTP_AUTH_TYPE_NONE)
{
if (userName != NULL && password != NULL && strlen(userName) > 0)
{
auth = userName;
@ -44,8 +46,16 @@ int DoGetRequest(const char* url, const char* userName, const char* password, ne
auth += password;
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)
{
@ -69,22 +79,40 @@ int DoGetRequest(const char* url, const char* userName, const char* password, ne
curl_easy_setopt(curl, CURLOPT_CONNECTTIMEOUT, 10);
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);
}
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;
CURL *curl = curl_easy_init();
curl_easy_setopt(curl, CURLOPT_CUSTOMREQUEST, "PUT");
curl_easy_setopt(curl, CURLOPT_URL, url);
if (authType != HTTP_AUTH_TYPE_NONE)
{
if (userName != NULL && password != NULL && strlen(userName) > 0)
{
auth = userName;
@ -92,8 +120,16 @@ int DoPutRequest(const char* url, const char* userName, const char* password, ne
auth += password;
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)
{
@ -137,7 +173,7 @@ bool requestCapture(uint8_t channel, uint8_t preset, const NET_PHOTO_INFO& photo
url += photoInfo.ip;
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 (!data.empty())
@ -170,7 +206,7 @@ bool requestCapture(uint8_t channel, uint8_t preset, const NET_PHOTO_INFO& photo
url += photoInfo.ip;
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);
}
@ -191,7 +227,7 @@ namespace nc_hk
url += photoInfo.ip;
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
if (0 == nRet)
{
@ -225,7 +261,7 @@ namespace nc_ys
url += photoInfo.ip;
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
if (0 == nRet)
{

@ -16,7 +16,7 @@
bool setIPAddress(const char *if_name, const char *ip_addr, const char *net_mask, const char *gateway_addr);
int DoGetRequest(const char* url, const char* userName, const char* password, net_handle_t netHandle, std::vector<uint8_t>& data);
int DoPutRequest(const char* url, const char* userName, const char* password, net_handle_t netHandle, const char* contents, 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);
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);
#endif // __HTTP_CLIENT__

@ -5,6 +5,9 @@
#ifndef __NET_CAMERA__
#define __NET_CAMERA__
#define HTTP_AUTH_TYPE_NONE 0
#define HTTP_AUTH_TYPE_BASIC 1
#define HTTP_AUTH_TYPE_DIGEST 2
struct NET_PHOTO_INFO
{

Loading…
Cancel
Save