XI.CHEN 6 months ago
commit cd1e7b8a8c

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

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

@ -16,7 +16,7 @@
bool setIPAddress(const char *if_name, const char *ip_addr, const char *net_mask, const char *gateway_addr); 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 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, 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);
#endif // __HTTP_CLIENT__ #endif // __HTTP_CLIENT__

@ -5,6 +5,9 @@
#ifndef __NET_CAMERA__ #ifndef __NET_CAMERA__
#define __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 struct NET_PHOTO_INFO
{ {

Loading…
Cancel
Save