Add some platform abstractions.
(This is a merge of http://go/wvgerrit/70303) This adds a platform.h file to abstract some of the differences between Windows and POSIX platforms. This includes ntohl, setenv, and ssize_t. Bug: 122953649 Test: Android Unit Tests Change-Id: I3235f3f284b53d24d7365ff3f4a06dcd9b403697
This commit is contained in:
@@ -5,14 +5,13 @@
|
||||
#ifndef WVCDM_CORE_DEVICE_FILES_H_
|
||||
#define WVCDM_CORE_DEVICE_FILES_H_
|
||||
|
||||
#include <unistd.h>
|
||||
|
||||
#include <set>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
#include "device_files.pb.h"
|
||||
#include "disallow_copy_and_assign.h"
|
||||
#include "platform.h"
|
||||
#include "wv_cdm_types.h"
|
||||
|
||||
#if defined(UNIT_TEST)
|
||||
|
||||
@@ -5,6 +5,7 @@
|
||||
#include "buffer_reader.h"
|
||||
|
||||
#include "log.h"
|
||||
#include "platform.h"
|
||||
|
||||
namespace wvcdm {
|
||||
|
||||
|
||||
@@ -7,7 +7,6 @@
|
||||
|
||||
#include "crypto_session.h"
|
||||
|
||||
#include <arpa/inet.h> // needed for ntoh()
|
||||
#include <string.h>
|
||||
#include <algorithm>
|
||||
#include <iostream>
|
||||
@@ -20,6 +19,7 @@
|
||||
#include "openssl/asn1.h"
|
||||
#include "openssl/sha.h"
|
||||
#include "openssl/x509v3.h"
|
||||
#include "platform.h"
|
||||
#include "properties.h"
|
||||
#include "pst_report.h"
|
||||
#include "string_conversions.h"
|
||||
|
||||
@@ -4,7 +4,6 @@
|
||||
|
||||
#include "initialization_data.h"
|
||||
|
||||
#include <arpa/inet.h>
|
||||
#include <string.h>
|
||||
#include <sstream>
|
||||
|
||||
@@ -12,6 +11,7 @@
|
||||
#include "cdm_engine.h"
|
||||
#include "jsmn.h"
|
||||
#include "log.h"
|
||||
#include "platform.h"
|
||||
#include "properties.h"
|
||||
#include "string_conversions.h"
|
||||
#include "wv_cdm_constants.h"
|
||||
|
||||
@@ -4,7 +4,6 @@
|
||||
|
||||
#include "license.h"
|
||||
|
||||
#include <arpa/inet.h>
|
||||
#include <sstream>
|
||||
#include <vector>
|
||||
|
||||
@@ -15,6 +14,7 @@
|
||||
#include "crypto_session.h"
|
||||
#include "device_files.h"
|
||||
#include "log.h"
|
||||
#include "platform.h"
|
||||
#include "policy_engine.h"
|
||||
#include "privacy_crypto.h"
|
||||
#include "properties.h"
|
||||
|
||||
@@ -4,7 +4,6 @@
|
||||
|
||||
#include <string>
|
||||
#include <errno.h>
|
||||
#include <getopt.h>
|
||||
#include <gtest/gtest.h>
|
||||
|
||||
#include "buffer_reader.h"
|
||||
|
||||
@@ -2,7 +2,6 @@
|
||||
// source code may only be used and distributed under the Widevine Master
|
||||
// License Agreement.
|
||||
|
||||
#include <arpa/inet.h>
|
||||
#include <memory>
|
||||
#include <string>
|
||||
|
||||
@@ -13,6 +12,7 @@
|
||||
#include "key_session.h"
|
||||
#include "license_protocol.pb.h"
|
||||
#include "log.h"
|
||||
#include "platform.h"
|
||||
#include "metrics.pb.h"
|
||||
#include "metrics_collections.h"
|
||||
#include "test_base.h"
|
||||
|
||||
@@ -7,7 +7,6 @@
|
||||
// This is because we need a valid RSA certificate, and will attempt to connect
|
||||
// to the provisioning server to request one if we don't.
|
||||
|
||||
#include <arpa/inet.h>
|
||||
#include <gtest/gtest.h>
|
||||
#include <memory>
|
||||
#include <string>
|
||||
@@ -19,6 +18,7 @@
|
||||
#include "oec_session_util.h"
|
||||
#include "oemcrypto_session_tests_helper.h"
|
||||
#include "oemcrypto_types.h"
|
||||
#include "platform.h"
|
||||
#include "properties.h"
|
||||
#include "string_conversions.h"
|
||||
#include "test_base.h"
|
||||
|
||||
@@ -2,13 +2,13 @@
|
||||
// source code may only be used and distributed under the Widevine Master
|
||||
// License Agreement.
|
||||
|
||||
#include <arpa/inet.h>
|
||||
#include <gmock/gmock.h>
|
||||
#include <gtest/gtest.h>
|
||||
|
||||
#include "file_store.h"
|
||||
#include "initialization_data.h"
|
||||
#include "license_protocol.pb.h"
|
||||
#include "platform.h"
|
||||
#include "string_conversions.h"
|
||||
#include "wv_cdm_constants.h"
|
||||
|
||||
|
||||
@@ -21,6 +21,7 @@
|
||||
#include "log.h"
|
||||
#include "oec_device_features.h"
|
||||
#include "oec_test_data.h"
|
||||
#include "platform.h"
|
||||
#include "properties.h"
|
||||
#include "test_printers.h"
|
||||
#include "url_request.h"
|
||||
|
||||
@@ -7,12 +7,13 @@
|
||||
#ifndef WVCDM_UTIL_FILE_STORE_H_
|
||||
#define WVCDM_UTIL_FILE_STORE_H_
|
||||
|
||||
#include <unistd.h>
|
||||
#include <cstdint>
|
||||
#include <memory>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
#include "disallow_copy_and_assign.h"
|
||||
#include "platform.h"
|
||||
#include "util_common.h"
|
||||
|
||||
namespace wvcdm {
|
||||
|
||||
33
libwvdrmengine/cdm/util/include/platform.h
Normal file
33
libwvdrmengine/cdm/util/include/platform.h
Normal file
@@ -0,0 +1,33 @@
|
||||
// Copyright 2018 Google LLC. All Rights Reserved. This file and proprietary
|
||||
// source code may only be used and distributed under the Widevine Master
|
||||
// License Agreement.
|
||||
//
|
||||
// Platform - Abstracts some utilities between platforms.
|
||||
//
|
||||
#ifndef WVCDM_UTIL_PLATFORM_H_
|
||||
#define WVCDM_UTIL_PLATFORM_H_
|
||||
|
||||
#include "util_common.h"
|
||||
|
||||
#ifdef _WIN32
|
||||
# include <wtypes.h>
|
||||
# include <BaseTsd.h>
|
||||
# include <winsock2.h> // For htonl and ntohl.
|
||||
# define __PRETTY_FUNCTION__ __FUNCTION__
|
||||
# undef NO_ERROR
|
||||
# undef GetCurrentTime
|
||||
# undef DeleteFile
|
||||
|
||||
using ssize_t = SSIZE_T;
|
||||
|
||||
inline void sleep(int seconds) {
|
||||
Sleep(seconds * 1000);
|
||||
}
|
||||
CORE_UTIL_EXPORT int setenv(const char* key, const char* value, int overwrite);
|
||||
#else
|
||||
# include <arpa/inet.h>
|
||||
# include <sys/types.h>
|
||||
# include <unistd.h>
|
||||
#endif
|
||||
|
||||
#endif // WVCDM_UTIL_PLATFORM_H_
|
||||
21
libwvdrmengine/cdm/util/src/platform.cpp
Normal file
21
libwvdrmengine/cdm/util/src/platform.cpp
Normal file
@@ -0,0 +1,21 @@
|
||||
// Copyright 2018 Google LLC. All Rights Reserved. This file and proprietary
|
||||
// source code may only be used and distributed under the Widevine Master
|
||||
// License Agreement.
|
||||
|
||||
#include "platform.h"
|
||||
|
||||
#include "stdlib.h"
|
||||
|
||||
#ifdef _WIN32
|
||||
|
||||
int setenv(const char* key, const char* value, int overwrite) {
|
||||
if (!overwrite) {
|
||||
size_t size;
|
||||
errno_t err = getenv_s(&size, nullptr, 0, key);
|
||||
if (err != 0 || size != 0)
|
||||
return err; // Return 0 if it exists, but don't change.
|
||||
}
|
||||
return _putenv_s(key, value);
|
||||
}
|
||||
|
||||
#endif
|
||||
@@ -4,7 +4,6 @@
|
||||
|
||||
#include "string_conversions.h"
|
||||
|
||||
#include <arpa/inet.h>
|
||||
#include <ctype.h>
|
||||
#include <stdint.h>
|
||||
#include <stdio.h>
|
||||
@@ -13,6 +12,7 @@
|
||||
#include <vector>
|
||||
|
||||
#include "log.h"
|
||||
#include "platform.h"
|
||||
|
||||
namespace wvcdm {
|
||||
|
||||
|
||||
@@ -6,7 +6,6 @@
|
||||
//
|
||||
#include "oemcrypto_engine_ref.h"
|
||||
|
||||
#include <arpa/inet.h>
|
||||
#include <assert.h>
|
||||
#include <chrono>
|
||||
#include <string.h>
|
||||
|
||||
@@ -6,13 +6,14 @@
|
||||
//
|
||||
#include "oemcrypto_keybox_ref.h"
|
||||
|
||||
#include <arpa/inet.h> // needed for ntoh()
|
||||
#include <string.h>
|
||||
#include <sys/types.h>
|
||||
|
||||
#include <cstdint>
|
||||
#include <string>
|
||||
|
||||
#include "log.h"
|
||||
#include "oemcrypto_types.h"
|
||||
#include "platform.h"
|
||||
#include "wvcrc32.h"
|
||||
|
||||
namespace wvoec_ref {
|
||||
|
||||
@@ -6,7 +6,6 @@
|
||||
//
|
||||
#include "oemcrypto_session.h"
|
||||
|
||||
#include <arpa/inet.h>
|
||||
#include <assert.h>
|
||||
#include <string.h>
|
||||
#include <algorithm>
|
||||
@@ -30,6 +29,7 @@
|
||||
#include "oemcrypto_key_ref.h"
|
||||
#include "oemcrypto_rsa_key_shared.h"
|
||||
#include "oemcrypto_types.h"
|
||||
#include "platform.h"
|
||||
#include "disallow_copy_and_assign.h"
|
||||
#include "string_conversions.h"
|
||||
#include "wvcrc32.h"
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
//
|
||||
// Compute CRC32 Checksum. Needed for verification of WV Keybox.
|
||||
//
|
||||
#include <arpa/inet.h>
|
||||
#include "platform.h"
|
||||
#include "wvcrc32.h"
|
||||
|
||||
namespace wvoec_ref {
|
||||
|
||||
@@ -7,7 +7,6 @@
|
||||
|
||||
#include "oec_session_util.h"
|
||||
|
||||
#include <arpa/inet.h> // needed for ntoh()
|
||||
#include <openssl/aes.h>
|
||||
#include <openssl/bio.h>
|
||||
#include <openssl/cmac.h>
|
||||
@@ -32,6 +31,7 @@
|
||||
#include "oec_device_features.h"
|
||||
#include "oec_test_data.h"
|
||||
#include "oemcrypto_types.h"
|
||||
#include "platform.h"
|
||||
#include "string_conversions.h"
|
||||
|
||||
using namespace std;
|
||||
|
||||
@@ -4,9 +4,7 @@
|
||||
//
|
||||
// OEMCrypto unit tests
|
||||
//
|
||||
#include <arpa/inet.h> // needed for ntoh()
|
||||
#include <ctype.h>
|
||||
#include <getopt.h>
|
||||
#include <openssl/aes.h>
|
||||
#include <openssl/err.h>
|
||||
#include <openssl/hmac.h>
|
||||
@@ -35,6 +33,7 @@
|
||||
#include "oec_test_data.h"
|
||||
#include "oemcrypto_session_tests_helper.h"
|
||||
#include "oemcrypto_types.h"
|
||||
#include "platform.h"
|
||||
#include "string_conversions.h"
|
||||
#include "wvcrc32.h"
|
||||
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
//
|
||||
// Compute CRC32 Checksum. Needed for verification of WV Keybox.
|
||||
//
|
||||
#include <arpa/inet.h>
|
||||
#include "platform.h"
|
||||
#include "wvcrc32.h"
|
||||
|
||||
namespace wvoec {
|
||||
|
||||
Reference in New Issue
Block a user