Libpurple: Show more error messages when something goes wrong during PURPLE_IMAGE handling
This commit is contained in:
parent
5dd1aa90b4
commit
cb26fb0258
1 changed files with 8 additions and 1 deletions
|
@ -1182,21 +1182,28 @@ static void conv_write_im(PurpleConversation *conv, const char *who, const char
|
||||||
std::string name;
|
std::string name;
|
||||||
guchar * data = (guchar *) purple_imgstore_get_data_wrapped(image);
|
guchar * data = (guchar *) purple_imgstore_get_data_wrapped(image);
|
||||||
size_t len = purple_imgstore_get_size_wrapped(image);
|
size_t len = purple_imgstore_get_size_wrapped(image);
|
||||||
if (len < 300000 && data) {
|
if (len < 1000000 && data) {
|
||||||
ext = purple_imgstore_get_extension(image);
|
ext = purple_imgstore_get_extension(image);
|
||||||
char *hash = calculate_data_hash(data, len, "sha1");
|
char *hash = calculate_data_hash(data, len, "sha1");
|
||||||
if (!hash) {
|
if (!hash) {
|
||||||
|
LOG4CXX_WARN(logger, "Cannot compute hash for the image.");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
name = hash;
|
name = hash;
|
||||||
g_free(hash);
|
g_free(hash);
|
||||||
|
|
||||||
std::ofstream output;
|
std::ofstream output;
|
||||||
|
LOG4CXX_INFO(logger, "Storing image to " << std::string(CONFIG_STRING(config, "service.web_directory") + "/" + name + "." + ext));
|
||||||
output.open(std::string(CONFIG_STRING(config, "service.web_directory") + "/" + name + "." + ext).c_str(), std::ios::out | std::ios::binary);
|
output.open(std::string(CONFIG_STRING(config, "service.web_directory") + "/" + name + "." + ext).c_str(), std::ios::out | std::ios::binary);
|
||||||
|
if (output.fail()) {
|
||||||
|
LOG4CXX_ERROR(logger, "Open file failure: " << strerror(errno));
|
||||||
|
return;
|
||||||
|
}
|
||||||
output.write((char *)data, len);
|
output.write((char *)data, len);
|
||||||
output.close();
|
output.close();
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
|
LOG4CXX_WARN(logger, "Image bigger than 1MB.");
|
||||||
purple_imgstore_unref_wrapped(image);
|
purple_imgstore_unref_wrapped(image);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue