#include <image_util.h>
#define CTSVC_IMAGE_MAX_SIZE 1080
+#define CTSVC_IMAGE_THUMBNAIL_SIZE 96
+#define CTSVC_IMAGE_THUMBNAIL_SUFFIX "_thumbnail"
#define CTSVC_IMAGE_ENCODE_QUALITY 50
int ctsvc_image_util_get_mimetype(image_util_colorspace_e colorspace, int *p_mimetype);
unsigned char **image, unsigned int *image_size)
{
int ret;
- vcard_image_info info = {.src = src, .image = image, .image_size = image_size, ret = CONTACTS_ERROR_SYSTEM};
+ vcard_image_info info = {src, image, image_size, CONTACTS_ERROR_SYSTEM};
ret = image_util_foreach_supported_jpeg_colorspace(
_ctsvc_vcard_image_util_supported_jpeg_colorspace_cb, &info);
Name: contacts-service
Summary: Contacts Service
-Version: 0.13.51
+Version: 0.13.52
Release: 0
Group: Social & Content/Service
License: Apache-2.0
#include "ctsvc_server_setting.h"
#include "ctsvc_list.h"
#include "ctsvc_localize.h"
+#include "ctsvc_db_plugin_image_helper.h"
#ifdef ENABLE_LOG_FEATURE
#include "ctsvc_server_phonelog.h"
cts_stmt stmt;
char *image_path;
char query[CTS_SQL_MAX_LEN] = {0};
+ char *thumbnail_path;
ret = ctsvc_begin_trans();
RETVM_IF(ret < CONTACTS_ERROR_NONE, ret, "ctsvc_begin_trans() Fail(%d)", ret);
if (false == is_default) {
snprintf(query, sizeof(query),
"UPDATE "CTS_TABLE_DATA" SET is_default=0 WHERE datatype=%d AND is_my_profile = 0 "
- "AND contact_id = (SELECT contact_id FROM "CTS_TABLE_DATA" WHERE id=%d) ",
- CONTACTS_DATA_TYPE_IMAGE, id);
+ "AND contact_id = %d ", CONTACTS_DATA_TYPE_IMAGE, contact_id);
ret = ctsvc_query_exec(query);
if (CONTACTS_ERROR_NONE != ret) {
ctsvc_end_trans(false);
return ret;
}
+
+ thumbnail_path = ctsvc_utils_make_thumbnail(image_path);
+ } else {
+ thumbnail_path = ctsvc_utils_get_thumbnail_path(image_path);
}
+ free(image_path);
+
/* set is_default, is _primary_default */
snprintf(query, sizeof(query),
"UPDATE "CTS_TABLE_DATA" SET is_primary_default=1, is_default=1 WHERE id=%d ", id);
ret = ctsvc_query_exec(query);
if (CONTACTS_ERROR_NONE != ret) {
ERR("ctsvc_query_exec() Fail(%d)", ret);
- free(image_path);
+ free(thumbnail_path);
ctsvc_end_trans(false);
return ret;
}
ret = ctsvc_query_prepare(query, &stmt);
if (NULL == stmt) {
ERR("ctsvc_query_prepare() Fail(%d)", ret);
- free(image_path);
+ free(thumbnail_path);
ctsvc_end_trans(false);
return ret;
}
- ctsvc_stmt_bind_text(stmt, 1, image_path);
+ ctsvc_stmt_bind_text(stmt, 1, thumbnail_path);
ret = ctsvc_stmt_step(stmt);
if (CONTACTS_ERROR_NONE != ret) {
ERR("ctsvc_stmt_step() Fail(%d)", ret);
ctsvc_stmt_finalize(stmt);
- free(image_path);
+ free(thumbnail_path);
ctsvc_end_trans(false);
return ret;
}
ctsvc_stmt_finalize(stmt);
/* update contact's image_thumbnail_path */
- snprintf(query, sizeof(query),
- "UPDATE "CTS_TABLE_CONTACTS" SET image_thumbnail_path=? WHERE contact_id=%d ", contact_id);
- ret = ctsvc_query_prepare(query, &stmt);
- if (NULL == stmt) {
- ERR("ctsvc_query_prepare() Fail(%d)", ret);
- free(image_path);
- ctsvc_end_trans(false);
- return ret;
- }
+ if (false == is_default) {
+ snprintf(query, sizeof(query),
+ "UPDATE "CTS_TABLE_CONTACTS" SET image_thumbnail_path=? WHERE contact_id=%d ", contact_id);
+ ret = ctsvc_query_prepare(query, &stmt);
+ if (NULL == stmt) {
+ ERR("ctsvc_query_prepare() Fail(%d)", ret);
+ free(thumbnail_path);
+ ctsvc_end_trans(false);
+ return ret;
+ }
- ctsvc_stmt_bind_text(stmt, 1, image_path);
- ret = ctsvc_stmt_step(stmt);
- if (CONTACTS_ERROR_NONE != ret) {
- ERR("ctsvc_stmt_step() Fail(%d)", ret);
+ ctsvc_stmt_bind_text(stmt, 1, thumbnail_path);
+ ret = ctsvc_stmt_step(stmt);
+ if (CONTACTS_ERROR_NONE != ret) {
+ ERR("ctsvc_stmt_step() Fail(%d)", ret);
+ ctsvc_stmt_finalize(stmt);
+ free(thumbnail_path);
+ ctsvc_end_trans(false);
+ return ret;
+ }
ctsvc_stmt_finalize(stmt);
- free(image_path);
- ctsvc_end_trans(false);
- return ret;
}
- ctsvc_stmt_finalize(stmt);
- free(image_path);
+ free(thumbnail_path);
ret = ctsvc_end_trans(true);
return ret;
/* check image_thumbnail_path */
if (person->image_thumbnail_path) {
- temp = __ctsvc_get_image_filename(person->image_thumbnail_path);
+ char *image_path = NULL;
+
+ image_path = ctsvc_utils_get_image_path(person->image_thumbnail_path);
snprintf(query, sizeof(query),
"SELECT D.id FROM "CTS_TABLE_CONTACTS" C, "CTS_TABLE_DATA" D "
"WHERE C.person_id=%d AND C.contact_id=D.contact_id AND C.deleted = 0 "
"AND D.datatype=%d AND D.is_primary_default = 1 AND D.data3='%s'",
- person->person_id, CONTACTS_DATA_TYPE_IMAGE, temp);
+ person->person_id, CONTACTS_DATA_TYPE_IMAGE, image_path);
+ free(image_path);
ret = ctsvc_query_get_first_int_result(query, &id);
if (ret == CONTACTS_ERROR_NONE)
- image_thumbnail_path = SAFE_STRDUP(temp);
- } else {
- image_thumbnail_path = NULL;
+ image_thumbnail_path = SAFE_STRDUP(person->image_thumbnail_path);
}
/* check name_contact_id */
len += snprintf(addressbook_ids + len, addressbooks_len -len, "%d%s", addressbook_id, ADDRESSBOOK_ID_DELIM);
if (NULL == image_thumbnail_path && contact_image_thumbnail_path && *contact_image_thumbnail_path) {
- temp = __ctsvc_get_image_filename(contact_image_thumbnail_path);
- image_thumbnail_path = SAFE_STRDUP(temp);
- /* update data table : is_primary_default */
+ image_thumbnail_path = SAFE_STRDUP(contact_image_thumbnail_path);
+
+ /*update data table : is_primary_default */
+ ctsvc_db_image_set_primary_default(contact_id, image_thumbnail_path, true);
}
free(contact_image_thumbnail_path);
int ret = CONTACTS_ERROR_NONE;
int count = 0;
ctsvc_image_s *image;
+ char *contact_image_path = NULL;
contacts_list_get_count((contacts_list_h)contact->images, &count);
if (count) {
break;
} while (CONTACTS_ERROR_NONE == contacts_list_next((contacts_list_h)contact->images));
- if ((NULL == contact->image_thumbnail_path && image->path) ||
- (contact->image_thumbnail_path && NULL == image->path) ||
- (contact->image_thumbnail_path && image->path && (STRING_EQUAL != strcmp(contact->image_thumbnail_path, image->path)))) {
+ contact_image_path = ctsvc_utils_get_image_path(contact->image_thumbnail_path);
+
+ if ((NULL == contact_image_path && image->path) ||
+ (contact_image_path && NULL == image->path) ||
+ (contact_image_path && image->path && (STRING_EQUAL != strcmp(contact_image_path, image->path)))) {
ctsvc_record_set_property_flag((ctsvc_record_s*)contact, _contacts_contact.image_thumbnail_path, CTSVC_PROPERTY_FLAG_DIRTY);
- if (ctsvc_contact_check_image_location(image->path))
- contact->image_thumbnail_path = SAFE_STRDUP(image->path + strlen(CTSVC_CONTACT_IMG_FULL_LOCATION) + 1);
- else
- contact->image_thumbnail_path = SAFE_STRDUP(image->path);
+ if (image->path)
+ contact->image_thumbnail_path = ctsvc_utils_make_thumbnail(image->path);
}
+ free(contact_image_path);
} else if (contact->image_thumbnail_path) {
free(contact->image_thumbnail_path);
contact->image_thumbnail_path = NULL;
}
if (image->path && image->is_default) {
- contact->image_thumbnail_path = strdup(image->path);
+ contact->image_thumbnail_path = ctsvc_utils_make_thumbnail(image->path);
break;
}
} while (CONTACTS_ERROR_NONE == contacts_list_next((contacts_list_h)contact->images));
int ret = CONTACTS_ERROR_NONE;
int count = 0;
ctsvc_image_s *image;
+ char *contact_image_path = NULL;
contacts_list_get_count((contacts_list_h)contact->images, &count);
if (count) {
break;
} while (CONTACTS_ERROR_NONE == contacts_list_next((contacts_list_h)contact->images));
- if ((NULL == contact->image_thumbnail_path && image->path) ||
- (contact->image_thumbnail_path && NULL == image->path) ||
- (contact->image_thumbnail_path && image->path && STRING_EQUAL != strcmp(contact->image_thumbnail_path, image->path))) {
+ contact_image_path = ctsvc_utils_get_image_path(contact->image_thumbnail_path);
+ if ((NULL == contact_image_path && image->path) ||
+ (contact_image_path && NULL == image->path) ||
+ (contact_image_path && image->path && STRING_EQUAL != strcmp(contact_image_path, image->path))) {
ctsvc_record_set_property_flag((ctsvc_record_s*)contact, _contacts_contact.image_thumbnail_path, CTSVC_PROPERTY_FLAG_DIRTY);
- if (ctsvc_contact_check_image_location(image->path))
- contact->image_thumbnail_path = SAFE_STRDUP(image->path + strlen(CTSVC_CONTACT_IMG_FULL_LOCATION) + 1);
- else
- contact->image_thumbnail_path = SAFE_STRDUP(image->path);
+ if (image->path)
+ contact->image_thumbnail_path = ctsvc_utils_make_thumbnail(image->path);
}
+ free(contact_image_path);
} else if (contact->image_thumbnail_path) {
free(contact->image_thumbnail_path);
contact->image_thumbnail_path = NULL;
{
int ret;
char dest[CTSVC_IMG_FULL_PATH_SIZE_MAX] = {0};
+ char *thumbnail_path = NULL;
ret = __ctsvc_contact_get_current_image_file(img_id, dest, sizeof(dest));
ret = unlink(dest);
if (ret < 0)
WARN("unlink() Fail(%d)", errno);
+
+ /* remove thumbnail */
+ thumbnail_path = ctsvc_utils_get_thumbnail_path(dest);
+ if (thumbnail_path && 0 == access(thumbnail_path, F_OK)) {
+ ret = unlink(thumbnail_path);
+ if (ret < 0)
+ WARN("unlink() Fail(%d)", errno);
+ }
+ free(thumbnail_path);
}
if (src_img) {
if (image_path) {
char full_path[CTSVC_IMG_FULL_PATH_SIZE_MAX] = {0};
+ char *thumbnail_path = NULL;
snprintf(full_path, sizeof(full_path), "%s/%s", CTSVC_CONTACT_IMG_FULL_LOCATION, image_path);
ret = unlink(full_path);
if (ret < 0)
WARN("unlink() Fail(%d)", errno);
+
+ /* remove thumbnail */
+ thumbnail_path = ctsvc_utils_get_thumbnail_path(full_path);
+ if (thumbnail_path && 0 == access(thumbnail_path, F_OK)) {
+ ret = unlink(thumbnail_path);
+ if (ret < 0)
+ WARN("unlink() Fail(%d)", errno);
+ }
+ free(thumbnail_path);
}
return CONTACTS_ERROR_NONE;
return ret;
}
-static int __ctsvc_db_image_get_primary_default_image_id(int person_id)
+static int __ctsvc_db_image_get_primary_default_image_id(int person_id, int *image_id, char** image_path)
{
int ret;
- int default_image_id;
+ cts_stmt stmt;
char query[CTS_SQL_MAX_LEN] = {0};
snprintf(query, sizeof(query),
- "SELECT id FROM "CTS_TABLE_CONTACTS" c, "CTS_TABLE_DATA" d "
+ "SELECT id d.data3 FROM "CTS_TABLE_CONTACTS" c, "CTS_TABLE_DATA" d "
"WHERE c.person_id = %d AND d.datatype = %d AND c.contact_id = d.contact_id AND d.is_default = 1",
person_id, CONTACTS_DATA_TYPE_IMAGE);
- ret = ctsvc_query_get_first_int_result(query, &default_image_id);
- if (CONTACTS_ERROR_NONE != ret)
- return 0;
- return default_image_id;
+
+ ret = ctsvc_query_prepare(query, &stmt);
+ if (NULL == stmt) {
+ ERR("ctsvc_query_prepare() Fail(%d)", ret);
+ return ret;
+ }
+
+ ret = ctsvc_stmt_step(stmt);
+ if (1 != ret) {
+ ERR("ctsvc_stmt_step() Fail(%d)", ret);
+ ctsvc_stmt_finalize(stmt);
+ if (ret == CONTACTS_ERROR_NONE)
+ return CONTACTS_ERROR_NO_DATA;
+ else
+ return ret;
+ }
+
+ *image_id = ctsvc_stmt_get_int(stmt, 0);
+ *image_path = ctsvc_stmt_get_text(stmt, 1);
+ ctsvc_stmt_finalize(stmt);
+
+ return CONTACTS_ERROR_NONE;
}
static int __ctsvc_db_image_get_primary_default_contact_id(int person_id)
return default_contact_id;
}
-static int __ctsvc_db_image_update_contact_image(int contact_id, const char *image_path)
+static int __ctsvc_db_image_update_contact_image(int contact_id, const char *image_thumbnail_path)
{
int ret;
char query[CTS_SQL_MAX_LEN] = {0};
ret = ctsvc_query_prepare(query, &stmt);
RETVM_IF(NULL == stmt, ret, "ctsvc_query_prepare() Fail(%d)", ret);
- if (image_path)
- ctsvc_stmt_bind_text(stmt, 1, image_path);
+ if (image_thumbnail_path)
+ ctsvc_stmt_bind_text(stmt, 1, image_thumbnail_path);
ret = ctsvc_stmt_step(stmt);
WARN_IF(CONTACTS_ERROR_NONE != ret, "ctsvc_stmt_step() Fail(%d)", ret);
return ret;
}
-static int __ctsvc_db_image_update_person_image(int person_id, const char *image_path)
+static int __ctsvc_db_image_update_person_image(int person_id, const char *image_thumbnail_path)
{
int ret;
char query[CTS_SQL_MAX_LEN] = {0};
ret = ctsvc_query_prepare(query, &stmt);
RETVM_IF(NULL == stmt, ret, "ctsvc_query_prepare() Fail(%d)", ret);
- if (image_path)
- ctsvc_stmt_bind_text(stmt, 1, image_path);
+ if (image_thumbnail_path)
+ ctsvc_stmt_bind_text(stmt, 1, image_thumbnail_path);
ret = ctsvc_stmt_step(stmt);
WARN_IF(CONTACTS_ERROR_NONE != ret, "ctsvc_stmt_step() Fail(%d)", ret);
char query[CTS_SQL_MAX_LEN] = {0};
ctsvc_image_s *image = (ctsvc_image_s*)record;
cts_stmt stmt = NULL;
+ char *thumbnail_path = NULL;
RETV_IF(NULL == image->path, CONTACTS_ERROR_INVALID_PARAMETER);
ret = ctsvc_query_prepare(query, &stmt);
RETVM_IF(NULL == stmt, ret, "ctsvc_query_prepare() Fail(%d)", ret);
- if (image->is_default)
- ctsvc_stmt_bind_text(stmt, 1, image->path);
-
+ if (image->is_default) {
+ thumbnail_path = ctsvc_utils_make_thumbnail(image->path);
+ if (thumbnail_path)
+ ctsvc_stmt_bind_text(stmt, 1, thumbnail_path);
+ }
ret = ctsvc_stmt_step(stmt);
WARN_IF(CONTACTS_ERROR_NONE != ret, "ctsvc_stmt_step() Fail(%d)", ret);
ctsvc_stmt_finalize(stmt);
if (image->is_default) {
int primary_default_contact_id;
-
+ __ctsvc_db_image_update_contact_image(image->contact_id, thumbnail_path);
primary_default_contact_id = __ctsvc_db_image_get_primary_default_contact_id(person_id);
if (primary_default_contact_id == 0 || primary_default_contact_id == image->contact_id) {
__ctsvc_db_image_set_primary_default(*id, true);
- __ctsvc_db_image_update_person_image(person_id, image->path);
+ __ctsvc_db_image_update_person_image(person_id, thumbnail_path);
}
}
+ free(thumbnail_path);
ctsvc_set_contact_noti();
ctsvc_set_person_noti();
char query[CTS_SQL_MAX_LEN] = {0};
ctsvc_image_s *image = (ctsvc_image_s*)record;
cts_stmt stmt = NULL;
+ char *thumbnail_path = NULL;
+
RETVM_IF(NULL == image->path, CONTACTS_ERROR_INVALID_PARAMETER, "path is empty");
ret = ctsvc_begin_trans();
ret = ctsvc_query_prepare(query, &stmt);
RETVM_IF(NULL == stmt, ret, "ctsvc_query_prepare() Fail(%d)", ret);
- if (image->is_default)
- ctsvc_stmt_bind_text(stmt, 1, image->path);
+ if (image->is_default) {
+ thumbnail_path = ctsvc_utils_make_thumbnail(image->path);
+ ctsvc_stmt_bind_text(stmt, 1, thumbnail_path);
+ }
ret = ctsvc_stmt_step(stmt);
WARN_IF(CONTACTS_ERROR_NONE != ret, "ctsvc_stmt_step() Fail(%d)", ret);
if (image->is_default) {
int primary_default_contact_id;
- primary_default_contact_id = __ctsvc_db_image_get_primary_default_contact_id(image->contact_id);
- if (image->contact_id == primary_default_contact_id) {
+ __ctsvc_db_image_update_contact_image(image->contact_id, thumbnail_path);
+ primary_default_contact_id = __ctsvc_db_image_get_primary_default_contact_id(person_id);
+ if (primary_default_contact_id == image->contact_id) {
__ctsvc_db_image_set_primary_default(image->id, true);
- __ctsvc_db_image_update_person_image(person_id, image->path);
+ __ctsvc_db_image_update_person_image(person_id, thumbnail_path);
}
}
+ free(thumbnail_path);
ctsvc_set_contact_noti();
ctsvc_set_person_noti();
{
int ret;
int version;
- int image_id;
+ int image_id = 0;
int contact_id;
int person_id;
int is_default;
}
if (is_default) {
- snprintf(query, sizeof(query),
- "SELECT id FROM "CTS_TABLE_DATA" WHERE datatype = %d AND contact_id = %d AND is_my_profile = 0 limit 1",
- CONTACTS_DATA_TYPE_IMAGE, contact_id);
- ret = ctsvc_query_get_first_int_result(query, &image_id);
+ char *image_path = NULL;
+ char *thumbnail_path = NULL;
+
+ //TODO : make function
+ do {
+ snprintf(query, sizeof(query),
+ "SELECT id data3 FROM "CTS_TABLE_DATA" WHERE datatype = %d AND contact_id = %d AND is_my_profile = 0 limit 1",
+ CONTACTS_DATA_TYPE_IMAGE, contact_id);
+
+ ret = ctsvc_query_prepare(query, &stmt);
+ if (NULL == stmt) {
+ ERR("ctsvc_query_prepare() Fail(%d)", ret);
+ break;
+ }
+
+ ret = ctsvc_stmt_step(stmt);
+ if (1 != ret) {
+ ERR("ctsvc_stmt_step() Fail(%d)", ret);
+ ctsvc_stmt_finalize(stmt);
+ break;
+ }
+
+ image_id = ctsvc_stmt_get_int(stmt, 0);
+ image_path = ctsvc_stmt_get_text(stmt, 1);
+ ctsvc_stmt_finalize(stmt);
+ } while (0);
- if (image_id) {
+ if (0 != image_id && NULL != image_path) {
__ctsvc_db_image_set_default(image_id, contact_id, is_default, is_primary_default);
+ thumbnail_path = ctsvc_utils_make_thumbnail(image_path);
+ __ctsvc_db_image_update_contact_image(contact_id, thumbnail_path);
+
+ if (is_primary_default)
+ __ctsvc_db_image_update_person_image(person_id, thumbnail_path);
} else {
__ctsvc_db_image_update_contact_image(contact_id, NULL);
+
if (is_primary_default) {
- int default_img_id = 0;
- default_img_id = __ctsvc_db_image_get_primary_default_image_id(person_id);
- if (default_img_id)
- __ctsvc_db_image_set_primary_default(default_img_id, true);
- else
+ image_id = 0;
+ image_path = NULL;
+ ret = __ctsvc_db_image_get_primary_default_image_id(person_id, &image_id, &image_path);
+ if (CONTACTS_ERROR_NONE == ret && 0 != image_id && NULL != image_path) {
+ __ctsvc_db_image_set_primary_default(image_id, true);
+ thumbnail_path = ctsvc_utils_get_thumbnail_path(image_path);
+ __ctsvc_db_image_update_person_image(person_id, thumbnail_path);
+ } else {
__ctsvc_db_image_update_person_image(person_id, NULL);
+ }
}
}
+ free(thumbnail_path);
}
ctsvc_set_contact_noti();
#include "ctsvc_notification.h"
#include "ctsvc_db_access_control.h"
#include "ctsvc_notify.h"
+#include "ctsvc_db_utils.h"
int ctsvc_db_image_get_value_from_stmt(cts_stmt stmt, contacts_record_h *record,
int start_count)
return;
}
+int ctsvc_db_image_set_primary_default(int contact_id, const char *image_thumbnail_path,
+ bool is_primary_default)
+{
+ int ret;
+ char *image_path = NULL;
+ char query[CTS_SQL_MAX_LEN] = {0};
+
+ RETV_IF(contact_id <= 0, CONTACTS_ERROR_INVALID_PARAMETER);
+ RETV_IF(NULL == image_thumbnail_path, CONTACTS_ERROR_INVALID_PARAMETER);
+
+ image_path = ctsvc_utils_get_image_path(image_thumbnail_path);
+
+ if (NULL == image_path) {
+ ERR("ctsvc_utils_get_image_path() Fail");
+ return CONTACTS_ERROR_INTERNAL;
+ }
+
+ snprintf(query, sizeof(query),
+ "UPDATE "CTS_TABLE_DATA" SET is_primary_default = %d WHERE contact_id = %d AND datatype = %d AND data3 = %s",
+ is_primary_default, contact_id, CONTACTS_DATA_TYPE_IMAGE, image_path);
+
+ free(image_path);
+ ret = ctsvc_query_exec(query);
+ WARN_IF(CONTACTS_ERROR_NONE != ret, "ctsvc_query_exec() Fail(%d)", ret);
+ return ret;
+}
int start_count);
void ctsvc_db_image_delete_callback(sqlite3_context *context, int argc,
sqlite3_value **argv);
+int ctsvc_db_image_set_primary_default(int contact_id, const char *image_thumbnail_path,
+ bool is_primary_default);
#endif /* __CTSVC_DB_PLUGIN_RELATIONSHIP_HELPER_H__ */
cts_stmt stmt = NULL;
char query[CTS_SQL_MIN_LEN] = {0};
char *temp = NULL;
- char *image_thumbnail_path = NULL;
+ char *image_path = NULL;
snprintf(query, sizeof(query),
"SELECT D.id FROM "CTS_TABLE_CONTACTS" C, "CTS_TABLE_DATA" D "
ctsvc_stmt_finalize(stmt);
return ret;
}
- temp = ctsvc_stmt_get_text(stmt, 1);
- image_thumbnail_path = SAFE_STRDUP(temp);
+
+ if (CONTACTS_DATA_TYPE_IMAGE == datatype) {
+ temp = ctsvc_stmt_get_text(stmt, 1);
+ image_path = SAFE_STRDUP(temp);
+ }
}
ctsvc_stmt_finalize(stmt);
if (CONTACTS_DATA_TYPE_IMAGE == datatype) {
- if (image_thumbnail_path) {
+ if (image_path) {
+ char *thumbnail_path = NULL;
+
snprintf(query, sizeof(query),
"UPDATE "CTS_TABLE_PERSONS" SET image_thumbnail_path=? WHERE person_id=%d", person_id);
ret = ctsvc_query_prepare(query, &stmt);
RETVM_IF(NULL == stmt, ret, "ctsvc_query_prepare() Fail(%d)", ret);
- ctsvc_stmt_bind_text(stmt, 1, image_thumbnail_path);
+ thumbnail_path = ctsvc_utils_get_thumbnail_path(image_path);
+ ctsvc_stmt_bind_text(stmt, 1, thumbnail_path);
ret = ctsvc_stmt_step(stmt);
ctsvc_stmt_finalize(stmt);
- free(image_thumbnail_path);
+ free(image_path);
+ free(thumbnail_path);
if (CONTACTS_ERROR_NONE != ret) {
ERR("ctsvc_stmt_step() Fail(%d)", ret);
return ret;
}
}
- } else {
- free(image_thumbnail_path);
}
}
free(lower_ext);
}
-static inline bool ctsvc_check_available_image_space(void)
+static inline bool _ctsvc_check_available_image_space(int need_size)
{
int ret;
struct statfs buf;
size = (long long)buf.f_bavail * (buf.f_bsize);
- if (1024*1024 < size) /* if available space to copy a image is larger than 1M */
+ if (need_size < size) /* if available space to copy a image is larger than need_size */
return true;
return false;
}
typedef struct {
const char *src;
const char *dest;
+ int max_size;
int ret;
} image_info;
buffer = buffer_temp;
}
- if (CTSVC_IMAGE_MAX_SIZE < width || CTSVC_IMAGE_MAX_SIZE < height) { /* need resize */
+ if (info->max_size < width || info->max_size < height) { /* need resize */
int resized_width;
int resized_height;
media_format_h fmt;
/* set resize */
if (width > height) {
- resized_width = CTSVC_IMAGE_MAX_SIZE;
- resized_height = height * CTSVC_IMAGE_MAX_SIZE / width;
+ resized_width = info->max_size;
+ resized_height = height * info->max_size / width;
} else {
- resized_height = CTSVC_IMAGE_MAX_SIZE;
- resized_width = width * CTSVC_IMAGE_MAX_SIZE / height;
+ resized_height = info->max_size;
+ resized_width = width * info->max_size / height;
}
if (resized_height % 8)
return false;
}
-static int _ctsvc_image_encode(const char *src, const char *dest)
+static int _ctsvc_image_encode(const char *src, const char *dest, int max_size)
{
int ret;
- image_info info = {.src = src, .dest = dest, ret = CONTACTS_ERROR_SYSTEM};
+ image_info info = {src, dest, max_size, CONTACTS_ERROR_SYSTEM};
ret = image_util_foreach_supported_jpeg_colorspace(
_ctsvc_image_util_supported_jpeg_colorspace_cb, &info);
char dest[strlen(dir) + strlen(file) + 2];
snprintf(dest, sizeof(dest), "%s/%s", dir, file);
- if (false == ctsvc_check_available_image_space())
+ if (false == _ctsvc_check_available_image_space(1204 * 1204)) /*need larger than 1M*/
return CONTACTS_ERROR_FILE_NO_SPACE;
- ret = _ctsvc_image_encode(src, dest);
+ ret = _ctsvc_image_encode(src, dest, CTSVC_IMAGE_MAX_SIZE);
if (CONTACTS_ERROR_NONE == ret)
return ret;
else
return CONTACTS_ERROR_NONE;
}
+char* ctsvc_utils_get_thumbnail_path(const char *image_path)
+{
+ int name_len = 0;
+ int full_len = 0;
+ char *thumbnail_path = NULL;
+ char *ext = NULL;
+
+ RETV_IF(NULL == image_path, NULL);
+ RETV_IF(NULL != strstr(image_path, CTSVC_IMAGE_THUMBNAIL_SUFFIX), NULL);
+
+ full_len = strlen(image_path) + strlen(CTSVC_IMAGE_THUMBNAIL_SUFFIX) + 1;
+ thumbnail_path = calloc(1, full_len);
+ if (NULL == thumbnail_path) {
+ ERR("calloc() Fail");
+ return NULL;
+ }
+
+ ext = strrchr(image_path, '.');
+ if (ext) {
+ name_len = ext -image_path;
+ strncpy(thumbnail_path, image_path, name_len);
+ snprintf(thumbnail_path+name_len, full_len-name_len, "%s%s", CTSVC_IMAGE_THUMBNAIL_SUFFIX, ext);
+ } else {
+ snprintf(thumbnail_path, full_len, "%s%s", image_path, CTSVC_IMAGE_THUMBNAIL_SUFFIX);
+ }
+
+ return thumbnail_path;
+}
+
+char* ctsvc_utils_get_image_path(const char *thumbnail_path)
+{
+ int name_len = 0;
+ int full_len = 0;
+ char *image_path = NULL;
+ char *ext = NULL;
+
+ RETV_IF(NULL == thumbnail_path, NULL);
+ RETV_IF(NULL == strstr(thumbnail_path, CTSVC_IMAGE_THUMBNAIL_SUFFIX), NULL);
+
+ full_len = strlen(thumbnail_path) - strlen(CTSVC_IMAGE_THUMBNAIL_SUFFIX) + 1;
+ image_path = calloc(1, full_len);
+ if (NULL == image_path) {
+ ERR("calloc() Fail");
+ return NULL;
+ }
+
+ ext = strrchr(thumbnail_path, '.');
+ if (ext) {
+ name_len = ext -thumbnail_path - strlen(CTSVC_IMAGE_THUMBNAIL_SUFFIX);
+ strncpy(image_path, thumbnail_path, name_len);
+ snprintf(image_path + name_len, full_len -name_len, "%s", ext);
+ } else {
+ name_len = strlen(thumbnail_path) - strlen(CTSVC_IMAGE_THUMBNAIL_SUFFIX);
+ strncpy(image_path, thumbnail_path, name_len);
+ }
+ return image_path;
+}
+
+char* ctsvc_utils_make_thumbnail(const char *image_path)
+{
+ int ret;
+ char src[CTSVC_IMG_FULL_PATH_SIZE_MAX] = {0};
+ char dest[CTSVC_IMG_FULL_PATH_SIZE_MAX] = {0};
+ char *thumbnail_path = NULL;
+
+ RETV_IF(NULL == image_path, NULL);
+ RETV_IF(NULL != strstr(image_path, CTSVC_IMAGE_THUMBNAIL_SUFFIX), NULL);
+
+ if (false == _ctsvc_check_available_image_space(
+ CTSVC_IMAGE_THUMBNAIL_SIZE * CTSVC_IMAGE_THUMBNAIL_SIZE)) {
+ ERR("No space to make thumbnail");
+ return NULL;
+ }
+
+ thumbnail_path = ctsvc_utils_get_thumbnail_path(image_path);
+ if (NULL == thumbnail_path) {
+ ERR("ctsvc_image_util_get_thumbnail_path() Fail");
+ return NULL;
+ }
+
+ if (0 == access(dest, F_OK)) {
+ DBG("already exist");
+ return thumbnail_path;
+ }
+
+ snprintf(src, sizeof(src), "%s/%s", CTSVC_CONTACT_IMG_FULL_LOCATION, image_path);
+ snprintf(dest, sizeof(dest), "%s/%s", CTSVC_CONTACT_IMG_FULL_LOCATION, thumbnail_path);
+
+ ret = _ctsvc_image_encode(src, dest, CTSVC_IMAGE_THUMBNAIL_SIZE);
+ if (CONTACTS_ERROR_NONE != ret) {
+ ERR("_ctsvc_image_encode() Fail(%d)", ret);
+ free(thumbnail_path);
+ return NULL;
+ }
+
+ return strdup(thumbnail_path);
+}
+
int ctsvc_get_next_ver(void)
{
const char *query;
int ctsvc_utils_copy_image(const char *dir, const char *src, const char *file);
void ctsvc_utils_make_image_file_name(int parent_id, int id, char *src_img, char *dest,
int dest_size);
+char* ctsvc_utils_get_thumbnail_path(const char *image_path);
+char* ctsvc_utils_get_image_path(const char *thumbnail_path);
+char* ctsvc_utils_make_thumbnail(const char *image_path);
int SAFE_SNPRINTF(char **buf, int *buf_size, int len, const char *src);