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 int g_feature_enabled = -1;
38 static int g_privilege_allowed = 1; /* Always True */
39 static cynara *p_cynara = NULL;
40 static GList *g_cmd_list = NULL;
41 static GList *g_cmdlist_list = NULL;
44 // For getting timestamp using regular expression
45 static regex_t reg[MAX_NUM_REGEX];
46 static time_t t_now; //time_t is based on UTC
47 static struct tm td_now; //if use localtime function, the value follows the local time zone, otherwise it follows the UTC.
49 static int g_time_flag;
50 static int g_date_flag;
52 static int g_data_sidx;
53 static int g_data_eidx;
55 static int __vc_cmd_get_feature_enabled()
57 if (0 == g_feature_enabled) {
58 SLOG(LOG_ERROR, TAG_VCCMD, "[ERROR] Voice control feature NOT supported");
59 return VC_ERROR_NOT_SUPPORTED;
60 } else if (-1 == g_feature_enabled) {
61 bool vc_supported = false;
62 bool mic_supported = false;
63 if (0 == system_info_get_platform_bool(VC_FEATURE_PATH, &vc_supported)) {
64 if (0 == system_info_get_platform_bool(VC_MIC_FEATURE_PATH, &mic_supported)) {
65 if (false == vc_supported || false == mic_supported) {
66 SLOG(LOG_ERROR, TAG_VCCMD, "[ERROR] Voice control feature NOT supported");
67 g_feature_enabled = 0;
68 return VC_ERROR_NOT_SUPPORTED;
71 g_feature_enabled = 1;
73 SLOG(LOG_ERROR, TAG_VCCMD, "[ERROR] Fail to get feature value");
74 return VC_ERROR_NOT_SUPPORTED;
77 SLOG(LOG_ERROR, TAG_VCCMD, "[ERROR] Fail to get feature value");
78 return VC_ERROR_NOT_SUPPORTED;
85 static int __check_privilege_initialize()
87 int ret = cynara_initialize(&p_cynara, NULL);
88 if (CYNARA_API_SUCCESS != ret)
89 SLOG(LOG_ERROR, TAG_VCCMD, "[ERROR] fail to initialize");
91 return ret == CYNARA_API_SUCCESS;
94 static int __check_privilege(const char* uid, const char * privilege)
97 char label_path[1024] = "/proc/self/attr/current";
98 char smack_label[1024] = {'\0',};
104 fp = fopen(label_path, "r");
106 if (0 >= fread(smack_label, 1, sizeof(smack_label), fp))
107 SLOG(LOG_ERROR, TAG_VCCMD, "[ERROR] fail to fread");
112 pid_t pid = getpid();
113 char *session = cynara_session_from_pid(pid);
114 int ret = cynara_check(p_cynara, smack_label, session, uid, privilege);
115 SLOG(LOG_DEBUG, TAG_VCCMD, "[Client]cynara_check returned %d(%s)", ret, (CYNARA_API_ACCESS_ALLOWED == ret) ? "Allowed" : "Denied");
119 if (ret != CYNARA_API_ACCESS_ALLOWED)
124 static void __check_privilege_deinitialize()
127 cynara_finish(p_cynara);
131 static int __vc_cmd_check_privilege()
135 if (0 == g_privilege_allowed) {
136 SLOG(LOG_ERROR, TAG_VCCMD, "[ERROR] Permission is denied");
137 return VC_ERROR_PERMISSION_DENIED;
138 } else if (-1 == g_privilege_allowed) {
139 if (false == __check_privilege_initialize()) {
140 SLOG(LOG_ERROR, TAG_VCCMD, "[ERROR] privilege initialize is failed");
141 return VC_ERROR_PERMISSION_DENIED;
143 snprintf(uid, 16, "%d", getuid());
144 if (false == __check_privilege(uid, VC_PRIVILEGE)) {
145 SLOG(LOG_ERROR, TAG_VCCMD, "[ERROR] Permission is denied");
146 g_privilege_allowed = 0;
147 __check_privilege_deinitialize();
148 return VC_ERROR_PERMISSION_DENIED;
150 __check_privilege_deinitialize();
153 g_privilege_allowed = 1;
155 return VC_ERROR_NONE;
158 static bool __vc_cmd_is_valid(vc_cmd_h vc_command)
160 if (NULL == g_cmd_list) {
161 SLOG(LOG_WARN, TAG_VCCMD, "[WARNING] cmd_list is not valid");
165 if (g_list_length(g_cmd_list) == 0) {
166 SLOG(LOG_WARN, TAG_VCCMD, "[WARNING] cmd_list is not valid");
171 vc_cmd_s *command = NULL;
172 command = (vc_cmd_s *)vc_command;
175 iter = g_list_first(g_cmd_list);
176 while (NULL != iter) {
177 vc_cmd_s *data = NULL;
179 if (NULL != data && command == data) {
183 iter = g_list_next(iter);
187 SLOG(LOG_WARN, TAG_VCCMD, "[WARNING] command(%p) is not valid", command);
192 static bool __vc_cmd_list_is_valid(vc_cmd_list_h vc_cmd_list)
194 if (NULL == g_cmdlist_list) {
195 SLOG(LOG_WARN, TAG_VCCMD, "[WARNING] cmdlist_list is not valid");
199 if (g_list_length(g_cmdlist_list) == 0) {
200 SLOG(LOG_WARN, TAG_VCCMD, "[WARNING] cmdlist_list is not valid");
205 vc_cmd_list_s *list = NULL;
206 list = (vc_cmd_list_s *)vc_cmd_list;
209 iter = g_list_first(g_cmdlist_list);
210 while (NULL != iter) {
211 vc_cmd_list_s *data = NULL;
213 if (NULL != data && list == data) {
217 iter = g_list_next(iter);
221 SLOG(LOG_WARN, TAG_VCCMD, "[WARNING] list(%p) is not valid", list);
226 int vc_cmd_list_create(vc_cmd_list_h* vc_cmd_list)
228 if (0 != __vc_cmd_get_feature_enabled()) {
229 return VC_ERROR_NOT_SUPPORTED;
231 if (0 != __vc_cmd_check_privilege()) {
232 return VC_ERROR_PERMISSION_DENIED;
235 if (NULL == vc_cmd_list) {
236 SLOG(LOG_ERROR, TAG_VCCMD, "[ERROR] Input parameter is NULL");
237 return VC_ERROR_INVALID_PARAMETER;
240 vc_cmd_list_s* list = (vc_cmd_list_s*)calloc(1, sizeof(vc_cmd_list_s));
243 SLOG(LOG_ERROR, TAG_VCCMD, "[ERROR] Not enough memory");
244 return VC_ERROR_OUT_OF_MEMORY;
250 *vc_cmd_list = (vc_cmd_list_h)list;
252 g_cmdlist_list = g_list_append(g_cmdlist_list, list);
254 SLOG(LOG_DEBUG, TAG_VCCMD, "[List] list(%p)", *vc_cmd_list);
256 return VC_ERROR_NONE;
259 int vc_cmd_list_destroy(vc_cmd_list_h vc_cmd_list, bool release_command)
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) {
269 SLOG(LOG_ERROR, TAG_VCCMD, "[ERROR] Input parameter is NULL");
270 return VC_ERROR_INVALID_PARAMETER;
273 if (false == __vc_cmd_list_is_valid(vc_cmd_list)) {
274 SLOG(LOG_ERROR, TAG_VCCMD, "[ERROR] Input parameter is NULL");
275 return VC_ERROR_INVALID_PARAMETER;
278 vc_cmd_list_remove_all(vc_cmd_list, release_command);
280 vc_cmd_list_s* list = NULL;
281 list = (vc_cmd_list_s*)vc_cmd_list;
283 SLOG(LOG_DEBUG, TAG_VCCMD, "[List] list(%p)", list);
286 vc_cmd_list_s *data = NULL;
288 /* if list have item */
289 if (g_list_length(g_cmdlist_list) > 0) {
290 /* Get a first item */
291 iter = g_list_first(g_cmdlist_list);
293 while (NULL != iter) {
295 if (NULL != data && list == data) {
296 g_cmdlist_list = g_list_remove_link(g_cmdlist_list, iter);
301 SLOG(LOG_DEBUG, TAG_VCCMD, "Client destroy");
305 return VC_ERROR_NONE;
308 iter = g_list_next(iter);
311 SLOG(LOG_ERROR, TAG_VCCMD, "Fail to destroy client : handle is not valid");
313 return VC_ERROR_INVALID_PARAMETER;
316 int vc_cmd_list_get_count(vc_cmd_list_h vc_cmd_list, int* count)
318 if (0 != __vc_cmd_get_feature_enabled()) {
319 return VC_ERROR_NOT_SUPPORTED;
321 if (0 != __vc_cmd_check_privilege()) {
322 return VC_ERROR_PERMISSION_DENIED;
325 if (NULL == vc_cmd_list || NULL == count) {
326 SLOG(LOG_ERROR, TAG_VCCMD, "[ERROR] Get command count : Input parameter is NULL");
327 return VC_ERROR_INVALID_PARAMETER;
330 vc_cmd_list_s* list = NULL;
331 list = (vc_cmd_list_s*)vc_cmd_list;
333 *count = g_slist_length(list->list);
335 SLOG(LOG_DEBUG, TAG_VCCMD, "[List] list(%p), count(%d)", list, *count);
337 return VC_ERROR_NONE;
340 int vc_cmd_list_add(vc_cmd_list_h vc_cmd_list, vc_cmd_h vc_command)
342 if (0 != __vc_cmd_get_feature_enabled()) {
343 return VC_ERROR_NOT_SUPPORTED;
345 if (0 != __vc_cmd_check_privilege()) {
346 return VC_ERROR_PERMISSION_DENIED;
349 if (NULL == vc_cmd_list || NULL == vc_command) {
350 SLOG(LOG_ERROR, TAG_VCCMD, "[ERROR] Input parameter is NULL");
351 return VC_ERROR_INVALID_PARAMETER;
354 vc_cmd_list_s* list = NULL;
355 list = (vc_cmd_list_s*)vc_cmd_list;
357 vc_cmd_s* cmd = NULL;
358 cmd = (vc_cmd_s*)vc_command;
360 list->list = g_slist_append(list->list, cmd);
362 if (1 == g_slist_length(list->list)) {
366 SLOG(LOG_DEBUG, TAG_VCCMD, "[List] list(%p), command(%p)", list, cmd);
368 return VC_ERROR_NONE;
371 int vc_cmd_list_remove(vc_cmd_list_h vc_cmd_list, vc_cmd_h vc_command)
373 if (0 != __vc_cmd_get_feature_enabled()) {
374 return VC_ERROR_NOT_SUPPORTED;
376 if (0 != __vc_cmd_check_privilege()) {
377 return VC_ERROR_PERMISSION_DENIED;
380 if (NULL == vc_cmd_list || NULL == vc_command) {
381 SLOG(LOG_ERROR, TAG_VCCMD, "[ERROR] Input parameter is NULL");
382 return VC_ERROR_INVALID_PARAMETER;
385 vc_cmd_list_s* list = NULL;
386 list = (vc_cmd_list_s*)vc_cmd_list;
388 vc_cmd_s* cmd = NULL;
389 cmd = (vc_cmd_s*)vc_command;
391 SLOG(LOG_DEBUG, TAG_VCCMD, "[List] list(%p), command(%p)", list, cmd);
393 vc_cmd_s* temp_cmd = NULL;
396 iter = g_slist_nth(list->list, 0);
398 while (NULL != iter) {
399 temp_cmd = iter->data;
401 if (NULL != temp_cmd && cmd == temp_cmd) {
402 list->list = g_slist_remove(list->list, temp_cmd);
404 if (true == release_command) {
405 SLOG(LOG_DEBUG, TAG_VCCMD, "Release command data");
406 if (NULL != temp_cmd->command) free(temp_cmd->command);
407 if (NULL != temp_cmd->parameter) free(temp_cmd->parameter);
414 iter = g_slist_next(iter);
417 int count = g_slist_length(list->list);
421 } else if (list->index == count) {
422 list->index = count - 1;
425 return VC_ERROR_NONE;
428 int vc_cmd_list_remove_all(vc_cmd_list_h vc_cmd_list, bool release_command)
430 if (0 != __vc_cmd_get_feature_enabled()) {
431 return VC_ERROR_NOT_SUPPORTED;
433 if (0 != __vc_cmd_check_privilege()) {
434 return VC_ERROR_PERMISSION_DENIED;
437 SLOG(LOG_DEBUG, TAG_VCCMD, "@@@ Destroy all command");
439 if (NULL == vc_cmd_list) {
440 SLOG(LOG_ERROR, TAG_VCCMD, "[ERROR] Input parameter is NULL");
441 return VC_ERROR_INVALID_PARAMETER;
444 vc_cmd_list_s* list = NULL;
445 list = (vc_cmd_list_s*)vc_cmd_list;
447 SLOG(LOG_DEBUG, TAG_VCCMD, "[List] list (%p), release command (%s)"
448 , list, release_command ? "true" : "false");
450 int count = g_slist_length(list->list);
451 for (int i = 0; i < count ; i++) {
452 vc_cmd_s *temp_cmd = g_slist_nth_data(list->list, 0);
454 if (NULL != temp_cmd) {
455 list->list = g_slist_remove(list->list, temp_cmd);
457 if (true == release_command) {
458 SLOG(LOG_DEBUG, TAG_VCCMD, "Free command(%p)", temp_cmd);
459 if (NULL != temp_cmd->command) free(temp_cmd->command);
460 if (NULL != temp_cmd->parameter) free(temp_cmd->parameter);
461 if (NULL != temp_cmd->appid) free(temp_cmd->appid);
462 if (NULL != temp_cmd->invocation_name) free(temp_cmd->invocation_name);
463 if (NULL != temp_cmd->fixed) free(temp_cmd->fixed);
472 SLOG(LOG_DEBUG, TAG_VCCMD, "@@@");
474 return VC_ERROR_NONE;
477 int vc_cmd_list_foreach_commands(vc_cmd_list_h vc_cmd_list, vc_cmd_list_cb callback, void* user_data)
479 if (0 != __vc_cmd_get_feature_enabled()) {
480 return VC_ERROR_NOT_SUPPORTED;
482 if (0 != __vc_cmd_check_privilege()) {
483 return VC_ERROR_PERMISSION_DENIED;
486 if (NULL == vc_cmd_list) {
487 SLOG(LOG_ERROR, TAG_VCCMD, "[ERROR] Input parameter is NULL");
488 return VC_ERROR_INVALID_PARAMETER;
491 vc_cmd_list_s* list = NULL;
492 list = (vc_cmd_list_s*)vc_cmd_list;
494 int count = g_slist_length(list->list);
500 iter = g_slist_nth(list->list, 0);
502 for (i = 0; i < count; i++) {
504 SLOG(LOG_ERROR, TAG_VCCMD, "[ERROR] No command in list");
505 return VC_ERROR_OPERATION_FAILED;
508 temp_cmd = iter->data;
510 if (NULL != temp_cmd) {
511 if (false == callback((vc_cmd_h)temp_cmd, user_data)) {
516 iter = g_slist_next(iter);
519 SLOG(LOG_DEBUG, TAG_VCCMD, "@@@ Foreach commands Done");
521 return VC_ERROR_NONE;
524 int vc_cmd_list_filter_by_type(vc_cmd_list_h original, int type, vc_cmd_list_h* filtered)
526 SLOG(LOG_DEBUG, TAG_VCCMD, "@@@ Filter by type");
528 if (0 != __vc_cmd_get_feature_enabled()) {
529 return VC_ERROR_NOT_SUPPORTED;
531 if (0 != __vc_cmd_check_privilege()) {
532 return VC_ERROR_PERMISSION_DENIED;
535 if (NULL == original) {
536 SLOG(LOG_ERROR, TAG_VCCMD, "[ERROR] Input parameter is NULL");
537 return VC_ERROR_INVALID_PARAMETER;
540 if (VC_COMMAND_TYPE_NONE >= type || VC_COMMAND_TYPE_EXCLUSIVE < type) {
541 SLOG(LOG_ERROR, TAG_VCCMD, "[ERROR] Invalid type");
542 return VC_ERROR_INVALID_PARAMETER;
545 vc_cmd_list_s* list = NULL;
546 list = (vc_cmd_list_s*)original;
548 vc_cmd_list_h temp_list;
549 if (0 != vc_cmd_list_create(&temp_list)) {
550 SLOG(LOG_ERROR, TAG_VCCMD, "[ERROR] Fail to list create");
551 return VC_ERROR_OPERATION_FAILED;
554 int count = g_slist_length(list->list);
560 iter = g_slist_nth(list->list, 0);
562 for (i = 0; i < count; i++) {
564 SLOG(LOG_ERROR, TAG_VCCMD, "[ERROR] No command in list");
565 return VC_ERROR_OPERATION_FAILED;
567 if (NULL != iter->data) {
568 iter_cmd = iter->data;
570 if (NULL != iter_cmd) {
572 if (0 != vc_cmd_get_type((vc_cmd_h)iter_cmd, &iter_type)) {
573 SLOG(LOG_ERROR, TAG_VCCMD, "[ERROR] Fail to get command type");
577 if (iter_type == type) {
579 if (0 != vc_cmd_create(&temp_cmd)) {
580 SLOG(LOG_ERROR, TAG_VCCMD, "[ERROR] Fail to create cmd");
584 memcpy(temp_cmd, iter_cmd, sizeof(vc_cmd_s));
585 if (NULL != iter_cmd->command) {
586 ((vc_cmd_s*)temp_cmd)->command = strdup(iter_cmd->command);
588 if (NULL != iter_cmd->parameter) {
589 ((vc_cmd_s*)temp_cmd)->parameter = strdup(iter_cmd->parameter);
592 if (0 != vc_cmd_list_add(temp_list, temp_cmd)) {
593 SLOG(LOG_ERROR, TAG_VCCMD, "[ERROR] Fail to cmd list add");
594 vc_cmd_destroy(temp_cmd);
600 iter = g_slist_next(iter);
604 if (0 != vc_cmd_list_get_count(temp_list, &count)) {
605 SLOG(LOG_ERROR, TAG_VCCMD, "[ERROR] Fail to get count");
607 SLOG(LOG_DEBUG, TAG_VCCMD, "Filtering result : (%d) command", count);
610 *filtered = temp_list;
612 SLOG(LOG_DEBUG, TAG_VCCMD, "@@@");
614 return VC_ERROR_NONE;
617 int vc_cmd_list_first(vc_cmd_list_h vc_cmd_list)
619 if (0 != __vc_cmd_get_feature_enabled()) {
620 return VC_ERROR_NOT_SUPPORTED;
622 if (0 != __vc_cmd_check_privilege()) {
623 return VC_ERROR_PERMISSION_DENIED;
626 if (NULL == vc_cmd_list) {
627 SLOG(LOG_ERROR, TAG_VCCMD, "[ERROR] Input parameter is NULL");
628 return VC_ERROR_INVALID_PARAMETER;
631 vc_cmd_list_s* list = NULL;
632 list = (vc_cmd_list_s*)vc_cmd_list;
634 if (0 == g_slist_length(list->list)) {
635 SLOG(LOG_ERROR, TAG_VCCMD, "[ERROR] List is empty");
636 return VC_ERROR_EMPTY;
641 return VC_ERROR_NONE;
644 int vc_cmd_list_last(vc_cmd_list_h vc_cmd_list)
646 if (0 != __vc_cmd_get_feature_enabled()) {
647 return VC_ERROR_NOT_SUPPORTED;
649 if (0 != __vc_cmd_check_privilege()) {
650 return VC_ERROR_PERMISSION_DENIED;
653 if (NULL == vc_cmd_list) {
654 SLOG(LOG_ERROR, TAG_VCCMD, "[ERROR] Input parameter is NULL");
655 return VC_ERROR_INVALID_PARAMETER;
658 vc_cmd_list_s* list = NULL;
659 list = (vc_cmd_list_s*)vc_cmd_list;
661 int count = g_slist_length(list->list);
664 SLOG(LOG_ERROR, TAG_VCCMD, "[ERROR] List is empty");
665 return VC_ERROR_EMPTY;
667 list->index = count - 1;
668 SLOG(LOG_DEBUG, TAG_VCCMD, "[DEBUG] List index : %d", list->index);
671 return VC_ERROR_NONE;
674 int vc_cmd_list_next(vc_cmd_list_h vc_cmd_list)
676 if (0 != __vc_cmd_get_feature_enabled()) {
677 return VC_ERROR_NOT_SUPPORTED;
679 if (0 != __vc_cmd_check_privilege()) {
680 return VC_ERROR_PERMISSION_DENIED;
683 if (NULL == vc_cmd_list) {
684 SLOG(LOG_ERROR, TAG_VCCMD, "[ERROR] Input parameter is NULL");
685 return VC_ERROR_INVALID_PARAMETER;
688 vc_cmd_list_s* list = NULL;
689 list = (vc_cmd_list_s*)vc_cmd_list;
691 int count = g_slist_length(list->list);
693 if (list->index < count - 1) {
694 list->index = list->index + 1;
695 SLOG(LOG_DEBUG, TAG_VCCMD, "[DEBUG] List index : %d", list->index);
697 SLOG(LOG_DEBUG, TAG_VCCMD, "[DEBUG] List index : %d", list->index);
698 return VC_ERROR_ITERATION_END;
701 return VC_ERROR_NONE;
704 int vc_cmd_list_prev(vc_cmd_list_h vc_cmd_list)
706 if (0 != __vc_cmd_get_feature_enabled()) {
707 return VC_ERROR_NOT_SUPPORTED;
709 if (0 != __vc_cmd_check_privilege()) {
710 return VC_ERROR_PERMISSION_DENIED;
713 if (NULL == vc_cmd_list) {
714 SLOG(LOG_ERROR, TAG_VCCMD, "[ERROR] Input parameter is NULL");
715 return VC_ERROR_INVALID_PARAMETER;
718 vc_cmd_list_s* list = NULL;
719 list = (vc_cmd_list_s*)vc_cmd_list;
721 if (list->index > 0) {
722 list->index = list->index - 1;
723 SLOG(LOG_DEBUG, TAG_VCCMD, "[DEBUG] List index : %d", list->index);
725 SLOG(LOG_DEBUG, TAG_VCCMD, "[DEBUG] List index : %d", list->index);
726 return VC_ERROR_ITERATION_END;
729 return VC_ERROR_NONE;
732 int vc_cmd_list_get_current(vc_cmd_list_h vc_cmd_list, vc_cmd_h* vc_command)
734 if (0 != __vc_cmd_get_feature_enabled()) {
735 return VC_ERROR_NOT_SUPPORTED;
737 if (0 != __vc_cmd_check_privilege()) {
738 return VC_ERROR_PERMISSION_DENIED;
741 if (NULL == vc_cmd_list || NULL == vc_command) {
742 SLOG(LOG_ERROR, TAG_VCCMD, "[ERROR] Input parameter is NULL");
743 return VC_ERROR_INVALID_PARAMETER;
746 vc_cmd_list_s* list = NULL;
747 list = (vc_cmd_list_s*)vc_cmd_list;
749 SLOG(LOG_DEBUG, TAG_VCCMD, "[List] list (%p), index (%d)", list, list->index);
751 if (0 == g_slist_length(list->list)) {
752 SLOG(LOG_DEBUG, TAG_VCCMD, "[List] list is empty");
754 return VC_ERROR_EMPTY;
757 vc_cmd_s *temp_cmd = NULL;
758 temp_cmd = g_slist_nth_data(list->list, list->index);
760 *vc_command = (vc_cmd_h)temp_cmd;
762 SLOG(LOG_DEBUG, TAG_VCCMD, "[List] Get current command (%p)", *vc_command);
764 return VC_ERROR_NONE;
768 int vc_cmd_create(vc_cmd_h* vc_command)
770 if (0 != __vc_cmd_get_feature_enabled()) {
771 return VC_ERROR_NOT_SUPPORTED;
773 if (0 != __vc_cmd_check_privilege()) {
774 return VC_ERROR_PERMISSION_DENIED;
777 if (NULL == vc_command) {
778 SLOG(LOG_ERROR, TAG_VCCMD, "[ERROR] Input parameter is NULL");
779 return VC_ERROR_INVALID_PARAMETER;
782 vc_cmd_s* command = (vc_cmd_s*)calloc(1, sizeof(vc_cmd_s));
784 if (NULL == command) {
785 SLOG(LOG_ERROR, TAG_VCCMD, "[ERROR] Not enough memory");
786 return VC_ERROR_OUT_OF_MEMORY;
792 command->type = VC_COMMAND_TYPE_NONE;
793 command->format = VC_CMD_FORMAT_FIXED;
794 command->command = NULL;
795 command->parameter = NULL;
797 command->priority = 0;
798 command->key = VC_KEY_NONE;
799 command->modifier = VC_MODIFIER_NONE;
800 command->invocation_name = NULL;
801 command->appid = NULL;
802 command->fixed = NULL;
803 command->coordinates = NULL;
805 *vc_command = (vc_cmd_h)command;
807 g_cmd_list = g_list_append(g_cmd_list, command);
809 SLOG(LOG_DEBUG, TAG_VCCMD, "[Create command][%p]", *vc_command);
811 return VC_ERROR_NONE;
814 int vc_cmd_destroy(vc_cmd_h vc_command)
816 if (0 != __vc_cmd_get_feature_enabled()) {
817 return VC_ERROR_NOT_SUPPORTED;
819 if (0 != __vc_cmd_check_privilege()) {
820 return VC_ERROR_PERMISSION_DENIED;
823 if (NULL == vc_command) {
824 SLOG(LOG_ERROR, TAG_VCCMD, "[ERROR] Input parameter is NULL");
825 return VC_ERROR_INVALID_PARAMETER;
828 if (false == __vc_cmd_is_valid(vc_command)) {
829 SLOG(LOG_ERROR, TAG_VCCMD, "[ERROR] Input parameter is NULL");
830 return VC_ERROR_INVALID_PARAMETER;
833 vc_cmd_s* command = NULL;
834 command = (vc_cmd_s*)vc_command;
836 SLOG(LOG_DEBUG, TAG_VCCMD, "[Destroy command][%p]", command);
840 iter = g_list_first(g_cmd_list);
841 while (NULL != iter) {
842 vc_cmd_s *data = NULL;
844 if (NULL != data && command == data) {
845 g_cmd_list = g_list_remove_link(g_cmd_list, iter);
849 iter = g_list_next(iter);
853 SLOG(LOG_ERROR, TAG_VCCMD, "Fail to destroy client : handle is not valid");
854 return VC_ERROR_INVALID_PARAMETER;
861 if (NULL != command) {
862 if (NULL != command->command) {
863 free(command->command);
864 command->command = NULL;
866 if (NULL != command->parameter) {
867 free(command->parameter);
868 command->parameter = NULL;
870 if (NULL != command->invocation_name) {
871 free(command->invocation_name);
872 command->invocation_name = NULL;
874 if (NULL != command->appid) {
875 free(command->appid);
876 command->appid = NULL;
878 if (NULL != command->fixed) {
879 free(command->fixed);
880 command->fixed = NULL;
882 if (NULL != command->coordinates) {
883 free(command->coordinates);
884 command->coordinates = NULL;
890 return VC_ERROR_NONE;
893 int vc_cmd_set_id(vc_cmd_h vc_command, int id)
895 if (0 != __vc_cmd_get_feature_enabled()) {
896 return VC_ERROR_NOT_SUPPORTED;
898 if (0 != __vc_cmd_check_privilege()) {
899 return VC_ERROR_PERMISSION_DENIED;
902 if (NULL == vc_command) {
903 SLOG(LOG_ERROR, TAG_VCCMD, "[ERROR] Invalid parameter ");
904 return VC_ERROR_INVALID_PARAMETER;
907 vc_cmd_s* cmd = NULL;
908 cmd = (vc_cmd_s*)vc_command;
912 SLOG(LOG_DEBUG, TAG_VCCMD, "[Set id][%p] id(%d)", vc_command, cmd->id);
918 int vc_cmd_get_id(vc_cmd_h vc_command, int* id)
920 if (0 != __vc_cmd_get_feature_enabled()) {
921 return VC_ERROR_NOT_SUPPORTED;
923 if (0 != __vc_cmd_check_privilege()) {
924 return VC_ERROR_PERMISSION_DENIED;
927 if (NULL == vc_command || NULL == id) {
928 SLOG(LOG_ERROR, TAG_VCCMD, "[ERROR] Invalid handle ");
929 return VC_ERROR_INVALID_PARAMETER;
932 vc_cmd_s* cmd = NULL;
933 cmd = (vc_cmd_s*)vc_command;
937 SLOG(LOG_DEBUG, TAG_VCCMD, "[Get id][%p] id(%d)", vc_command, *id);
943 int vc_cmd_set_appid(vc_cmd_h vc_command, const char* appid)
945 if (0 != __vc_cmd_get_feature_enabled()) {
946 return VC_ERROR_NOT_SUPPORTED;
949 if (NULL == vc_command) {
950 SLOG(LOG_ERROR, TAG_VCCMD, "[ERROR] Invalid parameter, vc_command is NULL");
951 return VC_ERROR_INVALID_PARAMETER;
955 SLOG(LOG_ERROR, TAG_VCCMD, "[ERROR] Invalid parameter, appid is NULL");
956 return VC_ERROR_INVALID_PARAMETER;
959 vc_cmd_s* cmd = NULL;
960 cmd = (vc_cmd_s*)vc_command;
962 if (NULL != cmd->appid) {
967 cmd->appid = strdup(appid);
969 SLOG(LOG_DEBUG, TAG_VCCMD, "[Set appid][%p] appid(%s)", vc_command, cmd->appid);
973 int vc_cmd_get_appid(vc_cmd_h vc_command, char** appid)
975 if (0 != __vc_cmd_get_feature_enabled()) {
976 return VC_ERROR_NOT_SUPPORTED;
979 if (NULL == vc_command || NULL == appid) {
980 SLOG(LOG_ERROR, TAG_VCCMD, "[ERROR] Invalid handle ");
981 return VC_ERROR_INVALID_PARAMETER;
984 vc_cmd_s* cmd = NULL;
985 cmd = (vc_cmd_s*)vc_command;
987 if (NULL != cmd->appid) {
988 *appid = strdup(gettext(cmd->appid));
991 SLOG(LOG_DEBUG, TAG_VCCMD, "[Get appid][%p] appid(%s)", vc_command, *appid);
995 int vc_cmd_set_command(vc_cmd_h vc_command, const char* command)
997 if (0 != __vc_cmd_get_feature_enabled()) {
998 return VC_ERROR_NOT_SUPPORTED;
1000 if (0 != __vc_cmd_check_privilege()) {
1001 return VC_ERROR_PERMISSION_DENIED;
1004 if (NULL == vc_command) {
1005 SLOG(LOG_ERROR, TAG_VCCMD, "[ERROR] Invalid parameter ");
1006 return VC_ERROR_INVALID_PARAMETER;
1009 vc_cmd_s* cmd = NULL;
1010 cmd = (vc_cmd_s*)vc_command;
1012 if (NULL != cmd->command) {
1016 cmd->command = NULL;
1018 if (NULL != command) {
1019 cmd->command = strdup(command);
1022 SLOG(LOG_DEBUG, TAG_VCCMD, "[Set command][%p] Command(%s)", vc_command, cmd->command);
1027 int vc_cmd_get_command(vc_cmd_h vc_command, char** command)
1029 if (0 != __vc_cmd_get_feature_enabled()) {
1030 return VC_ERROR_NOT_SUPPORTED;
1032 if (0 != __vc_cmd_check_privilege()) {
1033 return VC_ERROR_PERMISSION_DENIED;
1036 if (NULL == vc_command || NULL == command) {
1037 SLOG(LOG_ERROR, TAG_VCCMD, "[ERROR] Invalid handle ");
1038 return VC_ERROR_INVALID_PARAMETER;
1041 vc_cmd_s* cmd = NULL;
1042 cmd = (vc_cmd_s*)vc_command;
1044 if (NULL != cmd->command) {
1045 *command = strdup(gettext(cmd->command));
1048 SLOG(LOG_DEBUG, TAG_VCCMD, "[Get command][%p] Command(%s)", vc_command, *command);
1053 int vc_cmd_set_unfixed_command(vc_cmd_h vc_command, const char* command)
1055 if (0 != __vc_cmd_get_feature_enabled()) {
1056 return VC_ERROR_NOT_SUPPORTED;
1058 if (0 != __vc_cmd_check_privilege()) {
1059 return VC_ERROR_PERMISSION_DENIED;
1062 if (NULL == vc_command) {
1063 SLOG(LOG_ERROR, TAG_VCCMD, "[ERROR] Invalid parameter ");
1064 return VC_ERROR_INVALID_PARAMETER;
1067 vc_cmd_s* cmd = NULL;
1068 cmd = (vc_cmd_s*)vc_command;
1070 if (NULL != cmd->parameter) {
1071 free(cmd->parameter);
1074 cmd->parameter = NULL;
1076 if (NULL != command) {
1077 cmd->parameter = strdup(command);
1078 SLOG(LOG_DEBUG, TAG_VCCMD, "[Set unfixed command][%p] unfixed command(%s)", vc_command, cmd->parameter);
1084 int vc_cmd_get_unfixed_command(vc_cmd_h vc_command, char** command)
1086 if (0 != __vc_cmd_get_feature_enabled()) {
1087 return VC_ERROR_NOT_SUPPORTED;
1090 if (NULL == vc_command || NULL == command) {
1091 SLOG(LOG_ERROR, TAG_VCCMD, "[ERROR] Invalid handle ");
1092 return VC_ERROR_INVALID_PARAMETER;
1095 vc_cmd_s* cmd = NULL;
1096 cmd = (vc_cmd_s*)vc_command;
1098 if (NULL != cmd->parameter) {
1099 *command = strdup(gettext(cmd->parameter));
1100 SLOG(LOG_DEBUG, TAG_VCCMD, "[Get unfixed command][%p] unfixed command(%s)", vc_command, *command);
1106 int vc_cmd_set_fixed_command(vc_cmd_h vc_command, const char* fixed)
1108 if (0 != __vc_cmd_get_feature_enabled()) {
1109 return VC_ERROR_NOT_SUPPORTED;
1112 if (NULL == vc_command) {
1113 SLOG(LOG_ERROR, TAG_VCCMD, "[ERROR] Invalid parameter ");
1114 return VC_ERROR_INVALID_PARAMETER;
1117 if (NULL == fixed) {
1118 SLOG(LOG_ERROR, TAG_VCCMD, "[ERROR] Invalid parameter, fixed is NULL");
1119 return VC_ERROR_INVALID_PARAMETER;
1122 vc_cmd_s* cmd = NULL;
1123 cmd = (vc_cmd_s*)vc_command;
1125 if (NULL != cmd->fixed) {
1130 cmd->fixed = strdup(fixed);
1132 SLOG(LOG_DEBUG, TAG_VCCMD, "[Set parameter][%p] fixed command(%s)", vc_command, cmd->fixed);
1136 int vc_cmd_get_fixed_command(vc_cmd_h vc_command, char** fixed)
1138 if (0 != __vc_cmd_get_feature_enabled()) {
1139 return VC_ERROR_NOT_SUPPORTED;
1142 if (NULL == vc_command || NULL == fixed) {
1143 SLOG(LOG_ERROR, TAG_VCCMD, "[ERROR] Invalid handle ");
1144 return VC_ERROR_INVALID_PARAMETER;
1147 vc_cmd_s* cmd = NULL;
1148 cmd = (vc_cmd_s*)vc_command;
1150 if (NULL != cmd->fixed) {
1151 *fixed = strdup(gettext(cmd->fixed));
1152 SLOG(LOG_DEBUG, TAG_VCCMD, "[Get fixed command][%p] fixed command(%s)", vc_command, *fixed);
1158 int vc_cmd_set_invocation_name(vc_cmd_h vc_command, const char* invocation_name)
1160 if (0 != __vc_cmd_get_feature_enabled()) {
1161 return VC_ERROR_NOT_SUPPORTED;
1164 if (NULL == vc_command) {
1165 SLOG(LOG_ERROR, TAG_VCCMD, "[ERROR] Invalid parameter, vc_command is NULL");
1166 return VC_ERROR_INVALID_PARAMETER;
1169 if (NULL == invocation_name) {
1170 SLOG(LOG_ERROR, TAG_VCCMD, "[ERROR] Invalid parameter, invocation_name is NULL");
1171 return VC_ERROR_INVALID_PARAMETER;
1174 vc_cmd_s* cmd = NULL;
1175 cmd = (vc_cmd_s*)vc_command;
1177 if (NULL != cmd->invocation_name) {
1178 free(cmd->invocation_name);
1179 cmd->invocation_name = NULL;
1182 cmd->invocation_name = strdup(invocation_name);
1184 SLOG(LOG_DEBUG, TAG_VCCMD, "[Set invocation name][%p] invocation_name(%s)", vc_command, cmd->invocation_name);
1188 int vc_cmd_get_invocation_name(vc_cmd_h vc_command, char** invocation_name)
1190 if (0 != __vc_cmd_get_feature_enabled()) {
1191 return VC_ERROR_NOT_SUPPORTED;
1194 if (NULL == vc_command || NULL == invocation_name) {
1195 SLOG(LOG_ERROR, TAG_VCCMD, "[ERROR] Invalid handle ");
1196 return VC_ERROR_INVALID_PARAMETER;
1199 vc_cmd_s* cmd = NULL;
1200 cmd = (vc_cmd_s*)vc_command;
1202 if (NULL != cmd->invocation_name) {
1203 *invocation_name = strdup(gettext(cmd->invocation_name));
1206 SLOG(LOG_DEBUG, TAG_VCCMD, "[Get invocation name][%p] invocation_name(%s)", vc_command, *invocation_name);
1210 int vc_cmd_set_type(vc_cmd_h vc_command, int type)
1212 if (0 != __vc_cmd_get_feature_enabled()) {
1213 return VC_ERROR_NOT_SUPPORTED;
1215 if (0 != __vc_cmd_check_privilege()) {
1216 return VC_ERROR_PERMISSION_DENIED;
1219 if (NULL == vc_command) {
1220 SLOG(LOG_ERROR, TAG_VCCMD, "[ERROR] Invalid parameter ");
1221 return VC_ERROR_INVALID_PARAMETER;
1224 vc_cmd_s* cmd = NULL;
1225 cmd = (vc_cmd_s*)vc_command;
1229 SLOG(LOG_DEBUG, TAG_VCCMD, "[Set type][%p] type(%d)", vc_command, cmd->type);
1234 int vc_cmd_get_type(vc_cmd_h vc_command, int* type)
1236 if (0 != __vc_cmd_get_feature_enabled()) {
1237 return VC_ERROR_NOT_SUPPORTED;
1239 if (0 != __vc_cmd_check_privilege()) {
1240 return VC_ERROR_PERMISSION_DENIED;
1243 if (NULL == vc_command || NULL == type) {
1244 SLOG(LOG_ERROR, TAG_VCCMD, "[ERROR] Invalid parameter ");
1245 return VC_ERROR_INVALID_PARAMETER;
1248 vc_cmd_s* cmd = NULL;
1249 cmd = (vc_cmd_s*)vc_command;
1253 SLOG(LOG_DEBUG, TAG_VCCMD, "[Get type][%p] type(%d)", vc_command, *type);
1258 int vc_cmd_set_format(vc_cmd_h vc_command, int format)
1260 if (0 != __vc_cmd_get_feature_enabled()) {
1261 return VC_ERROR_NOT_SUPPORTED;
1264 if (NULL == vc_command) {
1265 SLOG(LOG_ERROR, TAG_VCCMD, "[ERROR] Invalid parameter ");
1266 return VC_ERROR_INVALID_PARAMETER;
1269 vc_cmd_s* cmd = NULL;
1270 cmd = (vc_cmd_s*)vc_command;
1272 cmd->format = format;
1274 SLOG(LOG_DEBUG, TAG_VCCMD, "[Set format][%p] format(%d)", vc_command, format);
1279 int vc_cmd_get_format(vc_cmd_h vc_command, int* format)
1281 if (0 != __vc_cmd_get_feature_enabled()) {
1282 return VC_ERROR_NOT_SUPPORTED;
1285 if (NULL == vc_command || NULL == format) {
1286 SLOG(LOG_ERROR, TAG_VCCMD, "[ERROR] Invalid parameter ");
1287 return VC_ERROR_INVALID_PARAMETER;
1290 vc_cmd_s* cmd = NULL;
1291 cmd = (vc_cmd_s*)vc_command;
1293 *format = cmd->format;
1295 SLOG(LOG_DEBUG, TAG_VCCMD, "[Get format][%p] format(%d)", vc_command, *format);
1300 int vc_cmd_set_pid(vc_cmd_h vc_command, int pid)
1302 if (0 != __vc_cmd_get_feature_enabled()) {
1303 return VC_ERROR_NOT_SUPPORTED;
1305 if (0 != __vc_cmd_check_privilege()) {
1306 return VC_ERROR_PERMISSION_DENIED;
1309 if (NULL == vc_command) {
1310 SLOG(LOG_ERROR, TAG_VCCMD, "[ERROR] Invalid parameter ");
1311 return VC_ERROR_INVALID_PARAMETER;
1314 vc_cmd_s* cmd = NULL;
1315 cmd = (vc_cmd_s*)vc_command;
1319 SLOG(LOG_DEBUG, TAG_VCCMD, "[Set pid][%p] pid(%d)", vc_command, cmd->pid);
1324 int vc_cmd_get_pid(vc_cmd_h vc_command, int* pid)
1326 if (0 != __vc_cmd_get_feature_enabled()) {
1327 return VC_ERROR_NOT_SUPPORTED;
1329 if (0 != __vc_cmd_check_privilege()) {
1330 return VC_ERROR_PERMISSION_DENIED;
1333 if (NULL == vc_command || NULL == pid) {
1334 SLOG(LOG_ERROR, TAG_VCCMD, "[ERROR] Invalid parameter ");
1335 return VC_ERROR_INVALID_PARAMETER;
1338 vc_cmd_s* cmd = NULL;
1339 cmd = (vc_cmd_s*)vc_command;
1343 SLOG(LOG_DEBUG, TAG_VCCMD, "[Get pid][%p] pid(%d)", vc_command, *pid);
1348 int vc_cmd_set_domain(vc_cmd_h vc_command, int domain)
1350 if (0 != __vc_cmd_get_feature_enabled()) {
1351 return VC_ERROR_NOT_SUPPORTED;
1353 if (0 != __vc_cmd_check_privilege()) {
1354 return VC_ERROR_PERMISSION_DENIED;
1357 if (NULL == vc_command) {
1358 SLOG(LOG_ERROR, TAG_VCCMD, "[ERROR] Invalid parameter ");
1359 return VC_ERROR_INVALID_PARAMETER;
1362 vc_cmd_s* cmd = NULL;
1363 cmd = (vc_cmd_s*)vc_command;
1365 cmd->domain = domain;
1367 SLOG(LOG_DEBUG, TAG_VCCMD, "[Set domain] domain : %d", domain);
1372 int vc_cmd_get_domain(vc_cmd_h vc_command, int* domain)
1374 if (0 != __vc_cmd_get_feature_enabled()) {
1375 return VC_ERROR_NOT_SUPPORTED;
1377 if (0 != __vc_cmd_check_privilege()) {
1378 return VC_ERROR_PERMISSION_DENIED;
1381 if (NULL == vc_command || NULL == domain) {
1382 SLOG(LOG_ERROR, TAG_VCCMD, "[ERROR] Invalid parameter ");
1383 return VC_ERROR_INVALID_PARAMETER;
1386 vc_cmd_s* cmd = NULL;
1387 cmd = (vc_cmd_s*)vc_command;
1389 *domain = cmd->domain;
1391 SLOG(LOG_DEBUG, TAG_VCCMD, "[Get domain] domain : %d", *domain);
1397 * @brief Sets key value of command.
1399 * @param[in] vc_command Command handle
1400 * @param[in] key key value
1401 * @param[in] modifier modifier value
1403 * @return 0 on success, otherwise a negative error value
1404 * @retval #VC_ERROR_NONE Successful
1405 * @retval #VC_ERROR_INVALID_PARAMETER Invalid parameter
1407 * @see vc_cmd_get_result_key()
1409 int vc_cmd_set_result_key(vc_cmd_h vc_command, int key, int modifier)
1411 SLOG(LOG_DEBUG, TAG_VCCMD, "@@@ Set result key");
1413 if (NULL == vc_command) {
1414 SLOG(LOG_ERROR, TAG_VCCMD, "[ERROR] Invalid parameter ");
1415 return VC_ERROR_INVALID_PARAMETER;
1418 vc_cmd_s* cmd = NULL;
1419 cmd = (vc_cmd_s*)vc_command;
1421 SLOG(LOG_DEBUG, TAG_VCCMD, "key : %d, modifier : %d", key, modifier);
1424 cmd->modifier = modifier;
1426 SLOG(LOG_DEBUG, TAG_VCCMD, "@@@");
1432 * @brief Gets key value of command.
1434 * @param[in] vc_command Command handle
1435 * @param[out] key key value
1436 * @param[out] modifier modifier value
1438 * @return 0 on success, otherwise a negative error value
1439 * @retval #VC_ERROR_NONE Successful
1440 * @retval #VC_ERROR_INVALID_PARAMETER Invalid parameter
1442 * @see vc_cmd_add_result_key()
1444 int vc_cmd_get_result_key(vc_cmd_h vc_command, int* key, int* modifier)
1446 SLOG(LOG_DEBUG, TAG_VCCMD, "@@@ Get result key");
1448 if (NULL == vc_command || NULL == key || NULL == modifier) {
1449 SLOG(LOG_ERROR, TAG_VCCMD, "[ERROR] Invalid parameter ");
1450 return VC_ERROR_INVALID_PARAMETER;
1453 vc_cmd_s* cmd = NULL;
1454 cmd = (vc_cmd_s*)vc_command;
1457 *modifier = cmd->modifier;
1459 SLOG(LOG_DEBUG, TAG_VCCMD, "@@@");
1464 int vc_cmd_print_list(vc_cmd_list_h vc_cmd_list)
1466 if (NULL == vc_cmd_list) {
1470 vc_cmd_list_s* list = NULL;
1471 list = (vc_cmd_list_s*)vc_cmd_list;
1473 SLOG(LOG_DEBUG, TAG_VCCMD, "@ Command List @");
1474 SLOG(LOG_DEBUG, TAG_VCCMD, "[List][%p]", list);
1476 int count = g_slist_length(list->list);
1479 vc_cmd_s *cmd = NULL;
1481 for (i = 0; i < count ; i++) {
1482 cmd = g_slist_nth_data(list->list, i);
1485 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)",
1486 i, cmd, cmd->pid, cmd->index, cmd->type, cmd->format, cmd->command, cmd->parameter, cmd->appid, cmd->invocation_name, cmd->fixed);
1490 SLOG(LOG_DEBUG, TAG_VCCMD, "@@@");
1495 int vc_cmd_get_nlu_json(vc_cmd_h vc_cmd, char** json)
1497 if (0 != __vc_cmd_get_feature_enabled()) {
1498 return VC_ERROR_NOT_SUPPORTED;
1501 if (NULL == vc_cmd || NULL == json) {
1502 SLOG(LOG_ERROR, TAG_VCCMD, "[ERROR] NULL parameter");
1503 return VC_ERROR_INVALID_PARAMETER;
1506 vc_cmd_s* cmd = NULL;
1507 cmd = (vc_cmd_s*)vc_cmd;
1509 if (VC_CMD_FORMAT_ACTION != cmd->format) {
1510 SLOG(LOG_ERROR, TAG_VCCMD, "[ERROR] Not Action format");
1511 return VC_ERROR_INVALID_PARAMETER;
1514 if (0 != vc_info_parser_get_nlu_result(json)) {
1515 SLOG(LOG_ERROR, TAG_VCCMD, "[ERROR] Fail to get nlu result");
1516 return VC_ERROR_OPERATION_FAILED;
1522 static void __vc_cmd_regex_deinit(int num_regex)
1524 SLOG(LOG_DEBUG, TAG_VCCMD, "@@@ Start Deinitialize regex @@@");
1527 for (i = 0; num_regex > i; i++) {
1531 SLOG(LOG_DEBUG, TAG_VCCMD, "@@@");
1534 static int __vc_cmd_regex_init()
1536 SLOG(LOG_DEBUG, TAG_VCCMD, "@@@ Initialize regular expression @@@");
1538 int cflags = REG_EXTENDED | REG_ICASE;
1544 vc_config_mgr_get_default_language(&lang);
1546 SLOG(LOG_ERROR, TAG_VCCMD, "[ERROR] Fail to get current language");
1547 return VC_ERROR_OPERATION_FAILED;
1550 if (!strcmp("en_US", lang)) {
1552 } else if (!strcmp("ko_KR", lang)) {
1558 SLOG(LOG_ERROR, TAG_VCCMD, "[ERROR] Not supported language type");
1559 return VC_ERROR_INVALID_LANGUAGE;
1565 SLOG(LOG_DEBUG, TAG_VCCMD, "@@@ lang type > %d @@@", lang_type);
1567 re_syntax_options = RE_SYNTAX_POSIX_EXTENDED;
1569 SLOG(LOG_DEBUG, TAG_VCCMD, "Regular expression > %s" , TIME_ABS1_REGEX[lang_type]);
1570 ret = regcomp(®[0], TIME_ABS1_REGEX[lang_type], cflags);
1572 regerror(ret, ®[0], errStr, sizeof(errStr));
1574 SLOG(LOG_ERROR, TAG_VCCMD, "[ERROR] regcomp() error > %s", errStr);
1575 return VC_ERROR_OPERATION_FAILED;
1578 SLOG(LOG_DEBUG, TAG_VCCMD, "Regular expression > %s", TIME_ABS2_REGEX[lang_type]);
1579 ret = regcomp(®[1], TIME_ABS2_REGEX[lang_type], cflags);
1581 regerror(ret, ®[1], errStr, sizeof(errStr));
1582 __vc_cmd_regex_deinit(1);
1584 SLOG(LOG_ERROR, TAG_VCCMD, "[ERROR] regcomp() error > %s", errStr);
1585 return VC_ERROR_OPERATION_FAILED;
1588 SLOG(LOG_DEBUG, TAG_VCCMD, "Regular expression > %s", TIME_ABS3_REGEX[lang_type]);
1589 ret = regcomp(®[2], TIME_ABS3_REGEX[lang_type], cflags);
1591 regerror(ret, ®[2], errStr, sizeof(errStr));
1592 __vc_cmd_regex_deinit(2);
1594 SLOG(LOG_ERROR, TAG_VCCMD, "[ERROR] regcomp() error > %s", errStr);
1595 return VC_ERROR_OPERATION_FAILED;
1598 SLOG(LOG_DEBUG, TAG_VCCMD, "Regular expression > %s", TIME_REL1_REGEX[lang_type]);
1599 ret = regcomp(®[3], TIME_REL1_REGEX[lang_type], cflags);
1601 regerror(ret, ®[3], errStr, sizeof(errStr));
1602 __vc_cmd_regex_deinit(3);
1604 SLOG(LOG_ERROR, TAG_VCCMD, "[ERROR] regcomp() error > %s", errStr);
1605 return VC_ERROR_OPERATION_FAILED;
1608 SLOG(LOG_DEBUG, TAG_VCCMD, "Regular expression > %s", TIME_REL2_REGEX[lang_type]);
1609 ret = regcomp(®[4], TIME_REL2_REGEX[lang_type], cflags);
1611 regerror(ret, ®[4], errStr, sizeof(errStr));
1612 __vc_cmd_regex_deinit(4);
1614 SLOG(LOG_ERROR, TAG_VCCMD, "[ERROR] regcomp() error > %s", errStr);
1615 return VC_ERROR_OPERATION_FAILED;
1618 SLOG(LOG_DEBUG, TAG_VCCMD, "Regular expression > %s", TIME_REL3_REGEX[lang_type]);
1619 ret = regcomp(®[5], TIME_REL3_REGEX[lang_type], cflags);
1621 regerror(ret, ®[5], errStr, sizeof(errStr));
1622 __vc_cmd_regex_deinit(5);
1624 SLOG(LOG_ERROR, TAG_VCCMD, "[ERROR] regcomp() error > %s", errStr);
1625 return VC_ERROR_OPERATION_FAILED;
1628 SLOG(LOG_DEBUG, TAG_VCCMD, "Regular expression > %s", TIME_PHR_REGEX[lang_type]);
1629 ret = regcomp(®[6], TIME_PHR_REGEX[lang_type], cflags);
1631 regerror(ret, ®[6], errStr, sizeof(errStr));
1632 __vc_cmd_regex_deinit(6);
1634 SLOG(LOG_ERROR, TAG_VCCMD, "[ERROR] regcomp() error > %s", errStr);
1635 return VC_ERROR_OPERATION_FAILED;
1638 SLOG(LOG_DEBUG, TAG_VCCMD, "Regular expression > %s", DATE_ABS1_REGEX[lang_type]);
1639 ret = regcomp(®[7], DATE_ABS1_REGEX[lang_type], cflags);
1641 regerror(ret, ®[7], errStr, sizeof(errStr));
1642 __vc_cmd_regex_deinit(7);
1644 SLOG(LOG_ERROR, TAG_VCCMD, "[ERROR] regcomp() error > %s", errStr);
1645 return VC_ERROR_OPERATION_FAILED;
1648 SLOG(LOG_DEBUG, TAG_VCCMD, "Regular expression > %s", DATE_ABS2_REGEX[lang_type]);
1649 ret = regcomp(®[8], DATE_ABS2_REGEX[lang_type], cflags);
1651 regerror(ret, ®[8], errStr, sizeof(errStr));
1652 __vc_cmd_regex_deinit(8);
1654 SLOG(LOG_ERROR, TAG_VCCMD, "[ERROR] regcomp() error > %s", errStr);
1655 return VC_ERROR_OPERATION_FAILED;
1658 SLOG(LOG_DEBUG, TAG_VCCMD, "Regular expression > %s", DATE_ABS3_REGEX[lang_type]);
1659 ret = regcomp(®[9], DATE_ABS3_REGEX[lang_type], cflags);
1661 regerror(ret, ®[9], errStr, sizeof(errStr));
1662 __vc_cmd_regex_deinit(9);
1664 SLOG(LOG_ERROR, TAG_VCCMD, "[ERROR] regcomp() error > %s", errStr);
1665 return VC_ERROR_OPERATION_FAILED;
1668 SLOG(LOG_DEBUG, TAG_VCCMD, "Regular expression > %s", DATE_PHR1_REGEX[lang_type]);
1669 ret = regcomp(®[10], DATE_PHR1_REGEX[lang_type], cflags);
1671 regerror(ret, ®[10], errStr, sizeof(errStr));
1672 __vc_cmd_regex_deinit(10);
1674 SLOG(LOG_ERROR, TAG_VCCMD, "[ERROR] regcomp() error > %s", errStr);
1675 return VC_ERROR_OPERATION_FAILED;
1678 SLOG(LOG_DEBUG, TAG_VCCMD, "Regular expression > %s", DATE_PHR2_REGEX[lang_type]);
1679 ret = regcomp(®[11], DATE_PHR2_REGEX[lang_type], cflags);
1681 regerror(ret, ®[11], errStr, sizeof(errStr));
1682 __vc_cmd_regex_deinit(11);
1684 SLOG(LOG_ERROR, TAG_VCCMD, "[ERROR] regcomp() error > %s", errStr);
1685 return VC_ERROR_OPERATION_FAILED;
1688 SLOG(LOG_DEBUG, TAG_VCCMD, "@@@");
1690 return VC_ERROR_NONE;
1693 static void __vc_cmd_add_year(struct tm *td, int year)
1695 td->tm_year += year;
1698 static void __vc_cmd_add_mon(struct tm *td, int mon)
1702 mon = td->tm_mon + mon;
1706 __vc_cmd_add_year(td, year);
1709 td->tm_mon = mon % 12;
1712 static void __vc_cmd_add_mday(struct tm *td, int mday)
1714 int max_day[12] = {31, 28, 31, 30, 31, 30, 31, 30, 30, 31, 30, 31};
1715 int year = td->tm_year + 1900;
1719 if ((0 == year % 4 && 0 != year % 100) || 0 == year % 400) max_day[1] = 29;
1721 mday = td->tm_mday + mday;
1723 for (mon = td->tm_mon; mday >= max_day[mon % 12]; mon++) {
1724 mday -= max_day[mon % 12];
1726 if (11 == mon % 12) {
1729 if ((0 == year % 4 && 0 != year % 100) || 0 == year % 400) {
1737 mon = mon - td->tm_mon;
1740 __vc_cmd_add_mon(td, mon);
1746 static void __vc_cmd_add_hour(struct tm *td, int hour)
1750 hour = td->tm_hour + hour;
1754 __vc_cmd_add_mday(td, day);
1757 td->tm_hour = hour % 24;
1760 static void __vc_cmd_add_min(struct tm *td, int min)
1764 min = td->tm_min + min;
1768 __vc_cmd_add_hour(td, hour);
1771 td->tm_min = min % 60;
1774 static void __copy_struct_tm(struct tm *des, struct tm *src)
1776 SLOG(LOG_DEBUG, TAG_VCCMD, "@@@ Start to copy struct tm @@@");
1778 des->tm_sec = src->tm_sec;
1779 des->tm_min = src->tm_min;
1780 des->tm_hour = src->tm_hour;
1781 des->tm_mday = src->tm_mday;
1782 des->tm_mon = src->tm_mon;
1783 des->tm_year = src->tm_year;
1784 des->tm_wday = src->tm_wday;
1785 des->tm_yday = src->tm_yday;
1786 des->tm_isdst = src->tm_isdst;
1788 des->tm_gmtoff = src->tm_gmtoff;
1789 des->tm_zone = src->tm_zone;
1792 static void __update_data_sidx(int idx)
1794 if (0 > g_data_sidx || idx < g_data_sidx) g_data_sidx = idx;
1797 static void __update_data_eidx(int idx)
1799 if (0 > g_data_eidx || idx > g_data_eidx) g_data_eidx = idx;
1802 static int __vc_cmd_tphrase_check(const char *str, struct tm *td, int *exist)
1804 regmatch_t pmatch[3];
1810 ret = regexec(®[6], str, 3, pmatch, 0);
1813 len = pmatch[idx].rm_eo - pmatch[idx].rm_so;
1815 if (12 < td->tm_hour) {
1816 __vc_cmd_add_mday(td, 1);
1822 len = pmatch[idx].rm_eo - pmatch[idx].rm_so;
1824 __vc_cmd_add_mday(td, 1);
1829 SLOG(LOG_DEBUG, TAG_VCCMD, "Matched string > %.*s", len, str + pmatch[0].rm_so);
1831 __update_data_sidx(pmatch[0].rm_so);
1832 __update_data_eidx(pmatch[0].rm_eo);
1835 return VC_ERROR_NONE;
1838 SLOG(LOG_DEBUG, TAG_VCCMD, "[REGEX] There is no matched string");
1839 return VC_ERROR_NONE;
1842 static int __vc_cmd_trelative_check(const char *str, struct tm *td, int *exist)
1844 regmatch_t pmatch[2];
1852 char *tempstr = NULL;
1855 ret = regexec(®[3], str, 1, pmatch, 0);
1857 SLOG(LOG_DEBUG, TAG_VCCMD, "Matched string > %.*s", pmatch[0].rm_eo - pmatch[0].rm_so, str+pmatch[0].rm_so);
1860 sidx = pmatch[0].rm_so;
1861 eidx = pmatch[0].rm_eo;
1863 ret = regexec(®[4], str, 2, pmatch, 0);
1865 len = pmatch[1].rm_eo - pmatch[1].rm_so;
1868 SLOG(LOG_ERROR, TAG_VCCMD, "[ERROR] Invalid string length");
1869 return VC_ERROR_OPERATION_FAILED;
1871 tempstr = strndup(str + pmatch[1].rm_so, (size_t)len);
1873 if (NULL == tempstr) {
1874 SLOG(LOG_ERROR, TAG_VCCMD, "[ERROR] Memory allocation is failed");
1875 return VC_ERROR_OUT_OF_MEMORY;
1878 hour = atoi(tempstr);
1883 SLOG(LOG_DEBUG, TAG_VCCMD, "Matched string > %.*s", len, str + pmatch[0].rm_so);
1885 if (pmatch[0].rm_so < sidx) sidx = pmatch[0].rm_so;
1886 if (pmatch[0].rm_eo > eidx) eidx = pmatch[0].rm_eo;
1889 ret = regexec(®[5], str, 2, pmatch, 0);
1891 len = pmatch[1].rm_eo - pmatch[1].rm_so;
1894 SLOG(LOG_ERROR, TAG_VCCMD, "[ERROR] Invalid string length");
1895 return VC_ERROR_OPERATION_FAILED;
1897 tempstr = strndup(str + pmatch[1].rm_so, (size_t)len);
1899 if (NULL == tempstr) {
1900 SLOG(LOG_ERROR, TAG_VCCMD, "[ERROR] Memory allocation is failed");
1901 return VC_ERROR_OUT_OF_MEMORY;
1904 min = atoi(tempstr);
1909 SLOG(LOG_DEBUG, TAG_VCCMD, "Matched string > %.*s", len, str + pmatch[0].rm_so);
1911 if (pmatch[0].rm_so < sidx) sidx = pmatch[0].rm_so;
1912 if (pmatch[0].rm_eo > eidx) eidx = pmatch[0].rm_eo;
1915 if (hour < 0 && min < 0) {
1916 SLOG(LOG_DEBUG, TAG_VCCMD, "[REGEX] There is no matched string");
1917 return VC_ERROR_NONE;
1920 hour = 0 > hour ? 0 : hour;
1921 min = 0 > min ? 0 : min;
1923 min = min + (hour * 60);
1925 __vc_cmd_add_min(td, min);
1928 __update_data_sidx(sidx);
1929 __update_data_eidx(eidx);
1932 return VC_ERROR_NONE;
1935 SLOG(LOG_DEBUG, TAG_VCCMD, "[REGEX] There is no matched string");
1936 return VC_ERROR_NONE;
1939 static int __vc_cmd_tabsolute_check(const char *str, struct tm *td, int *exist)
1941 regmatch_t pmatch[5];
1950 char *tempstr = NULL;
1953 ret = regexec(®[0], str, 5, pmatch, 0);
1955 for (idx = 1; 5 > idx && 0 >= pmatch[idx].rm_eo - pmatch[idx].rm_so; idx++);
1959 sidx = pmatch[0].rm_so;
1960 eidx = pmatch[0].rm_eo;
1963 ret = regexec(®[1], str, 2, pmatch, 0);
1965 len = pmatch[1].rm_eo - pmatch[1].rm_so;
1968 SLOG(LOG_ERROR, TAG_VCCMD, "[ERROR] Invalid string length");
1969 return VC_ERROR_OPERATION_FAILED;
1971 tempstr = strndup(str + pmatch[1].rm_so, (size_t)len);
1973 if (NULL == tempstr) {
1974 SLOG(LOG_ERROR, TAG_VCCMD, "[ERROR] Memory allocation is failed");
1975 return VC_ERROR_OUT_OF_MEMORY;
1978 hour = atoi(tempstr);
1981 hour = hour + 12 * flag;
1983 if (12 == hour) hour = 0;
1984 else if (24 == hour) hour = 12;
1987 if (0 > hour || 24 <= hour || (0 == flag && 12 < hour)) {
1988 SLOG(LOG_DEBUG, TAG_VCCMD, "[REGEX] Incoming sentence is weird");
1989 return VC_ERROR_NONE;
1995 SLOG(LOG_DEBUG, TAG_VCCMD, "Matched string > %.*s", len, str + pmatch[0].rm_so);
1997 if (0 > sidx || pmatch[0].rm_so < sidx) sidx = pmatch[0].rm_so;
1998 if (0 > eidx || pmatch[0].rm_eo > eidx) eidx = pmatch[0].rm_eo;
1999 } else if (0 < flag) {
2000 SLOG(LOG_DEBUG, TAG_VCCMD, "[REGEX] Incoming sentence is weird");
2001 return VC_ERROR_NONE;
2004 ret = regexec(®[2], str, 2, pmatch, 0);
2007 len = pmatch[idx].rm_eo - pmatch[idx].rm_so;
2009 tempstr = strndup(str + pmatch[idx].rm_so, (size_t)len);
2011 if (NULL == tempstr) {
2012 SLOG(LOG_ERROR, TAG_VCCMD, "[ERROR] Memory allocation is failed");
2013 return VC_ERROR_OUT_OF_MEMORY;
2016 min = atoi(tempstr);
2018 if (0 > min || 60 <= min) {
2019 SLOG(LOG_DEBUG, TAG_VCCMD, "[REGEX] Incoming sentence is weird");
2020 return VC_ERROR_NONE;
2032 SLOG(LOG_DEBUG, TAG_VCCMD, "Matched string > %.*s", pmatch[0].rm_eo - pmatch[0].rm_so, str + pmatch[0].rm_so);
2033 if (0 > sidx || pmatch[0].rm_so < sidx) sidx = pmatch[0].rm_so;
2034 if (0 > eidx || pmatch[0].rm_eo > eidx) eidx = pmatch[0].rm_eo;
2037 if (0 > hour && 0 > min) {
2038 SLOG(LOG_DEBUG, TAG_VCCMD, "[REGEX] There is no matched string");
2039 return VC_ERROR_NONE;
2042 if (0 <= min && 0 <= hour) {
2043 if (hour < td->tm_hour || (hour == td->tm_hour && min <= td->tm_min)) __vc_cmd_add_mday(td, 1);
2047 } else if (0 <= min) {
2049 vc_config_mgr_get_default_language(&lang);
2051 SLOG(LOG_ERROR, TAG_VCCMD, "[ERROR] Fail to get current language");
2052 return VC_ERROR_OPERATION_FAILED;
2055 if (!strcmp("en_US", lang)) {
2056 SLOG(LOG_DEBUG, TAG_VCCMD, "[REGEX] Incoming sentence is weird");
2059 return VC_ERROR_NONE;
2061 if (min <= td->tm_min) __vc_cmd_add_hour(td, 1);
2068 if (hour <= td->tm_hour) __vc_cmd_add_mday(td, 1);
2076 __update_data_sidx(sidx);
2077 __update_data_eidx(eidx);
2080 return VC_ERROR_NONE;
2083 static int __vc_cmd_dphrase_check(const char *str, struct tm *td, int *exist)
2085 regmatch_t pmatch[10];
2091 ret = regexec(®[10], str, 5, pmatch, 0);
2093 for (idx = 1; 5 > idx && 0 >= pmatch[idx].rm_eo - pmatch[idx].rm_so; idx++);
2095 len = pmatch[idx].rm_eo - pmatch[idx].rm_so;
2097 td->tm_year = td_now.tm_year;
2098 td->tm_mon = td_now.tm_mon;
2099 td->tm_mday = td_now.tm_mday;
2101 __vc_cmd_add_mday(td, idx - 1);
2103 SLOG(LOG_DEBUG, TAG_VCCMD, "Matched string > %.*s", len, str + pmatch[0].rm_so);
2105 __update_data_sidx(pmatch[0].rm_so);
2106 __update_data_eidx(pmatch[0].rm_eo);
2109 return VC_ERROR_NONE;
2112 ret = regexec(®[11], str, 10, pmatch, 0);
2114 for (idx = 1; 10 > idx; idx++) {
2115 len = pmatch[idx].rm_eo - pmatch[idx].rm_so;
2120 td->tm_year = td_now.tm_year;
2121 td->tm_mon = td_now.tm_mon;
2122 td->tm_mday = td_now.tm_mday;
2124 __vc_cmd_add_mday(td, idx + 1);
2126 SLOG(LOG_DEBUG, TAG_VCCMD, "Matched string > %.*s", len, str + pmatch[0].rm_so);
2128 __update_data_sidx(pmatch[0].rm_so);
2129 __update_data_eidx(pmatch[0].rm_eo);
2132 return VC_ERROR_NONE;
2135 SLOG(LOG_DEBUG, TAG_VCCMD, "[REGEX] There is no matched string");
2136 return VC_ERROR_NONE;
2139 static int __vc_cmd_dabsolute_check(const char *str, struct tm *td, int *exist)
2141 regmatch_t pmatch[13];
2152 char *tempstr = NULL;
2155 ret = regexec(®[9], str, 2, pmatch, 0);
2157 len = pmatch[1].rm_eo - pmatch[1].rm_so;
2160 SLOG(LOG_ERROR, TAG_VCCMD, "[ERROR] Invalid string length");
2161 return VC_ERROR_OPERATION_FAILED;
2163 tempstr = strndup(str + pmatch[1].rm_so, (size_t)len);
2165 if (NULL == tempstr) {
2166 SLOG(LOG_ERROR, TAG_VCCMD, "[ERROR] Memory allocation is failed");
2167 return VC_ERROR_OUT_OF_MEMORY;
2170 day = atoi(tempstr);
2175 SLOG(LOG_DEBUG, TAG_VCCMD, "Matched string > %.*s", len, str + pmatch[0].rm_so);
2177 sidx = pmatch[0].rm_so;
2178 eidx = pmatch[0].rm_eo;
2180 SLOG(LOG_DEBUG, TAG_VCCMD, "[REGEX] Incoming sentence is weird");
2181 return VC_ERROR_NONE;
2184 ret = regexec(®[8], str, 13, pmatch, 0);
2186 for (idx = 1; 13 > idx; idx++) {
2187 len = pmatch[idx].rm_eo - pmatch[idx].rm_so;
2197 SLOG(LOG_DEBUG, TAG_VCCMD, "Matched string > %.*s", len, str + pmatch[0].rm_so);
2199 if (0 > sidx || pmatch[0].rm_so < sidx) sidx = pmatch[0].rm_so;
2200 if (0 > eidx || pmatch[0].rm_eo > eidx) eidx = pmatch[0].rm_eo;
2203 vc_config_mgr_get_default_language(&lang);
2205 SLOG(LOG_ERROR, TAG_VCCMD, "[ERROR] Fail to get current language");
2206 return VC_ERROR_OPERATION_FAILED;
2209 if (!strcmp("en_US", lang)) {
2210 SLOG(LOG_DEBUG, TAG_VCCMD, "[REGEX] Incoming sentence is weird");
2213 return VC_ERROR_NONE;
2222 ret = regexec(®[7], str, 3, pmatch, 0);
2224 if (!m_flag) return -1;
2226 len = pmatch[2].rm_eo - pmatch[2].rm_so;
2229 SLOG(LOG_ERROR, TAG_VCCMD, "[ERROR] Invalid string length");
2230 return VC_ERROR_OPERATION_FAILED;
2232 tempstr = strndup(str + pmatch[2].rm_so, (size_t)len);
2234 if (NULL == tempstr) {
2235 SLOG(LOG_ERROR, TAG_VCCMD, "[ERROR] Memory allocation is failed");
2236 return VC_ERROR_OUT_OF_MEMORY;
2239 year = atoi(tempstr);
2240 year = 1900 < year ? year - 1900 : year + 100;
2246 SLOG(LOG_DEBUG, TAG_VCCMD, "Matched string > %.*s", len, str + pmatch[0].rm_so);
2248 if (0 > sidx || pmatch[0].rm_so < sidx) sidx = pmatch[0].rm_so;
2249 if (0 > eidx || pmatch[0].rm_eo > eidx) eidx = pmatch[0].rm_eo;
2254 if (0 > g_time_flag) {
2258 } else if (2 == g_time_flag) {
2259 SLOG(LOG_DEBUG, TAG_VCCMD, "[REGEX] Incoming sentence is weird");
2260 return VC_ERROR_NONE;
2263 int max_day[12] = {31, 28, 31, 30, 31, 30, 31, 30, 30, 31, 30, 31};
2264 if ((0 == (year + 1900) % 4 && 0 != (year + 1900) % 100) || 0 == (year + 1900) % 400) max_day[1] = 29;
2266 if (max_day[mon] < day || 1 > day) {
2267 SLOG(LOG_DEBUG, TAG_VCCMD, "[REGEX] Incoming sentence is weird");
2268 return VC_ERROR_NONE;
2277 if (day < td_now.tm_mday) __vc_cmd_add_mon(td, 1);
2279 if (mon < td_now.tm_mon) __vc_cmd_add_year(td, 1);
2280 else if (mon == td_now.tm_mon && day < td_now.tm_mday) __vc_cmd_add_year(td, 1);
2284 __update_data_sidx(sidx);
2285 __update_data_eidx(eidx);
2288 return VC_ERROR_NONE;
2291 static int __vc_cmd_time_check(const char *str, struct tm *td)
2293 SLOG(LOG_DEBUG, TAG_VCCMD, "@@@ Check time value in string \"%s\"", str);
2298 ret = __vc_cmd_tphrase_check(str, td, &exist);
2302 SLOG(LOG_DEBUG, TAG_VCCMD, "@@@ Time value is exist");
2304 } else if (VC_ERROR_NONE != ret) {
2305 SLOG(LOG_ERROR, TAG_VCCMD, "[ERROR] Error is occurred > (%d)", ret);
2309 ret = __vc_cmd_trelative_check(str, td, &exist);
2313 SLOG(LOG_DEBUG, TAG_VCCMD, "@@@ Time value is exist");
2315 } else if (VC_ERROR_NONE != ret) {
2316 SLOG(LOG_ERROR, TAG_VCCMD, "[ERROR] Error is occurred > (%d)", ret);
2320 ret = __vc_cmd_tabsolute_check(str, td, &exist);
2324 SLOG(LOG_DEBUG, TAG_VCCMD, "@@@ Time value is exist");
2326 } else if (VC_ERROR_NONE != ret) {
2327 SLOG(LOG_ERROR, TAG_VCCMD, "[ERROR] Error is occurred > (%d)", ret);
2331 SLOG(LOG_DEBUG, TAG_VCCMD, "@@@ There is no time value");
2332 return VC_ERROR_NONE;
2335 static int __vc_cmd_date_check(const char *str, struct tm *td)
2337 SLOG(LOG_DEBUG, TAG_VCCMD, "@@@ Check date value in string \"%s\"", str);
2342 ret = __vc_cmd_dphrase_check(str, td, &exist);
2346 SLOG(LOG_DEBUG, TAG_VCCMD, "@@@ Date value is exist");
2348 } else if (VC_ERROR_NONE != ret) {
2349 SLOG(LOG_ERROR, TAG_VCCMD, "[ERROR] Error is occurred > (%d)", ret);
2353 ret = __vc_cmd_dabsolute_check(str, td, &exist);
2357 SLOG(LOG_DEBUG, TAG_VCCMD, "@@@ Date value is exist");
2359 } else if (VC_ERROR_NONE != ret) {
2360 SLOG(LOG_ERROR, TAG_VCCMD, "[ERROR] Error is occurred > (%d)", ret);
2364 SLOG(LOG_DEBUG, TAG_VCCMD, "@@@ There is no date value");
2365 return VC_ERROR_NONE;
2368 int vc_cmd_get_datetime(const char *text, time_t *result, char **remain)
2370 SLOG(LOG_DEBUG, TAG_VCCMD, "@@@ Get timestamp data");
2373 const char *day_name[7] = {"Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"};
2376 if (NULL == text || NULL == result || NULL == remain) {
2377 SLOG(LOG_ERROR, TAG_VCCMD, "[ERROR] Invalid parameter");
2378 return VC_ERROR_INVALID_PARAMETER;
2382 ret = __vc_cmd_regex_init();
2383 if (VC_ERROR_NONE != ret) {
2384 SLOG(LOG_ERROR, TAG_VCCMD, "[ERROR] initialize regex failed");
2388 g_data_sidx = g_data_eidx = -1;
2391 localtime_r(&t_now, &td_now);
2392 SLOG(LOG_DEBUG, TAG_VCCMD, "Current timestamp = %d", (int)t_now);
2394 __copy_struct_tm(&td, &td_now);
2395 SLOG(LOG_DEBUG, TAG_VCCMD, "%d-%d-%d (%s), %d:%d:%d",
2396 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);
2398 g_time_flag = g_date_flag = -1;
2400 ret = __vc_cmd_time_check(text, &td);
2401 if (VC_ERROR_NONE != ret) {
2402 SLOG(LOG_ERROR, TAG_VCCMD, "[ERROR] Error is occurred in the check > (%d)", ret);
2406 ret = __vc_cmd_date_check(text, &td);
2407 if (VC_ERROR_NONE != ret) {
2408 SLOG(LOG_ERROR, TAG_VCCMD, "[ERROR] Error is occurred in the check > (%d)", ret);
2412 __vc_cmd_regex_deinit(12);
2414 if (g_time_flag > 0 || g_date_flag > 0) {
2415 *result = mktime(&td);
2417 SLOG(LOG_DEBUG, TAG_VCCMD, "Timestamp in the text = %ld", *result);
2418 SLOG(LOG_DEBUG, TAG_VCCMD, "%d-%d-%d (%s), %d:%d:%d",
2419 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);
2421 *remain = (char *)calloc(sizeof(char), (strlen(text) + 1 - g_data_eidx + g_data_sidx));
2423 if (NULL == *remain) {
2424 SLOG(LOG_ERROR, TAG_VCCMD, "[ERROR] Out of memory error");
2425 return VC_ERROR_OUT_OF_MEMORY;
2428 strncpy(*remain, text, g_data_sidx);
2429 strncat(*remain, text + g_data_eidx, strlen(text) - g_data_eidx);
2431 SLOG(LOG_DEBUG, TAG_VCCMD, "[REGEX] There is no data in the text");
2434 SLOG(LOG_DEBUG, TAG_VCCMD, "@@@");
2436 return VC_ERROR_NONE;