2 * Copyright (c) 2011-2015 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.
19 #include <cynara-client.h>
20 #include <cynara-error.h>
21 #include <cynara-session.h>
24 #include <system_info.h>
26 #include "vc_command.h"
27 #include "vc_info_parser.h"
29 #include "vc_regex_rule.h"
30 #include "vc_config_mgr.h"
31 #include "voice_control_command.h"
32 #include "voice_control_command_expand.h"
33 #include "voice_control_common.h"
34 #include "voice_control_key_defines.h"
36 static pthread_mutex_t g_cmd_mutex = PTHREAD_MUTEX_INITIALIZER;
37 static pthread_mutex_t g_cmd_list_mutex = PTHREAD_MUTEX_INITIALIZER;
38 #define CMD_MUTEX_LOCK() pthread_mutex_lock(&g_cmd_mutex)
39 #define CMD_MUTEX_UNLOCK() pthread_mutex_unlock(&g_cmd_mutex)
40 #define CMD_LIST_MUTEX_LOCK() pthread_mutex_lock(&g_cmd_list_mutex)
41 #define CMD_LIST_MUTEX_UNLOCK() pthread_mutex_unlock(&g_cmd_list_mutex)
43 static int g_feature_enabled = -1;
44 static bool g_privilege_allowed = false;
46 static pthread_mutex_t g_cynara_mutex = PTHREAD_MUTEX_INITIALIZER;
47 static cynara *p_cynara = NULL;
48 static GList *g_cmd_list = NULL;
49 static GList *g_cmdlist_list = NULL;
52 // For getting timestamp using regular expression
53 static regex_t reg[MAX_NUM_REGEX];
54 static time_t t_now; //time_t is based on UTC
55 static struct tm td_now; //if use localtime function, the value follows the local time zone, otherwise it follows the UTC.
57 static int g_time_flag;
58 static int g_date_flag;
60 static int g_data_sidx;
61 static int g_data_eidx;
63 static int __vc_cmd_get_feature_enabled()
65 if (0 == g_feature_enabled) {
66 SLOG(LOG_ERROR, TAG_VCCMD, "[ERROR] Voice control feature NOT supported");
67 return VC_ERROR_NOT_SUPPORTED;
68 } else if (-1 == g_feature_enabled) {
69 bool vc_supported = false;
70 bool mic_supported = false;
71 if (0 == system_info_get_platform_bool(VC_FEATURE_PATH, &vc_supported)) {
72 if (0 == system_info_get_platform_bool(VC_MIC_FEATURE_PATH, &mic_supported)) {
73 if (false == vc_supported || false == mic_supported) {
74 SLOG(LOG_ERROR, TAG_VCCMD, "[ERROR] Voice control feature NOT supported");
75 g_feature_enabled = 0;
76 return VC_ERROR_NOT_SUPPORTED;
79 g_feature_enabled = 1;
81 SLOG(LOG_ERROR, TAG_VCCMD, "[ERROR] Fail to get feature value");
82 return VC_ERROR_NOT_SUPPORTED;
85 SLOG(LOG_ERROR, TAG_VCCMD, "[ERROR] Fail to get feature value");
86 return VC_ERROR_NOT_SUPPORTED;
93 static int __check_privilege_initialize()
95 int ret = cynara_initialize(&p_cynara, NULL);
96 if (CYNARA_API_SUCCESS != ret)
97 SLOG(LOG_ERROR, TAG_VCCMD, "[ERROR] fail to initialize");
99 return ret == CYNARA_API_SUCCESS;
102 static int __check_privilege(const char* uid, const char * privilege)
105 char label_path[1024] = "/proc/self/attr/current";
106 char smack_label[1024] = {'\0',};
112 fp = fopen(label_path, "r");
114 if (0 >= fread(smack_label, 1, sizeof(smack_label), fp))
115 SLOG(LOG_ERROR, TAG_VCCMD, "[ERROR] fail to fread");
120 pid_t pid = getpid();
121 char *session = cynara_session_from_pid(pid);
122 int ret = cynara_check(p_cynara, smack_label, session, uid, privilege);
123 SLOG(LOG_DEBUG, TAG_VCCMD, "[Client]cynara_check returned %d(%s)", ret, (CYNARA_API_ACCESS_ALLOWED == ret) ? "Allowed" : "Denied");
127 if (ret != CYNARA_API_ACCESS_ALLOWED)
132 static void __check_privilege_deinitialize()
136 int ret = cynara_finish(p_cynara);
137 if (ret != CYNARA_API_SUCCESS)
138 SLOG(LOG_ERROR, TAG_VCCMD, "[ERROR] cynara finish %d", ret);
143 static int __vc_cmd_check_privilege()
145 if (true == g_privilege_allowed)
146 return VC_ERROR_NONE;
148 pthread_mutex_lock(&g_cynara_mutex);
150 if (false == g_privilege_allowed) {
152 ret = __check_privilege_initialize();
154 SLOG(LOG_ERROR, TAG_VCCMD, "[ERROR] privilege initialize is failed");
155 g_privilege_allowed = false;
156 pthread_mutex_unlock(&g_cynara_mutex);
157 return VC_ERROR_PERMISSION_DENIED;
161 snprintf(uid, 32, "%d", getuid());
163 ret = __check_privilege(uid, VC_PRIVILEGE);
164 __check_privilege_deinitialize();
166 SLOG(LOG_ERROR, TAG_VCCMD, "[ERROR] Permission is denied");
167 g_privilege_allowed = false;
168 pthread_mutex_unlock(&g_cynara_mutex);
169 return VC_ERROR_PERMISSION_DENIED;
173 g_privilege_allowed = true;
174 pthread_mutex_unlock(&g_cynara_mutex);
175 return VC_ERROR_NONE;
178 int vc_cmd_list_create(vc_cmd_list_h* vc_cmd_list)
180 if (0 != __vc_cmd_get_feature_enabled()) {
181 return VC_ERROR_NOT_SUPPORTED;
183 if (0 != __vc_cmd_check_privilege()) {
184 return VC_ERROR_PERMISSION_DENIED;
187 CMD_LIST_MUTEX_LOCK();
189 if (NULL == vc_cmd_list) {
190 SLOG(LOG_ERROR, TAG_VCCMD, "[ERROR] Input parameter is NULL");
191 CMD_LIST_MUTEX_UNLOCK();
192 return VC_ERROR_INVALID_PARAMETER;
195 vc_cmd_list_s* list = (vc_cmd_list_s*)calloc(1, sizeof(vc_cmd_list_s));
198 SLOG(LOG_ERROR, TAG_VCCMD, "[ERROR] Not enough memory");
199 CMD_LIST_MUTEX_UNLOCK();
200 return VC_ERROR_OUT_OF_MEMORY;
206 *vc_cmd_list = (vc_cmd_list_h)list;
208 g_cmdlist_list = g_list_append(g_cmdlist_list, list);
210 SLOG(LOG_DEBUG, TAG_VCCMD, "[List] list(%p)", *vc_cmd_list);
212 CMD_LIST_MUTEX_UNLOCK();
213 return VC_ERROR_NONE;
216 int vc_cmd_list_destroy(vc_cmd_list_h vc_cmd_list, bool release_command)
218 if (0 != __vc_cmd_get_feature_enabled()) {
219 return VC_ERROR_NOT_SUPPORTED;
221 if (0 != __vc_cmd_check_privilege()) {
222 return VC_ERROR_PERMISSION_DENIED;
225 CMD_LIST_MUTEX_LOCK();
227 if (NULL == vc_cmd_list) {
228 SLOG(LOG_ERROR, TAG_VCCMD, "[ERROR] Input parameter is NULL");
229 CMD_LIST_MUTEX_UNLOCK();
230 return VC_ERROR_INVALID_PARAMETER;
234 vc_cmd_list_s* list = NULL;
235 list = (vc_cmd_list_s*)vc_cmd_list;
237 SLOG(LOG_DEBUG, TAG_VCCMD, "[List] list(%p)", list);
240 iter = g_list_find(g_cmdlist_list, list);
242 SLOG(LOG_ERROR, TAG_VCCMD, "Fail to destroy client : handle is not valid");
243 CMD_LIST_MUTEX_UNLOCK();
244 return VC_ERROR_INVALID_PARAMETER;
247 g_cmdlist_list = g_list_delete_link(g_cmdlist_list, iter);
249 vc_cmd_list_remove_all((vc_cmd_list_h)list, release_command);
253 SLOG(LOG_DEBUG, TAG_VCCMD, "Client destroy");
255 CMD_LIST_MUTEX_UNLOCK();
256 return VC_ERROR_NONE;
259 int vc_cmd_list_get_count(vc_cmd_list_h vc_cmd_list, int* count)
261 if (0 != __vc_cmd_get_feature_enabled()) {
262 return VC_ERROR_NOT_SUPPORTED;
264 if (0 != __vc_cmd_check_privilege()) {
265 return VC_ERROR_PERMISSION_DENIED;
268 if (NULL == vc_cmd_list || NULL == count) {
269 SLOG(LOG_ERROR, TAG_VCCMD, "[ERROR] Get command count : Input parameter is NULL");
270 return VC_ERROR_INVALID_PARAMETER;
273 vc_cmd_list_s* list = NULL;
274 list = (vc_cmd_list_s*)vc_cmd_list;
276 *count = g_slist_length(list->list);
278 SLOG(LOG_DEBUG, TAG_VCCMD, "[List] list(%p), count(%d)", list, *count);
280 return VC_ERROR_NONE;
283 int vc_cmd_list_add(vc_cmd_list_h vc_cmd_list, vc_cmd_h vc_command)
285 if (0 != __vc_cmd_get_feature_enabled()) {
286 return VC_ERROR_NOT_SUPPORTED;
288 if (0 != __vc_cmd_check_privilege()) {
289 return VC_ERROR_PERMISSION_DENIED;
292 if (NULL == vc_cmd_list || NULL == vc_command) {
293 SLOG(LOG_ERROR, TAG_VCCMD, "[ERROR] Input parameter is NULL");
294 return VC_ERROR_INVALID_PARAMETER;
297 vc_cmd_list_s* list = NULL;
298 list = (vc_cmd_list_s*)vc_cmd_list;
300 vc_cmd_s* cmd = NULL;
301 cmd = (vc_cmd_s*)vc_command;
303 list->list = g_slist_append(list->list, cmd);
305 if (1 == g_slist_length(list->list)) {
309 SLOG(LOG_DEBUG, TAG_VCCMD, "[List] list(%p), command(%p)", list, cmd);
311 return VC_ERROR_NONE;
314 int vc_cmd_list_remove(vc_cmd_list_h vc_cmd_list, vc_cmd_h vc_command)
316 if (0 != __vc_cmd_get_feature_enabled()) {
317 return VC_ERROR_NOT_SUPPORTED;
319 if (0 != __vc_cmd_check_privilege()) {
320 return VC_ERROR_PERMISSION_DENIED;
323 if (NULL == vc_cmd_list || NULL == vc_command) {
324 SLOG(LOG_ERROR, TAG_VCCMD, "[ERROR] Input parameter is NULL");
325 return VC_ERROR_INVALID_PARAMETER;
328 vc_cmd_list_s* list = NULL;
329 list = (vc_cmd_list_s*)vc_cmd_list;
331 vc_cmd_s* cmd = NULL;
332 cmd = (vc_cmd_s*)vc_command;
334 SLOG(LOG_DEBUG, TAG_VCCMD, "[List] list(%p), command(%p)", list, cmd);
337 iter = g_slist_find(list->list, cmd);
339 SLOG(LOG_ERROR, TAG_VCCMD, "Fail to destroy command : handle is not valid");
340 return VC_ERROR_INVALID_PARAMETER;
343 list->list = g_slist_remove_link(list->list, iter);
344 SLOG(LOG_DEBUG, TAG_VCCMD, "destroy command");
346 int len = g_slist_length(list->list);
349 else if (list->index == len)
350 list->index = len - 1;
352 return VC_ERROR_NONE;
355 static void __vc_cmd_list_remove_all_foreach(gpointer data, gpointer user_data)
357 vc_cmd_s *temp = NULL;
360 SLOG(LOG_DEBUG, TAG_VCCMD, "Free command(%p)", temp);
361 vc_cmd_destroy((vc_cmd_h)temp);
367 int vc_cmd_list_remove_all(vc_cmd_list_h vc_cmd_list, bool release_command)
369 if (0 != __vc_cmd_get_feature_enabled()) {
370 return VC_ERROR_NOT_SUPPORTED;
372 if (0 != __vc_cmd_check_privilege()) {
373 return VC_ERROR_PERMISSION_DENIED;
376 SLOG(LOG_DEBUG, TAG_VCCMD, "@@@ Destroy all command");
378 if (NULL == vc_cmd_list) {
379 SLOG(LOG_ERROR, TAG_VCCMD, "[ERROR] Input parameter is NULL");
380 return VC_ERROR_INVALID_PARAMETER;
383 vc_cmd_list_s* list = NULL;
384 list = (vc_cmd_list_s*)vc_cmd_list;
386 SLOG(LOG_DEBUG, TAG_VCCMD, "[List] list (%p), release command (%s)"
387 , list, release_command ? "true" : "false");
389 if (true == release_command) {
391 g_slist_foreach(list->list, __vc_cmd_list_remove_all_foreach, NULL);
392 g_slist_free(list->list);
398 SLOG(LOG_DEBUG, TAG_VCCMD, "@@@");
400 return VC_ERROR_NONE;
403 int vc_cmd_list_foreach_commands(vc_cmd_list_h vc_cmd_list, vc_cmd_list_cb callback, void* user_data)
405 if (0 != __vc_cmd_get_feature_enabled()) {
406 return VC_ERROR_NOT_SUPPORTED;
408 if (0 != __vc_cmd_check_privilege()) {
409 return VC_ERROR_PERMISSION_DENIED;
412 if (NULL == vc_cmd_list) {
413 SLOG(LOG_ERROR, TAG_VCCMD, "[ERROR] Input parameter is NULL");
414 return VC_ERROR_INVALID_PARAMETER;
417 vc_cmd_list_s* list = NULL;
418 list = (vc_cmd_list_s*)vc_cmd_list;
421 iter = g_slist_nth(list->list, 0);
422 while (NULL != iter) {
423 vc_cmd_s *temp_cmd = NULL;
424 temp_cmd = iter->data;
425 if (NULL == temp_cmd) {
426 SLOG(LOG_ERROR, TAG_VCCMD, "[ERROR] No command in list");
427 return VC_ERROR_OPERATION_FAILED;
429 if (false == callback((vc_cmd_h)temp_cmd, user_data))
432 iter = g_slist_next(iter);
435 SLOG(LOG_DEBUG, TAG_VCCMD, "@@@ Foreach commands Done");
437 return VC_ERROR_NONE;
440 int vc_cmd_list_filter_by_type(vc_cmd_list_h original, int type, vc_cmd_list_h* filtered)
442 SLOG(LOG_DEBUG, TAG_VCCMD, "@@@ Filter by type");
444 if (0 != __vc_cmd_get_feature_enabled()) {
445 return VC_ERROR_NOT_SUPPORTED;
447 if (0 != __vc_cmd_check_privilege()) {
448 return VC_ERROR_PERMISSION_DENIED;
451 if (NULL == original) {
452 SLOG(LOG_ERROR, TAG_VCCMD, "[ERROR] Input parameter is NULL");
453 return VC_ERROR_INVALID_PARAMETER;
456 if (VC_COMMAND_TYPE_NONE >= type || VC_COMMAND_TYPE_EXCLUSIVE < type) {
457 SLOG(LOG_ERROR, TAG_VCCMD, "[ERROR] Invalid type");
458 return VC_ERROR_INVALID_PARAMETER;
461 vc_cmd_list_s* list = NULL;
462 list = (vc_cmd_list_s*)original;
464 vc_cmd_list_h temp_list;
465 if (0 != vc_cmd_list_create(&temp_list)) {
466 SLOG(LOG_ERROR, TAG_VCCMD, "[ERROR] Fail to list create");
467 return VC_ERROR_OPERATION_FAILED;
471 iter = g_slist_nth(list->list, 0);
472 while (NULL != iter) {
473 vc_cmd_s *iter_cmd = NULL;
474 iter_cmd = iter->data;
475 if (NULL == iter_cmd) {
476 SLOG(LOG_ERROR, TAG_VCCMD, "[ERROR] No command in list");
477 return VC_ERROR_OPERATION_FAILED;
481 if (0 != vc_cmd_get_type((vc_cmd_h)iter_cmd, &iter_type)) {
482 SLOG(LOG_ERROR, TAG_VCCMD, "[ERROR] Fail to get command type");
486 if (iter_type == type) {
488 if (0 != vc_cmd_create(&temp_cmd)) {
489 SLOG(LOG_ERROR, TAG_VCCMD, "[ERROR] Fail to create cmd");
493 memcpy(temp_cmd, iter_cmd, sizeof(vc_cmd_s));
494 if (NULL != iter_cmd->command)
495 ((vc_cmd_s *)temp_cmd)->command = strdup(iter_cmd->command);
496 if (NULL != iter_cmd->parameter)
497 ((vc_cmd_s *)temp_cmd)->parameter = strdup(iter_cmd->parameter);
499 if (0 != vc_cmd_list_add(temp_list, temp_cmd)) {
500 SLOG(LOG_ERROR, TAG_VCCMD, "[ERROR] Fail to cmd list add");
501 vc_cmd_destroy(temp_cmd);
505 iter = g_slist_next(iter);
509 if (0 != vc_cmd_list_get_count(temp_list, &count)) {
510 SLOG(LOG_ERROR, TAG_VCCMD, "[ERROR] Fail to get count");
512 SLOG(LOG_DEBUG, TAG_VCCMD, "Filtering result : (%d) command", count);
515 *filtered = temp_list;
517 SLOG(LOG_DEBUG, TAG_VCCMD, "@@@");
519 return VC_ERROR_NONE;
522 int vc_cmd_list_first(vc_cmd_list_h vc_cmd_list)
524 if (0 != __vc_cmd_get_feature_enabled()) {
525 return VC_ERROR_NOT_SUPPORTED;
527 if (0 != __vc_cmd_check_privilege()) {
528 return VC_ERROR_PERMISSION_DENIED;
531 if (NULL == vc_cmd_list) {
532 SLOG(LOG_ERROR, TAG_VCCMD, "[ERROR] Input parameter is NULL");
533 return VC_ERROR_INVALID_PARAMETER;
536 vc_cmd_list_s* list = NULL;
537 list = (vc_cmd_list_s*)vc_cmd_list;
539 if (0 == g_slist_length(list->list)) {
540 SLOG(LOG_ERROR, TAG_VCCMD, "[ERROR] List is empty");
541 return VC_ERROR_EMPTY;
546 return VC_ERROR_NONE;
549 int vc_cmd_list_last(vc_cmd_list_h vc_cmd_list)
551 if (0 != __vc_cmd_get_feature_enabled()) {
552 return VC_ERROR_NOT_SUPPORTED;
554 if (0 != __vc_cmd_check_privilege()) {
555 return VC_ERROR_PERMISSION_DENIED;
558 if (NULL == vc_cmd_list) {
559 SLOG(LOG_ERROR, TAG_VCCMD, "[ERROR] Input parameter is NULL");
560 return VC_ERROR_INVALID_PARAMETER;
563 vc_cmd_list_s* list = NULL;
564 list = (vc_cmd_list_s*)vc_cmd_list;
566 int count = g_slist_length(list->list);
569 SLOG(LOG_ERROR, TAG_VCCMD, "[ERROR] List is empty");
570 return VC_ERROR_EMPTY;
572 list->index = count - 1;
573 SLOG(LOG_DEBUG, TAG_VCCMD, "[DEBUG] List index : %d", list->index);
576 return VC_ERROR_NONE;
579 int vc_cmd_list_next(vc_cmd_list_h vc_cmd_list)
581 if (0 != __vc_cmd_get_feature_enabled()) {
582 return VC_ERROR_NOT_SUPPORTED;
584 if (0 != __vc_cmd_check_privilege()) {
585 return VC_ERROR_PERMISSION_DENIED;
588 if (NULL == vc_cmd_list) {
589 SLOG(LOG_ERROR, TAG_VCCMD, "[ERROR] Input parameter is NULL");
590 return VC_ERROR_INVALID_PARAMETER;
593 vc_cmd_list_s* list = NULL;
594 list = (vc_cmd_list_s*)vc_cmd_list;
596 int count = g_slist_length(list->list);
598 if (list->index < count - 1) {
599 list->index = list->index + 1;
600 SLOG(LOG_DEBUG, TAG_VCCMD, "[DEBUG] List index : %d", list->index);
602 SLOG(LOG_DEBUG, TAG_VCCMD, "[DEBUG] List index : %d", list->index);
603 return VC_ERROR_ITERATION_END;
606 return VC_ERROR_NONE;
609 int vc_cmd_list_prev(vc_cmd_list_h vc_cmd_list)
611 if (0 != __vc_cmd_get_feature_enabled()) {
612 return VC_ERROR_NOT_SUPPORTED;
614 if (0 != __vc_cmd_check_privilege()) {
615 return VC_ERROR_PERMISSION_DENIED;
618 if (NULL == vc_cmd_list) {
619 SLOG(LOG_ERROR, TAG_VCCMD, "[ERROR] Input parameter is NULL");
620 return VC_ERROR_INVALID_PARAMETER;
623 vc_cmd_list_s* list = NULL;
624 list = (vc_cmd_list_s*)vc_cmd_list;
626 if (list->index > 0) {
627 list->index = list->index - 1;
628 SLOG(LOG_DEBUG, TAG_VCCMD, "[DEBUG] List index : %d", list->index);
630 SLOG(LOG_DEBUG, TAG_VCCMD, "[DEBUG] List index : %d", list->index);
631 return VC_ERROR_ITERATION_END;
634 return VC_ERROR_NONE;
637 int vc_cmd_list_get_current(vc_cmd_list_h vc_cmd_list, vc_cmd_h* vc_command)
639 if (0 != __vc_cmd_get_feature_enabled()) {
640 return VC_ERROR_NOT_SUPPORTED;
642 if (0 != __vc_cmd_check_privilege()) {
643 return VC_ERROR_PERMISSION_DENIED;
646 if (NULL == vc_cmd_list || NULL == vc_command) {
647 SLOG(LOG_ERROR, TAG_VCCMD, "[ERROR] Input parameter is NULL");
648 return VC_ERROR_INVALID_PARAMETER;
651 vc_cmd_list_s* list = NULL;
652 list = (vc_cmd_list_s*)vc_cmd_list;
654 SLOG(LOG_DEBUG, TAG_VCCMD, "[List] list (%p), index (%d)", list, list->index);
656 if (0 == g_slist_length(list->list)) {
657 SLOG(LOG_DEBUG, TAG_VCCMD, "[List] list is empty");
659 return VC_ERROR_EMPTY;
662 vc_cmd_s *temp_cmd = NULL;
663 temp_cmd = g_slist_nth_data(list->list, list->index);
665 *vc_command = (vc_cmd_h)temp_cmd;
667 SLOG(LOG_DEBUG, TAG_VCCMD, "[List] Get current command (%p)", *vc_command);
669 return VC_ERROR_NONE;
673 int vc_cmd_create(vc_cmd_h* vc_command)
675 if (0 != __vc_cmd_get_feature_enabled()) {
676 return VC_ERROR_NOT_SUPPORTED;
678 if (0 != __vc_cmd_check_privilege()) {
679 return VC_ERROR_PERMISSION_DENIED;
684 if (NULL == vc_command) {
685 SLOG(LOG_ERROR, TAG_VCCMD, "[ERROR] Input parameter is NULL");
687 return VC_ERROR_INVALID_PARAMETER;
690 vc_cmd_s* command = (vc_cmd_s*)calloc(1, sizeof(vc_cmd_s));
692 if (NULL == command) {
693 SLOG(LOG_ERROR, TAG_VCCMD, "[ERROR] Not enough memory");
695 return VC_ERROR_OUT_OF_MEMORY;
701 command->type = VC_COMMAND_TYPE_NONE;
702 command->format = VC_CMD_FORMAT_FIXED;
703 command->command = NULL;
704 command->parameter = NULL;
706 command->priority = 0;
707 command->key = VC_KEY_NONE;
708 command->modifier = VC_MODIFIER_NONE;
709 command->invocation_name = NULL;
710 command->appid = NULL;
711 command->fixed = NULL;
712 command->coordinates = NULL;
714 *vc_command = (vc_cmd_h)command;
716 g_cmd_list = g_list_append(g_cmd_list, command);
718 SLOG(LOG_DEBUG, TAG_VCCMD, "[Create command][%p]", *vc_command);
721 return VC_ERROR_NONE;
724 int vc_cmd_destroy(vc_cmd_h vc_command)
726 if (0 != __vc_cmd_get_feature_enabled()) {
727 return VC_ERROR_NOT_SUPPORTED;
729 if (0 != __vc_cmd_check_privilege()) {
730 return VC_ERROR_PERMISSION_DENIED;
735 if (NULL == vc_command) {
736 SLOG(LOG_ERROR, TAG_VCCMD, "[ERROR] Input parameter is NULL");
738 return VC_ERROR_INVALID_PARAMETER;
741 vc_cmd_s* command = NULL;
742 command = (vc_cmd_s*)vc_command;
744 SLOG(LOG_DEBUG, TAG_VCCMD, "[Destroy command][%p]", command);
747 iter = g_list_find(g_cmd_list, command);
749 SLOG(LOG_ERROR, TAG_VCCMD, "Fail to command destroy : handle is not valid");
751 return VC_ERROR_INVALID_PARAMETER;
754 g_cmd_list = g_list_delete_link(g_cmd_list, iter);
756 if (command->command)
757 free(command->command);
758 command->command = NULL;
759 if (command->parameter)
760 free(command->parameter);
761 command->parameter = NULL;
762 if (command->invocation_name)
763 free(command->invocation_name);
764 command->invocation_name = NULL;
766 free(command->appid);
767 command->appid = NULL;
769 free(command->fixed);
770 command->fixed = NULL;
771 if (command->coordinates)
772 free(command->coordinates);
773 command->coordinates = NULL;
778 return VC_ERROR_NONE;
781 int vc_cmd_set_id(vc_cmd_h vc_command, int id)
783 if (0 != __vc_cmd_get_feature_enabled()) {
784 return VC_ERROR_NOT_SUPPORTED;
786 if (0 != __vc_cmd_check_privilege()) {
787 return VC_ERROR_PERMISSION_DENIED;
790 if (NULL == vc_command) {
791 SLOG(LOG_ERROR, TAG_VCCMD, "[ERROR] Invalid parameter ");
792 return VC_ERROR_INVALID_PARAMETER;
795 vc_cmd_s* cmd = NULL;
796 cmd = (vc_cmd_s*)vc_command;
799 SLOG(LOG_DEBUG, TAG_VCCMD, "[Set id][%p] id(%d)", vc_command, cmd->id);
801 return VC_ERROR_NONE;
804 int vc_cmd_get_id(vc_cmd_h vc_command, int* id)
806 if (0 != __vc_cmd_get_feature_enabled()) {
807 return VC_ERROR_NOT_SUPPORTED;
809 if (0 != __vc_cmd_check_privilege()) {
810 return VC_ERROR_PERMISSION_DENIED;
813 if (NULL == vc_command || NULL == id) {
814 SLOG(LOG_ERROR, TAG_VCCMD, "[ERROR] Invalid handle ");
815 return VC_ERROR_INVALID_PARAMETER;
818 vc_cmd_s* cmd = NULL;
819 cmd = (vc_cmd_s*)vc_command;
822 SLOG(LOG_DEBUG, TAG_VCCMD, "[Get id][%p] id(%d)", vc_command, *id);
824 return VC_ERROR_NONE;
827 int vc_cmd_set_appid(vc_cmd_h vc_command, const char* appid)
829 if (0 != __vc_cmd_get_feature_enabled()) {
830 return VC_ERROR_NOT_SUPPORTED;
833 if (NULL == vc_command) {
834 SLOG(LOG_ERROR, TAG_VCCMD, "[ERROR] Invalid parameter, vc_command is NULL");
835 return VC_ERROR_INVALID_PARAMETER;
839 SLOG(LOG_ERROR, TAG_VCCMD, "[ERROR] Invalid parameter, appid is NULL");
840 return VC_ERROR_INVALID_PARAMETER;
843 vc_cmd_s* cmd = NULL;
844 cmd = (vc_cmd_s*)vc_command;
849 cmd->appid = strdup(appid);
851 SLOG(LOG_DEBUG, TAG_VCCMD, "[Set appid][%p] appid(%s)", vc_command, cmd->appid);
852 return VC_ERROR_NONE;
855 int vc_cmd_get_appid(vc_cmd_h vc_command, char** appid)
857 if (0 != __vc_cmd_get_feature_enabled()) {
858 return VC_ERROR_NOT_SUPPORTED;
861 if (NULL == vc_command || NULL == appid) {
862 SLOG(LOG_ERROR, TAG_VCCMD, "[ERROR] Invalid handle ");
863 return VC_ERROR_INVALID_PARAMETER;
866 vc_cmd_s* cmd = NULL;
867 cmd = (vc_cmd_s*)vc_command;
870 *appid = strdup(gettext(cmd->appid));
874 SLOG(LOG_DEBUG, TAG_VCCMD, "[Get appid][%p] appid(%s)", vc_command, *appid);
876 return VC_ERROR_NONE;
879 int vc_cmd_set_command(vc_cmd_h vc_command, const char* command)
881 if (0 != __vc_cmd_get_feature_enabled()) {
882 return VC_ERROR_NOT_SUPPORTED;
884 if (0 != __vc_cmd_check_privilege()) {
885 return VC_ERROR_PERMISSION_DENIED;
888 if (NULL == vc_command || NULL == command) {
889 SLOG(LOG_ERROR, TAG_VCCMD, "[ERROR] Invalid parameter ");
890 return VC_ERROR_INVALID_PARAMETER;
893 vc_cmd_s* cmd = NULL;
894 cmd = (vc_cmd_s*)vc_command;
899 cmd->command = strdup(command);
901 SLOG(LOG_DEBUG, TAG_VCCMD, "[Set command][%p] Command(%s)", vc_command, cmd->command);
903 return VC_ERROR_NONE;
906 int vc_cmd_get_command(vc_cmd_h vc_command, char** command)
908 if (0 != __vc_cmd_get_feature_enabled()) {
909 return VC_ERROR_NOT_SUPPORTED;
911 if (0 != __vc_cmd_check_privilege()) {
912 return VC_ERROR_PERMISSION_DENIED;
915 if (NULL == vc_command || NULL == command) {
916 SLOG(LOG_ERROR, TAG_VCCMD, "[ERROR] Invalid handle ");
917 return VC_ERROR_INVALID_PARAMETER;
920 vc_cmd_s* cmd = NULL;
921 cmd = (vc_cmd_s*)vc_command;
924 *command = strdup(gettext(cmd->command));
928 SLOG(LOG_DEBUG, TAG_VCCMD, "[Get command][%p] Command(%s)", vc_command, *command);
930 return VC_ERROR_NONE;
933 int vc_cmd_set_unfixed_command(vc_cmd_h vc_command, const char* command)
935 if (0 != __vc_cmd_get_feature_enabled()) {
936 return VC_ERROR_NOT_SUPPORTED;
938 if (0 != __vc_cmd_check_privilege()) {
939 return VC_ERROR_PERMISSION_DENIED;
942 if (NULL == vc_command || NULL == command) {
943 SLOG(LOG_ERROR, TAG_VCCMD, "[ERROR] Invalid parameter ");
944 return VC_ERROR_INVALID_PARAMETER;
947 vc_cmd_s* cmd = NULL;
948 cmd = (vc_cmd_s*)vc_command;
951 free(cmd->parameter);
952 cmd->parameter = NULL;
953 cmd->parameter = strdup(command);
954 SLOG(LOG_DEBUG, TAG_VCCMD, "[Set unfixed command][%p] unfixed command(%s)", vc_command, cmd->parameter);
956 return VC_ERROR_NONE;
959 int vc_cmd_get_unfixed_command(vc_cmd_h vc_command, char** command)
961 if (0 != __vc_cmd_get_feature_enabled()) {
962 return VC_ERROR_NOT_SUPPORTED;
965 if (NULL == vc_command || NULL == command) {
966 SLOG(LOG_ERROR, TAG_VCCMD, "[ERROR] Invalid handle ");
967 return VC_ERROR_INVALID_PARAMETER;
970 vc_cmd_s* cmd = NULL;
971 cmd = (vc_cmd_s*)vc_command;
974 *command = strdup(gettext(cmd->parameter));
978 SLOG(LOG_DEBUG, TAG_VCCMD, "[Get unfixed command][%p] unfixed command(%s)", vc_command, *command);
980 return VC_ERROR_NONE;
983 int vc_cmd_set_fixed_command(vc_cmd_h vc_command, const char* fixed)
985 if (0 != __vc_cmd_get_feature_enabled()) {
986 return VC_ERROR_NOT_SUPPORTED;
989 if (NULL == vc_command) {
990 SLOG(LOG_ERROR, TAG_VCCMD, "[ERROR] Invalid parameter ");
991 return VC_ERROR_INVALID_PARAMETER;
995 SLOG(LOG_ERROR, TAG_VCCMD, "[ERROR] Invalid parameter, fixed is NULL");
996 return VC_ERROR_INVALID_PARAMETER;
999 vc_cmd_s* cmd = NULL;
1000 cmd = (vc_cmd_s*)vc_command;
1005 cmd->fixed = strdup(fixed);
1007 SLOG(LOG_DEBUG, TAG_VCCMD, "[Set parameter][%p] fixed command(%s)", vc_command, cmd->fixed);
1008 return VC_ERROR_NONE;
1011 int vc_cmd_get_fixed_command(vc_cmd_h vc_command, char** fixed)
1013 if (0 != __vc_cmd_get_feature_enabled()) {
1014 return VC_ERROR_NOT_SUPPORTED;
1017 if (NULL == vc_command || NULL == fixed) {
1018 SLOG(LOG_ERROR, TAG_VCCMD, "[ERROR] Invalid handle ");
1019 return VC_ERROR_INVALID_PARAMETER;
1022 vc_cmd_s* cmd = NULL;
1023 cmd = (vc_cmd_s*)vc_command;
1026 *fixed = strdup(gettext(cmd->fixed));
1030 SLOG(LOG_DEBUG, TAG_VCCMD, "[Get fixed command][%p] fixed command(%s)", vc_command, *fixed);
1032 return VC_ERROR_NONE;
1035 int vc_cmd_set_invocation_name(vc_cmd_h vc_command, const char* invocation_name)
1037 if (0 != __vc_cmd_get_feature_enabled()) {
1038 return VC_ERROR_NOT_SUPPORTED;
1041 if (NULL == vc_command) {
1042 SLOG(LOG_ERROR, TAG_VCCMD, "[ERROR] Invalid parameter, vc_command is NULL");
1043 return VC_ERROR_INVALID_PARAMETER;
1046 if (NULL == invocation_name) {
1047 SLOG(LOG_ERROR, TAG_VCCMD, "[ERROR] Invalid parameter, invocation_name is NULL");
1048 return VC_ERROR_INVALID_PARAMETER;
1051 vc_cmd_s* cmd = NULL;
1052 cmd = (vc_cmd_s*)vc_command;
1054 if (cmd->invocation_name)
1055 free(cmd->invocation_name);
1056 cmd->invocation_name = NULL;
1057 cmd->invocation_name = strdup(invocation_name);
1059 SLOG(LOG_DEBUG, TAG_VCCMD, "[Set invocation name][%p] invocation_name(%s)", vc_command, cmd->invocation_name);
1060 return VC_ERROR_NONE;
1063 int vc_cmd_get_invocation_name(vc_cmd_h vc_command, char** invocation_name)
1065 if (0 != __vc_cmd_get_feature_enabled()) {
1066 return VC_ERROR_NOT_SUPPORTED;
1069 if (NULL == vc_command || NULL == invocation_name) {
1070 SLOG(LOG_ERROR, TAG_VCCMD, "[ERROR] Invalid handle ");
1071 return VC_ERROR_INVALID_PARAMETER;
1074 vc_cmd_s* cmd = NULL;
1075 cmd = (vc_cmd_s*)vc_command;
1077 if (cmd->invocation_name)
1078 *invocation_name = strdup(gettext(cmd->invocation_name));
1080 *invocation_name = NULL;
1082 SLOG(LOG_DEBUG, TAG_VCCMD, "[Get invocation name][%p] invocation_name(%s)", vc_command, *invocation_name);
1083 return VC_ERROR_NONE;
1086 int vc_cmd_set_type(vc_cmd_h vc_command, int type)
1088 if (0 != __vc_cmd_get_feature_enabled()) {
1089 return VC_ERROR_NOT_SUPPORTED;
1091 if (0 != __vc_cmd_check_privilege()) {
1092 return VC_ERROR_PERMISSION_DENIED;
1095 if (NULL == vc_command) {
1096 SLOG(LOG_ERROR, TAG_VCCMD, "[ERROR] Invalid parameter ");
1097 return VC_ERROR_INVALID_PARAMETER;
1100 vc_cmd_s* cmd = NULL;
1101 cmd = (vc_cmd_s*)vc_command;
1105 SLOG(LOG_DEBUG, TAG_VCCMD, "[Set type][%p] type(%d)", vc_command, cmd->type);
1107 return VC_ERROR_NONE;
1110 int vc_cmd_get_type(vc_cmd_h vc_command, int* type)
1112 if (0 != __vc_cmd_get_feature_enabled()) {
1113 return VC_ERROR_NOT_SUPPORTED;
1115 if (0 != __vc_cmd_check_privilege()) {
1116 return VC_ERROR_PERMISSION_DENIED;
1119 if (NULL == vc_command || NULL == type) {
1120 SLOG(LOG_ERROR, TAG_VCCMD, "[ERROR] Invalid parameter ");
1121 return VC_ERROR_INVALID_PARAMETER;
1124 vc_cmd_s* cmd = NULL;
1125 cmd = (vc_cmd_s*)vc_command;
1129 SLOG(LOG_DEBUG, TAG_VCCMD, "[Get type][%p] type(%d)", vc_command, *type);
1131 return VC_ERROR_NONE;
1134 int vc_cmd_set_format(vc_cmd_h vc_command, int format)
1136 if (0 != __vc_cmd_get_feature_enabled()) {
1137 return VC_ERROR_NOT_SUPPORTED;
1140 if (NULL == vc_command) {
1141 SLOG(LOG_ERROR, TAG_VCCMD, "[ERROR] Invalid parameter ");
1142 return VC_ERROR_INVALID_PARAMETER;
1145 vc_cmd_s* cmd = NULL;
1146 cmd = (vc_cmd_s*)vc_command;
1148 cmd->format = format;
1150 SLOG(LOG_DEBUG, TAG_VCCMD, "[Set format][%p] format(%d)", vc_command, format);
1152 return VC_ERROR_NONE;
1155 int vc_cmd_get_format(vc_cmd_h vc_command, int* format)
1157 if (0 != __vc_cmd_get_feature_enabled()) {
1158 return VC_ERROR_NOT_SUPPORTED;
1161 if (NULL == vc_command || NULL == format) {
1162 SLOG(LOG_ERROR, TAG_VCCMD, "[ERROR] Invalid parameter ");
1163 return VC_ERROR_INVALID_PARAMETER;
1166 vc_cmd_s* cmd = NULL;
1167 cmd = (vc_cmd_s*)vc_command;
1169 *format = cmd->format;
1171 SLOG(LOG_DEBUG, TAG_VCCMD, "[Get format][%p] format(%d)", vc_command, *format);
1173 return VC_ERROR_NONE;
1176 int vc_cmd_set_pid(vc_cmd_h vc_command, int pid)
1178 if (0 != __vc_cmd_get_feature_enabled()) {
1179 return VC_ERROR_NOT_SUPPORTED;
1181 if (0 != __vc_cmd_check_privilege()) {
1182 return VC_ERROR_PERMISSION_DENIED;
1185 if (NULL == vc_command) {
1186 SLOG(LOG_ERROR, TAG_VCCMD, "[ERROR] Invalid parameter ");
1187 return VC_ERROR_INVALID_PARAMETER;
1190 vc_cmd_s* cmd = NULL;
1191 cmd = (vc_cmd_s*)vc_command;
1195 SLOG(LOG_DEBUG, TAG_VCCMD, "[Set pid][%p] pid(%d)", vc_command, cmd->pid);
1197 return VC_ERROR_NONE;
1200 int vc_cmd_get_pid(vc_cmd_h vc_command, int* pid)
1202 if (0 != __vc_cmd_get_feature_enabled()) {
1203 return VC_ERROR_NOT_SUPPORTED;
1205 if (0 != __vc_cmd_check_privilege()) {
1206 return VC_ERROR_PERMISSION_DENIED;
1209 if (NULL == vc_command || NULL == pid) {
1210 SLOG(LOG_ERROR, TAG_VCCMD, "[ERROR] Invalid parameter ");
1211 return VC_ERROR_INVALID_PARAMETER;
1214 vc_cmd_s* cmd = NULL;
1215 cmd = (vc_cmd_s*)vc_command;
1219 SLOG(LOG_DEBUG, TAG_VCCMD, "[Get pid][%p] pid(%d)", vc_command, *pid);
1221 return VC_ERROR_NONE;
1224 int vc_cmd_set_domain(vc_cmd_h vc_command, int domain)
1226 if (0 != __vc_cmd_get_feature_enabled()) {
1227 return VC_ERROR_NOT_SUPPORTED;
1229 if (0 != __vc_cmd_check_privilege()) {
1230 return VC_ERROR_PERMISSION_DENIED;
1233 if (NULL == vc_command) {
1234 SLOG(LOG_ERROR, TAG_VCCMD, "[ERROR] Invalid parameter ");
1235 return VC_ERROR_INVALID_PARAMETER;
1238 vc_cmd_s* cmd = NULL;
1239 cmd = (vc_cmd_s*)vc_command;
1241 cmd->domain = domain;
1243 SLOG(LOG_DEBUG, TAG_VCCMD, "[Set domain] domain : %d", domain);
1245 return VC_ERROR_NONE;
1248 int vc_cmd_get_domain(vc_cmd_h vc_command, int* domain)
1250 if (0 != __vc_cmd_get_feature_enabled()) {
1251 return VC_ERROR_NOT_SUPPORTED;
1253 if (0 != __vc_cmd_check_privilege()) {
1254 return VC_ERROR_PERMISSION_DENIED;
1257 if (NULL == vc_command || NULL == domain) {
1258 SLOG(LOG_ERROR, TAG_VCCMD, "[ERROR] Invalid parameter ");
1259 return VC_ERROR_INVALID_PARAMETER;
1262 vc_cmd_s* cmd = NULL;
1263 cmd = (vc_cmd_s*)vc_command;
1265 *domain = cmd->domain;
1267 SLOG(LOG_DEBUG, TAG_VCCMD, "[Get domain] domain : %d", *domain);
1269 return VC_ERROR_NONE;
1273 * @brief Sets key value of command.
1275 * @param[in] vc_command Command handle
1276 * @param[in] key key value
1277 * @param[in] modifier modifier value
1279 * @return 0 on success, otherwise a negative error value
1280 * @retval #VC_ERROR_NONE Successful
1281 * @retval #VC_ERROR_INVALID_PARAMETER Invalid parameter
1283 * @see vc_cmd_get_result_key()
1285 int vc_cmd_set_result_key(vc_cmd_h vc_command, int key, int modifier)
1287 SLOG(LOG_DEBUG, TAG_VCCMD, "@@@ Set result key");
1289 if (NULL == vc_command) {
1290 SLOG(LOG_ERROR, TAG_VCCMD, "[ERROR] Invalid parameter ");
1291 return VC_ERROR_INVALID_PARAMETER;
1294 vc_cmd_s* cmd = NULL;
1295 cmd = (vc_cmd_s*)vc_command;
1297 SLOG(LOG_DEBUG, TAG_VCCMD, "key : %d, modifier : %d", key, modifier);
1300 cmd->modifier = modifier;
1302 SLOG(LOG_DEBUG, TAG_VCCMD, "@@@");
1304 return VC_ERROR_NONE;
1308 * @brief Gets key value of command.
1310 * @param[in] vc_command Command handle
1311 * @param[out] key key value
1312 * @param[out] modifier modifier value
1314 * @return 0 on success, otherwise a negative error value
1315 * @retval #VC_ERROR_NONE Successful
1316 * @retval #VC_ERROR_INVALID_PARAMETER Invalid parameter
1318 * @see vc_cmd_add_result_key()
1320 int vc_cmd_get_result_key(vc_cmd_h vc_command, int* key, int* modifier)
1322 SLOG(LOG_DEBUG, TAG_VCCMD, "@@@ Get result key");
1324 if (NULL == vc_command || NULL == key || NULL == modifier) {
1325 SLOG(LOG_ERROR, TAG_VCCMD, "[ERROR] Invalid parameter ");
1326 return VC_ERROR_INVALID_PARAMETER;
1329 vc_cmd_s* cmd = NULL;
1330 cmd = (vc_cmd_s*)vc_command;
1333 *modifier = cmd->modifier;
1335 SLOG(LOG_DEBUG, TAG_VCCMD, "@@@");
1337 return VC_ERROR_NONE;
1340 int vc_cmd_print_list(vc_cmd_list_h vc_cmd_list)
1342 if (NULL == vc_cmd_list) {
1346 vc_cmd_list_s* list = NULL;
1347 list = (vc_cmd_list_s*)vc_cmd_list;
1349 SLOG(LOG_DEBUG, TAG_VCCMD, "@ Command List @");
1350 SLOG(LOG_DEBUG, TAG_VCCMD, "[List][%p]", list);
1353 GSList *iter = NULL;
1354 iter = g_slist_nth(list->list, 0);
1355 while (NULL != iter) {
1356 vc_cmd_s *cmd = NULL;
1359 SLOG(LOG_ERROR, TAG_VCCMD, "[ERROR] No command in list");
1360 return VC_ERROR_OPERATION_FAILED;
1362 SLOG(LOG_DEBUG, TAG_VCCMD, " [%d][%p] PID(%d) ID(%d) Type(%d) Format(%d) Command(%s) Param(%s) Appid(%s) Invocation(%s) Fixed(%s)",
1363 i++, cmd, cmd->pid, cmd->index, cmd->type, cmd->format, cmd->command, cmd->parameter, cmd->appid, cmd->invocation_name, cmd->fixed);
1365 iter = g_slist_next(iter);
1368 SLOG(LOG_DEBUG, TAG_VCCMD, "@@@");
1370 return VC_ERROR_NONE;
1373 int vc_cmd_get_nlu_json(vc_cmd_h vc_cmd, char** json)
1375 if (0 != __vc_cmd_get_feature_enabled()) {
1376 return VC_ERROR_NOT_SUPPORTED;
1379 if (NULL == vc_cmd || NULL == json) {
1380 SLOG(LOG_ERROR, TAG_VCCMD, "[ERROR] NULL parameter");
1381 return VC_ERROR_INVALID_PARAMETER;
1384 vc_cmd_s* cmd = NULL;
1385 cmd = (vc_cmd_s*)vc_cmd;
1387 if (VC_CMD_FORMAT_ACTION != cmd->format) {
1388 SLOG(LOG_ERROR, TAG_VCCMD, "[ERROR] Not Action format");
1389 return VC_ERROR_INVALID_PARAMETER;
1392 if (0 != vc_info_parser_get_nlu_result(json)) {
1393 SLOG(LOG_ERROR, TAG_VCCMD, "[ERROR] Fail to get nlu result");
1394 return VC_ERROR_OPERATION_FAILED;
1397 return VC_ERROR_NONE;
1400 static void __vc_cmd_regex_deinit(int num_regex)
1402 SLOG(LOG_DEBUG, TAG_VCCMD, "@@@ Start Deinitialize regex @@@");
1405 for (i = 0; num_regex > i; i++) {
1409 SLOG(LOG_DEBUG, TAG_VCCMD, "@@@");
1412 static int __vc_cmd_regex_init()
1414 SLOG(LOG_DEBUG, TAG_VCCMD, "@@@ Initialize regular expression @@@");
1416 int cflags = REG_EXTENDED | REG_ICASE;
1422 vc_config_mgr_get_default_language(&lang);
1424 SLOG(LOG_ERROR, TAG_VCCMD, "[ERROR] Fail to get current language");
1425 return VC_ERROR_OPERATION_FAILED;
1428 if (!strcmp("en_US", lang)) {
1430 } else if (!strcmp("ko_KR", lang)) {
1436 SLOG(LOG_ERROR, TAG_VCCMD, "[ERROR] Not supported language type");
1437 return VC_ERROR_INVALID_LANGUAGE;
1443 SLOG(LOG_DEBUG, TAG_VCCMD, "@@@ lang type > %d @@@", lang_type);
1445 re_syntax_options = RE_SYNTAX_POSIX_EXTENDED;
1447 SLOG(LOG_DEBUG, TAG_VCCMD, "Regular expression > %s" , TIME_ABS1_REGEX[lang_type]);
1448 ret = regcomp(®[0], TIME_ABS1_REGEX[lang_type], cflags);
1450 regerror(ret, ®[0], errStr, sizeof(errStr));
1452 SLOG(LOG_ERROR, TAG_VCCMD, "[ERROR] regcomp() error > %s", errStr);
1453 return VC_ERROR_OPERATION_FAILED;
1456 SLOG(LOG_DEBUG, TAG_VCCMD, "Regular expression > %s", TIME_ABS2_REGEX[lang_type]);
1457 ret = regcomp(®[1], TIME_ABS2_REGEX[lang_type], cflags);
1459 regerror(ret, ®[1], errStr, sizeof(errStr));
1460 __vc_cmd_regex_deinit(1);
1462 SLOG(LOG_ERROR, TAG_VCCMD, "[ERROR] regcomp() error > %s", errStr);
1463 return VC_ERROR_OPERATION_FAILED;
1466 SLOG(LOG_DEBUG, TAG_VCCMD, "Regular expression > %s", TIME_ABS3_REGEX[lang_type]);
1467 ret = regcomp(®[2], TIME_ABS3_REGEX[lang_type], cflags);
1469 regerror(ret, ®[2], errStr, sizeof(errStr));
1470 __vc_cmd_regex_deinit(2);
1472 SLOG(LOG_ERROR, TAG_VCCMD, "[ERROR] regcomp() error > %s", errStr);
1473 return VC_ERROR_OPERATION_FAILED;
1476 SLOG(LOG_DEBUG, TAG_VCCMD, "Regular expression > %s", TIME_REL1_REGEX[lang_type]);
1477 ret = regcomp(®[3], TIME_REL1_REGEX[lang_type], cflags);
1479 regerror(ret, ®[3], errStr, sizeof(errStr));
1480 __vc_cmd_regex_deinit(3);
1482 SLOG(LOG_ERROR, TAG_VCCMD, "[ERROR] regcomp() error > %s", errStr);
1483 return VC_ERROR_OPERATION_FAILED;
1486 SLOG(LOG_DEBUG, TAG_VCCMD, "Regular expression > %s", TIME_REL2_REGEX[lang_type]);
1487 ret = regcomp(®[4], TIME_REL2_REGEX[lang_type], cflags);
1489 regerror(ret, ®[4], errStr, sizeof(errStr));
1490 __vc_cmd_regex_deinit(4);
1492 SLOG(LOG_ERROR, TAG_VCCMD, "[ERROR] regcomp() error > %s", errStr);
1493 return VC_ERROR_OPERATION_FAILED;
1496 SLOG(LOG_DEBUG, TAG_VCCMD, "Regular expression > %s", TIME_REL3_REGEX[lang_type]);
1497 ret = regcomp(®[5], TIME_REL3_REGEX[lang_type], cflags);
1499 regerror(ret, ®[5], errStr, sizeof(errStr));
1500 __vc_cmd_regex_deinit(5);
1502 SLOG(LOG_ERROR, TAG_VCCMD, "[ERROR] regcomp() error > %s", errStr);
1503 return VC_ERROR_OPERATION_FAILED;
1506 SLOG(LOG_DEBUG, TAG_VCCMD, "Regular expression > %s", TIME_PHR_REGEX[lang_type]);
1507 ret = regcomp(®[6], TIME_PHR_REGEX[lang_type], cflags);
1509 regerror(ret, ®[6], errStr, sizeof(errStr));
1510 __vc_cmd_regex_deinit(6);
1512 SLOG(LOG_ERROR, TAG_VCCMD, "[ERROR] regcomp() error > %s", errStr);
1513 return VC_ERROR_OPERATION_FAILED;
1516 SLOG(LOG_DEBUG, TAG_VCCMD, "Regular expression > %s", DATE_ABS1_REGEX[lang_type]);
1517 ret = regcomp(®[7], DATE_ABS1_REGEX[lang_type], cflags);
1519 regerror(ret, ®[7], errStr, sizeof(errStr));
1520 __vc_cmd_regex_deinit(7);
1522 SLOG(LOG_ERROR, TAG_VCCMD, "[ERROR] regcomp() error > %s", errStr);
1523 return VC_ERROR_OPERATION_FAILED;
1526 SLOG(LOG_DEBUG, TAG_VCCMD, "Regular expression > %s", DATE_ABS2_REGEX[lang_type]);
1527 ret = regcomp(®[8], DATE_ABS2_REGEX[lang_type], cflags);
1529 regerror(ret, ®[8], errStr, sizeof(errStr));
1530 __vc_cmd_regex_deinit(8);
1532 SLOG(LOG_ERROR, TAG_VCCMD, "[ERROR] regcomp() error > %s", errStr);
1533 return VC_ERROR_OPERATION_FAILED;
1536 SLOG(LOG_DEBUG, TAG_VCCMD, "Regular expression > %s", DATE_ABS3_REGEX[lang_type]);
1537 ret = regcomp(®[9], DATE_ABS3_REGEX[lang_type], cflags);
1539 regerror(ret, ®[9], errStr, sizeof(errStr));
1540 __vc_cmd_regex_deinit(9);
1542 SLOG(LOG_ERROR, TAG_VCCMD, "[ERROR] regcomp() error > %s", errStr);
1543 return VC_ERROR_OPERATION_FAILED;
1546 SLOG(LOG_DEBUG, TAG_VCCMD, "Regular expression > %s", DATE_PHR1_REGEX[lang_type]);
1547 ret = regcomp(®[10], DATE_PHR1_REGEX[lang_type], cflags);
1549 regerror(ret, ®[10], errStr, sizeof(errStr));
1550 __vc_cmd_regex_deinit(10);
1552 SLOG(LOG_ERROR, TAG_VCCMD, "[ERROR] regcomp() error > %s", errStr);
1553 return VC_ERROR_OPERATION_FAILED;
1556 SLOG(LOG_DEBUG, TAG_VCCMD, "Regular expression > %s", DATE_PHR2_REGEX[lang_type]);
1557 ret = regcomp(®[11], DATE_PHR2_REGEX[lang_type], cflags);
1559 regerror(ret, ®[11], errStr, sizeof(errStr));
1560 __vc_cmd_regex_deinit(11);
1562 SLOG(LOG_ERROR, TAG_VCCMD, "[ERROR] regcomp() error > %s", errStr);
1563 return VC_ERROR_OPERATION_FAILED;
1566 SLOG(LOG_DEBUG, TAG_VCCMD, "@@@");
1568 return VC_ERROR_NONE;
1571 static void __vc_cmd_add_year(struct tm *td, int year)
1573 td->tm_year += year;
1576 static void __vc_cmd_add_mon(struct tm *td, int mon)
1580 mon = td->tm_mon + mon;
1584 __vc_cmd_add_year(td, year);
1587 td->tm_mon = mon % 12;
1590 static void __vc_cmd_add_mday(struct tm *td, int mday)
1592 int max_day[12] = {31, 28, 31, 30, 31, 30, 31, 30, 30, 31, 30, 31};
1593 int year = td->tm_year + 1900;
1597 if ((0 == year % 4 && 0 != year % 100) || 0 == year % 400) max_day[1] = 29;
1599 mday = td->tm_mday + mday;
1601 for (mon = td->tm_mon; mday >= max_day[mon % 12]; mon++) {
1602 mday -= max_day[mon % 12];
1604 if (11 == mon % 12) {
1607 if ((0 == year % 4 && 0 != year % 100) || 0 == year % 400) {
1615 mon = mon - td->tm_mon;
1618 __vc_cmd_add_mon(td, mon);
1624 static void __vc_cmd_add_hour(struct tm *td, int hour)
1628 hour = td->tm_hour + hour;
1632 __vc_cmd_add_mday(td, day);
1635 td->tm_hour = hour % 24;
1638 static void __vc_cmd_add_min(struct tm *td, int min)
1642 min = td->tm_min + min;
1646 __vc_cmd_add_hour(td, hour);
1649 td->tm_min = min % 60;
1652 static void __copy_struct_tm(struct tm *des, struct tm *src)
1654 SLOG(LOG_DEBUG, TAG_VCCMD, "@@@ Start to copy struct tm @@@");
1656 des->tm_sec = src->tm_sec;
1657 des->tm_min = src->tm_min;
1658 des->tm_hour = src->tm_hour;
1659 des->tm_mday = src->tm_mday;
1660 des->tm_mon = src->tm_mon;
1661 des->tm_year = src->tm_year;
1662 des->tm_wday = src->tm_wday;
1663 des->tm_yday = src->tm_yday;
1664 des->tm_isdst = src->tm_isdst;
1666 des->tm_gmtoff = src->tm_gmtoff;
1667 des->tm_zone = src->tm_zone;
1670 static void __update_data_sidx(int idx)
1672 if (0 > g_data_sidx || idx < g_data_sidx) g_data_sidx = idx;
1675 static void __update_data_eidx(int idx)
1677 if (0 > g_data_eidx || idx > g_data_eidx) g_data_eidx = idx;
1680 static int __vc_cmd_tphrase_check(const char *str, struct tm *td, int *exist)
1682 regmatch_t pmatch[3];
1688 ret = regexec(®[6], str, 3, pmatch, 0);
1691 len = pmatch[idx].rm_eo - pmatch[idx].rm_so;
1693 if (12 < td->tm_hour) {
1694 __vc_cmd_add_mday(td, 1);
1700 len = pmatch[idx].rm_eo - pmatch[idx].rm_so;
1702 __vc_cmd_add_mday(td, 1);
1707 SLOG(LOG_DEBUG, TAG_VCCMD, "Matched string > %.*s", len, str + pmatch[0].rm_so);
1709 __update_data_sidx(pmatch[0].rm_so);
1710 __update_data_eidx(pmatch[0].rm_eo);
1713 return VC_ERROR_NONE;
1716 SLOG(LOG_DEBUG, TAG_VCCMD, "[REGEX] There is no matched string");
1717 return VC_ERROR_NONE;
1720 static int __vc_cmd_trelative_check(const char *str, struct tm *td, int *exist)
1722 regmatch_t pmatch[2];
1730 char *tempstr = NULL;
1733 ret = regexec(®[3], str, 1, pmatch, 0);
1735 SLOG(LOG_DEBUG, TAG_VCCMD, "Matched string > %.*s", pmatch[0].rm_eo - pmatch[0].rm_so, str+pmatch[0].rm_so);
1738 sidx = pmatch[0].rm_so;
1739 eidx = pmatch[0].rm_eo;
1741 ret = regexec(®[4], str, 2, pmatch, 0);
1743 len = pmatch[1].rm_eo - pmatch[1].rm_so;
1746 SLOG(LOG_ERROR, TAG_VCCMD, "[ERROR] Invalid string length");
1747 return VC_ERROR_OPERATION_FAILED;
1749 tempstr = strndup(str + pmatch[1].rm_so, (size_t)len);
1751 if (NULL == tempstr) {
1752 SLOG(LOG_ERROR, TAG_VCCMD, "[ERROR] Memory allocation is failed");
1753 return VC_ERROR_OUT_OF_MEMORY;
1756 hour = atoi(tempstr);
1761 SLOG(LOG_DEBUG, TAG_VCCMD, "Matched string > %.*s", len, str + pmatch[0].rm_so);
1763 if (pmatch[0].rm_so < sidx) sidx = pmatch[0].rm_so;
1764 if (pmatch[0].rm_eo > eidx) eidx = pmatch[0].rm_eo;
1767 ret = regexec(®[5], str, 2, pmatch, 0);
1769 len = pmatch[1].rm_eo - pmatch[1].rm_so;
1772 SLOG(LOG_ERROR, TAG_VCCMD, "[ERROR] Invalid string length");
1773 return VC_ERROR_OPERATION_FAILED;
1775 tempstr = strndup(str + pmatch[1].rm_so, (size_t)len);
1777 if (NULL == tempstr) {
1778 SLOG(LOG_ERROR, TAG_VCCMD, "[ERROR] Memory allocation is failed");
1779 return VC_ERROR_OUT_OF_MEMORY;
1782 min = atoi(tempstr);
1787 SLOG(LOG_DEBUG, TAG_VCCMD, "Matched string > %.*s", len, str + pmatch[0].rm_so);
1789 if (pmatch[0].rm_so < sidx) sidx = pmatch[0].rm_so;
1790 if (pmatch[0].rm_eo > eidx) eidx = pmatch[0].rm_eo;
1793 if (hour < 0 && min < 0) {
1794 SLOG(LOG_DEBUG, TAG_VCCMD, "[REGEX] There is no matched string");
1795 return VC_ERROR_NONE;
1798 hour = 0 > hour ? 0 : hour;
1799 min = 0 > min ? 0 : min;
1801 min = min + (hour * 60);
1803 __vc_cmd_add_min(td, min);
1806 __update_data_sidx(sidx);
1807 __update_data_eidx(eidx);
1810 return VC_ERROR_NONE;
1813 SLOG(LOG_DEBUG, TAG_VCCMD, "[REGEX] There is no matched string");
1814 return VC_ERROR_NONE;
1817 static int __vc_cmd_tabsolute_check(const char *str, struct tm *td, int *exist)
1819 regmatch_t pmatch[5];
1828 char *tempstr = NULL;
1831 ret = regexec(®[0], str, 5, pmatch, 0);
1833 for (idx = 1; 5 > idx && 0 >= pmatch[idx].rm_eo - pmatch[idx].rm_so; idx++);
1837 sidx = pmatch[0].rm_so;
1838 eidx = pmatch[0].rm_eo;
1841 ret = regexec(®[1], str, 2, pmatch, 0);
1843 len = pmatch[1].rm_eo - pmatch[1].rm_so;
1846 SLOG(LOG_ERROR, TAG_VCCMD, "[ERROR] Invalid string length");
1847 return VC_ERROR_OPERATION_FAILED;
1849 tempstr = strndup(str + pmatch[1].rm_so, (size_t)len);
1851 if (NULL == tempstr) {
1852 SLOG(LOG_ERROR, TAG_VCCMD, "[ERROR] Memory allocation is failed");
1853 return VC_ERROR_OUT_OF_MEMORY;
1856 hour = atoi(tempstr);
1859 hour = hour + 12 * flag;
1861 if (12 == hour) hour = 0;
1862 else if (24 == hour) hour = 12;
1865 if (0 > hour || 24 <= hour || (0 == flag && 12 < hour)) {
1866 SLOG(LOG_DEBUG, TAG_VCCMD, "[REGEX] Incoming sentence is weird");
1869 return VC_ERROR_NONE;
1875 SLOG(LOG_DEBUG, TAG_VCCMD, "Matched string > %.*s", len, str + pmatch[0].rm_so);
1877 if (0 > sidx || pmatch[0].rm_so < sidx) sidx = pmatch[0].rm_so;
1878 if (0 > eidx || pmatch[0].rm_eo > eidx) eidx = pmatch[0].rm_eo;
1879 } else if (0 < flag) {
1880 SLOG(LOG_DEBUG, TAG_VCCMD, "[REGEX] Incoming sentence is weird");
1881 return VC_ERROR_NONE;
1884 ret = regexec(®[2], str, 2, pmatch, 0);
1887 len = pmatch[idx].rm_eo - pmatch[idx].rm_so;
1889 tempstr = strndup(str + pmatch[idx].rm_so, (size_t)len);
1891 if (NULL == tempstr) {
1892 SLOG(LOG_ERROR, TAG_VCCMD, "[ERROR] Memory allocation is failed");
1893 return VC_ERROR_OUT_OF_MEMORY;
1896 min = atoi(tempstr);
1898 if (0 > min || 60 <= min) {
1899 SLOG(LOG_DEBUG, TAG_VCCMD, "[REGEX] Incoming sentence is weird");
1902 return VC_ERROR_NONE;
1914 SLOG(LOG_DEBUG, TAG_VCCMD, "Matched string > %.*s", pmatch[0].rm_eo - pmatch[0].rm_so, str + pmatch[0].rm_so);
1915 if (0 > sidx || pmatch[0].rm_so < sidx) sidx = pmatch[0].rm_so;
1916 if (0 > eidx || pmatch[0].rm_eo > eidx) eidx = pmatch[0].rm_eo;
1919 if (0 > hour && 0 > min) {
1920 SLOG(LOG_DEBUG, TAG_VCCMD, "[REGEX] There is no matched string");
1921 return VC_ERROR_NONE;
1924 if (0 <= min && 0 <= hour) {
1925 if (hour < td->tm_hour || (hour == td->tm_hour && min <= td->tm_min)) __vc_cmd_add_mday(td, 1);
1929 } else if (0 <= min) {
1931 vc_config_mgr_get_default_language(&lang);
1933 SLOG(LOG_ERROR, TAG_VCCMD, "[ERROR] Fail to get current language");
1934 return VC_ERROR_OPERATION_FAILED;
1937 if (!strcmp("en_US", lang)) {
1938 SLOG(LOG_DEBUG, TAG_VCCMD, "[REGEX] Incoming sentence is weird");
1941 return VC_ERROR_NONE;
1943 if (min <= td->tm_min) __vc_cmd_add_hour(td, 1);
1950 if (hour <= td->tm_hour) __vc_cmd_add_mday(td, 1);
1958 __update_data_sidx(sidx);
1959 __update_data_eidx(eidx);
1962 return VC_ERROR_NONE;
1965 static int __vc_cmd_dphrase_check(const char *str, struct tm *td, int *exist)
1967 regmatch_t pmatch[10];
1973 ret = regexec(®[10], str, 5, pmatch, 0);
1975 for (idx = 1; 5 > idx && 0 >= pmatch[idx].rm_eo - pmatch[idx].rm_so; idx++);
1977 len = pmatch[idx].rm_eo - pmatch[idx].rm_so;
1979 td->tm_year = td_now.tm_year;
1980 td->tm_mon = td_now.tm_mon;
1981 td->tm_mday = td_now.tm_mday;
1983 __vc_cmd_add_mday(td, idx - 1);
1985 SLOG(LOG_DEBUG, TAG_VCCMD, "Matched string > %.*s", len, str + pmatch[0].rm_so);
1987 __update_data_sidx(pmatch[0].rm_so);
1988 __update_data_eidx(pmatch[0].rm_eo);
1991 return VC_ERROR_NONE;
1994 ret = regexec(®[11], str, 10, pmatch, 0);
1996 for (idx = 1; 10 > idx; idx++) {
1997 len = pmatch[idx].rm_eo - pmatch[idx].rm_so;
2002 td->tm_year = td_now.tm_year;
2003 td->tm_mon = td_now.tm_mon;
2004 td->tm_mday = td_now.tm_mday;
2006 __vc_cmd_add_mday(td, idx + 1);
2008 SLOG(LOG_DEBUG, TAG_VCCMD, "Matched string > %.*s", len, str + pmatch[0].rm_so);
2010 __update_data_sidx(pmatch[0].rm_so);
2011 __update_data_eidx(pmatch[0].rm_eo);
2014 return VC_ERROR_NONE;
2017 SLOG(LOG_DEBUG, TAG_VCCMD, "[REGEX] There is no matched string");
2018 return VC_ERROR_NONE;
2021 static int __vc_cmd_dabsolute_check(const char *str, struct tm *td, int *exist)
2023 regmatch_t pmatch[13];
2034 char *tempstr = NULL;
2037 ret = regexec(®[9], str, 2, pmatch, 0);
2039 len = pmatch[1].rm_eo - pmatch[1].rm_so;
2042 SLOG(LOG_ERROR, TAG_VCCMD, "[ERROR] Invalid string length");
2043 return VC_ERROR_OPERATION_FAILED;
2045 tempstr = strndup(str + pmatch[1].rm_so, (size_t)len);
2047 if (NULL == tempstr) {
2048 SLOG(LOG_ERROR, TAG_VCCMD, "[ERROR] Memory allocation is failed");
2049 return VC_ERROR_OUT_OF_MEMORY;
2052 day = atoi(tempstr);
2057 SLOG(LOG_DEBUG, TAG_VCCMD, "Matched string > %.*s", len, str + pmatch[0].rm_so);
2059 sidx = pmatch[0].rm_so;
2060 eidx = pmatch[0].rm_eo;
2062 SLOG(LOG_DEBUG, TAG_VCCMD, "[REGEX] Incoming sentence is weird");
2063 return VC_ERROR_NONE;
2066 ret = regexec(®[8], str, 13, pmatch, 0);
2068 for (idx = 1; 13 > idx; idx++) {
2069 len = pmatch[idx].rm_eo - pmatch[idx].rm_so;
2079 SLOG(LOG_DEBUG, TAG_VCCMD, "Matched string > %.*s", len, str + pmatch[0].rm_so);
2081 if (0 > sidx || pmatch[0].rm_so < sidx) sidx = pmatch[0].rm_so;
2082 if (0 > eidx || pmatch[0].rm_eo > eidx) eidx = pmatch[0].rm_eo;
2085 vc_config_mgr_get_default_language(&lang);
2087 SLOG(LOG_ERROR, TAG_VCCMD, "[ERROR] Fail to get current language");
2088 return VC_ERROR_OPERATION_FAILED;
2091 if (!strcmp("en_US", lang)) {
2092 SLOG(LOG_DEBUG, TAG_VCCMD, "[REGEX] Incoming sentence is weird");
2095 return VC_ERROR_NONE;
2104 ret = regexec(®[7], str, 3, pmatch, 0);
2106 if (!m_flag) return -1;
2108 len = pmatch[2].rm_eo - pmatch[2].rm_so;
2111 SLOG(LOG_ERROR, TAG_VCCMD, "[ERROR] Invalid string length");
2112 return VC_ERROR_OPERATION_FAILED;
2114 tempstr = strndup(str + pmatch[2].rm_so, (size_t)len);
2116 if (NULL == tempstr) {
2117 SLOG(LOG_ERROR, TAG_VCCMD, "[ERROR] Memory allocation is failed");
2118 return VC_ERROR_OUT_OF_MEMORY;
2121 year = atoi(tempstr);
2122 year = 1900 < year ? year - 1900 : year + 100;
2128 SLOG(LOG_DEBUG, TAG_VCCMD, "Matched string > %.*s", len, str + pmatch[0].rm_so);
2130 if (0 > sidx || pmatch[0].rm_so < sidx) sidx = pmatch[0].rm_so;
2131 if (0 > eidx || pmatch[0].rm_eo > eidx) eidx = pmatch[0].rm_eo;
2136 if (0 > g_time_flag) {
2140 } else if (2 == g_time_flag) {
2141 SLOG(LOG_DEBUG, TAG_VCCMD, "[REGEX] Incoming sentence is weird");
2142 return VC_ERROR_NONE;
2145 int max_day[12] = {31, 28, 31, 30, 31, 30, 31, 30, 30, 31, 30, 31};
2146 if ((0 == (year + 1900) % 4 && 0 != (year + 1900) % 100) || 0 == (year + 1900) % 400) max_day[1] = 29;
2148 if (max_day[mon] < day || 1 > day) {
2149 SLOG(LOG_DEBUG, TAG_VCCMD, "[REGEX] Incoming sentence is weird");
2150 return VC_ERROR_NONE;
2159 if (day < td_now.tm_mday) __vc_cmd_add_mon(td, 1);
2161 if (mon < td_now.tm_mon) __vc_cmd_add_year(td, 1);
2162 else if (mon == td_now.tm_mon && day < td_now.tm_mday) __vc_cmd_add_year(td, 1);
2166 __update_data_sidx(sidx);
2167 __update_data_eidx(eidx);
2170 return VC_ERROR_NONE;
2173 static int __vc_cmd_time_check(const char *str, struct tm *td)
2175 SLOG(LOG_DEBUG, TAG_VCCMD, "@@@ Check time value in string \"%s\"", str);
2180 ret = __vc_cmd_tphrase_check(str, td, &exist);
2184 SLOG(LOG_DEBUG, TAG_VCCMD, "@@@ Time value is exist");
2186 } else if (VC_ERROR_NONE != ret) {
2187 SLOG(LOG_ERROR, TAG_VCCMD, "[ERROR] Error is occurred > (%d)", ret);
2191 ret = __vc_cmd_trelative_check(str, td, &exist);
2195 SLOG(LOG_DEBUG, TAG_VCCMD, "@@@ Time value is exist");
2197 } else if (VC_ERROR_NONE != ret) {
2198 SLOG(LOG_ERROR, TAG_VCCMD, "[ERROR] Error is occurred > (%d)", ret);
2202 ret = __vc_cmd_tabsolute_check(str, td, &exist);
2206 SLOG(LOG_DEBUG, TAG_VCCMD, "@@@ Time value is exist");
2208 } else if (VC_ERROR_NONE != ret) {
2209 SLOG(LOG_ERROR, TAG_VCCMD, "[ERROR] Error is occurred > (%d)", ret);
2213 SLOG(LOG_DEBUG, TAG_VCCMD, "@@@ There is no time value");
2214 return VC_ERROR_NONE;
2217 static int __vc_cmd_date_check(const char *str, struct tm *td)
2219 SLOG(LOG_DEBUG, TAG_VCCMD, "@@@ Check date value in string \"%s\"", str);
2224 ret = __vc_cmd_dphrase_check(str, td, &exist);
2228 SLOG(LOG_DEBUG, TAG_VCCMD, "@@@ Date value is exist");
2230 } else if (VC_ERROR_NONE != ret) {
2231 SLOG(LOG_ERROR, TAG_VCCMD, "[ERROR] Error is occurred > (%d)", ret);
2235 ret = __vc_cmd_dabsolute_check(str, td, &exist);
2239 SLOG(LOG_DEBUG, TAG_VCCMD, "@@@ Date value is exist");
2241 } else if (VC_ERROR_NONE != ret) {
2242 SLOG(LOG_ERROR, TAG_VCCMD, "[ERROR] Error is occurred > (%d)", ret);
2246 SLOG(LOG_DEBUG, TAG_VCCMD, "@@@ There is no date value");
2247 return VC_ERROR_NONE;
2250 int vc_cmd_get_datetime(const char *text, time_t *result, char **remain)
2252 SLOG(LOG_DEBUG, TAG_VCCMD, "@@@ Get timestamp data");
2255 const char *day_name[7] = {"Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"};
2258 if (NULL == text || NULL == result || NULL == remain) {
2259 SLOG(LOG_ERROR, TAG_VCCMD, "[ERROR] Invalid parameter");
2260 return VC_ERROR_INVALID_PARAMETER;
2264 ret = __vc_cmd_regex_init();
2265 if (VC_ERROR_NONE != ret) {
2266 SLOG(LOG_ERROR, TAG_VCCMD, "[ERROR] initialize regex failed");
2270 g_data_sidx = g_data_eidx = -1;
2273 localtime_r(&t_now, &td_now);
2274 SLOG(LOG_DEBUG, TAG_VCCMD, "Current timestamp = %d", (int)t_now);
2276 __copy_struct_tm(&td, &td_now);
2277 SLOG(LOG_DEBUG, TAG_VCCMD, "%d-%d-%d (%s), %d:%d:%d",
2278 td.tm_year + 1900, td.tm_mon + 1, td.tm_mday, day_name[td.tm_wday], td.tm_hour, td.tm_min, td.tm_sec);
2280 g_time_flag = g_date_flag = -1;
2282 ret = __vc_cmd_time_check(text, &td);
2283 if (VC_ERROR_NONE != ret) {
2284 SLOG(LOG_ERROR, TAG_VCCMD, "[ERROR] Error is occurred in the check > (%d)", ret);
2288 ret = __vc_cmd_date_check(text, &td);
2289 if (VC_ERROR_NONE != ret) {
2290 SLOG(LOG_ERROR, TAG_VCCMD, "[ERROR] Error is occurred in the check > (%d)", ret);
2294 __vc_cmd_regex_deinit(12);
2296 if (g_time_flag > 0 || g_date_flag > 0) {
2297 *result = mktime(&td);
2299 SLOG(LOG_DEBUG, TAG_VCCMD, "Timestamp in the text = %ld", *result);
2300 SLOG(LOG_DEBUG, TAG_VCCMD, "%d-%d-%d (%s), %d:%d:%d",
2301 td.tm_year + 1900, td.tm_mon + 1, td.tm_mday, day_name[td.tm_wday], td.tm_hour, td.tm_min, td.tm_sec);
2303 *remain = (char *)calloc(sizeof(char), (strlen(text) + 1 - g_data_eidx + g_data_sidx));
2305 if (NULL == *remain) {
2306 SLOG(LOG_ERROR, TAG_VCCMD, "[ERROR] Out of memory error");
2307 return VC_ERROR_OUT_OF_MEMORY;
2310 strncpy(*remain, text, g_data_sidx);
2311 strncat(*remain, text + g_data_eidx, strlen(text) - g_data_eidx);
2313 SLOG(LOG_DEBUG, TAG_VCCMD, "[REGEX] There is no data in the text");
2316 SLOG(LOG_DEBUG, TAG_VCCMD, "@@@");
2318 return VC_ERROR_NONE;