Fixed a bug
This commit is contained in:
parent
b2ee501bbe
commit
bfda88d350
8 changed files with 367 additions and 88 deletions
|
@ -26,6 +26,11 @@ namespace Connector_HTTP{
|
|||
/// Needed for base64_encode function
|
||||
static const std::string base64_chars = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
|
||||
|
||||
/// Helper for base64_decode function
|
||||
static inline bool is_base64(unsigned char c) {
|
||||
return (isalnum(c) || (c == '+') || (c == '/'));
|
||||
}
|
||||
|
||||
/// Used to base64 encode data. Input is the plaintext as std::string, output is the encoded data as std::string.
|
||||
/// \param input Plaintext data to encode.
|
||||
/// \returns Base64 encoded data.
|
||||
|
@ -49,6 +54,38 @@ namespace Connector_HTTP{
|
|||
return ret;
|
||||
}//base64_encode
|
||||
|
||||
/// Used to base64 decode data. Input is the encoded data as std::string, output is the plaintext data as std::string.
|
||||
/// \param input Base64 encoded data to decode.
|
||||
/// \returns Plaintext decoded data.
|
||||
std::string base64_decode(std::string const& encoded_string) {
|
||||
int in_len = encoded_string.size();
|
||||
int i = 0;
|
||||
int j = 0;
|
||||
int in_ = 0;
|
||||
unsigned char char_array_4[4], char_array_3[3];
|
||||
std::string ret;
|
||||
while (in_len-- && ( encoded_string[in_] != '=') && is_base64(encoded_string[in_])) {
|
||||
char_array_4[i++] = encoded_string[in_]; in_++;
|
||||
if (i ==4) {
|
||||
for (i = 0; i <4; i++){char_array_4[i] = base64_chars.find(char_array_4[i]);}
|
||||
char_array_3[0] = (char_array_4[0] << 2) + ((char_array_4[1] & 0x30) >> 4);
|
||||
char_array_3[1] = ((char_array_4[1] & 0xf) << 4) + ((char_array_4[2] & 0x3c) >> 2);
|
||||
char_array_3[2] = ((char_array_4[2] & 0x3) << 6) + char_array_4[3];
|
||||
for (i = 0; (i < 3); i++){ret += char_array_3[i];}
|
||||
i = 0;
|
||||
}
|
||||
}
|
||||
if (i) {
|
||||
for (j = i; j <4; j++){char_array_4[j] = 0;}
|
||||
for (j = 0; j <4; j++){char_array_4[j] = base64_chars.find(char_array_4[j]);}
|
||||
char_array_3[0] = (char_array_4[0] << 2) + ((char_array_4[1] & 0x30) >> 4);
|
||||
char_array_3[1] = ((char_array_4[1] & 0xf) << 4) + ((char_array_4[2] & 0x3c) >> 2);
|
||||
char_array_3[2] = ((char_array_4[2] & 0x3) << 6) + char_array_4[3];
|
||||
for (j = 0; (j < i - 1); j++) ret += char_array_3[j];
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
/// Returns AMF-format metadata for Adobe HTTP Dynamic Streaming.
|
||||
std::string GetMetaData( ) {
|
||||
AMF::Object amfreply("container", AMF::AMF0_DDV_CONTAINER);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue