diff options
author | Kim Kibum <kb0929.kim@samsung.com> | 2012-04-29 17:01:52 +0900 |
---|---|---|
committer | Kim Kibum <kb0929.kim@samsung.com> | 2012-04-29 17:01:52 +0900 |
commit | 703f4f8dd9069e4436e848688e50c79de14d03ac (patch) | |
tree | cc1142054e9a8b44a422f2b66dd8372942d9d735 /client | |
parent | 563412390a7fdd82b9ebb1f1162a43cecaf56c5f (diff) | |
download | secure-storage-703f4f8dd9069e4436e848688e50c79de14d03ac.tar.gz secure-storage-703f4f8dd9069e4436e848688e50c79de14d03ac.tar.bz2 secure-storage-703f4f8dd9069e4436e848688e50c79de14d03ac.zip |
upload tizen1.0 source
Diffstat (limited to 'client')
-rw-r--r-- | client/include/ss_client_intf.h | 68 | ||||
-rw-r--r-- | client/include/ss_client_ipc.h | 32 | ||||
-rw-r--r-- | client/src/ss_client_intf.c | 417 | ||||
-rw-r--r-- | client/src/ss_client_ipc.c | 105 | ||||
-rw-r--r-- | client/src/ss_manager.c | 214 |
5 files changed, 836 insertions, 0 deletions
diff --git a/client/include/ss_client_intf.h b/client/include/ss_client_intf.h new file mode 100644 index 0000000..49255ea --- /dev/null +++ b/client/include/ss_client_intf.h @@ -0,0 +1,68 @@ +/* + * secure storage + * + * Copyright (c) 2000 - 2012 Samsung Electronics Co., Ltd All Rights Reserved + * + * Contact: Kidong Kim <kd0228.kim@samsung.com> + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + */ + +#ifndef __SS_MANAGER__ +#include "ss_manager.h" +#endif + +/* + * Declare new function + * + * @name: SsClientDataStore + * @parameter + * - filepath: [in] + * - flag: [in] + * @return type: int + * - 1: success + * - <1: error + */ +int SsClientDataStoreFromFile(const char* filepath, ssm_flag flag, const char* group_id); +int SsClientDataStoreFromBuffer(char* writebuffer, size_t bufLen, const char* filename, ssm_flag flag, const char* group_id); + +/* + * Declare new function + * + * @name: SsClientDataRead + * @parameter + * - filepath: [in] + * - pRetBuf: [out] + * - bufLen: [in] + * - readLen: [out] + * @return type: int + * - 1: success + * - <1: error + */ +int SsClientDataRead(const char* filepath, char* pRetBuf, size_t bufLen, size_t *readLen, ssm_flag flag, const char* group_id); + +/* + * Declare new function + * + * @name: SsClientGetInfo + * @parameter + * - filepath: [in] + * - sfi: [out] + * @return type: int + * - 1: success + * - <1: error + */ +int SsClientGetInfo(const char* filepath, ssm_file_info_t* sfi, ssm_flag flag, const char* group_id); + +int SsClientDeleteFile(const char* pFilePath, ssm_flag flag, const char* group_id); diff --git a/client/include/ss_client_ipc.h b/client/include/ss_client_ipc.h new file mode 100644 index 0000000..036d49b --- /dev/null +++ b/client/include/ss_client_ipc.h @@ -0,0 +1,32 @@ +/* + * secure storage + * + * Copyright (c) 2000 - 2012 Samsung Electronics Co., Ltd All Rights Reserved + * + * Contact: Kidong Kim <kd0228.kim@samsung.com> + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + */ + +/* + * Declare new function + * + * @name: SsClientComm + * @parameter: client_data + * @return type: RspData_t + */ + +#include "secure_storage.h" + +RspData_t SsClientComm(ReqData_t* client_data); diff --git a/client/src/ss_client_intf.c b/client/src/ss_client_intf.c new file mode 100644 index 0000000..27a2282 --- /dev/null +++ b/client/src/ss_client_intf.c @@ -0,0 +1,417 @@ +/* + * secure storage + * + * Copyright (c) 2000 - 2012 Samsung Electronics Co., Ltd All Rights Reserved + * + * Contact: Kidong Kim <kd0228.kim@samsung.com> + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + */ + +#include <stdio.h> +#include <stdlib.h> +#include <string.h> +#include <unistd.h> + +#include "secure_storage.h" +#include "ss_client_intf.h" +#include "ss_client_ipc.h" +#include "ss_manager.h" + +#include "security-server.h" + +int SsClientDataStoreFromFile(const char* filepath, ssm_flag flag, const char* group_id) +{ + ReqData_t* send_data = NULL; + RspData_t recv_data; + int temp_len = 0; + int cookie_size; + + cookie_size = security_server_get_cookie_size(); + char cookie_content[cookie_size]; + + if(security_server_request_cookie(cookie_content, cookie_size) < 0) // error while getting cookie + { + SLOGE("[%s] Fail to get cookie\n", __func__); + recv_data.rsp_type = SS_SECURE_STORAGE_ERROR; + goto Error; + } + + if(!filepath) + { + SLOGE( "[%s] Parameter error in SsClientDataStoreFromFile..\n", __func__); + recv_data.rsp_type = SS_PARAM_ERROR; + goto Error; + } + + send_data = (ReqData_t*)malloc(sizeof(ReqData_t)); + + if(!send_data) + { + SLOGE( "[%s] Memory allocation fail in SsClientDataStoreFromFile..\n", __func__); + recv_data.rsp_type = SS_MEMORY_ERROR; + goto Error; + } + + send_data->req_type = 1; // file store + send_data->enc_type = 1; // initial type + send_data->count = 0; + send_data->flag = flag; // flag + temp_len = strlen(filepath); + if(temp_len < MAX_FILENAME_LEN) + { + strncpy(send_data->data_infilepath, filepath, MAX_FILENAME_LEN - 1); + send_data->data_infilepath[temp_len] = '\0'; + } + else + { + SLOGE("[%s] filepath is too long.\n", __func__); + recv_data.rsp_type = SS_PARAM_ERROR; + goto Free_and_Error; + } + memset(send_data->cookie, 0x00, MAX_COOKIE_LEN); + memset(send_data->group_id, 0x00, MAX_GROUP_ID_LEN); + memcpy(send_data->cookie, cookie_content, cookie_size); + if(group_id) + strncpy(send_data->group_id, group_id, MAX_GROUP_ID_LEN - 1); + else + strncpy(send_data->group_id, "NOTUSED", MAX_GROUP_ID_LEN - 1); + + memset(send_data->buffer, 0x00, MAX_SEND_DATA_LEN + 1); + recv_data = SsClientComm(send_data); + +Free_and_Error: + free(send_data); +Error: + return recv_data.rsp_type; +} + +int SsClientDataStoreFromBuffer(char* writebuffer, size_t bufLen, const char* filename, ssm_flag flag, const char* group_id) +{ + ReqData_t* send_data = NULL; + RspData_t recv_data; + int temp_len = 0; + int cookie_size; + + cookie_size = security_server_get_cookie_size(); + char cookie_content[cookie_size]; + + if(security_server_request_cookie(cookie_content, cookie_size) < 0) // error while getting cookie + { + SLOGE("[%s] Fail to get cookie\n", __func__); + recv_data.rsp_type = SS_SECURE_STORAGE_ERROR; + goto Error; + } + + if(!writebuffer || !filename) + { + SLOGE("[%s] Parameter error in SsClientDataStoreFromBuffer..\n", __func__); + recv_data.rsp_type = SS_PARAM_ERROR; + goto Error; + } + + send_data = (ReqData_t*)malloc(sizeof(ReqData_t)); + if(!send_data) + { + SLOGE("[%s] Memory allocation fail in SsClientDataStoreFromBuffer..\n", __func__); + recv_data.rsp_type = SS_MEMORY_ERROR; + goto Error; + } + + send_data->req_type = 2; // buffer store + send_data->enc_type = 1; + send_data->count = bufLen; + send_data->flag = flag; + temp_len = strlen(filename); + if(temp_len < MAX_FILENAME_LEN) + { + strncpy(send_data->data_infilepath, filename, MAX_FILENAME_LEN - 1); + send_data->data_infilepath[temp_len] = '\0'; + } + else + { + SLOGE("[%s] filepath is too long.\n", __func__); + recv_data.rsp_type = SS_PARAM_ERROR; + goto Free_and_Error; + } + memset(send_data->cookie, 0x00, MAX_COOKIE_LEN); + memset(send_data->group_id, 0x00, MAX_GROUP_ID_LEN); + memcpy(send_data->cookie, cookie_content, cookie_size); + if(group_id) + strncpy(send_data->group_id, group_id, MAX_GROUP_ID_LEN - 1); + else + strncpy(send_data->group_id, "NOTUSED", MAX_GROUP_ID_LEN - 1); + + memcpy(send_data->buffer, writebuffer, bufLen); + recv_data = SsClientComm(send_data); + +Free_and_Error: + free(send_data); +Error: + return recv_data.rsp_type; +} + +int SsClientDataRead(const char* filepath, char* pRetBuf, size_t bufLen, size_t *readLen, ssm_flag flag, const char* group_id) +{ + unsigned int count = (unsigned int)(bufLen / MAX_RECV_DATA_LEN + 1); + unsigned int rest = (unsigned int)(bufLen % MAX_RECV_DATA_LEN); + char* buffer; + ReqData_t* send_data = NULL; + RspData_t recv_data; + int temp_len = 0; + int cookie_size; + + cookie_size = security_server_get_cookie_size(); + char cookie_content[cookie_size]; + + if(security_server_request_cookie(cookie_content, cookie_size) < 0) // error while getting cookie + { + SLOGE("[%s] Fail to get cookie\n", __func__); + recv_data.rsp_type = SS_SECURE_STORAGE_ERROR; + goto Error; + } + + if(!filepath) + { + SLOGE("[%s] filepath Parameter error in SsClientDataRead..\n", __func__); + recv_data.rsp_type = SS_PARAM_ERROR; + goto Error; + } + if(!readLen) + { + SLOGE("[%s] readLen Parameter error in SsClientDataRead..\n", __func__); + recv_data.rsp_type = SS_PARAM_ERROR; + goto Error; + } + + *readLen = 0; + buffer = pRetBuf; + + send_data = (ReqData_t*)malloc(sizeof(ReqData_t)); + + if(!send_data) + { + SLOGE("[%s] Memory allocation fail in SsClientDataRead..\n", __func__); + recv_data.rsp_type = SS_MEMORY_ERROR; + goto Error; + } + + // fill send_data + send_data->req_type = 3; // read data from storage + send_data->enc_type = 1; // initial type + send_data->count = 0; + send_data->flag = flag & 0x000000ff; //flag; + temp_len = strlen(filepath); + if(temp_len < MAX_FILENAME_LEN) + { + strncpy(send_data->data_infilepath, filepath, MAX_FILENAME_LEN - 1); + send_data->data_infilepath[temp_len] = '\0'; + } + else + { + SLOGE("[%s] filepath is too long.\n", __func__); + recv_data.rsp_type = SS_PARAM_ERROR; + goto Free_and_Error; + } + memset(send_data->cookie, 0x00, MAX_COOKIE_LEN); + memset(send_data->group_id, 0x00, MAX_GROUP_ID_LEN); + memcpy(send_data->cookie, cookie_content, MAX_COOKIE_LEN); + if(group_id) + strncpy(send_data->group_id, group_id, MAX_GROUP_ID_LEN - 1); + else + strncpy(send_data->group_id, "NOTUSED", MAX_GROUP_ID_LEN - 1); + memset(send_data->buffer, 0x00, MAX_SEND_DATA_LEN+1); + + // Call Server per 4KB data (count from 0 to ~) + for ( ; send_data->count < count; send_data->count++) + { + //receive data from server + recv_data = SsClientComm(send_data); + + // check response type + if(recv_data.rsp_type != 1) + { + SLOGE("[%s] data read error from server...\n", __func__); + goto Free_and_Error; + } + // copy the last data (last count) + if(send_data->count == (count - 1)) + { + memcpy(buffer, recv_data.buffer, rest); + *readLen += (size_t)rest; + goto Last; + //break; + } + + memcpy(buffer, recv_data.buffer, MAX_RECV_DATA_LEN); + *readLen += (size_t)recv_data.readLen; + buffer += recv_data.readLen; + } +Last : + if(bufLen != *readLen) + { + SLOGE( "[%s] Decrypted abnormally\n", __func__); + recv_data.rsp_type = SS_DECRYPTION_ERROR; + goto Free_and_Error; + } + + SLOGE("[%s] Decrypted file name : %s\n", __func__, recv_data.data_filepath); +Free_and_Error: + free(send_data); +Error: + return recv_data.rsp_type; +} + +int SsClientGetInfo(const char* filepath, ssm_file_info_t* sfi, ssm_flag flag, const char* group_id) +{ + + ReqData_t* send_data = NULL; + RspData_t recv_data; + ssm_file_info_convert_t sfic; + int temp_len = 0; + int cookie_size; + + cookie_size = security_server_get_cookie_size(); + char cookie_content[cookie_size]; + + if(security_server_request_cookie(cookie_content, cookie_size) < 0) // error while getting cookie + { + SLOGE("[%s] Fail to get cookie\n", __func__); + recv_data.rsp_type = SS_SECURE_STORAGE_ERROR; + goto Error; + } + + if(!filepath || !sfi) + { + SLOGE("[%s] Parameter error in SsClientGetInfo..\n", __func__); + recv_data.rsp_type = SS_PARAM_ERROR; + goto Error; + } + + send_data = (ReqData_t*)malloc(sizeof(ReqData_t)); + + if(!send_data) + { + SLOGE("[%s] Memory allocation fail in SsClientGetInfo..\n", __func__); + recv_data.rsp_type = SS_MEMORY_ERROR; + goto Error; + } + + // fill send_data + send_data->req_type = 4; // get info type + send_data->enc_type = 1; // initial type + send_data->count = 0; + send_data->flag = flag & 0x000000ff; //flag; + temp_len = strlen(filepath); + if(temp_len < MAX_FILENAME_LEN) + { + strncpy(send_data->data_infilepath, filepath, MAX_FILENAME_LEN - 1); + send_data->data_infilepath[temp_len] = '\0'; + } + else + { + SLOGE("[%s] filepath is too long.\n", __func__); + recv_data.rsp_type = SS_PARAM_ERROR; + goto Free_and_Error; + } + memset(send_data->cookie, 0x00, MAX_COOKIE_LEN); + memset(send_data->group_id, 0x00, MAX_GROUP_ID_LEN); + memcpy(send_data->cookie, cookie_content, cookie_size); + if(group_id) + strncpy(send_data->group_id, group_id, MAX_GROUP_ID_LEN - 1); + else + strncpy(send_data->group_id, "NOTUSED", MAX_GROUP_ID_LEN - 1); + memset(send_data->buffer, 0x00, MAX_SEND_DATA_LEN + 1); + + recv_data = SsClientComm(send_data); + + memcpy(sfic.fInfoArray, recv_data.buffer, sizeof(ssm_file_info_t)); + sfi->originSize = sfic.fInfoStruct.originSize; + sfi->storedSize = sfic.fInfoStruct.storedSize; + memcpy(sfi->reserved, sfic.fInfoStruct.reserved, 8); + +Free_and_Error: + free(send_data); +Error: + return recv_data.rsp_type; +} + +int SsClientDeleteFile(const char *pFilePath, ssm_flag flag, const char* group_id) +{ + ReqData_t* send_data = NULL; + RspData_t recv_data; + int temp_len = 0; + int cookie_size; + + cookie_size = security_server_get_cookie_size(); + char cookie_content[cookie_size]; + + if(security_server_request_cookie(cookie_content, cookie_size) < 0) // error while getting cookie + { + SLOGE("[%s] Fail to get cookie\n", __func__); + recv_data.rsp_type = SS_SECURE_STORAGE_ERROR; + goto Error; + } + + if(!pFilePath) + { + SLOGE("[%s] Parameter error in SsClientDeleteFile..\n", __func__); + recv_data.rsp_type = SS_PARAM_ERROR; + goto Error; + } + + send_data = (ReqData_t*)malloc(sizeof(ReqData_t)); + + if(!send_data) + { + SLOGE("[%s] Memory allocation fail in SsClientDeleteFile..\n", __func__); + recv_data.rsp_type = SS_MEMORY_ERROR; + goto Error; + } + + send_data->req_type = 10; // delete file + send_data->enc_type = 1; // initial type + send_data->count = 0; + send_data->flag = flag; // flag + temp_len = strlen(pFilePath); + if(temp_len < MAX_FILENAME_LEN) + { + strncpy(send_data->data_infilepath, pFilePath, MAX_FILENAME_LEN - 1); + send_data->data_infilepath[temp_len] = '\0'; + } + else + { + SLOGE("[%s] filepath is too long.\n", __func__); + recv_data.rsp_type = SS_PARAM_ERROR; + goto Free_and_Error; + } + memset(send_data->cookie, 0x00, MAX_COOKIE_LEN); + memset(send_data->group_id, 0x00, MAX_GROUP_ID_LEN); + memcpy(send_data->cookie, cookie_content, cookie_size); + if(group_id) + strncpy(send_data->group_id, group_id, MAX_GROUP_ID_LEN - 1); + else + strncpy(send_data->group_id, "NOTUSED", MAX_GROUP_ID_LEN - 1); + memset(send_data->buffer, 0x00, MAX_SEND_DATA_LEN+1); + + recv_data = SsClientComm(send_data); + +Free_and_Error: + free(send_data); + + SLOGE("[%s] Deleted file name: %s\n", __func__, recv_data.data_filepath); + +Error: + return recv_data.rsp_type; +} diff --git a/client/src/ss_client_ipc.c b/client/src/ss_client_ipc.c new file mode 100644 index 0000000..59899e2 --- /dev/null +++ b/client/src/ss_client_ipc.c @@ -0,0 +1,105 @@ +/* + * secure storage + * + * Copyright (c) 2000 - 2012 Samsung Electronics Co., Ltd All Rights Reserved + * + * Contact: Kidong Kim <kd0228.kim@samsung.com> + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + */ + +#include <stdio.h> +#include <stdlib.h> +#include <string.h> +#include <unistd.h> +#include <sys/stat.h> +#include <sys/un.h> +#include <sys/types.h> +#include <sys/socket.h> +#include <errno.h> + +#include "ss_client_ipc.h" +#include "secure_storage.h" + +#include "security-server.h" + +RspData_t SsClientComm(ReqData_t* client_data) +{ + int sockfd = 0; + int client_len = 0; + struct sockaddr_un clientaddr; + ReqData_t send_data = {0, }; + RspData_t recv_data = {0, }; + int temp_len_in = 0; + int temp_len_sock = 0; + int cookie_size = 0; + + send_data.req_type = client_data->req_type; + send_data.enc_type = client_data->enc_type; + send_data.count = client_data->count; + send_data.flag = client_data->flag; + + temp_len_in = strlen(client_data->data_infilepath); + + strncpy(send_data.data_infilepath, client_data->data_infilepath, MAX_FILENAME_LEN - 1); + send_data.data_infilepath[temp_len_in] = '\0'; + + cookie_size = security_server_get_cookie_size(); + memcpy(send_data.cookie, client_data->cookie, cookie_size); + strncpy(send_data.group_id, client_data->group_id, MAX_GROUP_ID_LEN - 1); + + memcpy(send_data.buffer, client_data->buffer, MAX_SEND_DATA_LEN); + + if((sockfd = socket(AF_UNIX, SOCK_STREAM, 0)) < 0) + { + SLOGE("[%s] Error in function socket()..\n", __func__); + recv_data.rsp_type = SS_SOCKET_ERROR; // ipc error + goto Error_exit; + } + + temp_len_sock = strlen(SS_SOCK_PATH); + + bzero(&clientaddr, sizeof(clientaddr)); + clientaddr.sun_family = AF_UNIX; + strncpy(clientaddr.sun_path, SS_SOCK_PATH, temp_len_sock); + clientaddr.sun_path[temp_len_sock] = '\0'; + client_len = sizeof(clientaddr); + + if(connect(sockfd, (struct sockaddr*)&clientaddr, client_len) < 0) + { + SLOGE("[%s] Error in function connect()..\n", __func__); + recv_data.rsp_type = SS_SOCKET_ERROR; // ipc error + goto Error_close_exit; + } + + if(write(sockfd, (char*)&send_data, sizeof(send_data)) < 0) + { + SLOGE("[%s] Error in function write()..\n", __func__); + recv_data.rsp_type = SS_SOCKET_ERROR; // ipc error + goto Error_close_exit; + } + + if(read(sockfd, (char*)&recv_data, sizeof(recv_data)) < 0) + { + SLOGE("[%s] Error in function read()..\n", __func__); + recv_data.rsp_type = SS_SOCKET_ERROR; // ipc error + goto Error_close_exit; + } + +Error_close_exit: + close(sockfd); + +Error_exit: + return recv_data; +} diff --git a/client/src/ss_manager.c b/client/src/ss_manager.c new file mode 100644 index 0000000..be8bc0f --- /dev/null +++ b/client/src/ss_manager.c @@ -0,0 +1,214 @@ +/* + * secure storage + * + * Copyright (c) 2000 - 2012 Samsung Electronics Co., Ltd All Rights Reserved + * + * Contact: Kidong Kim <kd0228.kim@samsung.com> + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + */ + +#include <stdio.h> +#include <stdlib.h> +#include <string.h> +#include <unistd.h> + +#include "secure_storage.h" +#include "ss_client_intf.h" + +#ifndef SS_API +#define SS_API __attribute__((visibility("default"))) +#endif + +/***************************************************************************** + * Internal Functions + *****************************************************************************/ +SS_API +int ssm_getinfo(const char* pFilePath, ssm_file_info_t *sfi, ssm_flag flag, const char* group_id) +{ + int ret = 0; + + if(!pFilePath || !sfi) + { + SLOGE("[%s] Parameter error in ssm_getinfo()..\n", __func__); + ret = SS_PARAM_ERROR; + goto Error; + } + + ret = SsClientGetInfo(pFilePath, sfi, flag, group_id); + + if(ret == 1) + { + SLOGI("[%s] Getinfo Success.\n", __func__); + ret = 0; // return true + } + else + SLOGE("[%s] Getinfo Fail.\n", __func__); + +Error: + return -(ret); +} + +/***************************************************************************** + * Manager APIs + *****************************************************************************/ +SS_API +int ssm_write_file(const char* pFilePath, ssm_flag flag, const char* group_id) +{ + int ret = 0; + + if(!pFilePath) + { + SLOGE("[%s] Parameter error in ssm_write_file()..\n", __func__); + ret = SS_PARAM_ERROR; + goto Error; + } + + if(flag <= SSM_FLAG_NONE || flag >= SSM_FLAG_MAX) + { + SLOGE("[%s] Parameter error in ssm_write_file()..\n", __func__); + ret = SS_PARAM_ERROR; + goto Error; + } + + ret = SsClientDataStoreFromFile(pFilePath, flag, group_id); + if(ret == 1) + { + if(unlink(pFilePath) != 0) // if fail + { + SLOGE("[%s] unlink fail. [%s]\n", __func__, pFilePath); + return -1; // return false + } + SLOGI("[%s] Write file Success.\n", __func__); + return 0; // return true + } + else + SLOGE( "[%s] Write file Fail.\n", __func__); + +Error: + return -(ret); +} + +SS_API +int ssm_write_buffer(char* pWriteBuffer, size_t bufLen, const char* pFileName, ssm_flag flag, const char* group_id) +{ + int ret = 0; + + if(!pWriteBuffer || !pFileName || (pFileName[0] == '/')) + { + SLOGE("[%s] Parameter error in ssm_write_buffer()..\n", __func__); + ret = SS_PARAM_ERROR; + goto Error; + } + if(bufLen <= 0 || bufLen > 4096) + { + SLOGE( "[%s] Parameter error in ssm_write_buffer()..\n", __func__ ); + ret = SS_PARAM_ERROR; + goto Error; + } + if(flag <= SSM_FLAG_NONE || flag >= SSM_FLAG_MAX) + { + SLOGE( "[%s] Parameter error in ssm_write_buffer()..\n", __func__ ); + ret = SS_PARAM_ERROR; + goto Error; + } + + ret = SsClientDataStoreFromBuffer(pWriteBuffer, bufLen, pFileName, flag, group_id); + if(ret == 1) + { + SLOGI("[%s] Write buffer Success.\n", __func__); + return 0; // return true + } + else + SLOGE("[%s] Write buffer Fail.\n", __func__); + +Error: + return -(ret); +} + +SS_API +int ssm_read(const char* pFilePath, char* pRetBuf, size_t bufLen, size_t *readLen, ssm_flag flag, const char* group_id) +{ + int ret = 0; + ssm_file_info_t sfi; + + if(!pFilePath || !pRetBuf) + { + SLOGE( "[%s] Parameter error in ssm_read()..\n", __func__ ); + ret = SS_PARAM_ERROR; + goto Error; + } + if(!readLen) + { + SLOGE("[%s] Parameter error in ssm_read()...\n", __func__); + ret = SS_PARAM_ERROR; + goto Error; + } + + // get info + ret = ssm_getinfo(pFilePath, &sfi, flag, group_id); + if(ret != 0) // ret != true? + { + SLOGE("[%s] getinfo error in ssm_read()..\n", __func__); + goto Error; + } + // in case of flag mismatch... + // check flag... + // To do : + if((bufLen > sfi.originSize) || (sfi.reserved[0] != (flag & 0x000000ff))) + { + SLOGE("[%s] Flag mismatch or buffer length error in ssm_read()..\n", __func__); + ret = SS_PARAM_ERROR; + goto Error; + } + + ret = SsClientDataRead(pFilePath, pRetBuf, sfi.originSize, readLen, flag, group_id); + + if(ret == 1) + { + SLOGI("[%s] Read Success.\n", __func__); + return 0; // return true + } + else + SLOGE("[%s] Read Fail.\n", __func__); + +Error: + return -(ret); +} + +SS_API +int ssm_delete_file(const char *pFilePath, ssm_flag flag, const char* group_id) +{ + int ret = 0; + + if(!pFilePath) + { + SLOGE("[%s] Parameter error in ssm_delete_file()..\n", __func__); + ret = SS_PARAM_ERROR; + goto Error; + } + + ret = SsClientDeleteFile(pFilePath, flag, group_id); + + if(ret == 1) // success + { + SLOGI("[%s] Delete file Success.\n", __func__); + return 0; + } + else // fail + SLOGE("[%s] Delete file Fail.\n", __func__); + +Error: + return -(ret); +} |