From c3b87f283a5a99ed8bac513c516bc5a184406391 Mon Sep 17 00:00:00 2001 From: Andrei Karas Date: Wed, 15 Jan 2014 01:16:34 +0300 Subject: add option for edit screenshot dir. --- src/utils/base64.cpp | 29 +++++++++++++++++++++++++++++ src/utils/base64.h | 14 ++++++++++---- 2 files changed, 39 insertions(+), 4 deletions(-) (limited to 'src/utils') diff --git a/src/utils/base64.cpp b/src/utils/base64.cpp index 280e71ff0..f887a9e1b 100644 --- a/src/utils/base64.cpp +++ b/src/utils/base64.cpp @@ -174,3 +174,32 @@ unsigned char *php3_base64_decode(const unsigned char *restrict const string, result[k] = '\0'; return result; } + +std::string encodeBase64String(std::string value) +{ + int sz = 0; + unsigned char *str = reinterpret_cast( + const_cast(value.c_str())); + unsigned char *const buf = php3_base64_encode(str, value.size(), &sz); + if (!buf) + return std::string(); + + value = std::string(reinterpret_cast(buf), sz); + free(buf); + return value; +} + +std::string decodeBase64String(std::string value) +{ + int sz = 0; + unsigned char *str = reinterpret_cast( + const_cast(value.c_str())); + unsigned char *const buf = php3_base64_decode(str, value.size(), &sz); + + if (buf) + value = std::string(reinterpret_cast(buf), sz); + else + value.clear(); + free(buf); + return value; +} diff --git a/src/utils/base64.h b/src/utils/base64.h index 0e6546df5..4518a3e5a 100644 --- a/src/utils/base64.h +++ b/src/utils/base64.h @@ -30,11 +30,17 @@ #ifndef UTILS_BASE64_H #define UTILS_BASE64_H +#include + #include "localconsts.h" -extern unsigned char *php3_base64_encode(const unsigned char *restrict, - int, int *restrict) A_WARN_UNUSED; -extern unsigned char *php3_base64_decode(const unsigned char *restrict, - int, int *restrict ) A_WARN_UNUSED; +unsigned char *php3_base64_encode(const unsigned char *restrict, + int, int *restrict) A_WARN_UNUSED; +unsigned char *php3_base64_decode(const unsigned char *restrict, + int, int *restrict ) A_WARN_UNUSED; + +std::string encodeBase64String(std::string value) A_WARN_UNUSED; + +std::string decodeBase64String(std::string value) A_WARN_UNUSED; #endif // UTILS_BASE64_H -- cgit v1.2.3-60-g2f50