bug: 8601053
This import syncs to the widevine git repository change
commit 6a99ad1b59ad39495f62954b3065ddc22b78da49
It includes the following changes from the widevine git
repository, which complete the jb-mr2 features
Fix Unit Test Makefile
Adds support for device certificate provisioning.
Support application parameters
Certificate based licensing
Proto for client files
Implement Property Query API
Add Device Query For Unique ID
Implement Generic Crypto in DrmEngine
Do not validate Key IDs on clear playback
Allow OEMCrypto_DecryptCTR with clear content and no key
Add a case to the MediaDrm API test to repro b/8594163
Implement requiresSecureDecoderComponent
Implement Eventing API
Add end-to-end decryption test with vectors
Refactoring of properties class
Refactor OEMCrypto unittest.
Fix for b/8567853: License renewal doesn't renew license.
Add KEY_ERROR callback to WvContentDecryptionModule() ctor.
Merged certificate_provisioning.proto and
client_identification.proto to license_protocol.proto.
Fix nonce check failure after a malformed key in OEC Mock.
asynchronize decryption
Allow querying of control information
make debugging AddKey & Decrypt statuses easier
Revert "Revert "Send KEY_ERROR event to app on license
expiration or failure""
Revert "Send KEY_ERROR event to app on license expiration
or failure"
Send KEY_ERROR event to app on license expiration or failure
remove extra session id copy
use KeyError constants directly
replace variable-length arrays with std::vector and fixed-sized array
pass session ids as const references
refactor key extraction and update keys on renewal
Updates to enable renewals and signaling license expiration.
fix error constant in OEMCrypto_DecryptCTR
Change-Id: I5f7236c7bdff1d5ece6115fd2893f8a1e1e07c50
107 lines
2.8 KiB
C++
107 lines
2.8 KiB
C++
// Copyright 2013 Google Inc. All Rights Reserved.
|
|
|
|
#include "url_request.h"
|
|
|
|
#include "http_socket.h"
|
|
#include "log.h"
|
|
|
|
namespace wvcdm {
|
|
|
|
UrlRequest::UrlRequest(const std::string& url, const std::string& port)
|
|
: is_connected_(false),
|
|
port_("80"),
|
|
request_(""),
|
|
server_url_(url)
|
|
{
|
|
if (!port.empty()) {
|
|
port_.assign(port);
|
|
}
|
|
if (socket_.Connect((server_url_).c_str(), port_, true)) {
|
|
LOGD("connected to %s", socket_.domain_name().c_str());
|
|
is_connected_ = true;
|
|
} else {
|
|
LOGE("failed to connect to %s, port=%s",
|
|
socket_.domain_name().c_str(), port.c_str());
|
|
}
|
|
}
|
|
|
|
UrlRequest::~UrlRequest()
|
|
{
|
|
socket_.CloseSocket();
|
|
}
|
|
|
|
void UrlRequest::AppendChunkToUpload(const std::string& data) {
|
|
// format of chunk:
|
|
// size of chunk in hex\r\n
|
|
// data\r\n
|
|
// . . .
|
|
// 0\r\n
|
|
|
|
// buffer to store length of chunk
|
|
memset(buffer_, 0, kHttpBufferSize);
|
|
snprintf(buffer_, kHttpBufferSize, "%x\r\n", data.size());
|
|
request_.append(buffer_); // appends size of chunk
|
|
LOGD("...\r\n%s", request_.c_str());
|
|
request_.append(data);
|
|
request_.append("\r\n"); // marks end of data
|
|
}
|
|
|
|
int UrlRequest::GetResponse(std::string& response) {
|
|
response.clear();
|
|
|
|
const int kTimeoutInMs = 1500;
|
|
int bytes = 0;
|
|
int total_bytes = 0;
|
|
do {
|
|
memset(buffer_, 0, kHttpBufferSize);
|
|
bytes = socket_.Read(buffer_, kHttpBufferSize, kTimeoutInMs);
|
|
if (bytes > 0) {
|
|
response.append(buffer_, bytes);
|
|
total_bytes += bytes;
|
|
} else {
|
|
if (bytes < 0) LOGE("read error = ", errno);
|
|
// bytes == 0 indicates nothing to read
|
|
}
|
|
} while (bytes > 0);
|
|
return total_bytes;
|
|
}
|
|
|
|
int UrlRequest::GetStatusCode(const std::string& response) {
|
|
const std::string kHttpVersion("HTTP/1.1");
|
|
|
|
int status_code = -1;
|
|
size_t pos = response.find(kHttpVersion);
|
|
if (pos != std::string::npos) {
|
|
pos += kHttpVersion.size();
|
|
sscanf(response.substr(pos).c_str(), "%d", &status_code);
|
|
}
|
|
return status_code;
|
|
}
|
|
|
|
bool UrlRequest::PostRequest(const std::string& data) {
|
|
request_.assign("POST /");
|
|
request_.append(socket_.resource_path());
|
|
request_.append(" HTTP/1.1\r\n");
|
|
request_.append("Host: ");
|
|
request_.append(socket_.domain_name());
|
|
request_.append("\r\nConnection: Keep-Alive\r\n");
|
|
request_.append("Transfer-Encoding: chunked\r\n");
|
|
request_.append("User-Agent: Widevine CDM v1.0\r\n");
|
|
request_.append("Accept-Encoding: gzip,deflate\r\n");
|
|
request_.append("Accept-Language: en-us,fr\r\n");
|
|
request_.append("Accept-Charset: iso-8859-1,*,utf-8\r\n");
|
|
request_.append("\r\n"); // empty line to terminate header
|
|
|
|
// calls AppendChunkToUpload repeatedly for multiple chunks
|
|
AppendChunkToUpload(data);
|
|
|
|
// terminates last chunk with 0\r\n, then ends header with an empty line
|
|
request_.append("0\r\n\r\n");
|
|
|
|
socket_.Write(request_.c_str(), request_.size());
|
|
return true;
|
|
}
|
|
|
|
|
|
} // namespace wvcdm
|