mirror of https://github.com/kiwix/libkiwix.git
base64_encode takes a string instead of a char*
This commit is contained in:
parent
66a9a69480
commit
c7f9218350
|
@ -1,4 +1,4 @@
|
||||||
#include <string>
|
#include <string>
|
||||||
|
|
||||||
std::string base64_encode(unsigned char const* , unsigned int len);
|
std::string base64_encode(const std::string& inString);
|
||||||
std::string base64_decode(std::string const& s);
|
std::string base64_decode(const std::string& s);
|
||||||
|
|
|
@ -163,8 +163,7 @@ Java_org_kiwix_kiwixlib_JNIKiwixReader_getFavicon(JNIEnv* env, jobject obj)
|
||||||
std::string cMime;
|
std::string cMime;
|
||||||
READER->getFavicon(cContent, cMime);
|
READER->getFavicon(cContent, cMime);
|
||||||
favicon = c2jni(
|
favicon = c2jni(
|
||||||
base64_encode(reinterpret_cast<const unsigned char*>(cContent.c_str()),
|
base64_encode(cContent),
|
||||||
cContent.length()),
|
|
||||||
env);
|
env);
|
||||||
} catch (std::exception& e) {
|
} catch (std::exception& e) {
|
||||||
__android_log_print(ANDROID_LOG_ERROR, "kiwix", "Unable to get ZIM favicon");
|
__android_log_print(ANDROID_LOG_ERROR, "kiwix", "Unable to get ZIM favicon");
|
||||||
|
|
|
@ -37,8 +37,10 @@ static inline bool is_base64(unsigned char c) {
|
||||||
return (isalnum(c) || (c == '+') || (c == '/'));
|
return (isalnum(c) || (c == '+') || (c == '/'));
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string base64_encode(unsigned char const* bytes_to_encode, unsigned int in_len) {
|
std::string base64_encode(const std::string& inString) {
|
||||||
std::string ret;
|
std::string ret;
|
||||||
|
auto in_len = inString.size();
|
||||||
|
const unsigned char* bytes_to_encode = reinterpret_cast<const unsigned char*>(inString.data());
|
||||||
int i = 0;
|
int i = 0;
|
||||||
int j = 0;
|
int j = 0;
|
||||||
unsigned char char_array_3[3];
|
unsigned char char_array_3[3];
|
||||||
|
|
|
@ -135,7 +135,7 @@ bool Manager::parseOpdsDom(const pugi::xml_document& doc, const std::string& url
|
||||||
auto fileHandle = downloader.download(faviconUrl);
|
auto fileHandle = downloader.download(faviconUrl);
|
||||||
if (fileHandle.success) {
|
if (fileHandle.success) {
|
||||||
auto content = getFileContent(fileHandle.path);
|
auto content = getFileContent(fileHandle.path);
|
||||||
book.setFavicon(base64_encode((const unsigned char*)content.data(), content.size()));
|
book.setFavicon(base64_encode(content));
|
||||||
book.setFaviconMimeType(linkNode.attribute("type").value());
|
book.setFaviconMimeType(linkNode.attribute("type").value());
|
||||||
} else {
|
} else {
|
||||||
std::cerr << "Cannot get favicon content from " << faviconUrl << std::endl;
|
std::cerr << "Cannot get favicon content from " << faviconUrl << std::endl;
|
||||||
|
|
Loading…
Reference in New Issue