Merge "Fix bug about checking privilege" into tizen
[platform/core/uifw/stt.git] / client / stt.c
index 5fb6f49..163d67a 100644 (file)
@@ -1,5 +1,5 @@
 /*
-*  Copyright (c) 2011-2014 Samsung Electronics Co., Ltd All Rights Reserved
+*  Copyright (c) 2011-2016 Samsung Electronics Co., Ltd All Rights Reserved
 *  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
@@ -85,20 +85,21 @@ static int __check_privilege_initialize()
        int ret = cynara_initialize(&p_cynara, NULL);
        if (CYNARA_API_SUCCESS != ret)
                SLOG(LOG_ERROR, TAG_STTC, "[ERROR] fail to initialize");
-       
+
        return ret == CYNARA_API_SUCCESS;
 }
 
 static int __check_privilege(const char* uid, const char * privilege)
 {
        FILE *fp = NULL;
-       char smack_label[1024] = "/proc/self/attr/current";
+       char label_path[1024] = "/proc/self/attr/current";
+       char smack_label[1024] = {'\0',};
 
        if (!p_cynara) {
            return false;
        }
 
-       fp = fopen(smack_label, "r");
+       fp = fopen(label_path, "r");
        if (fp != NULL) {
            if (fread(smack_label, 1, sizeof(smack_label), fp) <= 0)
                SLOG(LOG_ERROR, TAG_STTC, "[ERROR] fail to fread");
@@ -110,8 +111,10 @@ static int __check_privilege(const char* uid, const char * privilege)
        char *session = cynara_session_from_pid(pid);
        int ret = cynara_check(p_cynara, smack_label, session, uid, privilege);
        SLOG(LOG_DEBUG, TAG_STTC, "[Client]cynara_check returned %d(%s)", ret, (CYNARA_API_ACCESS_ALLOWED == ret) ? "Allowed" : "Denied");
-       if (session)
-           free(session);
+       if (session) {
+               free(session);
+               session = NULL;
+       }
 
        if (ret != CYNARA_API_ACCESS_ALLOWED)
            return false;
@@ -133,7 +136,7 @@ static int __stt_check_privilege()
                SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Permission is denied");
                return STT_ERROR_PERMISSION_DENIED;
        } else if (-1 == g_privilege_allowed) {
-               if (false == __check_privilege_initialize()){
+               if (false == __check_privilege_initialize()) {
                        SLOG(LOG_ERROR, TAG_STTC, "[ERROR] privilege initialize is failed");
                        return STT_ERROR_PERMISSION_DENIED;
                }
@@ -148,7 +151,7 @@ static int __stt_check_privilege()
        }
 
        g_privilege_allowed = 1;
-       return STT_ERROR_NONE;  
+       return STT_ERROR_NONE;
 }
 
 static const char* __stt_get_error_code(stt_error_e err)
@@ -168,6 +171,7 @@ static const char* __stt_get_error_code(stt_error_e err)
        case STT_ERROR_ENGINE_NOT_FOUND:        return "STT_ERROR_ENGINE_NOT_FOUND";
        case STT_ERROR_OPERATION_FAILED:        return "STT_ERROR_OPERATION_FAILED";
        case STT_ERROR_NOT_SUPPORTED_FEATURE:   return "STT_ERROR_NOT_SUPPORTED_FEATURE";
+       case STT_ERROR_SERVICE_RESET:           return "STT_ERROR_SERVICE_RESET";
        default:
                return "Invalid error code";
        }
@@ -243,7 +247,7 @@ void __stt_config_engine_changed_cb(const char* engine_id, const char* setting,
        if (NULL != client->engine_changed_cb) {
                client->engine_changed_cb(stt, engine_id, language, support_silence, need_credential, client->engine_changed_user_data);
        } else {
-               SLOG(LOG_WARN, TAG_STTC, "No registered callback function of supported languages");
+               SLOG(LOG_WARN, TAG_STTC, "No registered callback function for engine change");
        }
        return;
 }
@@ -329,27 +333,18 @@ int stt_create(stt_h* stt)
 
 int stt_destroy(stt_h stt)
 {
+       stt_client_s* client = NULL;
        if (0 != __stt_get_feature_enabled()) {
                return STT_ERROR_NOT_SUPPORTED;
        }
        if (0 != __stt_check_privilege()) {
                return STT_ERROR_PERMISSION_DENIED;
        }
-
-       SLOG(LOG_DEBUG, TAG_STTC, "===== Destroy STT");
-
-       if (NULL == stt) {
-               SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Input handle is null");
+       if (0 != __stt_check_handle(stt, &client)) {
                return STT_ERROR_INVALID_PARAMETER;
        }
 
-       stt_client_s* client = stt_client_get(stt);
-
-       /* check handle */
-       if (NULL == client) {
-               SLOG(LOG_ERROR, TAG_STTC, "[ERROR] A handle is not available");
-               return STT_ERROR_INVALID_PARAMETER;
-       }
+       SLOG(LOG_DEBUG, TAG_STTC, "===== Destroy STT");
 
        /* check used callback */
        if (0 != stt_client_get_use_callback(client)) {
@@ -421,25 +416,21 @@ bool __stt_config_supported_engine_cb(const char* engine_id, const char* engine_
 
 int stt_foreach_supported_engines(stt_h stt, stt_supported_engine_cb callback, void* user_data)
 {
+       stt_client_s* client = NULL;
        if (0 != __stt_get_feature_enabled()) {
                return STT_ERROR_NOT_SUPPORTED;
        }
        if (0 != __stt_check_privilege()) {
                return STT_ERROR_PERMISSION_DENIED;
        }
-
-       SLOG(LOG_DEBUG, TAG_STTC, "===== Foreach Supported engine");
-
-       if (NULL == stt || NULL == callback) {
-               SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Input parameter is NULL");
+       if (0 != __stt_check_handle(stt, &client)) {
                return STT_ERROR_INVALID_PARAMETER;
        }
 
-       stt_client_s* client = stt_client_get(stt);
+       SLOG(LOG_DEBUG, TAG_STTC, "===== Foreach Supported engine");
 
-       /* check handle */
-       if (NULL == client) {
-               SLOG(LOG_ERROR, TAG_STTC, "[ERROR] A handle is not available");
+       if (NULL == callback) {
+               SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Input parameter is NULL");
                return STT_ERROR_INVALID_PARAMETER;
        }
 
@@ -469,22 +460,21 @@ int stt_foreach_supported_engines(stt_h stt, stt_supported_engine_cb callback, v
 
 int stt_get_engine(stt_h stt, char** engine_id)
 {
+       stt_client_s* client = NULL;
        if (0 != __stt_get_feature_enabled()) {
                return STT_ERROR_NOT_SUPPORTED;
        }
-
-       SLOG(LOG_DEBUG, TAG_STTC, "===== Get current engine");
-
-       if (NULL == stt || NULL == engine_id) {
-               SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Input parameter is NULL");
+       if (0 != __stt_check_privilege()) {
+               return STT_ERROR_PERMISSION_DENIED;
+       }
+       if (0 != __stt_check_handle(stt, &client)) {
                return STT_ERROR_INVALID_PARAMETER;
        }
 
-       stt_client_s* client = stt_client_get(stt);
+       SLOG(LOG_DEBUG, TAG_STTC, "===== Get current engine");
 
-       /* check handle */
-       if (NULL == client) {
-               SLOG(LOG_ERROR, TAG_STTC, "[ERROR] A handle is not available");
+       if (NULL == engine_id) {
+               SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Input parameter is NULL");
                return STT_ERROR_INVALID_PARAMETER;
        }
 
@@ -517,25 +507,21 @@ int stt_get_engine(stt_h stt, char** engine_id)
 
 int stt_set_engine(stt_h stt, const char* engine_id)
 {
+       stt_client_s* client = NULL;
        if (0 != __stt_get_feature_enabled()) {
                return STT_ERROR_NOT_SUPPORTED;
        }
        if (0 != __stt_check_privilege()) {
                return STT_ERROR_PERMISSION_DENIED;
        }
-
-       SLOG(LOG_DEBUG, TAG_STTC, "===== Set current engine");
-
-       if (NULL == stt || NULL == engine_id) {
-               SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Input parameter is NULL");
+       if (0 != __stt_check_handle(stt, &client)) {
                return STT_ERROR_INVALID_PARAMETER;
        }
 
-       stt_client_s* client = stt_client_get(stt);
+       SLOG(LOG_DEBUG, TAG_STTC, "===== Set current engine");
 
-       /* check handle */
-       if (NULL == client) {
-               SLOG(LOG_ERROR, TAG_STTC, "[ERROR] A handle is not available");
+       if (NULL == engine_id) {
+               SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Input parameter is NULL");
                return STT_ERROR_INVALID_PARAMETER;
        }
 
@@ -547,8 +533,11 @@ int stt_set_engine(stt_h stt, const char* engine_id)
 
        if (NULL != client->current_engine_id) {
                free(client->current_engine_id);
+               client->current_engine_id = NULL;
        }
 
+       SLOG(LOG_DEBUG, TAG_STTC, "===== engined_id(%s)", engine_id);
+
        client->current_engine_id = strdup(engine_id);
 
        SLOG(LOG_DEBUG, TAG_STTC, "=====");
@@ -559,25 +548,21 @@ int stt_set_engine(stt_h stt, const char* engine_id)
 
 int stt_set_credential(stt_h stt, const char* credential)
 {
+       stt_client_s* client = NULL;
        if (0 != __stt_get_feature_enabled()) {
                return STT_ERROR_NOT_SUPPORTED;
        }
        if (0 != __stt_check_privilege()) {
                return STT_ERROR_PERMISSION_DENIED;
        }
-
-       SLOG(LOG_DEBUG, TAG_STTC, "===== Set credential");
-
-       if (NULL == stt || NULL == credential) {
-               SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Input parameter is NULL, stt(%s), credential(%a)", stt, credential);
+       if (0 != __stt_check_handle(stt, &client)) {
                return STT_ERROR_INVALID_PARAMETER;
        }
 
-       stt_client_s* client = stt_client_get(stt);
+       SLOG(LOG_DEBUG, TAG_STTC, "===== Set credential");
 
-       /* check handle */
-       if (NULL == client) {
-               SLOG(LOG_ERROR, TAG_STTC, "[ERROR] A handle is not available");
+       if (NULL == credential) {
+               SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Input parameter is NULL");
                return STT_ERROR_INVALID_PARAMETER;
        }
 
@@ -587,6 +572,10 @@ int stt_set_credential(stt_h stt, const char* credential)
                return STT_ERROR_INVALID_STATE;
        }
 
+       if (NULL != client->credential) {
+               free(client->credential);
+               client->credential = NULL;
+       }
        client->credential = strdup(credential);
 
        SLOG(LOG_DEBUG, TAG_STTC, "=====");
@@ -598,7 +587,6 @@ int stt_set_credential(stt_h stt, const char* credential)
 int stt_set_private_data(stt_h stt, const char* key, const char* data)
 {
        stt_client_s* client = NULL;
-
        if (0 != __stt_get_feature_enabled()) {
                return STT_ERROR_NOT_SUPPORTED;
        }
@@ -651,7 +639,6 @@ int stt_set_private_data(stt_h stt, const char* key, const char* data)
 int stt_get_private_data(stt_h stt, const char* key, char** data)
 {
        stt_client_s* client = NULL;
-
        if (0 != __stt_get_feature_enabled()) {
                return STT_ERROR_NOT_SUPPORTED;
        }
@@ -695,6 +682,11 @@ int stt_get_private_data(stt_h stt, const char* key, char** data)
                }
        }
 
+       if (0 == strncmp(*data, "NULL", strlen(*data))) {
+               free(*data);
+               *data = NULL;
+       }
+
        SLOG(LOG_DEBUG, TAG_STTC, "=====");
        SLOG(LOG_DEBUG, TAG_STTC, "");
 
@@ -723,7 +715,7 @@ static Eina_Bool __stt_connect_daemon(void *data)
        }
 
        g_connect_timer = NULL;
-       SLOG(LOG_DEBUG, TAG_STTC, "===== Connect daemon");
+       SLOG(LOG_DEBUG, TAG_STTC, "===== Connect stt-service");
 
        /* request initialization */
        bool silence_supported = false;
@@ -743,17 +735,20 @@ static Eina_Bool __stt_connect_daemon(void *data)
                SLOG(LOG_ERROR, TAG_STTC, "[WARNING] Fail to connection. Retry to connect");
                return EINA_TRUE;
        } else {
-               /* success to connect stt-daemon */
+               /* success to connect stt-service */
                client->silence_supported = silence_supported;
                client->credential_needed = credential_needed;
                SLOG(LOG_DEBUG, TAG_STTC, "Supported options : silence(%s), credential(%s)", silence_supported ? "support" : "no support", credential_needed ? "need" : "no need");
        }
 
+#ifdef __UNUSED_CODES__
        if (NULL != client->current_engine_id) {
                ret = -1;
                int count = 0;
                silence_supported = false;
                credential_needed = false;
+               SLOG(LOG_DEBUG, TAG_STTC, "[WARNING] current_engine_id(%s)", client->current_engine_id);
+
                while (0 != ret) {
                        ret = stt_dbus_request_set_current_engine(client->uid, client->current_engine_id, &silence_supported, &credential_needed);
                        if (0 != ret) {
@@ -778,7 +773,7 @@ static Eina_Bool __stt_connect_daemon(void *data)
                        }
                }
        }
-
+#endif
        SLOG(LOG_DEBUG, TAG_STTC, "[SUCCESS] uid(%d)", client->uid);
 
        client->before_state = client->current_state;
@@ -802,20 +797,14 @@ static Eina_Bool __stt_connect_daemon(void *data)
 
 int stt_prepare(stt_h stt)
 {
+       stt_client_s* client = NULL;
        if (0 != __stt_get_feature_enabled()) {
                return STT_ERROR_NOT_SUPPORTED;
        }
        if (0 != __stt_check_privilege()) {
                return STT_ERROR_PERMISSION_DENIED;
        }
-
-       SLOG(LOG_DEBUG, TAG_STTC, "===== Prepare STT");
-
-       stt_client_s* client = stt_client_get(stt);
-
-       /* check handle */
-       if (NULL == client) {
-               SLOG(LOG_ERROR, TAG_STTC, "[ERROR] A handle is not available");
+       if (0 != __stt_check_handle(stt, &client)) {
                return STT_ERROR_INVALID_PARAMETER;
        }
 
@@ -835,23 +824,19 @@ int stt_prepare(stt_h stt)
 
 int stt_unprepare(stt_h stt)
 {
+       stt_client_s* client = NULL;
        if (0 != __stt_get_feature_enabled()) {
                return STT_ERROR_NOT_SUPPORTED;
        }
        if (0 != __stt_check_privilege()) {
                return STT_ERROR_PERMISSION_DENIED;
        }
-
-       SLOG(LOG_DEBUG, TAG_STTC, "===== Unprepare STT");
-
-       stt_client_s* client = stt_client_get(stt);
-
-       /* check handle */
-       if (NULL == client) {
-               SLOG(LOG_ERROR, TAG_STTC, "[ERROR] A handle is not available");
+       if (0 != __stt_check_handle(stt, &client)) {
                return STT_ERROR_INVALID_PARAMETER;
        }
 
+       SLOG(LOG_DEBUG, TAG_STTC, "===== Unprepare STT");
+
        /* check state */
        if (client->current_state != STT_STATE_READY) {
                SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Invalid State: Current state(%d) is not 'READY'", client->current_state);
@@ -925,25 +910,21 @@ bool __stt_config_supported_language_cb(const char* engine_id, const char* langu
 
 int stt_foreach_supported_languages(stt_h stt, stt_supported_language_cb callback, void* user_data)
 {
+       stt_client_s* client = NULL;
        if (0 != __stt_get_feature_enabled()) {
                return STT_ERROR_NOT_SUPPORTED;
        }
        if (0 != __stt_check_privilege()) {
                return STT_ERROR_PERMISSION_DENIED;
        }
-
-       SLOG(LOG_DEBUG, TAG_STTC, "===== Foreach Supported Language");
-
-       if (NULL == stt || NULL == callback) {
-               SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Input parameter is NULL");
+       if (0 != __stt_check_handle(stt, &client)) {
                return STT_ERROR_INVALID_PARAMETER;
        }
 
-       stt_client_s* client = stt_client_get(stt);
+       SLOG(LOG_DEBUG, TAG_STTC, "===== Foreach Supported Language");
 
-       /* check handle */
-       if (NULL == client) {
-               SLOG(LOG_ERROR, TAG_STTC, "[ERROR] A handle is not available");
+       if (NULL == callback) {
+               SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Input parameter is NULL");
                return STT_ERROR_INVALID_PARAMETER;
        }
 
@@ -976,6 +957,7 @@ int stt_foreach_supported_languages(stt_h stt, stt_supported_language_cb callbac
 
        if (NULL != current_engine_id) {
                free(current_engine_id);
+               current_engine_id = NULL;
        }
 
        client->supported_lang_cb = NULL;
@@ -989,26 +971,24 @@ int stt_foreach_supported_languages(stt_h stt, stt_supported_language_cb callbac
 
 int stt_get_default_language(stt_h stt, char** language)
 {
+       stt_client_s* client = NULL;
        if (0 != __stt_get_feature_enabled()) {
                return STT_ERROR_NOT_SUPPORTED;
        }
        if (0 != __stt_check_privilege()) {
                return STT_ERROR_PERMISSION_DENIED;
        }
+       if (0 != __stt_check_handle(stt, &client)) {
+               return STT_ERROR_INVALID_PARAMETER;
+       }
 
        SLOG(LOG_DEBUG, TAG_STTC, "===== Get Default Language");
 
-       if (NULL == stt || NULL == language) {
+       if (NULL == language) {
                SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Input parameter is NULL");
                return STT_ERROR_INVALID_PARAMETER;
        }
 
-       stt_client_s* client = stt_client_get(stt);
-       if (NULL == client) {
-               SLOG(LOG_ERROR, TAG_STTC, "[ERROR] A handle is not available");
-               return STT_ERROR_INVALID_PARAMETER;
-       }
-
        int ret = 0;
        ret = stt_config_mgr_get_default_language(language);
        ret = __stt_convert_config_error_code(ret);
@@ -1026,21 +1006,19 @@ int stt_get_default_language(stt_h stt, char** language)
 
 int stt_get_state(stt_h stt, stt_state_e* state)
 {
+       stt_client_s* client = NULL;
        if (0 != __stt_get_feature_enabled()) {
                return STT_ERROR_NOT_SUPPORTED;
        }
        if (0 != __stt_check_privilege()) {
                return STT_ERROR_PERMISSION_DENIED;
        }
-
-       if (NULL == stt || NULL == state) {
-               SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Input parameter is NULL");
+       if (0 != __stt_check_handle(stt, &client)) {
                return STT_ERROR_INVALID_PARAMETER;
        }
 
-       stt_client_s* client = stt_client_get(stt);
-       if (NULL == client) {
-               SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Get state : A handle is not valid");
+       if (NULL == state) {
+               SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Input parameter is NULL");
                return STT_ERROR_INVALID_PARAMETER;
        }
 
@@ -1059,14 +1037,18 @@ int stt_get_state(stt_h stt, stt_state_e* state)
 
 int stt_get_error_message(stt_h stt, char** err_msg)
 {
+       stt_client_s* client = NULL;
        if (0 != __stt_get_feature_enabled()) {
                return STT_ERROR_NOT_SUPPORTED;
        }
        if (0 != __stt_check_privilege()) {
                return STT_ERROR_PERMISSION_DENIED;
        }
+       if (0 != __stt_check_handle(stt, &client)) {
+               return STT_ERROR_INVALID_PARAMETER;
+       }
 
-       if (NULL == stt || NULL == err_msg) {
+       if (NULL == err_msg) {
                SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Input parameter is NULL");
                return STT_ERROR_INVALID_PARAMETER;
        }
@@ -1076,12 +1058,6 @@ int stt_get_error_message(stt_h stt, char** err_msg)
                return STT_ERROR_OPERATION_FAILED;
        }
 
-       stt_client_s* client = stt_client_get(stt);
-       if (NULL == client) {
-               SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Get error msg : A handle is not valid");
-               return STT_ERROR_INVALID_PARAMETER;
-       }
-
        if (NULL != client->err_msg) {
                *err_msg = strdup(client->err_msg);
                SLOG(LOG_DEBUG, TAG_STTC, "[SUCCESS] Error msg (%s)", *err_msg);
@@ -1097,21 +1073,19 @@ int stt_get_error_message(stt_h stt, char** err_msg)
 
 int stt_is_recognition_type_supported(stt_h stt, const char* type, bool* support)
 {
+       stt_client_s* client = NULL;
        if (0 != __stt_get_feature_enabled()) {
                return STT_ERROR_NOT_SUPPORTED;
        }
        if (0 != __stt_check_privilege()) {
                return STT_ERROR_PERMISSION_DENIED;
        }
-
-       if (NULL == stt || NULL == type || NULL == support) {
-               SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Input parameter is NULL");
+       if (0 != __stt_check_handle(stt, &client)) {
                return STT_ERROR_INVALID_PARAMETER;
        }
 
-       stt_client_s* client = stt_client_get(stt);
-       if (NULL == client) {
-               SLOG(LOG_ERROR, TAG_STTC, "[ERROR] A handle is not valid");
+       if (NULL == type || NULL == support) {
+               SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Input parameter is NULL");
                return STT_ERROR_INVALID_PARAMETER;
        }
 
@@ -1149,21 +1123,14 @@ int stt_is_recognition_type_supported(stt_h stt, const char* type, bool* support
 
 int stt_set_silence_detection(stt_h stt, stt_option_silence_detection_e type)
 {
+       stt_client_s* client = NULL;
        if (0 != __stt_get_feature_enabled()) {
                return STT_ERROR_NOT_SUPPORTED;
        }
        if (0 != __stt_check_privilege()) {
                return STT_ERROR_PERMISSION_DENIED;
        }
-
-       if (NULL == stt) {
-               SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Input parameter is NULL");
-               return STT_ERROR_INVALID_PARAMETER;
-       }
-
-       stt_client_s* client = stt_client_get(stt);
-       if (NULL == client) {
-               SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Get state : A handle is not valid");
+       if (0 != __stt_check_handle(stt, &client)) {
                return STT_ERROR_INVALID_PARAMETER;
        }
 
@@ -1189,16 +1156,20 @@ int stt_set_silence_detection(stt_h stt, stt_option_silence_detection_e type)
 
 int stt_set_start_sound(stt_h stt, const char* filename)
 {
+       stt_client_s* client = NULL;
        if (0 != __stt_get_feature_enabled()) {
                return STT_ERROR_NOT_SUPPORTED;
        }
        if (0 != __stt_check_privilege()) {
                return STT_ERROR_PERMISSION_DENIED;
        }
+       if (0 != __stt_check_handle(stt, &client)) {
+               return STT_ERROR_INVALID_PARAMETER;
+       }
 
        SLOG(LOG_DEBUG, TAG_STTC, "===== STT SET START SOUND");
 
-       if (NULL == stt || NULL == filename) {
+       if (NULL == filename) {
                SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Input parameter is NULL");
                return STT_ERROR_INVALID_PARAMETER;
        }
@@ -1208,12 +1179,6 @@ int stt_set_start_sound(stt_h stt, const char* filename)
                return STT_ERROR_INVALID_PARAMETER;
        }
 
-       stt_client_s* client = stt_client_get(stt);
-       if (NULL == client) {
-               SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Get state : A handle is not valid");
-               return STT_ERROR_INVALID_PARAMETER;
-       }
-
        /* check state */
        if (client->current_state != STT_STATE_READY) {
                SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Invalid State: Current state(%d) is not READY", client->current_state);
@@ -1248,26 +1213,18 @@ int stt_set_start_sound(stt_h stt, const char* filename)
 
 int stt_unset_start_sound(stt_h stt)
 {
+       stt_client_s* client = NULL;
        if (0 != __stt_get_feature_enabled()) {
                return STT_ERROR_NOT_SUPPORTED;
        }
        if (0 != __stt_check_privilege()) {
                return STT_ERROR_PERMISSION_DENIED;
        }
-
-       SLOG(LOG_DEBUG, TAG_STTC, "===== STT UNSET START SOUND");
-
-       if (NULL == stt) {
-               SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Input parameter is NULL");
+       if (0 != __stt_check_handle(stt, &client)) {
                return STT_ERROR_INVALID_PARAMETER;
        }
 
-       stt_client_s* client = stt_client_get(stt);
-
-       if (NULL == client) {
-               SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Get state : A handle is not valid");
-               return STT_ERROR_INVALID_PARAMETER;
-       }
+       SLOG(LOG_DEBUG, TAG_STTC, "===== STT UNSET START SOUND");
 
        /* check state */
        if (client->current_state != STT_STATE_READY) {
@@ -1303,16 +1260,20 @@ int stt_unset_start_sound(stt_h stt)
 
 int stt_set_stop_sound(stt_h stt, const char* filename)
 {
+       stt_client_s* client = NULL;
        if (0 != __stt_get_feature_enabled()) {
                return STT_ERROR_NOT_SUPPORTED;
        }
        if (0 != __stt_check_privilege()) {
                return STT_ERROR_PERMISSION_DENIED;
        }
+       if (0 != __stt_check_handle(stt, &client)) {
+               return STT_ERROR_INVALID_PARAMETER;
+       }
 
        SLOG(LOG_DEBUG, TAG_STTC, "===== STT SET STOP SOUND");
 
-       if (NULL == stt || NULL == filename) {
+       if (NULL == filename) {
                SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Input parameter is NULL");
                return STT_ERROR_INVALID_PARAMETER;
        }
@@ -1322,13 +1283,6 @@ int stt_set_stop_sound(stt_h stt, const char* filename)
                return STT_ERROR_INVALID_PARAMETER;
        }
 
-       stt_client_s* client = stt_client_get(stt);
-
-       if (NULL == client) {
-               SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Get state : A handle is not valid");
-               return STT_ERROR_INVALID_PARAMETER;
-       }
-
        /* check state */
        if (client->current_state != STT_STATE_READY) {
                SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Invalid State: Current state(%d) is not READY", client->current_state);
@@ -1363,26 +1317,18 @@ int stt_set_stop_sound(stt_h stt, const char* filename)
 
 int stt_unset_stop_sound(stt_h stt)
 {
+       stt_client_s* client = NULL;
        if (0 != __stt_get_feature_enabled()) {
                return STT_ERROR_NOT_SUPPORTED;
        }
        if (0 != __stt_check_privilege()) {
                return STT_ERROR_PERMISSION_DENIED;
        }
-
-       SLOG(LOG_DEBUG, TAG_STTC, "===== STT UNSET STOP SOUND");
-
-       if (NULL == stt) {
-               SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Input parameter is NULL");
+       if (0 != __stt_check_handle(stt, &client)) {
                return STT_ERROR_INVALID_PARAMETER;
        }
 
-       stt_client_s* client = stt_client_get(stt);
-
-       if (NULL == client) {
-               SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Get state : A handle is not valid");
-               return STT_ERROR_INVALID_PARAMETER;
-       }
+       SLOG(LOG_DEBUG, TAG_STTC, "===== STT UNSET STOP SOUND");
 
        /* check state */
        if (client->current_state != STT_STATE_READY) {
@@ -1418,25 +1364,18 @@ int stt_unset_stop_sound(stt_h stt)
 
 int stt_start(stt_h stt, const char* language, const char* type)
 {
+       stt_client_s* client = NULL;
        if (0 != __stt_get_feature_enabled()) {
                return STT_ERROR_NOT_SUPPORTED;
        }
        if (0 != __stt_check_privilege()) {
                return STT_ERROR_PERMISSION_DENIED;
        }
-
-       SLOG(LOG_DEBUG, TAG_STTC, "===== STT START");
-
-       if (NULL == stt) {
-               SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Input parameter is NULL");
+       if (0 != __stt_check_handle(stt, &client)) {
                return STT_ERROR_INVALID_PARAMETER;
        }
 
-       stt_client_s* client = stt_client_get(stt);
-       if (NULL == client) {
-               SLOG(LOG_ERROR, TAG_STTC, "[ERROR] A handle is not available");
-               return STT_ERROR_INVALID_PARAMETER;
-       }
+       SLOG(LOG_DEBUG, TAG_STTC, "===== STT START");
 
        /* check state */
        if (client->current_state != STT_STATE_READY) {
@@ -1489,25 +1428,18 @@ int stt_start(stt_h stt, const char* language, const char* type)
 
 int stt_stop(stt_h stt)
 {
+       stt_client_s* client = NULL;
        if (0 != __stt_get_feature_enabled()) {
                return STT_ERROR_NOT_SUPPORTED;
        }
        if (0 != __stt_check_privilege()) {
                return STT_ERROR_PERMISSION_DENIED;
        }
-
-       SLOG(LOG_DEBUG, TAG_STTC, "===== STT STOP");
-
-       if (NULL == stt) {
-               SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Input parameter is NULL");
+       if (0 != __stt_check_handle(stt, &client)) {
                return STT_ERROR_INVALID_PARAMETER;
        }
 
-       stt_client_s* client = stt_client_get(stt);
-       if (NULL == client) {
-               SLOG(LOG_ERROR, TAG_STTC, "[ERROR] A handle is not available");
-               return STT_ERROR_INVALID_PARAMETER;
-       }
+       SLOG(LOG_DEBUG, TAG_STTC, "===== STT STOP");
 
        /* check state */
        if (client->current_state != STT_STATE_RECORDING) {
@@ -1515,8 +1447,14 @@ int stt_stop(stt_h stt)
                return STT_ERROR_INVALID_STATE;
        }
 
-       if (STT_INTERNAL_STATE_NONE != client->internal_state) {
-               SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Invalid State : Internal state is NOT none : %d", client->internal_state);
+       if (STT_INTERNAL_STATE_STARTING == client->internal_state) {
+               SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Invalid State : Internal state is STARTING : %d", client->internal_state);
+               return STT_ERROR_IN_PROGRESS_TO_RECORDING;
+       } else if (STT_INTERNAL_STATE_CANCELING == client->internal_state) {
+               SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Invalid State : Internal state is CANCELING : %d", client->internal_state);
+               return STT_ERROR_IN_PROGRESS_TO_READY;
+       } else if (STT_INTERNAL_STATE_STOPPING == client->internal_state) {
+               SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Invalid State : Internal state is STOPPING : %d", client->internal_state);
                return STT_ERROR_IN_PROGRESS_TO_PROCESSING;
        }
 
@@ -1526,7 +1464,7 @@ int stt_stop(stt_h stt)
                SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Fail to stop : %s", __stt_get_error_code(ret));
        } else {
                SLOG(LOG_DEBUG, TAG_STTC, "[SUCCESS] Stop is successful but not done");
-               client->internal_state = STT_INTERNAL_STATE_STOPING;
+               client->internal_state = STT_INTERNAL_STATE_STOPPING;
        }
 
        SLOG(LOG_DEBUG, TAG_STTC, "=====");
@@ -1538,27 +1476,18 @@ int stt_stop(stt_h stt)
 
 int stt_cancel(stt_h stt)
 {
+       stt_client_s* client = NULL;
        if (0 != __stt_get_feature_enabled()) {
                return STT_ERROR_NOT_SUPPORTED;
        }
        if (0 != __stt_check_privilege()) {
                return STT_ERROR_PERMISSION_DENIED;
        }
-
-       SLOG(LOG_DEBUG, TAG_STTC, "===== STT CANCEL");
-
-       if (NULL == stt) {
-               SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Input handle is null");
+       if (0 != __stt_check_handle(stt, &client)) {
                return STT_ERROR_INVALID_PARAMETER;
        }
 
-       stt_client_s* client = stt_client_get(stt);
-
-       /* check handle */
-       if (NULL == client) {
-               SLOG(LOG_ERROR, TAG_STTC, "[ERROR] A handle is not available");
-               return STT_ERROR_INVALID_PARAMETER;
-       }
+       SLOG(LOG_DEBUG, TAG_STTC, "===== STT CANCEL");
 
        /* check state */
        if (STT_STATE_RECORDING != client->current_state && STT_STATE_PROCESSING != client->current_state) {
@@ -1566,8 +1495,14 @@ int stt_cancel(stt_h stt)
                return STT_ERROR_INVALID_STATE;
        }
 
-       if (STT_INTERNAL_STATE_NONE != client->internal_state) {
-               SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Invalid State : Internal state is NOT none : %d", client->internal_state);
+       if (STT_INTERNAL_STATE_STARTING == client->internal_state) {
+               SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Invalid State : Internal state is STARTING : %d", client->internal_state);
+               return STT_ERROR_IN_PROGRESS_TO_RECORDING;
+       } else if (STT_INTERNAL_STATE_STOPPING == client->internal_state) {
+               SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Invalid State : Internal state is STOPPING : %d", client->internal_state);
+               return STT_ERROR_IN_PROGRESS_TO_PROCESSING;
+       } else if (STT_INTERNAL_STATE_CANCELING == client->internal_state) {
+               SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Invalid State : Internal state is CANCELING : %d", client->internal_state);
                return STT_ERROR_IN_PROGRESS_TO_READY;
        }
 
@@ -1608,23 +1543,19 @@ int __stt_cb_set_volume(int uid, float volume)
 
 int stt_get_recording_volume(stt_h stt, float* volume)
 {
+       stt_client_s* client = NULL;
        if (0 != __stt_get_feature_enabled()) {
                return STT_ERROR_NOT_SUPPORTED;
        }
        if (0 != __stt_check_privilege()) {
                return STT_ERROR_PERMISSION_DENIED;
        }
-
-       if (NULL == stt || NULL == volume) {
-               SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Input parameter is NULL");
+       if (0 != __stt_check_handle(stt, &client)) {
                return STT_ERROR_INVALID_PARAMETER;
        }
 
-       stt_client_s* client = stt_client_get(stt);
-
-       /* check handle */
-       if (NULL == client) {
-               SLOG(LOG_ERROR, TAG_STTC, "[ERROR] A handle is not available");
+       if (NULL == volume) {
+               SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Input parameter is NULL");
                return STT_ERROR_INVALID_PARAMETER;
        }
 
@@ -1663,12 +1594,16 @@ bool __stt_result_time_cb(int index, int event, const char* text, long start_tim
 
 int stt_foreach_detailed_result(stt_h stt, stt_result_time_cb callback, void* user_data)
 {
+       stt_client_s* client = NULL;
        if (0 != __stt_get_feature_enabled()) {
                return STT_ERROR_NOT_SUPPORTED;
        }
        if (0 != __stt_check_privilege()) {
                return STT_ERROR_PERMISSION_DENIED;
        }
+       if (0 != __stt_check_handle(stt, &client)) {
+               return STT_ERROR_INVALID_PARAMETER;
+       }
 
        SLOG(LOG_DEBUG, TAG_STTC, "===== STT FOREACH DETAILED RESULT");
 
@@ -1677,14 +1612,6 @@ int stt_foreach_detailed_result(stt_h stt, stt_result_time_cb callback, void* us
                return STT_ERROR_INVALID_PARAMETER;
        }
 
-       stt_client_s* client = stt_client_get(stt);
-
-       /* check handle */
-       if (NULL == client) {
-               SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Fail : A handle is not valid");
-               return STT_ERROR_INVALID_PARAMETER;
-       }
-
        client->result_time_cb = callback;
        client->result_time_user_data = user_data;
 
@@ -1757,6 +1684,15 @@ int __stt_cb_error(int uid, int reason, char* err_msg)
                SLOG(LOG_WARN, TAG_STTC, "[WARNING] Error callback is null");
        }
 
+       if (STT_ERROR_SERVICE_RESET == reason) {
+               SLOG(LOG_WARN, TAG_STTC, "[WARNING] Service reset");
+
+               client->current_state = STT_STATE_CREATED;
+               if (0 != stt_prepare(client->stt)) {
+                       SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Fail to prepare");
+               }
+       }
+
        return 0;
 }
 
@@ -1777,7 +1713,7 @@ static void __stt_notify_state_changed(void *data)
        if (STT_INTERNAL_STATE_STARTING == client->internal_state && STT_STATE_RECORDING == client->current_state) {
                client->internal_state = STT_INTERNAL_STATE_NONE;
                SLOG(LOG_DEBUG, TAG_STTC, "Internal state change to NONE");
-       } else if (STT_INTERNAL_STATE_STOPING == client->internal_state && STT_STATE_PROCESSING == client->current_state) {
+       } else if (STT_INTERNAL_STATE_STOPPING == client->internal_state && STT_STATE_PROCESSING == client->current_state) {
                client->internal_state = STT_INTERNAL_STATE_NONE;
                SLOG(LOG_DEBUG, TAG_STTC, "Internal state change to NONE");
        } else if (STT_INTERNAL_STATE_CANCELING == client->internal_state && STT_STATE_READY == client->current_state) {
@@ -1939,23 +1875,19 @@ int __stt_cb_set_state(int uid, int state)
 
 int stt_set_recognition_result_cb(stt_h stt, stt_recognition_result_cb callback, void* user_data)
 {
+       stt_client_s* client = NULL;
        if (0 != __stt_get_feature_enabled()) {
                return STT_ERROR_NOT_SUPPORTED;
        }
        if (0 != __stt_check_privilege()) {
                return STT_ERROR_PERMISSION_DENIED;
        }
-
-       if (stt == NULL || callback == NULL)
+       if (0 != __stt_check_handle(stt, &client)) {
                return STT_ERROR_INVALID_PARAMETER;
+       }
 
-       stt_client_s* client = stt_client_get(stt);
-
-       /* check handle */
-       if (NULL == client) {
-               SLOG(LOG_ERROR, TAG_STTC, "[ERROR] A handle is not available");
+       if (callback == NULL)
                return STT_ERROR_INVALID_PARAMETER;
-       }
 
        if (STT_STATE_CREATED != client->current_state) {
                SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Current state(%d) is not 'Created'", client->current_state);
@@ -1970,21 +1902,14 @@ int stt_set_recognition_result_cb(stt_h stt, stt_recognition_result_cb callback,
 
 int stt_unset_recognition_result_cb(stt_h stt)
 {
+       stt_client_s* client = NULL;
        if (0 != __stt_get_feature_enabled()) {
                return STT_ERROR_NOT_SUPPORTED;
        }
        if (0 != __stt_check_privilege()) {
                return STT_ERROR_PERMISSION_DENIED;
        }
-
-       if (NULL == stt)
-               return STT_ERROR_INVALID_PARAMETER;
-
-       stt_client_s* client = stt_client_get(stt);
-
-       /* check handle */
-       if (NULL == client) {
-               SLOG(LOG_ERROR, TAG_STTC, "[ERROR] A handle is not available");
+       if (0 != __stt_check_handle(stt, &client)) {
                return STT_ERROR_INVALID_PARAMETER;
        }
 
@@ -2001,23 +1926,19 @@ int stt_unset_recognition_result_cb(stt_h stt)
 
 int stt_set_state_changed_cb(stt_h stt, stt_state_changed_cb callback, void* user_data)
 {
+       stt_client_s* client = NULL;
        if (0 != __stt_get_feature_enabled()) {
                return STT_ERROR_NOT_SUPPORTED;
        }
        if (0 != __stt_check_privilege()) {
                return STT_ERROR_PERMISSION_DENIED;
        }
-
-       if (NULL == stt || NULL == callback)
+       if (0 != __stt_check_handle(stt, &client)) {
                return STT_ERROR_INVALID_PARAMETER;
+       }
 
-       stt_client_s* client = stt_client_get(stt);
-
-       /* check handle */
-       if (NULL == client) {
-               SLOG(LOG_ERROR, TAG_STTC, "[ERROR] A handle is not available");
+       if (NULL == callback)
                return STT_ERROR_INVALID_PARAMETER;
-       }
 
        if (STT_STATE_CREATED != client->current_state) {
                SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Current state(%d) is not 'Created'", client->current_state);
@@ -2032,21 +1953,14 @@ int stt_set_state_changed_cb(stt_h stt, stt_state_changed_cb callback, void* use
 
 int stt_unset_state_changed_cb(stt_h stt)
 {
+       stt_client_s* client = NULL;
        if (0 != __stt_get_feature_enabled()) {
                return STT_ERROR_NOT_SUPPORTED;
        }
        if (0 != __stt_check_privilege()) {
                return STT_ERROR_PERMISSION_DENIED;
        }
-
-       if (NULL == stt)
-               return STT_ERROR_INVALID_PARAMETER;
-
-       stt_client_s* client = stt_client_get(stt);
-
-       /* check handle */
-       if (NULL == client) {
-               SLOG(LOG_ERROR, TAG_STTC, "[ERROR] A handle is not available");
+       if (0 != __stt_check_handle(stt, &client)) {
                return STT_ERROR_INVALID_PARAMETER;
        }
 
@@ -2063,23 +1977,19 @@ int stt_unset_state_changed_cb(stt_h stt)
 
 int stt_set_error_cb(stt_h stt, stt_error_cb callback, void* user_data)
 {
+       stt_client_s* client = NULL;
        if (0 != __stt_get_feature_enabled()) {
                return STT_ERROR_NOT_SUPPORTED;
        }
        if (0 != __stt_check_privilege()) {
                return STT_ERROR_PERMISSION_DENIED;
        }
-
-       if (NULL == stt || NULL == callback)
+       if (0 != __stt_check_handle(stt, &client)) {
                return STT_ERROR_INVALID_PARAMETER;
+       }
 
-       stt_client_s* client = stt_client_get(stt);
-
-       /* check handle */
-       if (NULL == client) {
-               SLOG(LOG_ERROR, TAG_STTC, "[ERROR] A handle is not available");
+       if (NULL == callback)
                return STT_ERROR_INVALID_PARAMETER;
-       }
 
        if (STT_STATE_CREATED != client->current_state) {
                SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Current state(%d) is not 'Created'", client->current_state);
@@ -2094,21 +2004,14 @@ int stt_set_error_cb(stt_h stt, stt_error_cb callback, void* user_data)
 
 int stt_unset_error_cb(stt_h stt)
 {
+       stt_client_s* client = NULL;
        if (0 != __stt_get_feature_enabled()) {
                return STT_ERROR_NOT_SUPPORTED;
        }
        if (0 != __stt_check_privilege()) {
                return STT_ERROR_PERMISSION_DENIED;
        }
-
-       if (NULL == stt)
-               return STT_ERROR_INVALID_PARAMETER;
-
-       stt_client_s* client = stt_client_get(stt);
-
-       /* check handle */
-       if (NULL == client) {
-               SLOG(LOG_ERROR, TAG_STTC, "[ERROR] A handle is not available");
+       if (0 != __stt_check_handle(stt, &client)) {
                return STT_ERROR_INVALID_PARAMETER;
        }
 
@@ -2125,23 +2028,19 @@ int stt_unset_error_cb(stt_h stt)
 
 int stt_set_default_language_changed_cb(stt_h stt, stt_default_language_changed_cb callback, void* user_data)
 {
+       stt_client_s* client = NULL;
        if (0 != __stt_get_feature_enabled()) {
                return STT_ERROR_NOT_SUPPORTED;
        }
        if (0 != __stt_check_privilege()) {
                return STT_ERROR_PERMISSION_DENIED;
        }
-
-       if (NULL == stt || NULL == callback)
+       if (0 != __stt_check_handle(stt, &client)) {
                return STT_ERROR_INVALID_PARAMETER;
+       }
 
-       stt_client_s* client = stt_client_get(stt);
-
-       /* check handle */
-       if (NULL == client) {
-               SLOG(LOG_ERROR, TAG_STTC, "[ERROR] A handle is not available");
+       if (NULL == callback)
                return STT_ERROR_INVALID_PARAMETER;
-       }
 
        if (STT_STATE_CREATED != client->current_state) {
                SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Current state(%d) is not 'Created'", client->current_state);
@@ -2156,21 +2055,14 @@ int stt_set_default_language_changed_cb(stt_h stt, stt_default_language_changed_
 
 int stt_unset_default_language_changed_cb(stt_h stt)
 {
+       stt_client_s* client = NULL;
        if (0 != __stt_get_feature_enabled()) {
                return STT_ERROR_NOT_SUPPORTED;
        }
        if (0 != __stt_check_privilege()) {
                return STT_ERROR_PERMISSION_DENIED;
        }
-
-       if (NULL == stt)
-               return STT_ERROR_INVALID_PARAMETER;
-
-       stt_client_s* client = stt_client_get(stt);
-
-       /* check handle */
-       if (NULL == client) {
-               SLOG(LOG_ERROR, TAG_STTC, "[ERROR] A handle is not available");
+       if (0 != __stt_check_handle(stt, &client)) {
                return STT_ERROR_INVALID_PARAMETER;
        }
 
@@ -2187,23 +2079,19 @@ int stt_unset_default_language_changed_cb(stt_h stt)
 
 int stt_set_engine_changed_cb(stt_h stt, stt_engine_changed_cb callback, void* user_data)
 {
+       stt_client_s* client = NULL;
        if (0 != __stt_get_feature_enabled()) {
                return STT_ERROR_NOT_SUPPORTED;
        }
        if (0 != __stt_check_privilege()) {
                return STT_ERROR_PERMISSION_DENIED;
        }
-
-       if (NULL == stt || NULL == callback)
+       if (0 != __stt_check_handle(stt, &client)) {
                return STT_ERROR_INVALID_PARAMETER;
+       }
 
-       stt_client_s* client = stt_client_get(stt);
-
-       /* check handle */
-       if (NULL == client) {
-               SLOG(LOG_ERROR, TAG_STTC, "[ERROR] A handle is not available");
+       if (NULL == callback)
                return STT_ERROR_INVALID_PARAMETER;
-       }
 
        if (STT_STATE_CREATED != client->current_state) {
                SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Current state(%d) is not 'Created'", client->current_state);
@@ -2218,21 +2106,14 @@ int stt_set_engine_changed_cb(stt_h stt, stt_engine_changed_cb callback, void* u
 
 int stt_unset_engine_changed_cb(stt_h stt)
 {
+       stt_client_s* client = NULL;
        if (0 != __stt_get_feature_enabled()) {
                return STT_ERROR_NOT_SUPPORTED;
        }
        if (0 != __stt_check_privilege()) {
                return STT_ERROR_PERMISSION_DENIED;
        }
-
-       if (NULL == stt)
-               return STT_ERROR_INVALID_PARAMETER;
-
-       stt_client_s* client = stt_client_get(stt);
-
-       /* check handle */
-       if (NULL == client) {
-               SLOG(LOG_ERROR, TAG_STTC, "[ERROR] A handle is not available");
+       if (0 != __stt_check_handle(stt, &client)) {
                return STT_ERROR_INVALID_PARAMETER;
        }