From 943af2dba06dd58a22c33a67e7c394a750344bea Mon Sep 17 00:00:00 2001 From: Minje Ahn Date: Mon, 13 Nov 2017 16:36:34 +0900 Subject: [PATCH] Change face uuid to id Change-Id: Ia2073317f35c59b259e05aa3af32462017b4a995 Signed-off-by: Minje Ahn --- include/media_info_private.h | 27 +++++------ include_product/media_info.h | 9 ++-- include_product/media_info_private.h | 27 +++++------ packaging/capi-content-media-content.spec | 2 +- src/media_db.c | 6 +-- src/media_face.c | 76 +++++++++++++++++++++---------- 6 files changed, 83 insertions(+), 64 deletions(-) diff --git a/include/media_info_private.h b/include/media_info_private.h index d1c4fd6..f3d424f 100755 --- a/include/media_info_private.h +++ b/include/media_info_private.h @@ -347,7 +347,7 @@ typedef struct { } media_storage_s; typedef struct { - char *face_id; /* face uuid */ + int face_id; /* face id */ char *media_id; /* media uuid */ unsigned int face_rect_x; /* x position of face */ unsigned int face_rect_y; /* y position of face */ @@ -528,7 +528,7 @@ typedef struct _media_content_cb_data { #define DB_FIELD_STORAGE_PATH "storage_path" /* DB field for Face */ -#define DB_FIELD_FACE_ID "face_uuid" +#define DB_FIELD_FACE_ID "face_id" #define DB_FIELD_FACE_TAG "face_tag" /* DB Query Keyword */ @@ -545,12 +545,9 @@ typedef struct _media_content_cb_data { /* DB TABLE JOIN */ /*#define FOLDER_MEDIA_JOIN "("DB_TABLE_FOLDER" AS f LEFT OUTER JOIN '%s' AS m ON f.folder_uuid=m.folder_uuid AND m.validity=1) WHERE f.storage_uuid IN (SELECT storage_uuid FROM "DB_TABLE_STORAGE" WHERE validity=1) " */ #define FOLDER_MEDIA_JOIN "("DB_TABLE_FOLDER" AS f LEFT OUTER JOIN '%s' AS m ON f.folder_uuid=m.folder_uuid AND m.validity=1) WHERE f.validity=1 " -#define BOOKMARK_MEDIA_JOIN "("DB_TABLE_BOOKMARK" AS b INNER JOIN '%s' AS m \ - ON (b.media_uuid = m.media_uuid)) WHERE m.validity=1" -#define ALBUM_MEDIA_JOIN "("DB_TABLE_ALBUM" AS a INNER JOIN '%s' AS m \ - ON (a.album_id = m.album_id)) WHERE m.validity=1" -#define FACE_MEDIA_JOIN "("DB_TABLE_FACE" AS fa INNER JOIN '%s' AS m \ - ON (fa.media_uuid = m.media_uuid)) WHERE m.validity=1" +#define BOOKMARK_MEDIA_JOIN "("DB_TABLE_BOOKMARK" AS b INNER JOIN '%s' AS m ON (b.media_uuid = m.media_uuid)) WHERE m.validity=1" +#define ALBUM_MEDIA_JOIN "("DB_TABLE_ALBUM" AS a INNER JOIN '%s' AS m ON (a.album_id = m.album_id)) WHERE m.validity=1" +#define FACE_MEDIA_JOIN "("DB_TABLE_FACE" AS fa INNER JOIN '%s' AS m ON (fa.media_uuid = m.media_uuid)) WHERE m.validity=1" /* Get Group List */ #define SELECT_ALBUM_LIST "SELECT DISTINCT a.album_id, a.name, a.artist, a.album_art FROM "ALBUM_MEDIA_JOIN @@ -659,18 +656,18 @@ typedef struct _media_content_cb_data { #define SELECT_STORAGE_INFO_FROM_STORAGE "SELECT storage_uuid, storage_path, storage_type FROM "DB_TABLE_STORAGE" WHERE validity=1 AND storage_uuid='%s'" /* Face */ -#define DELETE_FACE_FROM_FACE "DELETE FROM "DB_TABLE_FACE" WHERE face_uuid='%q'" -#define INSERT_FACE_TO_FACE "INSERT INTO "DB_TABLE_FACE" (face_uuid, media_uuid, face_rect_x , face_rect_y, face_rect_w, face_rect_h, orientation, face_tag, user_marked) VALUES ('%q', '%q', %d, %d, %d, %d, %d, %Q, 1);" -#define UPDATE_FACE_TO_FACE "UPDATE "DB_TABLE_FACE" SET face_rect_x=%d, face_rect_y=%d, face_rect_w=%d, face_rect_h=%d, orientation=%d, face_tag=%Q WHERE face_uuid='%q'" +#define DELETE_FACE_FROM_FACE "DELETE FROM "DB_TABLE_FACE" WHERE face_id=%d" +#define INSERT_FACE_TO_FACE "INSERT INTO "DB_TABLE_FACE" (media_uuid, face_rect_x , face_rect_y, face_rect_w, face_rect_h, orientation, face_tag, user_marked) VALUES ('%q', %d, %d, %d, %d, %d, %Q, 1);" +#define UPDATE_FACE_TO_FACE "UPDATE "DB_TABLE_FACE" SET face_rect_x=%d, face_rect_y=%d, face_rect_w=%d, face_rect_h=%d, orientation=%d, face_tag=%Q WHERE face_id=%d" #define SELECT_MEDIA_COUNT_FROM_MEDIA_BY_ID "SELECT COUNT(*) FROM "DB_TABLE_MEDIA_VIEW" WHERE media_uuid='%q' AND validity=1" #define SELECT_FACE_COUNT "SELECT COUNT(*) FROM "FACE_MEDIA_JOIN #define SELECT_FACE_COUNT_BY_MEDIA_ID "SELECT COUNT(*) FROM "FACE_MEDIA_JOIN" AND fa.media_uuid='%s'" -#define SELECT_FACE_LIST "SELECT fa.face_uuid, fa.media_uuid, fa.face_rect_x, fa.face_rect_y, fa.face_rect_w, fa.face_rect_h, fa.orientation, fa.face_tag FROM "FACE_MEDIA_JOIN -#define SELECT_FACE_LIST_BY_MEDIA_ID "SELECT fa.face_uuid, fa.media_uuid, fa.face_rect_x, fa.face_rect_y, fa.face_rect_w, fa.face_rect_h, fa.orientation, fa.face_tag FROM "FACE_MEDIA_JOIN" AND fa.media_uuid='%s'" +#define SELECT_FACE_LIST "SELECT fa.face_id, fa.media_uuid, fa.face_rect_x, fa.face_rect_y, fa.face_rect_w, fa.face_rect_h, fa.orientation, fa.face_tag FROM "FACE_MEDIA_JOIN +#define SELECT_FACE_LIST_BY_MEDIA_ID "SELECT fa.face_id, fa.media_uuid, fa.face_rect_x, fa.face_rect_y, fa.face_rect_w, fa.face_rect_h, fa.orientation, fa.face_tag FROM "FACE_MEDIA_JOIN" AND fa.media_uuid='%s'" #define SELECT_FACE_PATH_FROM_MEDIA "SELECT path FROM "DB_TABLE_MEDIA_VIEW" media_uuid='%s'" -#define SELECT_MEDIA_FROM_FACE "SELECT media_uuid FROM "DB_TABLE_FACE" WHERE face_uuid='%q' AND user_marked = 0" +#define SELECT_MEDIA_FROM_FACE "SELECT media_uuid FROM "DB_TABLE_FACE" WHERE face_id=%d AND user_marked = 0" #define UPDATE_MEDIA_INFO_IN_FACE_SCAN_LIST "UPDATE "DB_TABLE_FACE_SCAN_LIST" SET modified_time = 0 WHERE media_uuid='%q'" - +#define SELECT_FACE_ID_USER_MARKED "SELECT face_id FROM "DB_TABLE_FACE" WHERE media_uuid='%q' AND face_rect_x=%d AND face_rect_y=%d AND face_rect_w=%d AND face_rect_h=%d AND orientation=%d AND user_marked=1" #define DEFAULT_MEDIA_STORAGE_ID "media" diff --git a/include_product/media_info.h b/include_product/media_info.h index 90543ee..cdd31b8 100755 --- a/include_product/media_info.h +++ b/include_product/media_info.h @@ -1621,7 +1621,9 @@ int media_info_move_to_db(media_info_h media, const char* dst_path); * @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif * * @privlevel public - * @privilege %http://tizen.org/privilege/content.write + * @privilege %http://tizen.org/privilege/content.write \n + * %http://tizen.org/privilege/mediastorage \n + * %http://tizen.org/privilege/externalstorage * * @remarks If you want to destroy media handle before callback invoked, you must cancel thumbnail request by using media_info_cancel_thumbnail() \n * Since 3.0, if creation of a thumbnail is failed, empty string will be passed through media_thumbnail_completed_cb(). @@ -1684,7 +1686,8 @@ int media_info_cancel_thumbnail(media_info_h media); * * @privlevel public * @privilege %http://tizen.org/privilege/content.write \n - * %http://tizen.org/privilege/mediastorage + * %http://tizen.org/privilege/mediastorage \n + * %http://tizen.org/privilege/externalstorage * * @remarks If you want to destroy the media handle before callback invoked, you must cancel the face detection request by using media_info_cancel_face_detection(). \n * If face detection fails, the @a face_count argument in media_face_detection_completed_cb() will be set to 0. @@ -1881,12 +1884,10 @@ int media_info_set_genre(media_info_h media, const char *genre) TIZEN_DEPRECATED */ int media_info_set_recorded_date(media_info_h media, const char *recorded_date) TIZEN_DEPRECATED_API; - /** * @} */ - #ifdef __cplusplus } #endif /* __cplusplus */ diff --git a/include_product/media_info_private.h b/include_product/media_info_private.h index 4676c33..1df829b 100755 --- a/include_product/media_info_private.h +++ b/include_product/media_info_private.h @@ -371,7 +371,7 @@ typedef struct { } media_storage_s; typedef struct { - char *face_id; /* face uuid */ + int face_id; /* face id */ char *media_id; /* media uuid */ unsigned int face_rect_x; /* x position of face */ unsigned int face_rect_y; /* y position of face */ @@ -631,7 +631,7 @@ typedef struct _media_content_scan_cb_data_v2 { #define DB_FIELD_STORAGE_PATH "storage_path" /* DB field for Face */ -#define DB_FIELD_FACE_ID "face_uuid" +#define DB_FIELD_FACE_ID "face_id" #define DB_FIELD_FACE_TAG "face_tag" /* DB field for PVR*/ @@ -700,12 +700,9 @@ typedef struct _media_content_scan_cb_data_v2 { /* DB TABLE JOIN */ /*#define FOLDER_MEDIA_JOIN "("DB_TABLE_FOLDER" AS f LEFT OUTER JOIN '%s' AS m ON f.folder_uuid=m.folder_uuid AND m.validity=1) WHERE f.storage_uuid IN (SELECT storage_uuid FROM "DB_TABLE_STORAGE" WHERE validity=1) " */ #define FOLDER_MEDIA_JOIN "("DB_TABLE_FOLDER" AS f LEFT OUTER JOIN '%s' AS m ON f.folder_uuid=m.folder_uuid AND m.validity=1) WHERE f.validity=1 " -#define BOOKMARK_MEDIA_JOIN "("DB_TABLE_BOOKMARK" AS b INNER JOIN '%s' AS m \ - ON (b.media_uuid = m.media_uuid)) WHERE m.validity=1" -#define ALBUM_MEDIA_JOIN "("DB_TABLE_ALBUM" AS a INNER JOIN '%s' AS m \ - ON (a.album_id = m.album_id)) WHERE m.validity=1" -#define FACE_MEDIA_JOIN "("DB_TABLE_FACE" AS fa INNER JOIN '%s' AS m \ - ON (fa.media_uuid = m.media_uuid)) WHERE m.validity=1" +#define BOOKMARK_MEDIA_JOIN "("DB_TABLE_BOOKMARK" AS b INNER JOIN '%s' AS m ON (b.media_uuid = m.media_uuid)) WHERE m.validity=1" +#define ALBUM_MEDIA_JOIN "("DB_TABLE_ALBUM" AS a INNER JOIN '%s' AS m ON (a.album_id = m.album_id)) WHERE m.validity=1" +#define FACE_MEDIA_JOIN "("DB_TABLE_FACE" AS fa INNER JOIN '%s' AS m ON (fa.media_uuid = m.media_uuid)) WHERE m.validity=1" /* Get Group info */ #define SELECT_MEDIA_GROUP_AND_COUNT "SELECT %s, COUNT(*) FROM '%s' WHERE validity=1 " @@ -829,18 +826,18 @@ typedef struct _media_content_scan_cb_data_v2 { #define SELECT_STORAGE_INFO_FROM_STORAGE "SELECT storage_uuid, storage_path, storage_type FROM "DB_TABLE_STORAGE" WHERE validity=1 AND storage_uuid='%s'" /* Face */ -#define DELETE_FACE_FROM_FACE "DELETE FROM "DB_TABLE_FACE" WHERE face_uuid='%q'" -#define INSERT_FACE_TO_FACE "INSERT INTO "DB_TABLE_FACE" (face_uuid, media_uuid, face_rect_x , face_rect_y, face_rect_w, face_rect_h, orientation, face_tag, user_marked) VALUES ('%q', '%q', %d, %d, %d, %d, %d, %Q, 1);" -#define UPDATE_FACE_TO_FACE "UPDATE "DB_TABLE_FACE" SET face_rect_x=%d, face_rect_y=%d, face_rect_w=%d, face_rect_h=%d, orientation=%d, face_tag=%Q WHERE face_uuid='%q'" +#define DELETE_FACE_FROM_FACE "DELETE FROM "DB_TABLE_FACE" WHERE face_id=%d" +#define INSERT_FACE_TO_FACE "INSERT INTO "DB_TABLE_FACE" (media_uuid, face_rect_x , face_rect_y, face_rect_w, face_rect_h, orientation, face_tag, user_marked) VALUES ('%q', %d, %d, %d, %d, %d, %Q, 1);" +#define UPDATE_FACE_TO_FACE "UPDATE "DB_TABLE_FACE" SET face_rect_x=%d, face_rect_y=%d, face_rect_w=%d, face_rect_h=%d, orientation=%d, face_tag=%Q WHERE face_id=%d" #define SELECT_MEDIA_COUNT_FROM_MEDIA_BY_ID "SELECT COUNT(*) FROM "DB_TABLE_MEDIA_VIEW" WHERE media_uuid='%q' AND validity=1" #define SELECT_FACE_COUNT "SELECT COUNT(*) FROM "FACE_MEDIA_JOIN #define SELECT_FACE_COUNT_BY_MEDIA_ID "SELECT COUNT(*) FROM "FACE_MEDIA_JOIN" AND fa.media_uuid='%s'" -#define SELECT_FACE_LIST "SELECT fa.face_uuid, fa.media_uuid, fa.face_rect_x, fa.face_rect_y, fa.face_rect_w, fa.face_rect_h, fa.orientation, fa.face_tag FROM "FACE_MEDIA_JOIN -#define SELECT_FACE_LIST_BY_MEDIA_ID "SELECT fa.face_uuid, fa.media_uuid, fa.face_rect_x, fa.face_rect_y, fa.face_rect_w, fa.face_rect_h, fa.orientation, fa.face_tag FROM "FACE_MEDIA_JOIN" AND fa.media_uuid='%s'" +#define SELECT_FACE_LIST "SELECT fa.face_id, fa.media_uuid, fa.face_rect_x, fa.face_rect_y, fa.face_rect_w, fa.face_rect_h, fa.orientation, fa.face_tag FROM "FACE_MEDIA_JOIN +#define SELECT_FACE_LIST_BY_MEDIA_ID "SELECT fa.face_id, fa.media_uuid, fa.face_rect_x, fa.face_rect_y, fa.face_rect_w, fa.face_rect_h, fa.orientation, fa.face_tag FROM "FACE_MEDIA_JOIN" AND fa.media_uuid='%s'" #define SELECT_FACE_PATH_FROM_MEDIA "SELECT path FROM "DB_TABLE_MEDIA_VIEW" media_uuid='%s'" -#define SELECT_MEDIA_FROM_FACE "SELECT media_uuid FROM "DB_TABLE_FACE" WHERE face_uuid='%q' AND user_marked = 0" +#define SELECT_MEDIA_FROM_FACE "SELECT media_uuid FROM "DB_TABLE_FACE" WHERE face_id=%d AND user_marked = 0" #define UPDATE_MEDIA_INFO_IN_FACE_SCAN_LIST "UPDATE "DB_TABLE_FACE_SCAN_LIST" SET modified_time = 0 WHERE media_uuid='%q'" - +#define SELECT_FACE_ID_USER_MARKED "SELECT face_id FROM "DB_TABLE_FACE" WHERE media_uuid='%q' AND face_rect_x=%d AND face_rect_y=%d AND face_rect_w=%d AND face_rect_h=%d AND orientation=%d AND user_marked=1" #define DEFAULT_MEDIA_STORAGE_ID "media" diff --git a/packaging/capi-content-media-content.spec b/packaging/capi-content-media-content.spec index 2ddd8c3..e10b316 100755 --- a/packaging/capi-content-media-content.spec +++ b/packaging/capi-content-media-content.spec @@ -1,6 +1,6 @@ Name: capi-content-media-content Summary: A Media content library in Tizen Native API -Version: 0.3.30 +Version: 0.3.31 Release: 0 Group: Multimedia/API License: Apache-2.0 diff --git a/src/media_db.c b/src/media_db.c index 438ce3b..aaa7b89 100755 --- a/src/media_db.c +++ b/src/media_db.c @@ -272,10 +272,6 @@ int _media_db_get_group_count(filter_h filter, group_list_e group_type, int *gro break; case MEDIA_GROUP_FOLDER: attr = _content_get_alias_attirbute_handle(); - if (!SAFE_STRLCPY(select_query, SELECT_FOLDER_COUNT, sizeof(select_query))) { - media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER); - return MEDIA_CONTENT_ERROR_INVALID_PARAMETER; - } if ((_filter != NULL) && STRING_VALID(_filter->storage_id)) snprintf(select_query, sizeof(select_query), SELECT_FOLDER_COUNT_BY_STORAGE_ID, _filter->storage_id, _filter->storage_id); @@ -925,7 +921,7 @@ int _media_db_get_face(const char *media_id, filter_h filter, media_face_cb call return MEDIA_CONTENT_ERROR_OUT_OF_MEMORY; } - face->face_id = g_strdup((const char *)sqlite3_column_text(stmt, 0)); + face->face_id = (int)sqlite3_column_int(stmt, 0); face->media_id = g_strdup((const char *)sqlite3_column_text(stmt, 1)); face->face_rect_x = (int)sqlite3_column_int(stmt, 2); face->face_rect_y = (int)sqlite3_column_int(stmt, 3); diff --git a/src/media_face.c b/src/media_face.c index d061112..a6bb244 100755 --- a/src/media_face.c +++ b/src/media_face.c @@ -17,6 +17,8 @@ #include +#define MAX_SIZE 16 + static int __media_face_check_media_id(const char *media_id) { int ret = MEDIA_CONTENT_ERROR_NONE; @@ -47,7 +49,6 @@ int media_face_destroy(media_face_h face) media_content_retvm_if(face == NULL, MEDIA_CONTENT_ERROR_INVALID_PARAMETER, "Invalid handle"); - SAFE_FREE(_face->face_id); SAFE_FREE(_face->media_id); SAFE_FREE(_face->face_tag); SAFE_FREE(_face); @@ -64,15 +65,6 @@ int media_face_clone(media_face_h *dst, media_face_h src) media_face_s *_dst = (media_face_s *)calloc(1, sizeof(media_face_s)); media_content_retvm_if(_dst == NULL, MEDIA_CONTENT_ERROR_OUT_OF_MEMORY, "OUT_OF_MEMORY"); - if (STRING_VALID(_src->face_id)) { - _dst->face_id = strdup(_src->face_id); - if (_dst->face_id == NULL) { - media_face_destroy((media_face_h)_dst); - media_content_error("OUT_OF_MEMORY(0x%08x)", MEDIA_CONTENT_ERROR_OUT_OF_MEMORY); - return MEDIA_CONTENT_ERROR_OUT_OF_MEMORY; - } - } - if (STRING_VALID(_src->media_id)) { _dst->media_id = strdup(_src->media_id); if (_dst->media_id == NULL) { @@ -82,6 +74,7 @@ int media_face_clone(media_face_h *dst, media_face_h src) } } + _dst->face_id = _src->face_id; _dst->face_rect_x = _src->face_rect_x; _dst->face_rect_y = _src->face_rect_y; _dst->face_rect_w = _src->face_rect_w; @@ -102,14 +95,22 @@ int media_face_clone(media_face_h *dst, media_face_h src) return MEDIA_CONTENT_ERROR_NONE; } +static void __media_face_convert_itoa(int face_id, char **face_strid) +{ + char buf[MAX_SIZE] = {0, }; + + snprintf(buf, MAX_SIZE, "%d", face_id); + *face_strid = strndup(buf, strlen(buf)); +} + int media_face_get_face_id(media_face_h face, char **face_id) { media_face_s* _face = (media_face_s*)face; media_content_retvm_if(face == NULL, MEDIA_CONTENT_ERROR_INVALID_PARAMETER, "Invalid handle"); - if (STRING_VALID(_face->face_id)) { - *face_id = strdup(_face->face_id); + if (_face->face_id > 0) { + __media_face_convert_itoa(_face->face_id, face_id); media_content_retvm_if(*face_id == NULL, MEDIA_CONTENT_ERROR_OUT_OF_MEMORY, "Out of memory"); } else { *face_id = NULL; @@ -242,7 +243,7 @@ int media_face_insert_to_db(media_face_h face) { int ret = MEDIA_CONTENT_ERROR_NONE; char *query_str = NULL; - char *face_uuid = NULL; + sqlite3_stmt *stmt = NULL; media_face_s* _face = (media_face_s*)face; @@ -251,18 +252,22 @@ int media_face_insert_to_db(media_face_h face) media_content_retvm_if(_face->face_rect_w == 0, MEDIA_CONTENT_ERROR_INVALID_PARAMETER, "Invalid rect_w"); media_content_retvm_if(_face->face_rect_h == 0, MEDIA_CONTENT_ERROR_INVALID_PARAMETER, "Invalid rect_h"); - ret = media_svc_generate_uuid(&face_uuid); - media_content_retvm_if(ret != MS_MEDIA_ERR_NONE, MEDIA_CONTENT_ERROR_INVALID_OPERATION, "Fail to generate face_id"); - - SAFE_FREE(_face->face_id); - _face->face_id = strdup(face_uuid); - SAFE_FREE(face_uuid); - - query_str = sqlite3_mprintf(INSERT_FACE_TO_FACE, _face->face_id, _face->media_id, _face->face_rect_x, _face->face_rect_y, _face->face_rect_w, _face->face_rect_h, _face->orientation, _face->face_tag); + query_str = sqlite3_mprintf(INSERT_FACE_TO_FACE, _face->media_id, _face->face_rect_x, _face->face_rect_y, _face->face_rect_w, _face->face_rect_h, _face->orientation, _face->face_tag); ret = _content_query_sql(query_str); SQLITE3_SAFE_FREE(query_str); + query_str = sqlite3_mprintf(SELECT_FACE_ID_USER_MARKED, _face->media_id, _face->face_rect_x, _face->face_rect_y, _face->face_rect_w, _face->face_rect_h, _face->orientation); + ret = _content_query_prepare(&stmt, query_str, NULL, NULL); + SQLITE3_SAFE_FREE(query_str); + media_content_retv_if(ret != MEDIA_CONTENT_ERROR_NONE, ret); + + while (sqlite3_step(stmt) == SQLITE_ROW) + _face->face_id = (int)sqlite3_column_int(stmt, 0); + + SQLITE3_FINALIZE(stmt); + + return ret; } @@ -274,7 +279,7 @@ int media_face_update_to_db(media_face_h face) media_face_s* _face = (media_face_s*)face; media_content_retvm_if(face == NULL, MEDIA_CONTENT_ERROR_INVALID_PARAMETER, "Invalid handle"); - media_content_retvm_if(_face->face_id == NULL, MEDIA_CONTENT_ERROR_INVALID_PARAMETER, "Invalid face_id"); + media_content_retvm_if(_face->face_id == 0, MEDIA_CONTENT_ERROR_INVALID_PARAMETER, "Invalid face_id"); media_content_retvm_if(_face->media_id == NULL, MEDIA_CONTENT_ERROR_INVALID_PARAMETER, "Invalid media_id"); media_content_retvm_if(_face->face_rect_w == 0, MEDIA_CONTENT_ERROR_INVALID_PARAMETER, "Invalid rect_w"); media_content_retvm_if(_face->face_rect_h == 0, MEDIA_CONTENT_ERROR_INVALID_PARAMETER, "Invalid rect_h"); @@ -287,18 +292,41 @@ int media_face_update_to_db(media_face_h face) return ret; } +static int __media_face_safe_atoi(const char *buffer, int *si) +{ + char *end = NULL; + errno = 0; + media_content_retvm_if(buffer == NULL || si == NULL, MEDIA_CONTENT_ERROR_INVALID_PARAMETER, "invalid parameter"); + + const long sl = strtol(buffer, &end, 10); + + media_content_retvm_if(end == buffer, MEDIA_CONTENT_ERROR_INVALID_PARAMETER, "not a decimal number"); + media_content_retvm_if('\0' != *end, MEDIA_CONTENT_ERROR_INVALID_PARAMETER, "extra characters at end of input: %s", end); + media_content_retvm_if((LONG_MIN == sl || LONG_MAX == sl) && (ERANGE == errno), MEDIA_CONTENT_ERROR_INVALID_PARAMETER, "out of range of type long"); + media_content_retvm_if(sl > INT_MAX, MEDIA_CONTENT_ERROR_INVALID_PARAMETER, "greater than INT_MAX"); + media_content_retvm_if(sl < INT_MIN, MEDIA_CONTENT_ERROR_INVALID_PARAMETER, "less than INT_MIN"); + + *si = (int)sl; + + return MEDIA_CONTENT_ERROR_NONE; +} + int media_face_delete_from_db(const char *face_id) { int ret = MEDIA_CONTENT_ERROR_NONE; char *query_str = NULL; char *media_id = NULL; + int query_face_id = 0; sqlite3_stmt *stmt = NULL; media_content_retvm_if(!STRING_VALID(face_id), MEDIA_CONTENT_ERROR_INVALID_PARAMETER, "invalid face_id"); + ret = __media_face_safe_atoi(face_id, &query_face_id); + media_content_retvm_if(ret != MEDIA_CONTENT_ERROR_NONE, MEDIA_CONTENT_ERROR_INVALID_PARAMETER, "invalid face_id"); + /*To refresh face information(User try to start_face_detection again for the already scanned item), mark media modified_time to '0' if user delete system extracted face info. */ - query_str = sqlite3_mprintf(SELECT_MEDIA_FROM_FACE, face_id); + query_str = sqlite3_mprintf(SELECT_MEDIA_FROM_FACE, query_face_id); ret = _content_query_prepare(&stmt, query_str, NULL, NULL); SQLITE3_SAFE_FREE(query_str); media_content_retv_if(ret != MEDIA_CONTENT_ERROR_NONE, ret); @@ -314,7 +342,7 @@ int media_face_delete_from_db(const char *face_id) } SAFE_FREE(media_id); - query_str = sqlite3_mprintf(DELETE_FACE_FROM_FACE, face_id); + query_str = sqlite3_mprintf(DELETE_FACE_FROM_FACE, query_face_id); ret = _content_query_sql(query_str); SQLITE3_SAFE_FREE(query_str); -- 2.7.4