2 * Copyright (c) 2014 Samsung Electronics Co., Ltd. All rights reserved
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
23 #include <sys/smack.h>
29 #include <acl/libacl.h>
31 #include <media_content.h>
32 #include <thumbnail_util.h>
33 #include <image_util.h>
35 #include "MsgStorageTypes.h"
37 #include "MsgException.h"
38 #include "MsgUtilFile.h"
39 #include "MsgMmsTypes.h"
40 #include "MsgInternalTypes.h"
41 #include "MsgDrmWrapper.h"
51 void thumbnail_completed_cb(thumbnail_util_error_e error, const char *request_id,
52 int thumb_width, int thumb_height,
53 unsigned char *thumb_data, int thumb_size, void *user_data)
56 MSG_WARN("dstPath is NULL");
63 MSG_DEBUG("=================[RESULT]");
64 MSG_DEBUG("error_code [%d]", error);
65 MSG_DEBUG("request id [%s]", request_id);
66 MSG_DEBUG("width [%d], height [%d]", thumb_width, thumb_height);
67 MSG_DEBUG("raw_data [0x%x], size [%d]", *thumb_data, thumb_size);
70 ret = image_util_encode_jpeg(thumb_data, thumb_width, thumb_height, IMAGE_UTIL_COLORSPACE_BGRA8888, 100, (char *)user_data);
71 if (ret != IMAGE_UTIL_ERROR_NONE)
72 MSG_WARN("image_util_encode_jpeg() is failed");
80 /*==================================================================================================
81 FUNCTION IMPLEMENTATION
82 ==================================================================================================*/
83 bool MakeThumbnail(char *srcPath, char *dstPath)
85 if (srcPath == NULL || dstPath == NULL) {
86 MSG_SEC_DEBUG("Invalid Param src = %p, dst = %p", srcPath, dstPath);
90 if (MsgAccessFile(srcPath, R_OK) == false) {
91 MSG_SEC_DEBUG("not exist source file [%s]", srcPath);
99 int ret = THUMBNAIL_UTIL_ERROR_NONE;
102 thumbnail_util_create(&thumb_h);
103 thumbnail_util_set_path(thumb_h, srcPath);
105 ret = thumbnail_util_extract(thumb_h, thumbnail_completed_cb, dstPath, &req_id);
106 thumbnail_util_destroy(thumb_h);
112 if (ret != THUMBNAIL_UTIL_ERROR_NONE) {
113 MSG_ERR("thumbnail_util_extract is failed");
118 time_ret = g_cv.timedwait(g_mx.pMutex(), 5);
122 if (time_ret == ETIMEDOUT) {
123 MSG_ERR("@@ WAKE by timeout@@");
127 if (MsgAccessFile(dstPath, F_OK) == false) {
128 MSG_SEC_DEBUG("not exist result file [%s]", dstPath);
132 MSG_SEC_DEBUG("Make thumbnail: success [%s]", dstPath);
136 /* File operation wrappers */
137 FILE *MsgOpenFile(const char *filepath, const char *opt)
139 if (!filepath || !opt) {
140 MSG_FATAL("Null parameter");
144 MSG_SEC_DEBUG("[FILE] filepath : [%s], opt [%s]", filepath, opt);
149 pFile = fopen(filepath, opt);
150 MSG_DEBUG("[FILE] pFile [%p]", pFile);
151 } catch (exception &e) {
152 MSG_FATAL("%s", e.what());
159 void MsgCloseFile(FILE *pFile)
162 MSG_FATAL("NULL parameter");
166 MSG_DEBUG("[FILE] pFile [%p]", pFile);
170 } catch (exception &e) {
171 MSG_FATAL("%s", e.what());
175 int MsgFseek(FILE *pFile, long int offset, int origin)
178 MSG_FATAL("pFile NULL");
184 MSG_DEBUG("[FILE] pFile [%p], offset [%d], origin [%d]", pFile, offset, origin);
187 ret = fseek(pFile, offset, origin); /* return 0, if success. */
188 } catch (exception &e) {
189 MSG_FATAL("%s", e.what());
196 size_t MsgWriteFile(const char *pData, size_t size, size_t count, FILE *pFile)
198 if (!pData || !pFile) {
199 MSG_FATAL("pData or pFile NULL");
205 MSG_DEBUG("[FILE] pData [%p], size [%d], count [%d], pFile [%p]", pData, size, count, pFile);
208 nWrite = fwrite(pData, size, count, pFile);
209 } catch (exception &e) {
210 MSG_FATAL("%s", e.what());
216 size_t MsgReadFile(void *pData, size_t size, size_t count, FILE *pFile)
218 if (!pData || !pFile) {
219 MSG_FATAL("pData or pFile NULL");
226 nRead = fread(pData, size, count, pFile);
227 } catch (exception &e) {
228 MSG_FATAL("%s", e.what());
234 long int MsgFtell(FILE *pFile)
237 MSG_FATAL("pFile NULL");
241 long int ret = -1L; /* -1L return if error occured. */
245 } catch (exception &e) {
246 MSG_FATAL("%s", e.what());
252 int MsgFflush(FILE *pFile)
255 MSG_FATAL("pFile NULL");
262 ret = fflush(pFile); /* return 0 if success */
263 } catch (exception &e) {
264 MSG_FATAL("%s", e.what());
270 int MsgFsync(FILE *pFile)
273 MSG_FATAL("pFile NULL");
280 ret = fdatasync(pFile->_fileno); /* return 0 if success */
281 } catch (exception &e) {
282 MSG_FATAL("%s", e.what());
288 bool MsgCreateFileName(char *pFileName)
290 if (pFileName == NULL) {
291 MSG_DEBUG("[ERROR] pFileName is NULL");
298 if (clock_gettime(CLOCK_REALTIME, &ts) < 0) {
299 MSG_DEBUG("clock_gettime() error: %s", g_strerror(errno));
303 /* Create Random Number */
304 srandom((unsigned int)ts.tv_nsec);
306 MSG_DEBUG("ts.tv_nsec : %d", ts.tv_nsec);
308 /* between 1 - 1000000000 */
309 snprintf(pFileName, MSG_FILENAME_LEN_MAX, "MSG_%lu.DATA", random()%1000000000+1);
310 } catch (exception& e) {
311 MSG_FATAL("%s", e.what());
319 bool MsgOpenAndReadFile(const char *pFileName, char **ppData, int *pDataSize)
321 if (!pFileName || !ppData || !pDataSize) {
322 MSG_ERR("Invalid params!! pFileName=%x, ppData=%x, pDataSize=%x", pFileName, ppData, pDataSize);
326 MSG_DEBUG("MsgOpenAndReadFile");
330 char fullPath[MAX_FULL_PATH_SIZE] = {0};
332 snprintf(fullPath, MAX_FULL_PATH_SIZE, "%s%s", MSG_IPC_DATA_PATH, pFileName);
333 MSG_SEC_DEBUG("open file name: %s", fullPath);
335 pFile = MsgOpenFile(fullPath, "rb");
338 MSG_DEBUG("File Open Error: %s", g_strerror(errno));
342 if (MsgFseek(pFile, 0L, SEEK_END) < 0) {
344 MSG_DEBUG("File Read Error: %s", g_strerror(errno));
348 int FileSize = MsgFtell(pFile);
351 MSG_DEBUG("Filesize is error : %d", FileSize);
357 *ppData = new char[FileSize+1];
358 memset(*ppData, 0x00, (FileSize+1));
360 if (MsgFseek(pFile, 0L, SEEK_SET) < 0) {
362 MSG_DEBUG("File seek Error: %s", g_strerror(errno));
366 if (MsgReadFile(*ppData, sizeof(char), FileSize, pFile) != (size_t)FileSize) {
368 MSG_DEBUG("File Read Error: %s", g_strerror(errno));
372 *pDataSize = FileSize;
380 bool MsgReadFileForDecode(FILE *pFile, char *pBuf, int length, int *nSize)
384 if (MsgFseek(pFile, 0L, SEEK_CUR) < 0) {
385 MSG_DEBUG("File Seek Error: %s", g_strerror(errno));
390 *nSize = MsgReadFile(pBuf, sizeof(char), length, pFile);
397 bool MsgWriteIpcFile(const char *pFileName, const char *pData, int DataSize)
400 MSG_DEBUG("NULL parameter, pFileName [%p], pData [%p]", pFileName, pData);
404 char fullPath[MAX_FULL_PATH_SIZE] = {0};
406 snprintf(fullPath, MAX_FULL_PATH_SIZE, "%s%s", MSG_IPC_DATA_PATH, pFileName);
408 FILE *pFile = MsgOpenFile(fullPath, "wb+");
411 MSG_DEBUG("File Open Error: %s", g_strerror(errno));
415 if (MsgFseek(pFile, 0L, SEEK_SET) < 0) {
417 MSG_DEBUG("File Seek Error: %s", g_strerror(errno));
421 if (MsgWriteFile(pData, sizeof(char), DataSize, pFile) != (size_t)DataSize) {
423 MSG_DEBUG("File Write Error: %s", g_strerror(errno));
433 int MsgReadSmilFile(const char *pFileName, char **ppData)
436 MSG_DEBUG("pFileName is NULL");
441 char fullPath[MAX_FULL_PATH_SIZE] = {0};
443 snprintf(fullPath, MAX_FULL_PATH_SIZE, "%s%s", MSG_SMIL_FILE_PATH, pFileName);
445 MSG_SEC_DEBUG("open file name: %s", fullPath);
447 FILE *pFile = MsgOpenFile(fullPath, "rb");
450 MSG_DEBUG("File Open Error: %s", g_strerror(errno));
454 if (MsgFseek(pFile, 0L, SEEK_END) < 0) {
456 MSG_DEBUG("File Seek Error: %s", g_strerror(errno));
460 int FileSize = MsgFtell(pFile);
463 MSG_DEBUG("Filesize is error : %d", FileSize);
468 *ppData = new char[FileSize + 1];
469 memset(*ppData, 0x00, (FileSize+1));
471 if (MsgFseek(pFile, 0L, SEEK_SET) < 0) {
473 MSG_DEBUG("File Sead Error: %s", g_strerror(errno));
477 if (MsgReadFile(*ppData, sizeof(char), FileSize, pFile) != (size_t)FileSize) {
479 MSG_DEBUG("File Read Error: %s", g_strerror(errno));
483 /* ppData[FileSize] = '\0'; */
492 bool MsgWriteSmilFile(const char *pFilePath, char *pData, int DataSize)
495 MSG_DEBUG("pFilePath is NULL");
500 if (mkdir(MSG_SMIL_FILE_PATH, S_IRWXU | S_IRWXG | S_IROTH | S_IXOTH) < 0) {
501 if (errno == EEXIST) {
502 MSG_SEC_DEBUG("The %s already exists", MSG_SMIL_FILE_PATH);
504 MSG_SEC_DEBUG("Error while mkdir %s", MSG_SMIL_FILE_PATH);
509 FILE *pFile = MsgOpenFile(pFilePath, "wb+");
512 MSG_DEBUG("File Open Error: %s", g_strerror(errno));
516 if (MsgFseek(pFile, 0L, SEEK_SET) < 0) {
518 MSG_DEBUG("File Seek Error: %s", g_strerror(errno));
522 if (MsgWriteFile(pData, sizeof(char), DataSize, pFile) != (size_t)DataSize) {
524 MSG_DEBUG("File Write Error: %s", g_strerror(errno));
535 void MsgDeleteFile(const char *pFileName)
538 MSG_FATAL("pFileName is NULL");
542 if (strlen(pFileName) == 0) {
543 MSG_FATAL("pFileName has zero length");
547 char fullPath[MAX_FULL_PATH_SIZE] = {0};
550 snprintf(fullPath, MAX_FULL_PATH_SIZE, "%s%s", MSG_IPC_DATA_PATH, pFileName);
552 MSG_SEC_DEBUG("%s", fullPath);
554 if (remove(fullPath) != 0)
555 MSG_SEC_ERR("File Delete Error [%s]: %s", fullPath, g_strerror(errno));
556 } catch (exception &e) {
557 MSG_FATAL("%s", e.what());
562 void MsgDeleteSmilFile(const char *pFileName)
565 MSG_FATAL("pFileName NULL");
570 char fullPath[MAX_FULL_PATH_SIZE] = {0};
572 snprintf(fullPath, MAX_FULL_PATH_SIZE, "%s%s", MSG_SMIL_FILE_PATH, pFileName);
574 if (remove(fullPath) != 0)
575 MSG_SEC_ERR("File Delete Error [%s]: %s", fullPath, g_strerror(errno));
576 } catch (exception &e) {
577 MSG_FATAL("%s", e.what());
582 bool MsgGetFileSize(const char *pFilePath, int *nSize)
585 MSG_FATAL("pFileName NULL");
591 pFile = MsgOpenFile(pFilePath, "rb");
594 MSG_DEBUG("File Open error: %s", g_strerror(errno));
598 if (MsgFseek(pFile, 0L, SEEK_END) < 0) {
600 MSG_FATAL("File Read Error: %s", g_strerror(errno));
604 *nSize = MsgFtell(pFile);
612 FILE *MsgOpenMMSFile(char *pFileName)
617 MSG_DEBUG("pFileName NULL: %s", g_strerror(errno));
621 len = strlen(pFileName);
623 for (int i = 0; i < len; i++) {
624 switch (pFileName[i]) {
631 MSG_SEC_DEBUG("pFileName = %s", pFileName);
633 char fullPath[MAX_FULL_PATH_SIZE+1] = {0};
635 snprintf(fullPath, MAX_FULL_PATH_SIZE+1, "%s.mms", pFileName);
637 FILE *pFile = MsgOpenFile(fullPath, "wb+");
640 MSG_ERR("File Open Error: %s", g_strerror(errno));
644 if (MsgFseek(pFile, 0L, SEEK_CUR) < 0) {
646 MSG_ERR("File Read Error: %s", g_strerror(errno));
654 bool MsgWriteDataFromEncodeBuffer(FILE *pFile, char *pInBuffer, int *pPtr, int maxLen, int *pOffset )
656 if (!pFile || !pPtr || !pInBuffer || !pOffset) {
657 MSG_FATAL(" NULL parameter passed");
661 MSG_DEBUG("MsgWriteDataFromEncodeBuffer:");
662 MSG_DEBUG("pInBuffer %x", pInBuffer);
663 MSG_DEBUG("pPtr %d", (*pPtr));
664 MSG_DEBUG("before to fwite %x", pFile);
666 if (MsgWriteFile(pInBuffer, sizeof(char), (*pPtr), pFile) != (size_t)(*pPtr)) {
667 MSG_FATAL("MsgWriteFile failed");
671 MSG_DEBUG("after to fwite \n");
675 memset(pInBuffer, 0, maxLen);
679 if (MsgFseek(pFile, 0L, SEEK_END) < 0) {
680 MSG_FATAL("MsgFseek failed");
684 *pOffset = MsgFtell(pFile);
686 if (*pOffset == -1L) {
687 MSG_FATAL("MsgFtell failed");
695 bool MsgOpenCreateAndOverwriteFile(char *pFullPath, char *pBuff, int TotalLength)
699 if ((pFile = MsgOpenFile(pFullPath, "wb+")) == NULL) {
700 MSG_FATAL("MsgOpenFile errer");
704 if (MsgWriteFile(pBuff, sizeof(char), TotalLength, pFile) != (size_t)TotalLength) {
709 MsgFsync(pFile); /* file is written to device immediately, it prevents missing file data from unexpected power off */
717 char *MsgOpenAndReadMmsFile(const char *szFilePath, int offset, int size, int *npSize)
723 if (szFilePath == NULL) {
724 MSG_ERR("szFilePath id NULL");
730 pFile = MsgOpenFile(szFilePath, "rb");
733 MSG_ERR("Can't open file: %s", g_strerror(errno));
738 if (MsgGetFileSize(szFilePath, & readSize) == false) {
739 MSG_DEBUG("MsgGetFileSize: failed");
745 /* restore Kies backup data size greater than FM_READ_WRITE_BUFFER_MAX */
747 if (readSize > FM_READ_WRITE_BUFFER_MAX) {
748 MSG_DEBUG("MsgOpenAndReadMmsFile: File size tried to read too big");
753 pData = (char *)calloc(1, readSize + 1);
754 if ( NULL == pData ) {
755 MSG_ERR("pData MemAlloc Fail : %s", g_strerror(errno) );
759 if (MsgFseek(pFile, offset, SEEK_SET) < 0) {
760 MSG_ERR("FmSeekFile failed : %s", g_strerror(errno) );
764 *npSize = MsgReadFile(pData, sizeof(char), readSize, pFile);
770 *(pData + (*npSize)) = '\0';
791 /* it is equivalent to "rm -rf pDirPath" */
792 int MsgRmRf(char *pDirPath)
794 struct dirent *d = NULL;
798 dir = opendir(pDirPath);
801 MSG_FATAL("error opendir: %s", g_strerror(errno));
805 int size = strlen(pDirPath) + 256;
807 char *path = (char*)malloc(size);
810 MSG_DEBUG("path is NULL");
817 for (readdir_r(dir, &entry, &d); d != NULL; readdir_r(dir, &entry, &d)) {
818 if (d->d_type == DT_DIR) {
819 snprintf(path, size, "%s/%s", pDirPath, d->d_name);
821 if ((strcmp(".", d->d_name) == 0) || (strcmp("..", d->d_name) == 0))
826 if (rmdir(path) != 0) {
832 MSG_FATAL("error rmdir: %s", g_strerror(errno));
837 snprintf(path, size, "%s/%s", pDirPath, d->d_name);
839 if (MsgDrmIsDrmFile(path))
840 MsgDrmUnregisterFile(path);
842 if (remove(path) != 0) {
848 MSG_FATAL("error remove: %s", g_strerror(errno));
865 int MsgGetFileSize(const char *pFileName)
867 struct stat file_stat;
869 if (lstat(pFileName, &file_stat)) {
870 MSG_FATAL("error lstat: %s", g_strerror(errno));
874 return file_stat.st_size;
878 /* it is equivalent to "du dir_path" */
879 unsigned int MsgDu(const char *pDirPath)
881 struct dirent *d = NULL;
885 dir = opendir(pDirPath);
888 MSG_FATAL("error opendir: %s", g_strerror(errno));
892 int size = strlen(pDirPath) + 256;
893 char *path = (char*)malloc(size);
901 unsigned int totalFileSize = 0;
903 for (readdir_r(dir, &entry, &d); d != NULL; readdir_r(dir, &entry, &d)) {
904 if(d->d_type == DT_DIR) {
905 snprintf(path, size, "%s/%s", pDirPath, d->d_name);
907 if ((strcmp(".", d->d_name) == 0) || (strcmp("..", d->d_name) == 0))
910 unsigned int dirSize = MsgDu(path);
913 MSG_FATAL("error MsgDu");
919 totalFileSize += dirSize;
921 snprintf(path, size, "%s/%s", pDirPath, d->d_name);
922 int fileSize = MsgGetFileSize(path);
925 MSG_FATAL("error MsgGetFileSize");
931 totalFileSize += fileSize;
940 return totalFileSize;
944 bool MsgAppendFile(const char *pFilePath, const char *pData, int DataSize)
947 MSG_FATAL("NULL check error, pFileName %p, pData %p", pFilePath, pData);
951 char fullPath[MAX_FULL_PATH_SIZE] = {0};
953 snprintf(fullPath, MAX_FULL_PATH_SIZE, "%s", pFilePath);
955 FILE *pFile = MsgOpenFile(fullPath, "a+");
958 MSG_FATAL("File Open Error: %s", g_strerror(errno));
962 if (MsgFseek(pFile, 0L, SEEK_CUR) < 0) {
964 MSG_FATAL("File Sead Error: %s", g_strerror(errno));
968 if (MsgWriteFile(pData, sizeof(char), DataSize, pFile) != (size_t)DataSize) {
970 MSG_FATAL("File Write Error: %s", g_strerror(errno));
974 MsgFsync(pFile); /*file is written to device immediately, it prevents missing file data from unexpected power off */
982 struct dirent *d = NULL;
986 dir = opendir(MSG_DATA_PATH);
989 MSG_FATAL("error opendir: %s", g_strerror(errno));
993 /* Remove temporal Mms folder */
994 for (readdir_r(dir, &entry, &d); d != NULL; readdir_r(dir, &entry, &d)) {
995 if (d->d_type == DT_DIR) {
996 if ((strcmp(".", d->d_name) == 0) || (strcmp("..", d->d_name) == 0))
999 if(strstr(d->d_name, ".dir") != NULL) {
1000 char filePath[MSG_FILEPATH_LEN_MAX] = {0, };
1001 snprintf(filePath, MSG_FILEPATH_LEN_MAX, "%s%s", MSG_DATA_PATH, d->d_name);
1013 /* mode : R_OK, W_OK, X_OK, or the existence test F_OK. */
1014 bool MsgAccessFile(const char *filepath, int mode)
1017 if (filepath == NULL) {
1018 MSG_DEBUG("filepath is NULL");
1022 MSG_SEC_DEBUG("request access path = %s, mode = %d", filepath, mode);
1024 ret = access(filepath, mode);
1028 MSG_DEBUG("Fail to access file, ret = %d", ret);
1036 bool MsgChmod(const char *filepath, int mode)
1039 struct stat lstat_info;
1040 struct stat fstat_info;
1043 if (lstat(filepath, &lstat_info) == -1) {
1044 MSG_SEC_DEBUG("No such file as [%s].", filepath);
1048 fd = open(filepath, O_RDONLY);
1051 MSG_SEC_DEBUG("Fail to open [%s].", filepath);
1055 if (fstat(fd, &fstat_info) == -1) {
1056 MSG_SEC_DEBUG("Fail to fstat [%s].", filepath);
1061 if (lstat_info.st_mode == fstat_info.st_mode &&
1062 lstat_info.st_ino == fstat_info.st_ino &&
1063 lstat_info.st_dev == fstat_info.st_dev) {
1064 if (fchmod(fd, mode) < 0) {
1065 MSG_SEC_DEBUG("Fail to fchmod [%s].", filepath);
1077 bool MsgChown(const char *filepath, int uid, int gid)
1079 struct stat lstat_info;
1080 struct stat fstat_info;
1083 if (lstat(filepath, &lstat_info) == -1) {
1084 MSG_SEC_INFO("No such file as [%s].", filepath);
1088 fd = open(filepath, O_RDONLY);
1091 MSG_SEC_INFO("Fail to open [%s].", filepath);
1095 if (fstat(fd, &fstat_info) == -1) {
1096 MSG_SEC_INFO("Fail to fstat [%s].", filepath);
1101 if (lstat_info.st_mode == fstat_info.st_mode &&
1102 lstat_info.st_ino == fstat_info.st_ino &&
1103 lstat_info.st_dev == fstat_info.st_dev) {
1104 if (fchown(fd, uid, gid) < 0) {
1105 MSG_SEC_INFO("Fail to fchown [%s].", filepath);
1116 bool MsgCreateFile(const char *pFilePath, char *pData, int DataSize)
1119 MSG_DEBUG("pFilePath is NULL");
1123 FILE *pFile = MsgOpenFile(pFilePath, "wb+");
1125 if (pFile == NULL) {
1126 MSG_ERR("File Open Error: %s", g_strerror(errno));
1130 if (MsgFseek(pFile, 0L, SEEK_SET) < 0) {
1131 MsgCloseFile(pFile);
1132 MSG_ERR("File Seek Error: %s", g_strerror(errno));
1136 if (MsgWriteFile(pData, sizeof(char), DataSize, pFile) != (size_t)DataSize) {
1137 MsgCloseFile(pFile);
1138 MSG_ERR("File Write Error: %s", g_strerror(errno));
1144 MsgCloseFile(pFile);
1149 char *MsgGetDirName(char *file_path)
1151 return g_path_get_dirname(file_path);
1155 char *MsgGetFileName(char *file_path)
1157 return g_path_get_basename(file_path);
1161 int MsgCheckFilepathSmack(const char *app_smack_label, char *file_path)
1163 int err = MSG_SUCCESS;
1165 char *path_smack_label = NULL;
1166 char *dir_smack_label = NULL;
1167 char *dir_name = NULL;
1169 if (!file_path || file_path[0] == '\0') {
1174 if (stat(file_path, &st) != 0) {
1175 MSG_SEC_ERR("stat(%s, &st) != 0", file_path);
1176 return MSG_ERR_PERMISSION_DENIED;
1178 if (S_ISDIR(st.st_mode)) {
1179 MSG_ERR("S_ISDIR(st.st_mode)");
1180 return MSG_ERR_INVALID_PARAMETER;
1183 dir_name = MsgGetDirName(file_path);
1184 if (!dir_name || !g_strcmp0(dir_name, file_path)) {
1185 MSG_SEC_ERR("!dir_name || !g_strcmp0(dir_name, %s)", file_path);
1186 err = MSG_ERR_INVALID_PARAMETER;
1190 smack_getlabel(dir_name, &dir_smack_label, SMACK_LABEL_ACCESS);
1191 if (dir_smack_label == NULL) {
1192 MSG_ERR("smack_getlabel failed (dir_smack_label)");
1193 err = MSG_ERR_PERMISSION_DENIED;
1197 if (smack_have_access(app_smack_label, dir_smack_label, "RX") < 1) {
1198 MSG_ERR("smack_have_access failed (dir_smack_label)");
1199 err = MSG_ERR_PERMISSION_DENIED;
1203 smack_getlabel(file_path, &path_smack_label, SMACK_LABEL_ACCESS);
1204 if (path_smack_label == NULL) {
1205 MSG_ERR("smack_getlabel failed (path_smack_label)");
1206 err = MSG_ERR_PERMISSION_DENIED;
1210 if (smack_have_access(app_smack_label, path_smack_label, "R") < 1) {
1211 MSG_ERR("smack_have_access failed (path_smack_label)");
1212 err = MSG_ERR_PERMISSION_DENIED;
1216 MSG_DEBUG("smack_have_access pass successfully");
1219 MSG_FREE(path_smack_label);
1220 MSG_FREE(dir_smack_label);
1226 bool MsgScanFile(char *filePath)
1228 if (filePath == NULL) {
1229 MSG_DEBUG("Invalid Parameter src = %p", filePath);
1233 msg_error_t ret = media_content_connect();
1235 if (ret == MEDIA_CONTENT_ERROR_NONE) {
1236 if (media_content_scan_file(filePath) != MEDIA_CONTENT_ERROR_NONE) {
1237 MSG_ERR("media_content_scan_file() is failed , %d", ret);
1238 media_content_disconnect();
1242 ret = media_content_disconnect();
1244 if (ret != MEDIA_CONTENT_ERROR_NONE) {
1245 MSG_ERR("media_content_disconnect is failed , %d", ret);
1249 MSG_ERR("media_content_connect is failed , %d", ret);
1257 void MsgGetMimeType(char *filePath, char *mimeType, int size)
1259 aul_get_mime_from_file(filePath, mimeType, size);
1266 /* In msg-service.spec file use libacl-devel. Because acl get not process open API */
1267 /* So have to set TARGET_LINK_LIBRARIES(acl) in makefile */
1268 /* After GPL-3.0, not supply shell commend (setfacl, getfacl) by license issue, use the API */
1271 const char *priv_read =
1274 "group:priv_message_read:rwx\n"
1280 acl = acl_from_text(priv_read);
1282 MSG_ERR("%s: `%s': %s\n", MSG_IPC_DATA_PATH, priv_read, g_strerror(errno));
1286 ret = acl_check(acl, NULL);
1289 if (ret == ACL_DUPLICATE_ERROR) {
1290 MSG_DEBUG("Already Set ACL");
1293 MSG_ERR("acl_check Fail : [%d],[%s]", ret, acl_error(ret));
1297 ret = acl_set_file((const char *)MSG_IPC_DATA_PATH, ACL_TYPE_ACCESS, acl);
1299 MSG_ERR("acl_set_file Fail : [%d][%s]", ret, g_strerror(errno));