diff --git a/app/src/main/cpp/CMakeLists.txt b/app/src/main/cpp/CMakeLists.txt index cb99ef6f..736422ad 100644 --- a/app/src/main/cpp/CMakeLists.txt +++ b/app/src/main/cpp/CMakeLists.txt @@ -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) diff --git a/app/src/main/cpp/PhoneDevice.cpp b/app/src/main/cpp/PhoneDevice.cpp index 59554c9e..f404f027 100644 --- a/app/src/main/cpp/PhoneDevice.cpp +++ b/app/src/main/cpp/PhoneDevice.cpp @@ -1678,6 +1678,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) @@ -1688,15 +1689,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 { diff --git a/app/src/main/cpp/netcamera/httpclient.cpp b/app/src/main/cpp/netcamera/httpclient.cpp index b5d256c9..2f16d3b3 100644 --- a/app/src/main/cpp/netcamera/httpclient.cpp +++ b/app/src/main/cpp/netcamera/httpclient.cpp @@ -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& data) +int DoGetRequest(const char* url, int authType, const char* userName, const char* password, net_handle_t netHandle, std::vector& data) { CURLcode nRet; 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_easy_setopt(curl, CURLOPT_CUSTOMREQUEST, "GET"); curl_easy_setopt(curl, CURLOPT_URL, url); - if (userName != NULL && password != NULL && strlen(userName) > 0) + if (authType != HTTP_AUTH_TYPE_NONE) { - auth = userName; - auth += ":"; - auth += password; - curl_easy_setopt(curl, CURLOPT_USERPWD, auth.c_str()); - // DIGEST Auth - curl_easy_setopt(curl, CURLOPT_HTTPAUTH, CURLAUTH_DIGEST); + if (userName != NULL && password != NULL && strlen(userName) > 0) + { + auth = userName; + auth += ":"; + 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,30 +79,56 @@ 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& data) +int DoPutRequest(const char* url, int authType, const char* userName, const char* password, net_handle_t netHandle, const char* contents, std::vector& data) { std::string auth; CURL *curl = curl_easy_init(); curl_easy_setopt(curl, CURLOPT_CUSTOMREQUEST, "PUT"); curl_easy_setopt(curl, CURLOPT_URL, url); - if (userName != NULL && password != NULL && strlen(userName) > 0) + if (authType != HTTP_AUTH_TYPE_NONE) { - auth = userName; - auth += ":"; - auth += password; - curl_easy_setopt(curl, CURLOPT_USERPWD, auth.c_str()); - // DIGEST Auth - curl_easy_setopt(curl, CURLOPT_HTTPAUTH, CURLAUTH_DIGEST); + if (userName != NULL && password != NULL && strlen(userName) > 0) + { + auth = userName; + auth += ":"; + 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) { diff --git a/app/src/main/cpp/netcamera/httpclient.h b/app/src/main/cpp/netcamera/httpclient.h index e1cc05d9..71af1a76 100644 --- a/app/src/main/cpp/netcamera/httpclient.h +++ b/app/src/main/cpp/netcamera/httpclient.h @@ -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& data); -int DoPutRequest(const char* url, const char* userName, const char* password, net_handle_t netHandle, const char* contents, std::vector& data); +int DoGetRequest(const char* url, int authType, const char* userName, const char* password, net_handle_t netHandle, std::vector& data); +int DoPutRequest(const char* url, int authType, const char* userName, const char* password, net_handle_t netHandle, const char* contents, std::vector& data); #endif // __HTTP_CLIENT__ \ No newline at end of file diff --git a/app/src/main/cpp/netcamera/netcamera.h b/app/src/main/cpp/netcamera/netcamera.h index c5326734..9f0ab52e 100644 --- a/app/src/main/cpp/netcamera/netcamera.h +++ b/app/src/main/cpp/netcamera/netcamera.h @@ -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 {