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_cmdlist_list = NULL;
43 // For getting timestamp using regular expression
44 static regex_t reg[MAX_NUM_REGEX];
45 static time_t t_now; //time_t is based on UTC
46 static struct tm td_now; //if use localtime function, the value follows the local time zone, otherwise it follows the UTC.
48 static int g_time_flag;
49 static int g_date_flag;
51 static int g_data_sidx;
52 static int g_data_eidx;
54 static int __vc_cmd_get_feature_enabled()
56 if (0 == g_feature_enabled) {
57 SLOG(LOG_ERROR, TAG_VCCMD, "[ERROR] Voice control feature NOT supported");
58 return VC_ERROR_NOT_SUPPORTED;
59 } else if (-1 == g_feature_enabled) {
60 bool vc_supported = false;
61 bool mic_supported = false;
62 if (0 == system_info_get_platform_bool(VC_FEATURE_PATH, &vc_supported)) {
63 if (0 == system_info_get_platform_bool(VC_MIC_FEATURE_PATH, &mic_supported)) {
64 if (false == vc_supported || false == mic_supported) {
65 SLOG(LOG_ERROR, TAG_VCCMD, "[ERROR] Voice control feature NOT supported");
66 g_feature_enabled = 0;
67 return VC_ERROR_NOT_SUPPORTED;
70 g_feature_enabled = 1;
72 SLOG(LOG_ERROR, TAG_VCCMD, "[ERROR] Fail to get feature value");
73 return VC_ERROR_NOT_SUPPORTED;
76 SLOG(LOG_ERROR, TAG_VCCMD, "[ERROR] Fail to get feature value");
77 return VC_ERROR_NOT_SUPPORTED;
84 static int __check_privilege_initialize()
86 int ret = cynara_initialize(&p_cynara, NULL);
87 if (CYNARA_API_SUCCESS != ret)
88 SLOG(LOG_ERROR, TAG_VCCMD, "[ERROR] fail to initialize");
90 return ret == CYNARA_API_SUCCESS;
93 static int __check_privilege(const char* uid, const char * privilege)
96 char label_path[1024] = "/proc/self/attr/current";
97 char smack_label[1024] = {'\0',};
103 fp = fopen(label_path, "r");
105 if (fread(smack_label, 1, sizeof(smack_label), fp) <= 0)
106 SLOG(LOG_ERROR, TAG_VCCMD, "[ERROR] fail to fread");
111 pid_t pid = getpid();
112 char *session = cynara_session_from_pid(pid);
113 int ret = cynara_check(p_cynara, smack_label, session, uid, privilege);
114 SLOG(LOG_DEBUG, TAG_VCCMD, "[Client]cynara_check returned %d(%s)", ret, (CYNARA_API_ACCESS_ALLOWED == ret) ? "Allowed" : "Denied");
118 if (ret != CYNARA_API_ACCESS_ALLOWED)
123 static void __check_privilege_deinitialize()
126 cynara_finish(p_cynara);
130 static int __vc_cmd_check_privilege()
134 if (0 == g_privilege_allowed) {
135 SLOG(LOG_ERROR, TAG_VCCMD, "[ERROR] Permission is denied");
136 return VC_ERROR_PERMISSION_DENIED;
137 } else if (-1 == g_privilege_allowed) {
138 if (false == __check_privilege_initialize()) {
139 SLOG(LOG_ERROR, TAG_VCCMD, "[ERROR] privilege initialize is failed");
140 return VC_ERROR_PERMISSION_DENIED;
142 snprintf(uid, 16, "%d", getuid());
143 if (false == __check_privilege(uid, VC_PRIVILEGE)) {
144 SLOG(LOG_ERROR, TAG_VCCMD, "[ERROR] Permission is denied");
145 g_privilege_allowed = 0;
146 __check_privilege_deinitialize();
147 return VC_ERROR_PERMISSION_DENIED;
149 __check_privilege_deinitialize();
152 g_privilege_allowed = 1;
154 return VC_ERROR_NONE;
157 int vc_cmd_list_create(vc_cmd_list_h* vc_cmd_list)
159 if (0 != __vc_cmd_get_feature_enabled()) {
160 return VC_ERROR_NOT_SUPPORTED;
162 if (0 != __vc_cmd_check_privilege()) {
163 return VC_ERROR_PERMISSION_DENIED;
166 if (NULL == vc_cmd_list) {
167 SLOG(LOG_ERROR, TAG_VCCMD, "[ERROR] Input parameter is NULL");
168 return VC_ERROR_INVALID_PARAMETER;
171 vc_cmd_list_s* list = (vc_cmd_list_s*)calloc(1, sizeof(vc_cmd_list_s));
174 SLOG(LOG_ERROR, TAG_VCCMD, "[ERROR] Not enough memory");
175 return VC_ERROR_OUT_OF_MEMORY;
181 *vc_cmd_list = (vc_cmd_list_h)list;
183 g_cmdlist_list = g_list_append(g_cmdlist_list, list);
185 SLOG(LOG_DEBUG, TAG_VCCMD, "[List] list(%p)", *vc_cmd_list);
187 return VC_ERROR_NONE;
190 int vc_cmd_list_destroy(vc_cmd_list_h vc_cmd_list, bool release_command)
192 if (0 != __vc_cmd_get_feature_enabled()) {
193 return VC_ERROR_NOT_SUPPORTED;
195 if (0 != __vc_cmd_check_privilege()) {
196 return VC_ERROR_PERMISSION_DENIED;
199 if (NULL == vc_cmd_list) {
200 SLOG(LOG_ERROR, TAG_VCCMD, "[ERROR] Input parameter is NULL");
201 return VC_ERROR_INVALID_PARAMETER;
204 vc_cmd_list_remove_all(vc_cmd_list, release_command);
206 vc_cmd_list_s* list = NULL;
207 list = (vc_cmd_list_s*)vc_cmd_list;
209 SLOG(LOG_DEBUG, TAG_VCCMD, "[List] list(%p)", list);
212 vc_cmd_list_s *data = NULL;
214 /* if list have item */
215 if (g_list_length(g_cmdlist_list) > 0) {
216 /* Get a first item */
217 iter = g_list_first(g_cmdlist_list);
219 while (NULL != iter) {
221 if (data && list == data) {
222 g_cmdlist_list = g_list_remove_link(g_cmdlist_list, iter);
227 SLOG(LOG_DEBUG, TAG_VCCMD, "Client destroy");
230 return VC_ERROR_NONE;
233 iter = g_list_next(iter);
236 SLOG(LOG_ERROR, TAG_VCCMD, "Fail to destroy client : handle is not valid");
238 return VC_ERROR_INVALID_PARAMETER;
241 int vc_cmd_list_get_count(vc_cmd_list_h vc_cmd_list, int* count)
243 if (0 != __vc_cmd_get_feature_enabled()) {
244 return VC_ERROR_NOT_SUPPORTED;
246 if (0 != __vc_cmd_check_privilege()) {
247 return VC_ERROR_PERMISSION_DENIED;
250 if (NULL == vc_cmd_list || NULL == count) {
251 SLOG(LOG_ERROR, TAG_VCCMD, "[ERROR] Get command count : Input parameter is NULL");
252 return VC_ERROR_INVALID_PARAMETER;
255 vc_cmd_list_s* list = NULL;
256 list = (vc_cmd_list_s*)vc_cmd_list;
258 *count = g_slist_length(list->list);
260 SLOG(LOG_DEBUG, TAG_VCCMD, "[List] list(%p), count(%d)", list, *count);
262 return VC_ERROR_NONE;
265 int vc_cmd_list_add(vc_cmd_list_h vc_cmd_list, vc_cmd_h vc_command)
267 if (0 != __vc_cmd_get_feature_enabled()) {
268 return VC_ERROR_NOT_SUPPORTED;
270 if (0 != __vc_cmd_check_privilege()) {
271 return VC_ERROR_PERMISSION_DENIED;
274 if (NULL == vc_cmd_list || NULL == vc_command) {
275 SLOG(LOG_ERROR, TAG_VCCMD, "[ERROR] Input parameter is NULL");
276 return VC_ERROR_INVALID_PARAMETER;
279 vc_cmd_list_s* list = NULL;
280 list = (vc_cmd_list_s*)vc_cmd_list;
282 vc_cmd_s* cmd = NULL;
283 cmd = (vc_cmd_s*)vc_command;
285 list->list = g_slist_append(list->list, cmd);
287 if (1 == g_slist_length(list->list)) {
291 SLOG(LOG_DEBUG, TAG_VCCMD, "[List] list(%p), command(%p)", list, cmd);
293 return VC_ERROR_NONE;
296 int vc_cmd_list_remove(vc_cmd_list_h vc_cmd_list, vc_cmd_h vc_command)
298 if (0 != __vc_cmd_get_feature_enabled()) {
299 return VC_ERROR_NOT_SUPPORTED;
301 if (0 != __vc_cmd_check_privilege()) {
302 return VC_ERROR_PERMISSION_DENIED;
305 if (NULL == vc_cmd_list || NULL == vc_command) {
306 SLOG(LOG_ERROR, TAG_VCCMD, "[ERROR] Input parameter is NULL");
307 return VC_ERROR_INVALID_PARAMETER;
310 vc_cmd_list_s* list = NULL;
311 list = (vc_cmd_list_s*)vc_cmd_list;
313 vc_cmd_s* cmd = NULL;
314 cmd = (vc_cmd_s*)vc_command;
316 SLOG(LOG_DEBUG, TAG_VCCMD, "[List] list(%p), command(%p)", list, cmd);
318 vc_cmd_s* temp_cmd = NULL;
321 iter = g_slist_nth(list->list, 0);
323 while (NULL != iter) {
324 temp_cmd = iter->data;
326 if (NULL != temp_cmd && cmd == temp_cmd) {
327 list->list = g_slist_remove(list->list, temp_cmd);
329 if (true == release_command) {
330 SLOG(LOG_DEBUG, TAG_VCCMD, "Release command data");
331 if (NULL != temp_cmd->command) free(temp_cmd->command);
332 if (NULL != temp_cmd->parameter) free(temp_cmd->parameter);
339 iter = g_slist_next(iter);
342 int count = g_slist_length(list->list);
346 } else if (list->index == count) {
347 list->index = count - 1;
350 return VC_ERROR_NONE;
353 int vc_cmd_list_remove_all(vc_cmd_list_h vc_cmd_list, bool release_command)
355 if (0 != __vc_cmd_get_feature_enabled()) {
356 return VC_ERROR_NOT_SUPPORTED;
358 if (0 != __vc_cmd_check_privilege()) {
359 return VC_ERROR_PERMISSION_DENIED;
362 SLOG(LOG_DEBUG, TAG_VCCMD, "===== Destroy all command");
364 if (NULL == vc_cmd_list) {
365 SLOG(LOG_ERROR, TAG_VCCMD, "[ERROR] Input parameter is NULL");
366 return VC_ERROR_INVALID_PARAMETER;
369 vc_cmd_list_s* list = NULL;
370 list = (vc_cmd_list_s*)vc_cmd_list;
372 SLOG(LOG_DEBUG, TAG_VCCMD, "[List] list (%p), release command (%s)"
373 , list, release_command ? "true" : "false");
375 int count = g_slist_length(list->list);
380 for (i = 0; i < count ; i++) {
381 temp_cmd = g_slist_nth_data(list->list, 0);
383 if (NULL != temp_cmd) {
384 list->list = g_slist_remove(list->list, temp_cmd);
386 if (true == release_command) {
387 SLOG(LOG_DEBUG, TAG_VCCMD, "Free command(%p)", temp_cmd);
388 if (NULL != temp_cmd->command) free(temp_cmd->command);
389 if (NULL != temp_cmd->parameter) free(temp_cmd->parameter);
390 if (NULL != temp_cmd->appid) free(temp_cmd->appid);
391 if (NULL != temp_cmd->invocation_name) free(temp_cmd->invocation_name);
392 if (NULL != temp_cmd->fixed) free(temp_cmd->fixed);
401 SLOG(LOG_DEBUG, TAG_VCCMD, "=====");
402 SLOG(LOG_DEBUG, TAG_VCCMD, " ");
404 return VC_ERROR_NONE;
407 int vc_cmd_list_foreach_commands(vc_cmd_list_h vc_cmd_list, vc_cmd_list_cb callback, void* user_data)
409 if (0 != __vc_cmd_get_feature_enabled()) {
410 return VC_ERROR_NOT_SUPPORTED;
412 if (0 != __vc_cmd_check_privilege()) {
413 return VC_ERROR_PERMISSION_DENIED;
416 if (NULL == vc_cmd_list) {
417 SLOG(LOG_ERROR, TAG_VCCMD, "[ERROR] Input parameter is NULL");
418 return VC_ERROR_INVALID_PARAMETER;
421 vc_cmd_list_s* list = NULL;
422 list = (vc_cmd_list_s*)vc_cmd_list;
424 int count = g_slist_length(list->list);
430 iter = g_slist_nth(list->list, 0);
432 for (i = 0; i < count; i++) {
434 SLOG(LOG_ERROR, TAG_VCCMD, "[ERROR] No command in list");
435 return VC_ERROR_OPERATION_FAILED;
438 temp_cmd = iter->data;
440 if (NULL != temp_cmd) {
441 if (false == callback((vc_cmd_h)temp_cmd, user_data)) {
446 iter = g_slist_next(iter);
449 SLOG(LOG_DEBUG, TAG_VCCMD, "===== Foreach commands Done");
451 return VC_ERROR_NONE;
454 int vc_cmd_list_filter_by_type(vc_cmd_list_h original, int type, vc_cmd_list_h* filtered)
456 SLOG(LOG_DEBUG, TAG_VCCMD, "===== Filter by type");
458 if (0 != __vc_cmd_get_feature_enabled()) {
459 return VC_ERROR_NOT_SUPPORTED;
461 if (0 != __vc_cmd_check_privilege()) {
462 return VC_ERROR_PERMISSION_DENIED;
465 if (NULL == original) {
466 SLOG(LOG_ERROR, TAG_VCCMD, "[ERROR] Input parameter is NULL");
467 return VC_ERROR_INVALID_PARAMETER;
470 if (VC_COMMAND_TYPE_NONE >= type || VC_COMMAND_TYPE_EXCLUSIVE < type) {
471 SLOG(LOG_ERROR, TAG_VCCMD, "[ERROR] Invalid type");
472 return VC_ERROR_INVALID_PARAMETER;
475 vc_cmd_list_s* list = NULL;
476 list = (vc_cmd_list_s*)original;
478 vc_cmd_list_h temp_list;
479 if (0 != vc_cmd_list_create(&temp_list)) {
480 SLOG(LOG_ERROR, TAG_VCCMD, "[ERROR] Fail to list create");
481 return VC_ERROR_OPERATION_FAILED;
484 int count = g_slist_length(list->list);
490 iter = g_slist_nth(list->list, 0);
492 for (i = 0; i < count; i++) {
494 SLOG(LOG_ERROR, TAG_VCCMD, "[ERROR] No command in list");
495 return VC_ERROR_OPERATION_FAILED;
497 if (NULL != iter->data) {
498 iter_cmd = iter->data;
500 if (NULL != iter_cmd) {
502 if (0 != vc_cmd_get_type((vc_cmd_h)iter_cmd, &iter_type)) {
503 SLOG(LOG_ERROR, TAG_VCCMD, "[ERROR] Fail to get command type");
507 if (iter_type == type) {
509 if (0 != vc_cmd_create(&temp_cmd)) {
510 SLOG(LOG_ERROR, TAG_VCCMD, "[ERROR] Fail to create cmd");
514 memcpy(temp_cmd, iter_cmd, sizeof(vc_cmd_s));
515 if (NULL != iter_cmd->command) {
516 ((vc_cmd_s*)temp_cmd)->command = strdup(iter_cmd->command);
518 if (NULL != iter_cmd->parameter) {
519 ((vc_cmd_s*)temp_cmd)->parameter = strdup(iter_cmd->parameter);
522 if (0 != vc_cmd_list_add(temp_list, temp_cmd)) {
523 SLOG(LOG_ERROR, TAG_VCCMD, "[ERROR] Fail to cmd list add");
524 vc_cmd_destroy(temp_cmd);
530 iter = g_slist_next(iter);
534 if (0 != vc_cmd_list_get_count(temp_list, &count)) {
535 SLOG(LOG_ERROR, TAG_VCCMD, "[ERROR] Fail to get count");
537 SLOG(LOG_DEBUG, TAG_VCCMD, "Filtering result : (%d) command", count);
540 *filtered = temp_list;
542 SLOG(LOG_DEBUG, TAG_VCCMD, "=====");
544 return VC_ERROR_NONE;
547 int vc_cmd_list_first(vc_cmd_list_h vc_cmd_list)
549 if (0 != __vc_cmd_get_feature_enabled()) {
550 return VC_ERROR_NOT_SUPPORTED;
552 if (0 != __vc_cmd_check_privilege()) {
553 return VC_ERROR_PERMISSION_DENIED;
556 if (NULL == vc_cmd_list) {
557 SLOG(LOG_ERROR, TAG_VCCMD, "[ERROR] Input parameter is NULL");
558 return VC_ERROR_INVALID_PARAMETER;
561 vc_cmd_list_s* list = NULL;
562 list = (vc_cmd_list_s*)vc_cmd_list;
564 if (0 == g_slist_length(list->list)) {
565 SLOG(LOG_ERROR, TAG_VCCMD, "[ERROR] List is empty");
566 return VC_ERROR_EMPTY;
571 return VC_ERROR_NONE;
574 int vc_cmd_list_last(vc_cmd_list_h vc_cmd_list)
576 if (0 != __vc_cmd_get_feature_enabled()) {
577 return VC_ERROR_NOT_SUPPORTED;
579 if (0 != __vc_cmd_check_privilege()) {
580 return VC_ERROR_PERMISSION_DENIED;
583 if (NULL == vc_cmd_list) {
584 SLOG(LOG_ERROR, TAG_VCCMD, "[ERROR] Input parameter is NULL");
585 return VC_ERROR_INVALID_PARAMETER;
588 vc_cmd_list_s* list = NULL;
589 list = (vc_cmd_list_s*)vc_cmd_list;
591 int count = g_slist_length(list->list);
594 SLOG(LOG_ERROR, TAG_VCCMD, "[ERROR] List is empty");
595 return VC_ERROR_EMPTY;
597 list->index = count - 1;
598 SLOG(LOG_DEBUG, TAG_VCCMD, "[DEBUG] List index : %d", list->index);
601 return VC_ERROR_NONE;
604 int vc_cmd_list_next(vc_cmd_list_h vc_cmd_list)
606 if (0 != __vc_cmd_get_feature_enabled()) {
607 return VC_ERROR_NOT_SUPPORTED;
609 if (0 != __vc_cmd_check_privilege()) {
610 return VC_ERROR_PERMISSION_DENIED;
613 if (NULL == vc_cmd_list) {
614 SLOG(LOG_ERROR, TAG_VCCMD, "[ERROR] Input parameter is NULL");
615 return VC_ERROR_INVALID_PARAMETER;
618 vc_cmd_list_s* list = NULL;
619 list = (vc_cmd_list_s*)vc_cmd_list;
621 int count = g_slist_length(list->list);
623 if (list->index < count - 1) {
624 list->index = list->index + 1;
625 SLOG(LOG_DEBUG, TAG_VCCMD, "[DEBUG] List index : %d", list->index);
627 SLOG(LOG_DEBUG, TAG_VCCMD, "[DEBUG] List index : %d", list->index);
628 return VC_ERROR_ITERATION_END;
631 return VC_ERROR_NONE;
634 int vc_cmd_list_prev(vc_cmd_list_h vc_cmd_list)
636 if (0 != __vc_cmd_get_feature_enabled()) {
637 return VC_ERROR_NOT_SUPPORTED;
639 if (0 != __vc_cmd_check_privilege()) {
640 return VC_ERROR_PERMISSION_DENIED;
643 if (NULL == vc_cmd_list) {
644 SLOG(LOG_ERROR, TAG_VCCMD, "[ERROR] Input parameter is NULL");
645 return VC_ERROR_INVALID_PARAMETER;
648 vc_cmd_list_s* list = NULL;
649 list = (vc_cmd_list_s*)vc_cmd_list;
651 if (list->index > 0) {
652 list->index = list->index - 1;
653 SLOG(LOG_DEBUG, TAG_VCCMD, "[DEBUG] List index : %d", list->index);
655 SLOG(LOG_DEBUG, TAG_VCCMD, "[DEBUG] List index : %d", list->index);
656 return VC_ERROR_ITERATION_END;
659 return VC_ERROR_NONE;
662 int vc_cmd_list_get_current(vc_cmd_list_h vc_cmd_list, vc_cmd_h* vc_command)
664 if (0 != __vc_cmd_get_feature_enabled()) {
665 return VC_ERROR_NOT_SUPPORTED;
667 if (0 != __vc_cmd_check_privilege()) {
668 return VC_ERROR_PERMISSION_DENIED;
671 if (NULL == vc_cmd_list || NULL == vc_command) {
672 SLOG(LOG_ERROR, TAG_VCCMD, "[ERROR] Input parameter is NULL");
673 return VC_ERROR_INVALID_PARAMETER;
676 vc_cmd_list_s* list = NULL;
677 list = (vc_cmd_list_s*)vc_cmd_list;
679 SLOG(LOG_DEBUG, TAG_VCCMD, "[List] list (%p), index (%d)", list, list->index);
681 if (0 == g_slist_length(list->list)) {
682 SLOG(LOG_DEBUG, TAG_VCCMD, "[List] list is empty");
684 return VC_ERROR_EMPTY;
687 vc_cmd_s *temp_cmd = NULL;
688 temp_cmd = g_slist_nth_data(list->list, list->index);
690 *vc_command = (vc_cmd_h)temp_cmd;
692 SLOG(LOG_DEBUG, TAG_VCCMD, "[List] Get current command (%p)", *vc_command);
694 return VC_ERROR_NONE;
698 int vc_cmd_create(vc_cmd_h* vc_command)
700 if (0 != __vc_cmd_get_feature_enabled()) {
701 return VC_ERROR_NOT_SUPPORTED;
703 if (0 != __vc_cmd_check_privilege()) {
704 return VC_ERROR_PERMISSION_DENIED;
707 if (NULL == vc_command) {
708 SLOG(LOG_ERROR, TAG_VCCMD, "[ERROR] Input parameter is NULL");
709 return VC_ERROR_INVALID_PARAMETER;
712 vc_cmd_s* command = (vc_cmd_s*)calloc(1, sizeof(vc_cmd_s));
714 if (NULL == command) {
715 SLOG(LOG_ERROR, TAG_VCCMD, "[ERROR] Not enough memory");
716 return VC_ERROR_OUT_OF_MEMORY;
722 command->type = VC_COMMAND_TYPE_NONE;
723 command->format = VC_CMD_FORMAT_FIXED;
724 command->command = NULL;
725 command->parameter = NULL;
727 command->priority = 0;
728 command->key = VC_KEY_NONE;
729 command->modifier = VC_MODIFIER_NONE;
730 command->invocation_name = NULL;
731 command->appid = NULL;
732 command->fixed = NULL;
734 *vc_command = (vc_cmd_h)command;
736 SLOG(LOG_DEBUG, TAG_VCCMD, "[Create command][%p]", *vc_command);
738 return VC_ERROR_NONE;
741 int vc_cmd_destroy(vc_cmd_h vc_command)
743 if (0 != __vc_cmd_get_feature_enabled()) {
744 return VC_ERROR_NOT_SUPPORTED;
746 if (0 != __vc_cmd_check_privilege()) {
747 return VC_ERROR_PERMISSION_DENIED;
750 if (NULL == vc_command) {
751 SLOG(LOG_ERROR, TAG_VCCMD, "[ERROR] Input parameter is NULL");
752 return VC_ERROR_INVALID_PARAMETER;
755 vc_cmd_s* command = NULL;
756 command = (vc_cmd_s*)vc_command;
758 SLOG(LOG_DEBUG, TAG_VCCMD, "[Destroy command][%p]", command);
760 if (NULL != command) {
761 if (NULL != command->command) {
762 free(command->command);
763 command->command = NULL;
765 if (NULL != command->parameter) {
766 free(command->parameter);
767 command->parameter = NULL;
769 if (NULL != command->invocation_name) {
770 free(command->invocation_name);
771 command->invocation_name = NULL;
773 if (NULL != command->appid) {
774 free(command->appid);
775 command->appid = NULL;
777 if (NULL != command->fixed) {
778 free(command->fixed);
779 command->fixed = NULL;
785 return VC_ERROR_NONE;
788 int vc_cmd_set_id(vc_cmd_h vc_command, int id)
790 if (0 != __vc_cmd_get_feature_enabled()) {
791 return VC_ERROR_NOT_SUPPORTED;
793 if (0 != __vc_cmd_check_privilege()) {
794 return VC_ERROR_PERMISSION_DENIED;
797 if (NULL == vc_command) {
798 SLOG(LOG_ERROR, TAG_VCCMD, "[ERROR] Invalid parameter ");
799 return VC_ERROR_INVALID_PARAMETER;
802 vc_cmd_s* cmd = NULL;
803 cmd = (vc_cmd_s*)vc_command;
807 SLOG(LOG_DEBUG, TAG_VCCMD, "[Set id][%p] id(%d)", vc_command, cmd->id);
813 int vc_cmd_get_id(vc_cmd_h vc_command, int* id)
815 if (0 != __vc_cmd_get_feature_enabled()) {
816 return VC_ERROR_NOT_SUPPORTED;
818 if (0 != __vc_cmd_check_privilege()) {
819 return VC_ERROR_PERMISSION_DENIED;
822 if (NULL == vc_command || NULL == id) {
823 SLOG(LOG_ERROR, TAG_VCCMD, "[ERROR] Invalid handle ");
824 return VC_ERROR_INVALID_PARAMETER;
827 vc_cmd_s* cmd = NULL;
828 cmd = (vc_cmd_s*)vc_command;
832 SLOG(LOG_DEBUG, TAG_VCCMD, "[Get id][%p] id(%d)", vc_command, *id);
838 int vc_cmd_set_appid(vc_cmd_h vc_command, const char* appid)
840 if (0 != __vc_cmd_get_feature_enabled()) {
841 return VC_ERROR_NOT_SUPPORTED;
844 if (NULL == vc_command) {
845 SLOG(LOG_ERROR, TAG_VCCMD, "[ERROR] Invalid parameter, vc_command is NULL");
846 return VC_ERROR_INVALID_PARAMETER;
850 SLOG(LOG_ERROR, TAG_VCCMD, "[ERROR] Invalid parameter, appid is NULL");
851 return VC_ERROR_INVALID_PARAMETER;
854 vc_cmd_s* cmd = NULL;
855 cmd = (vc_cmd_s*)vc_command;
857 if (NULL != cmd->appid) {
862 cmd->appid = strdup(appid);
864 SLOG(LOG_DEBUG, TAG_VCCMD, "[Set appid][%p] appid(%s)", vc_command, cmd->appid);
868 int vc_cmd_get_appid(vc_cmd_h vc_command, char** appid)
870 if (0 != __vc_cmd_get_feature_enabled()) {
871 return VC_ERROR_NOT_SUPPORTED;
874 if (NULL == vc_command || NULL == appid) {
875 SLOG(LOG_ERROR, TAG_VCCMD, "[ERROR] Invalid handle ");
876 return VC_ERROR_INVALID_PARAMETER;
879 vc_cmd_s* cmd = NULL;
880 cmd = (vc_cmd_s*)vc_command;
882 if (NULL != cmd->appid) {
883 *appid = strdup(gettext(cmd->appid));
886 SLOG(LOG_DEBUG, TAG_VCCMD, "[Get appid][%p] appid(%s)", vc_command, *appid);
890 int vc_cmd_set_command(vc_cmd_h vc_command, const char* command)
892 if (0 != __vc_cmd_get_feature_enabled()) {
893 return VC_ERROR_NOT_SUPPORTED;
895 if (0 != __vc_cmd_check_privilege()) {
896 return VC_ERROR_PERMISSION_DENIED;
899 if (NULL == vc_command) {
900 SLOG(LOG_ERROR, TAG_VCCMD, "[ERROR] Invalid parameter ");
901 return VC_ERROR_INVALID_PARAMETER;
904 vc_cmd_s* cmd = NULL;
905 cmd = (vc_cmd_s*)vc_command;
907 if (NULL != cmd->command) {
913 if (NULL != command) {
914 cmd->command = strdup(command);
917 SLOG(LOG_DEBUG, TAG_VCCMD, "[Set command][%p] Command(%s)", vc_command, cmd->command);
922 int vc_cmd_get_command(vc_cmd_h vc_command, char** command)
924 if (0 != __vc_cmd_get_feature_enabled()) {
925 return VC_ERROR_NOT_SUPPORTED;
927 if (0 != __vc_cmd_check_privilege()) {
928 return VC_ERROR_PERMISSION_DENIED;
931 if (NULL == vc_command || NULL == command) {
932 SLOG(LOG_ERROR, TAG_VCCMD, "[ERROR] Invalid handle ");
933 return VC_ERROR_INVALID_PARAMETER;
936 vc_cmd_s* cmd = NULL;
937 cmd = (vc_cmd_s*)vc_command;
939 if (NULL != cmd->command) {
940 *command = strdup(gettext(cmd->command));
943 SLOG(LOG_DEBUG, TAG_VCCMD, "[Get command][%p] Command(%s)", vc_command, *command);
948 int vc_cmd_set_unfixed_command(vc_cmd_h vc_command, const char* command)
950 if (0 != __vc_cmd_get_feature_enabled()) {
951 return VC_ERROR_NOT_SUPPORTED;
953 if (0 != __vc_cmd_check_privilege()) {
954 return VC_ERROR_PERMISSION_DENIED;
957 if (NULL == vc_command) {
958 SLOG(LOG_ERROR, TAG_VCCMD, "[ERROR] Invalid parameter ");
959 return VC_ERROR_INVALID_PARAMETER;
962 vc_cmd_s* cmd = NULL;
963 cmd = (vc_cmd_s*)vc_command;
965 if (NULL != cmd->parameter) {
966 free(cmd->parameter);
969 cmd->parameter = NULL;
971 if (NULL != command) {
972 cmd->parameter = strdup(command);
973 SLOG(LOG_DEBUG, TAG_VCCMD, "[Set unfixed command][%p] unfixed command(%s)", vc_command, cmd->parameter);
979 int vc_cmd_get_unfixed_command(vc_cmd_h vc_command, char** command)
981 if (0 != __vc_cmd_get_feature_enabled()) {
982 return VC_ERROR_NOT_SUPPORTED;
985 if (NULL == vc_command || NULL == command) {
986 SLOG(LOG_ERROR, TAG_VCCMD, "[ERROR] Invalid handle ");
987 return VC_ERROR_INVALID_PARAMETER;
990 vc_cmd_s* cmd = NULL;
991 cmd = (vc_cmd_s*)vc_command;
993 if (NULL != cmd->parameter) {
994 *command = strdup(gettext(cmd->parameter));
995 SLOG(LOG_DEBUG, TAG_VCCMD, "[Get unfixed command][%p] unfixed command(%s)", vc_command, *command);
1001 int vc_cmd_set_fixed_command(vc_cmd_h vc_command, const char* fixed)
1003 if (0 != __vc_cmd_get_feature_enabled()) {
1004 return VC_ERROR_NOT_SUPPORTED;
1007 if (NULL == vc_command) {
1008 SLOG(LOG_ERROR, TAG_VCCMD, "[ERROR] Invalid parameter ");
1009 return VC_ERROR_INVALID_PARAMETER;
1012 if (NULL == fixed) {
1013 SLOG(LOG_ERROR, TAG_VCCMD, "[ERROR] Invalid parameter, fixed is NULL");
1014 return VC_ERROR_INVALID_PARAMETER;
1017 vc_cmd_s* cmd = NULL;
1018 cmd = (vc_cmd_s*)vc_command;
1020 if (NULL != cmd->fixed) {
1025 cmd->fixed = strdup(fixed);
1027 SLOG(LOG_DEBUG, TAG_VCCMD, "[Set parameter][%p] fixed command(%s)", vc_command, cmd->fixed);
1031 int vc_cmd_get_fixed_command(vc_cmd_h vc_command, char** fixed)
1033 if (0 != __vc_cmd_get_feature_enabled()) {
1034 return VC_ERROR_NOT_SUPPORTED;
1037 if (NULL == vc_command || NULL == fixed) {
1038 SLOG(LOG_ERROR, TAG_VCCMD, "[ERROR] Invalid handle ");
1039 return VC_ERROR_INVALID_PARAMETER;
1042 vc_cmd_s* cmd = NULL;
1043 cmd = (vc_cmd_s*)vc_command;
1045 if (NULL != cmd->fixed) {
1046 *fixed = strdup(gettext(cmd->fixed));
1047 SLOG(LOG_DEBUG, TAG_VCCMD, "[Get fixed command][%p] fixed command(%s)", vc_command, *fixed);
1053 int vc_cmd_set_invocation_name(vc_cmd_h vc_command, const char* invocation_name)
1055 if (0 != __vc_cmd_get_feature_enabled()) {
1056 return VC_ERROR_NOT_SUPPORTED;
1059 if (NULL == vc_command) {
1060 SLOG(LOG_ERROR, TAG_VCCMD, "[ERROR] Invalid parameter, vc_command is NULL");
1061 return VC_ERROR_INVALID_PARAMETER;
1064 if (NULL == invocation_name) {
1065 SLOG(LOG_ERROR, TAG_VCCMD, "[ERROR] Invalid parameter, invocation_name is NULL");
1066 return VC_ERROR_INVALID_PARAMETER;
1069 vc_cmd_s* cmd = NULL;
1070 cmd = (vc_cmd_s*)vc_command;
1072 if (NULL != cmd->invocation_name) {
1073 free(cmd->invocation_name);
1074 cmd->invocation_name = NULL;
1077 cmd->invocation_name = strdup(invocation_name);
1079 SLOG(LOG_DEBUG, TAG_VCCMD, "[Set invocation name][%p] invocation_name(%s)", vc_command, cmd->invocation_name);
1083 int vc_cmd_get_invocation_name(vc_cmd_h vc_command, char** invocation_name)
1085 if (0 != __vc_cmd_get_feature_enabled()) {
1086 return VC_ERROR_NOT_SUPPORTED;
1089 if (NULL == vc_command || NULL == invocation_name) {
1090 SLOG(LOG_ERROR, TAG_VCCMD, "[ERROR] Invalid handle ");
1091 return VC_ERROR_INVALID_PARAMETER;
1094 vc_cmd_s* cmd = NULL;
1095 cmd = (vc_cmd_s*)vc_command;
1097 if (NULL != cmd->invocation_name) {
1098 *invocation_name = strdup(gettext(cmd->invocation_name));
1101 SLOG(LOG_DEBUG, TAG_VCCMD, "[Get invocation name][%p] invocation_name(%s)", vc_command, *invocation_name);
1105 int vc_cmd_set_type(vc_cmd_h vc_command, int type)
1107 if (0 != __vc_cmd_get_feature_enabled()) {
1108 return VC_ERROR_NOT_SUPPORTED;
1110 if (0 != __vc_cmd_check_privilege()) {
1111 return VC_ERROR_PERMISSION_DENIED;
1114 if (NULL == vc_command) {
1115 SLOG(LOG_ERROR, TAG_VCCMD, "[ERROR] Invalid parameter ");
1116 return VC_ERROR_INVALID_PARAMETER;
1119 vc_cmd_s* cmd = NULL;
1120 cmd = (vc_cmd_s*)vc_command;
1124 SLOG(LOG_DEBUG, TAG_VCCMD, "[Set type][%p] type(%d)", vc_command, cmd->type);
1129 int vc_cmd_get_type(vc_cmd_h vc_command, int* type)
1131 if (0 != __vc_cmd_get_feature_enabled()) {
1132 return VC_ERROR_NOT_SUPPORTED;
1134 if (0 != __vc_cmd_check_privilege()) {
1135 return VC_ERROR_PERMISSION_DENIED;
1138 if (NULL == vc_command || NULL == type) {
1139 SLOG(LOG_ERROR, TAG_VCCMD, "[ERROR] Invalid parameter ");
1140 return VC_ERROR_INVALID_PARAMETER;
1143 vc_cmd_s* cmd = NULL;
1144 cmd = (vc_cmd_s*)vc_command;
1148 SLOG(LOG_DEBUG, TAG_VCCMD, "[Get type][%p] type(%d)", vc_command, *type);
1153 int vc_cmd_set_format(vc_cmd_h vc_command, int format)
1155 if (0 != __vc_cmd_get_feature_enabled()) {
1156 return VC_ERROR_NOT_SUPPORTED;
1159 if (NULL == vc_command) {
1160 SLOG(LOG_ERROR, TAG_VCCMD, "[ERROR] Invalid parameter ");
1161 return VC_ERROR_INVALID_PARAMETER;
1164 vc_cmd_s* cmd = NULL;
1165 cmd = (vc_cmd_s*)vc_command;
1167 cmd->format = format;
1169 SLOG(LOG_DEBUG, TAG_VCCMD, "[Set format][%p] format(%d)", vc_command, format);
1174 int vc_cmd_get_format(vc_cmd_h vc_command, int* format)
1176 if (0 != __vc_cmd_get_feature_enabled()) {
1177 return VC_ERROR_NOT_SUPPORTED;
1180 if (NULL == vc_command || NULL == format) {
1181 SLOG(LOG_ERROR, TAG_VCCMD, "[ERROR] Invalid parameter ");
1182 return VC_ERROR_INVALID_PARAMETER;
1185 vc_cmd_s* cmd = NULL;
1186 cmd = (vc_cmd_s*)vc_command;
1188 *format = cmd->format;
1190 SLOG(LOG_DEBUG, TAG_VCCMD, "[Get format][%p] format(%d)", vc_command, *format);
1195 int vc_cmd_set_pid(vc_cmd_h vc_command, int pid)
1197 if (0 != __vc_cmd_get_feature_enabled()) {
1198 return VC_ERROR_NOT_SUPPORTED;
1200 if (0 != __vc_cmd_check_privilege()) {
1201 return VC_ERROR_PERMISSION_DENIED;
1204 if (NULL == vc_command) {
1205 SLOG(LOG_ERROR, TAG_VCCMD, "[ERROR] Invalid parameter ");
1206 return VC_ERROR_INVALID_PARAMETER;
1209 vc_cmd_s* cmd = NULL;
1210 cmd = (vc_cmd_s*)vc_command;
1214 SLOG(LOG_DEBUG, TAG_VCCMD, "[Set pid][%p] pid(%d)", vc_command, cmd->pid);
1219 int vc_cmd_get_pid(vc_cmd_h vc_command, int* pid)
1221 if (0 != __vc_cmd_get_feature_enabled()) {
1222 return VC_ERROR_NOT_SUPPORTED;
1224 if (0 != __vc_cmd_check_privilege()) {
1225 return VC_ERROR_PERMISSION_DENIED;
1228 if (NULL == vc_command || NULL == pid) {
1229 SLOG(LOG_ERROR, TAG_VCCMD, "[ERROR] Invalid parameter ");
1230 return VC_ERROR_INVALID_PARAMETER;
1233 vc_cmd_s* cmd = NULL;
1234 cmd = (vc_cmd_s*)vc_command;
1238 SLOG(LOG_DEBUG, TAG_VCCMD, "[Get pid][%p] pid(%d)", vc_command, *pid);
1243 int vc_cmd_set_domain(vc_cmd_h vc_command, int domain)
1245 if (0 != __vc_cmd_get_feature_enabled()) {
1246 return VC_ERROR_NOT_SUPPORTED;
1248 if (0 != __vc_cmd_check_privilege()) {
1249 return VC_ERROR_PERMISSION_DENIED;
1252 if (NULL == vc_command) {
1253 SLOG(LOG_ERROR, TAG_VCCMD, "[ERROR] Invalid parameter ");
1254 return VC_ERROR_INVALID_PARAMETER;
1257 vc_cmd_s* cmd = NULL;
1258 cmd = (vc_cmd_s*)vc_command;
1260 cmd->domain = domain;
1262 SLOG(LOG_DEBUG, TAG_VCCMD, "[Set domain] domain : %d", domain);
1267 int vc_cmd_get_domain(vc_cmd_h vc_command, int* domain)
1269 if (0 != __vc_cmd_get_feature_enabled()) {
1270 return VC_ERROR_NOT_SUPPORTED;
1272 if (0 != __vc_cmd_check_privilege()) {
1273 return VC_ERROR_PERMISSION_DENIED;
1276 if (NULL == vc_command || NULL == domain) {
1277 SLOG(LOG_ERROR, TAG_VCCMD, "[ERROR] Invalid parameter ");
1278 return VC_ERROR_INVALID_PARAMETER;
1281 vc_cmd_s* cmd = NULL;
1282 cmd = (vc_cmd_s*)vc_command;
1284 *domain = cmd->domain;
1286 SLOG(LOG_DEBUG, TAG_VCCMD, "[Get domain] domain : %d", *domain);
1292 * @brief Sets key value of command.
1294 * @param[in] vc_command Command handle
1295 * @param[in] key key value
1296 * @param[in] modifier modifier value
1298 * @return 0 on success, otherwise a negative error value
1299 * @retval #VC_ERROR_NONE Successful
1300 * @retval #VC_ERROR_INVALID_PARAMETER Invalid parameter
1302 * @see vc_cmd_get_result_key()
1304 int vc_cmd_set_result_key(vc_cmd_h vc_command, int key, int modifier)
1306 SLOG(LOG_DEBUG, TAG_VCCMD, "===== Set result key");
1308 if (NULL == vc_command) {
1309 SLOG(LOG_ERROR, TAG_VCCMD, "[ERROR] Invalid parameter ");
1310 return VC_ERROR_INVALID_PARAMETER;
1313 vc_cmd_s* cmd = NULL;
1314 cmd = (vc_cmd_s*)vc_command;
1316 SLOG(LOG_DEBUG, TAG_VCCMD, "key : %d, modifier : %d", key, modifier);
1319 cmd->modifier = modifier;
1321 SLOG(LOG_DEBUG, TAG_VCCMD, "=====");
1322 SLOG(LOG_DEBUG, TAG_VCCMD, " ");
1328 * @brief Gets key value of command.
1330 * @param[in] vc_command Command handle
1331 * @param[out] key key value
1332 * @param[out] modifier modifier value
1334 * @return 0 on success, otherwise a negative error value
1335 * @retval #VC_ERROR_NONE Successful
1336 * @retval #VC_ERROR_INVALID_PARAMETER Invalid parameter
1338 * @see vc_cmd_add_result_key()
1340 int vc_cmd_get_result_key(vc_cmd_h vc_command, int* key, int* modifier)
1342 SLOG(LOG_DEBUG, TAG_VCCMD, "===== Get result key");
1344 if (NULL == vc_command || NULL == key || NULL == modifier) {
1345 SLOG(LOG_ERROR, TAG_VCCMD, "[ERROR] Invalid parameter ");
1346 return VC_ERROR_INVALID_PARAMETER;
1349 vc_cmd_s* cmd = NULL;
1350 cmd = (vc_cmd_s*)vc_command;
1353 *modifier = cmd->modifier;
1355 SLOG(LOG_DEBUG, TAG_VCCMD, "=====");
1356 SLOG(LOG_DEBUG, TAG_VCCMD, " ");
1361 int vc_cmd_print_list(vc_cmd_list_h vc_cmd_list)
1363 if (NULL == vc_cmd_list) {
1367 vc_cmd_list_s* list = NULL;
1368 list = (vc_cmd_list_s*)vc_cmd_list;
1370 SLOG(LOG_DEBUG, TAG_VCCMD, "=== Command List ===");
1371 SLOG(LOG_DEBUG, TAG_VCCMD, "[List][%p]", list);
1373 int count = g_slist_length(list->list);
1376 vc_cmd_s *cmd = NULL;
1378 for (i = 0; i < count ; i++) {
1379 cmd = g_slist_nth_data(list->list, i);
1382 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)",
1383 i, cmd, cmd->pid, cmd->index, cmd->type, cmd->format, cmd->command, cmd->parameter, cmd->appid, cmd->invocation_name, cmd->fixed);
1387 SLOG(LOG_DEBUG, TAG_VCCMD, "==================");
1388 SLOG(LOG_DEBUG, TAG_VCCMD, " ");
1393 int vc_cmd_get_nlu_json(vc_cmd_h vc_cmd, char** json)
1395 if (0 != __vc_cmd_get_feature_enabled()) {
1396 return VC_ERROR_NOT_SUPPORTED;
1399 if (NULL == vc_cmd || NULL == json) {
1400 SLOG(LOG_ERROR, TAG_VCCMD, "[ERROR] NULL parameter");
1401 return VC_ERROR_INVALID_PARAMETER;
1404 vc_cmd_s* cmd = NULL;
1405 cmd = (vc_cmd_s*)vc_cmd;
1407 if (VC_CMD_FORMAT_ACTION != cmd->format) {
1408 SLOG(LOG_ERROR, TAG_VCCMD, "[ERROR] Not Action format");
1409 return VC_ERROR_INVALID_PARAMETER;
1412 if (0 != vc_info_parser_get_nlu_result(json)) {
1413 SLOG(LOG_ERROR, TAG_VCCMD, "[ERROR] Fail to get nlu result");
1414 return VC_ERROR_OPERATION_FAILED;
1420 static void __vc_cmd_regex_deinit(int num_regex)
1422 SLOG(LOG_DEBUG, TAG_VCCMD, "==== Start Deinitialize regex ====");
1425 for (i = 0; num_regex > i; i++) {
1429 SLOG(LOG_DEBUG, TAG_VCCMD, "====");
1430 SLOG(LOG_DEBUG, TAG_VCCMD, "");
1433 static int __vc_cmd_regex_init()
1435 SLOG(LOG_DEBUG, TAG_VCCMD, "==== Initialize regular expression ====");
1437 int cflags = REG_EXTENDED | REG_ICASE;
1443 vc_config_mgr_get_default_language(&lang);
1445 SLOG(LOG_ERROR, TAG_VCCMD, "[ERROR] Fail to get current language");
1446 return VC_ERROR_OPERATION_FAILED;
1449 if (!strcmp("en_US", lang)) {
1451 } else if (!strcmp("ko_KR", lang)) {
1457 SLOG(LOG_ERROR, TAG_VCCMD, "[ERROR] Not supported language type");
1458 return VC_ERROR_INVALID_LANGUAGE;
1464 SLOG(LOG_DEBUG, TAG_VCCMD, "==== lang type > %d ====", lang_type);
1466 re_syntax_options = RE_SYNTAX_POSIX_EXTENDED;
1468 SLOG(LOG_DEBUG, TAG_VCCMD, "Regular expression > %s" , TIME_ABS1_REGEX[lang_type]);
1469 ret = regcomp(®[0], TIME_ABS1_REGEX[lang_type], cflags);
1471 regerror(ret, ®[0], errStr, sizeof(errStr));
1473 SLOG(LOG_ERROR, TAG_VCCMD, "[ERROR] regcomp() error > %s", errStr);
1474 return VC_ERROR_OPERATION_FAILED;
1477 SLOG(LOG_DEBUG, TAG_VCCMD, "Regular expression > %s", TIME_ABS2_REGEX[lang_type]);
1478 ret = regcomp(®[1], TIME_ABS2_REGEX[lang_type], cflags);
1480 regerror(ret, ®[1], errStr, sizeof(errStr));
1481 __vc_cmd_regex_deinit(1);
1483 SLOG(LOG_ERROR, TAG_VCCMD, "[ERROR] regcomp() error > %s", errStr);
1484 return VC_ERROR_OPERATION_FAILED;
1487 SLOG(LOG_DEBUG, TAG_VCCMD, "Regular expression > %s", TIME_ABS3_REGEX[lang_type]);
1488 ret = regcomp(®[2], TIME_ABS3_REGEX[lang_type], cflags);
1490 regerror(ret, ®[2], errStr, sizeof(errStr));
1491 __vc_cmd_regex_deinit(2);
1493 SLOG(LOG_ERROR, TAG_VCCMD, "[ERROR] regcomp() error > %s", errStr);
1494 return VC_ERROR_OPERATION_FAILED;
1497 SLOG(LOG_DEBUG, TAG_VCCMD, "Regular expression > %s", TIME_REL1_REGEX[lang_type]);
1498 ret = regcomp(®[3], TIME_REL1_REGEX[lang_type], cflags);
1500 regerror(ret, ®[3], errStr, sizeof(errStr));
1501 __vc_cmd_regex_deinit(3);
1503 SLOG(LOG_ERROR, TAG_VCCMD, "[ERROR] regcomp() error > %s", errStr);
1504 return VC_ERROR_OPERATION_FAILED;
1507 SLOG(LOG_DEBUG, TAG_VCCMD, "Regular expression > %s", TIME_REL2_REGEX[lang_type]);
1508 ret = regcomp(®[4], TIME_REL2_REGEX[lang_type], cflags);
1510 regerror(ret, ®[4], errStr, sizeof(errStr));
1511 __vc_cmd_regex_deinit(4);
1513 SLOG(LOG_ERROR, TAG_VCCMD, "[ERROR] regcomp() error > %s", errStr);
1514 return VC_ERROR_OPERATION_FAILED;
1517 SLOG(LOG_DEBUG, TAG_VCCMD, "Regular expression > %s", TIME_REL3_REGEX[lang_type]);
1518 ret = regcomp(®[5], TIME_REL3_REGEX[lang_type], cflags);
1520 regerror(ret, ®[5], errStr, sizeof(errStr));
1521 __vc_cmd_regex_deinit(5);
1523 SLOG(LOG_ERROR, TAG_VCCMD, "[ERROR] regcomp() error > %s", errStr);
1524 return VC_ERROR_OPERATION_FAILED;
1527 SLOG(LOG_DEBUG, TAG_VCCMD, "Regular expression > %s", TIME_PHR_REGEX[lang_type]);
1528 ret = regcomp(®[6], TIME_PHR_REGEX[lang_type], cflags);
1530 regerror(ret, ®[6], errStr, sizeof(errStr));
1531 __vc_cmd_regex_deinit(6);
1533 SLOG(LOG_ERROR, TAG_VCCMD, "[ERROR] regcomp() error > %s", errStr);
1534 return VC_ERROR_OPERATION_FAILED;
1537 SLOG(LOG_DEBUG, TAG_VCCMD, "Regular expression > %s", DATE_ABS1_REGEX[lang_type]);
1538 ret = regcomp(®[7], DATE_ABS1_REGEX[lang_type], cflags);
1540 regerror(ret, ®[7], errStr, sizeof(errStr));
1541 __vc_cmd_regex_deinit(7);
1543 SLOG(LOG_ERROR, TAG_VCCMD, "[ERROR] regcomp() error > %s", errStr);
1544 return VC_ERROR_OPERATION_FAILED;
1547 SLOG(LOG_DEBUG, TAG_VCCMD, "Regular expression > %s", DATE_ABS2_REGEX[lang_type]);
1548 ret = regcomp(®[8], DATE_ABS2_REGEX[lang_type], cflags);
1550 regerror(ret, ®[8], errStr, sizeof(errStr));
1551 __vc_cmd_regex_deinit(8);
1553 SLOG(LOG_ERROR, TAG_VCCMD, "[ERROR] regcomp() error > %s", errStr);
1554 return VC_ERROR_OPERATION_FAILED;
1557 SLOG(LOG_DEBUG, TAG_VCCMD, "Regular expression > %s", DATE_ABS3_REGEX[lang_type]);
1558 ret = regcomp(®[9], DATE_ABS3_REGEX[lang_type], cflags);
1560 regerror(ret, ®[9], errStr, sizeof(errStr));
1561 __vc_cmd_regex_deinit(9);
1563 SLOG(LOG_ERROR, TAG_VCCMD, "[ERROR] regcomp() error > %s", errStr);
1564 return VC_ERROR_OPERATION_FAILED;
1567 SLOG(LOG_DEBUG, TAG_VCCMD, "Regular expression > %s", DATE_PHR1_REGEX[lang_type]);
1568 ret = regcomp(®[10], DATE_PHR1_REGEX[lang_type], cflags);
1570 regerror(ret, ®[10], errStr, sizeof(errStr));
1571 __vc_cmd_regex_deinit(10);
1573 SLOG(LOG_ERROR, TAG_VCCMD, "[ERROR] regcomp() error > %s", errStr);
1574 return VC_ERROR_OPERATION_FAILED;
1577 SLOG(LOG_DEBUG, TAG_VCCMD, "Regular expression > %s", DATE_PHR2_REGEX[lang_type]);
1578 ret = regcomp(®[11], DATE_PHR2_REGEX[lang_type], cflags);
1580 regerror(ret, ®[11], errStr, sizeof(errStr));
1581 __vc_cmd_regex_deinit(11);
1583 SLOG(LOG_ERROR, TAG_VCCMD, "[ERROR] regcomp() error > %s", errStr);
1584 return VC_ERROR_OPERATION_FAILED;
1587 SLOG(LOG_DEBUG, TAG_VCCMD, "====");
1588 SLOG(LOG_DEBUG, TAG_VCCMD, "");
1590 return VC_ERROR_NONE;
1593 static void __vc_cmd_add_year(struct tm *td, int year)
1595 td->tm_year += year;
1598 static void __vc_cmd_add_mon(struct tm *td, int mon)
1602 mon = td->tm_mon + mon;
1606 __vc_cmd_add_year(td, year);
1609 td->tm_mon = mon % 12;
1612 static void __vc_cmd_add_mday(struct tm *td, int mday)
1614 int max_day[12] = {31, 28, 31, 30, 31, 30, 31, 30, 30, 31, 30, 31};
1615 int year = td->tm_year + 1900;
1619 if ((0 == year % 4 && 0 != year % 100) || 0 == year % 400) max_day[1] = 29;
1621 mday = td->tm_mday + mday;
1623 for (mon = td->tm_mon; mday >= max_day[mon % 12]; mon++) {
1624 mday -= max_day[mon % 12];
1626 if (11 == mon % 12) {
1629 if ((0 == year % 4 && 0 != year % 100) || 0 == year % 400) {
1637 mon = mon - td->tm_mon;
1640 __vc_cmd_add_mon(td, mon);
1646 static void __vc_cmd_add_hour(struct tm *td, int hour)
1650 hour = td->tm_hour + hour;
1654 __vc_cmd_add_mday(td, day);
1657 td->tm_hour = hour % 24;
1660 static void __vc_cmd_add_min(struct tm *td, int min)
1664 min = td->tm_min + min;
1668 __vc_cmd_add_hour(td, hour);
1671 td->tm_min = min % 60;
1674 static void __copy_struct_tm(struct tm *des, struct tm *src)
1676 SLOG(LOG_DEBUG, TAG_VCCMD, "==== Start to copy struct tm ====");
1678 des->tm_sec = src->tm_sec;
1679 des->tm_min = src->tm_min;
1680 des->tm_hour = src->tm_hour;
1681 des->tm_mday = src->tm_mday;
1682 des->tm_mon = src->tm_mon;
1683 des->tm_year = src->tm_year;
1684 des->tm_wday = src->tm_wday;
1685 des->tm_yday = src->tm_yday;
1686 des->tm_isdst = src->tm_isdst;
1688 des->tm_gmtoff = src->tm_gmtoff;
1689 des->tm_zone = src->tm_zone;
1692 static void __update_data_sidx(int idx)
1694 if (0 > g_data_sidx || idx < g_data_sidx) g_data_sidx = idx;
1697 static void __update_data_eidx(int idx)
1699 if (0 > g_data_eidx || idx > g_data_eidx) g_data_eidx = idx;
1702 static int __vc_cmd_tphrase_check(const char *str, struct tm *td, int *exist)
1704 regmatch_t pmatch[3];
1710 ret = regexec(®[6], str, 3, pmatch, 0);
1713 len = pmatch[idx].rm_eo - pmatch[idx].rm_so;
1715 if (12 < td->tm_hour) {
1716 __vc_cmd_add_mday(td, 1);
1722 len = pmatch[idx].rm_eo - pmatch[idx].rm_so;
1724 __vc_cmd_add_mday(td, 1);
1729 SLOG(LOG_DEBUG, TAG_VCCMD, "Matched string > %.*s", len, str + pmatch[0].rm_so);
1731 __update_data_sidx(pmatch[0].rm_so);
1732 __update_data_eidx(pmatch[0].rm_eo);
1735 return VC_ERROR_NONE;
1738 SLOG(LOG_DEBUG, TAG_VCCMD, "[REGEX] There is no matched string");
1739 return VC_ERROR_NONE;
1742 static int __vc_cmd_trelative_check(const char *str, struct tm *td, int *exist)
1744 regmatch_t pmatch[2];
1752 char *tempstr = NULL;
1755 ret = regexec(®[3], str, 1, pmatch, 0);
1757 SLOG(LOG_DEBUG, TAG_VCCMD, "Matched string > %.*s", pmatch[0].rm_eo - pmatch[0].rm_so, str+pmatch[0].rm_so);
1760 sidx = pmatch[0].rm_so;
1761 eidx = pmatch[0].rm_eo;
1763 ret = regexec(®[4], str, 2, pmatch, 0);
1765 len = pmatch[1].rm_eo - pmatch[1].rm_so;
1768 SLOG(LOG_ERROR, TAG_VCCMD, "[ERROR] Invalid string length");
1769 return VC_ERROR_OPERATION_FAILED;
1771 tempstr = strndup(str + pmatch[1].rm_so, (size_t)len);
1773 if (NULL == tempstr) {
1774 SLOG(LOG_ERROR, TAG_VCCMD, "[ERROR] Memory allocation is failed");
1775 return VC_ERROR_OUT_OF_MEMORY;
1778 hour = atoi(tempstr);
1783 SLOG(LOG_DEBUG, TAG_VCCMD, "Matched string > %.*s", len, str + pmatch[0].rm_so);
1785 if (pmatch[0].rm_so < sidx) sidx = pmatch[0].rm_so;
1786 if (pmatch[0].rm_eo > eidx) eidx = pmatch[0].rm_eo;
1789 ret = regexec(®[5], str, 2, pmatch, 0);
1791 len = pmatch[1].rm_eo - pmatch[1].rm_so;
1794 SLOG(LOG_ERROR, TAG_VCCMD, "[ERROR] Invalid string length");
1795 return VC_ERROR_OPERATION_FAILED;
1797 tempstr = strndup(str + pmatch[1].rm_so, (size_t)len);
1799 if (NULL == tempstr) {
1800 SLOG(LOG_ERROR, TAG_VCCMD, "[ERROR] Memory allocation is failed");
1801 return VC_ERROR_OUT_OF_MEMORY;
1804 min = atoi(tempstr);
1809 SLOG(LOG_DEBUG, TAG_VCCMD, "Matched string > %.*s", len, str + pmatch[0].rm_so);
1811 if (pmatch[0].rm_so < sidx) sidx = pmatch[0].rm_so;
1812 if (pmatch[0].rm_eo > eidx) eidx = pmatch[0].rm_eo;
1815 if (hour < 0 && min < 0) {
1816 SLOG(LOG_DEBUG, TAG_VCCMD, "[REGEX] There is no matched string");
1817 return VC_ERROR_NONE;
1820 hour = 0 > hour ? 0 : hour;
1821 min = 0 > min ? 0 : min;
1823 min = min + (hour * 60);
1825 __vc_cmd_add_min(td, min);
1828 __update_data_sidx(sidx);
1829 __update_data_eidx(eidx);
1832 return VC_ERROR_NONE;
1835 SLOG(LOG_DEBUG, TAG_VCCMD, "[REGEX] There is no matched string");
1836 return VC_ERROR_NONE;
1839 static int __vc_cmd_tabsolute_check(const char *str, struct tm *td, int *exist)
1841 regmatch_t pmatch[5];
1850 char *tempstr = NULL;
1853 ret = regexec(®[0], str, 5, pmatch, 0);
1855 for (idx = 1; 5 > idx && 0 >= pmatch[idx].rm_eo - pmatch[idx].rm_so; idx++);
1859 sidx = pmatch[0].rm_so;
1860 eidx = pmatch[0].rm_eo;
1863 ret = regexec(®[1], 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);
1881 hour = hour + 12 * flag;
1883 if (12 == hour) hour = 0;
1884 else if (24 == hour) hour = 12;
1887 if (0 > hour || 24 <= hour || (0 == flag && 12 < hour)) {
1888 SLOG(LOG_DEBUG, TAG_VCCMD, "[REGEX] Incomming sentence is weird");
1889 return VC_ERROR_NONE;
1895 SLOG(LOG_DEBUG, TAG_VCCMD, "Matched string > %.*s", len, str + pmatch[0].rm_so);
1897 if (0 > sidx || pmatch[0].rm_so < sidx) sidx = pmatch[0].rm_so;
1898 if (0 > eidx || pmatch[0].rm_eo > eidx) eidx = pmatch[0].rm_eo;
1899 } else if (0 < flag) {
1900 SLOG(LOG_DEBUG, TAG_VCCMD, "[REGEX] Incomming sentence is weird");
1901 return VC_ERROR_NONE;
1904 ret = regexec(®[2], str, 2, pmatch, 0);
1907 len = pmatch[idx].rm_eo - pmatch[idx].rm_so;
1909 tempstr = strndup(str + pmatch[idx].rm_so, (size_t)len);
1911 if (NULL == tempstr) {
1912 SLOG(LOG_ERROR, TAG_VCCMD, "[ERROR] Memory allocation is failed");
1913 return VC_ERROR_OUT_OF_MEMORY;
1916 min = atoi(tempstr);
1918 if (0 > min || 60 <= min) {
1919 SLOG(LOG_DEBUG, TAG_VCCMD, "[REGEX] Incomming sentence is weird");
1920 return VC_ERROR_NONE;
1932 SLOG(LOG_DEBUG, TAG_VCCMD, "Matched string > %.*s", pmatch[0].rm_eo - pmatch[0].rm_so, str + pmatch[0].rm_so);
1933 if (0 > sidx || pmatch[0].rm_so < sidx) sidx = pmatch[0].rm_so;
1934 if (0 > eidx || pmatch[0].rm_eo > eidx) eidx = pmatch[0].rm_eo;
1937 if (0 > hour && 0 > min) {
1938 SLOG(LOG_DEBUG, TAG_VCCMD, "[REGEX] There is no matched string");
1939 return VC_ERROR_NONE;
1942 if (0 <= min && 0 <= hour) {
1943 if (hour < td->tm_hour || (hour == td->tm_hour && min <= td->tm_min)) __vc_cmd_add_mday(td, 1);
1947 } else if (0 <= min) {
1949 vc_config_mgr_get_default_language(&lang);
1951 SLOG(LOG_ERROR, TAG_VCCMD, "[ERROR] Fail to get current language");
1952 return VC_ERROR_OPERATION_FAILED;
1955 if (!strcmp("en_US", lang)) {
1956 SLOG(LOG_DEBUG, TAG_VCCMD, "[REGEX] Incomming sentence is weird");
1959 return VC_ERROR_NONE;
1961 if (min <= td->tm_min) __vc_cmd_add_hour(td, 1);
1968 if (hour <= td->tm_hour) __vc_cmd_add_mday(td, 1);
1976 __update_data_sidx(sidx);
1977 __update_data_eidx(eidx);
1980 return VC_ERROR_NONE;
1983 static int __vc_cmd_dphrase_check(const char *str, struct tm *td, int *exist)
1985 regmatch_t pmatch[10];
1991 ret = regexec(®[10], str, 5, pmatch, 0);
1993 for (idx = 1; 5 > idx && 0 >= pmatch[idx].rm_eo - pmatch[idx].rm_so; idx++);
1995 len = pmatch[idx].rm_eo - pmatch[idx].rm_so;
1997 td->tm_year = td_now.tm_year;
1998 td->tm_mon = td_now.tm_mon;
1999 td->tm_mday = td_now.tm_mday;
2001 __vc_cmd_add_mday(td, idx - 1);
2003 SLOG(LOG_DEBUG, TAG_VCCMD, "Matched string > %.*s", len, str + pmatch[0].rm_so);
2005 __update_data_sidx(pmatch[0].rm_so);
2006 __update_data_eidx(pmatch[0].rm_eo);
2009 return VC_ERROR_NONE;
2012 ret = regexec(®[11], str, 10, pmatch, 0);
2014 for (idx = 1; 10 > idx; idx++) {
2015 len = pmatch[idx].rm_eo - pmatch[idx].rm_so;
2020 td->tm_year = td_now.tm_year;
2021 td->tm_mon = td_now.tm_mon;
2022 td->tm_mday = td_now.tm_mday;
2024 __vc_cmd_add_mday(td, idx + 1);
2026 SLOG(LOG_DEBUG, TAG_VCCMD, "Matched string > %.*s", len, str + pmatch[0].rm_so);
2028 __update_data_sidx(pmatch[0].rm_so);
2029 __update_data_eidx(pmatch[0].rm_eo);
2032 return VC_ERROR_NONE;
2035 SLOG(LOG_DEBUG, TAG_VCCMD, "[REGEX] There is no matched string");
2036 return VC_ERROR_NONE;
2039 static int __vc_cmd_dabsolute_check(const char *str, struct tm *td, int *exist)
2041 regmatch_t pmatch[13];
2052 char *tempstr = NULL;
2055 ret = regexec(®[9], str, 2, pmatch, 0);
2057 len = pmatch[1].rm_eo - pmatch[1].rm_so;
2060 SLOG(LOG_ERROR, TAG_VCCMD, "[ERROR] Invalid string length");
2061 return VC_ERROR_OPERATION_FAILED;
2063 tempstr = strndup(str + pmatch[1].rm_so, (size_t)len);
2065 if (NULL == tempstr) {
2066 SLOG(LOG_ERROR, TAG_VCCMD, "[ERROR] Memory allocation is failed");
2067 return VC_ERROR_OUT_OF_MEMORY;
2070 day = atoi(tempstr);
2075 SLOG(LOG_DEBUG, TAG_VCCMD, "Matched string > %.*s", len, str + pmatch[0].rm_so);
2077 sidx = pmatch[0].rm_so;
2078 eidx = pmatch[0].rm_eo;
2080 SLOG(LOG_DEBUG, TAG_VCCMD, "[REGEX] Incomming sentence is weird");
2081 return VC_ERROR_NONE;
2084 ret = regexec(®[8], str, 13, pmatch, 0);
2086 for (idx = 1; 13 > idx; idx++) {
2087 len = pmatch[idx].rm_eo - pmatch[idx].rm_so;
2097 SLOG(LOG_DEBUG, TAG_VCCMD, "Matched string > %.*s", len, str + pmatch[0].rm_so);
2099 if (0 > sidx || pmatch[0].rm_so < sidx) sidx = pmatch[0].rm_so;
2100 if (0 > eidx || pmatch[0].rm_eo > eidx) eidx = pmatch[0].rm_eo;
2103 vc_config_mgr_get_default_language(&lang);
2105 SLOG(LOG_ERROR, TAG_VCCMD, "[ERROR] Fail to get current language");
2106 return VC_ERROR_OPERATION_FAILED;
2109 if (!strcmp("en_US", lang)) {
2110 SLOG(LOG_DEBUG, TAG_VCCMD, "[REGEX] Incomming sentence is weird");
2113 return VC_ERROR_NONE;
2122 ret = regexec(®[7], str, 3, pmatch, 0);
2124 if (!m_flag) return -1;
2126 len = pmatch[2].rm_eo - pmatch[2].rm_so;
2129 SLOG(LOG_ERROR, TAG_VCCMD, "[ERROR] Invalid string length");
2130 return VC_ERROR_OPERATION_FAILED;
2132 tempstr = strndup(str + pmatch[2].rm_so, (size_t)len);
2134 if (NULL == tempstr) {
2135 SLOG(LOG_ERROR, TAG_VCCMD, "[ERROR] Memory allocation is failed");
2136 return VC_ERROR_OUT_OF_MEMORY;
2139 year = atoi(tempstr);
2140 year = 1900 < year ? year - 1900 : year + 100;
2146 SLOG(LOG_DEBUG, TAG_VCCMD, "Matched string > %.*s", len, str + pmatch[0].rm_so);
2148 if (0 > sidx || pmatch[0].rm_so < sidx) sidx = pmatch[0].rm_so;
2149 if (0 > eidx || pmatch[0].rm_eo > eidx) eidx = pmatch[0].rm_eo;
2154 if (0 > g_time_flag) {
2158 } else if (2 == g_time_flag) {
2159 SLOG(LOG_DEBUG, TAG_VCCMD, "[REGEX] Incomming sentence is weird");
2160 return VC_ERROR_NONE;
2163 int max_day[12] = {31, 28, 31, 30, 31, 30, 31, 30, 30, 31, 30, 31};
2164 if ((0 == (year + 1900) % 4 && 0 != (year + 1900) % 100) || 0 == (year + 1900) % 400) max_day[1] = 29;
2166 if (max_day[mon] < day || 1 > day) {
2167 SLOG(LOG_DEBUG, TAG_VCCMD, "[REGEX] Incomming sentence is weird");
2168 return VC_ERROR_NONE;
2177 if (day < td_now.tm_mday) __vc_cmd_add_mon(td, 1);
2179 if (mon < td_now.tm_mon) __vc_cmd_add_year(td, 1);
2180 else if (mon == td_now.tm_mon && day < td_now.tm_mday) __vc_cmd_add_year(td, 1);
2184 __update_data_sidx(sidx);
2185 __update_data_eidx(eidx);
2188 return VC_ERROR_NONE;
2191 static int __vc_cmd_time_check(const char *str, struct tm *td)
2193 SLOG(LOG_DEBUG, TAG_VCCMD, "==== Check time value in string \"%s\"", str);
2198 ret = __vc_cmd_tphrase_check(str, td, &exist);
2202 SLOG(LOG_DEBUG, TAG_VCCMD, "==== Time value is exist");
2204 } else if (VC_ERROR_NONE != ret) {
2205 SLOG(LOG_ERROR, TAG_VCCMD, "[ERROR] Error is occured > (%d)", ret);
2209 ret = __vc_cmd_trelative_check(str, td, &exist);
2213 SLOG(LOG_DEBUG, TAG_VCCMD, "==== Time value is exist");
2215 } else if (VC_ERROR_NONE != ret) {
2216 SLOG(LOG_ERROR, TAG_VCCMD, "[ERROR] Error is occured > (%d)", ret);
2220 ret = __vc_cmd_tabsolute_check(str, td, &exist);
2224 SLOG(LOG_DEBUG, TAG_VCCMD, "==== Time value is exist");
2226 } else if (VC_ERROR_NONE != ret) {
2227 SLOG(LOG_ERROR, TAG_VCCMD, "[ERROR] Error is occured > (%d)", ret);
2231 SLOG(LOG_DEBUG, TAG_VCCMD, "==== There is no time value");
2232 return VC_ERROR_NONE;
2235 static int __vc_cmd_date_check(const char *str, struct tm *td)
2237 SLOG(LOG_DEBUG, TAG_VCCMD, "==== Check date value in string \"%s\"", str);
2242 ret = __vc_cmd_dphrase_check(str, td, &exist);
2246 SLOG(LOG_DEBUG, TAG_VCCMD, "==== Date value is exist");
2248 } else if (VC_ERROR_NONE != ret) {
2249 SLOG(LOG_ERROR, TAG_VCCMD, "[ERROR] Error is occured > (%d)", ret);
2253 ret = __vc_cmd_dabsolute_check(str, td, &exist);
2257 SLOG(LOG_DEBUG, TAG_VCCMD, "==== Date value is exist");
2259 } else if (VC_ERROR_NONE != ret) {
2260 SLOG(LOG_ERROR, TAG_VCCMD, "[ERROR] Error is occured > (%d)", ret);
2264 SLOG(LOG_DEBUG, TAG_VCCMD, "==== There is no date value");
2265 return VC_ERROR_NONE;
2268 int vc_cmd_get_datetime(const char *text, time_t *result, char **remain)
2270 SLOG(LOG_DEBUG, TAG_VCCMD, "==== Get timestamp data");
2273 const char *day_name[7] = {"Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"};
2276 if (NULL == text || NULL == result || NULL == remain) {
2277 SLOG(LOG_ERROR, TAG_VCCMD, "[ERROR] Invalid parameter");
2278 return VC_ERROR_INVALID_PARAMETER;
2282 ret = __vc_cmd_regex_init();
2283 if (VC_ERROR_NONE != ret) {
2284 SLOG(LOG_ERROR, TAG_VCCMD, "[ERROR] initialize regex failed");
2288 g_data_sidx = g_data_eidx = -1;
2291 localtime_r(&t_now, &td_now);
2292 SLOG(LOG_DEBUG, TAG_VCCMD, "Current timestamp = %d", (int)t_now);
2294 __copy_struct_tm(&td, &td_now);
2295 SLOG(LOG_DEBUG, TAG_VCCMD, "%d-%d-%d (%s), %d:%d:%d",
2296 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);
2298 g_time_flag = g_date_flag = -1;
2300 ret = __vc_cmd_time_check(text, &td);
2301 if (VC_ERROR_NONE != ret) {
2302 SLOG(LOG_ERROR, TAG_VCCMD, "[ERROR] Error is occured in the check > (%d)", ret);
2306 ret = __vc_cmd_date_check(text, &td);
2307 if (VC_ERROR_NONE != ret) {
2308 SLOG(LOG_ERROR, TAG_VCCMD, "[ERROR] Error is occured in the check > (%d)", ret);
2312 __vc_cmd_regex_deinit(12);
2314 if (g_time_flag > 0 || g_date_flag > 0) {
2315 *result = mktime(&td);
2317 SLOG(LOG_DEBUG, TAG_VCCMD, "Timestamp in the text = %ld", *result);
2318 SLOG(LOG_DEBUG, TAG_VCCMD, "%d-%d-%d (%s), %d:%d:%d",
2319 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, td.tm_yday);
2321 *remain = (char *)calloc(sizeof(char), (strlen(text) + 1 - g_data_eidx + g_data_sidx));
2323 if (NULL == *remain) {
2324 SLOG(LOG_ERROR, TAG_VCCMD, "[ERROR] Out of memory error");
2325 return VC_ERROR_OUT_OF_MEMORY;
2328 strncpy(*remain, text, g_data_sidx);
2329 strncat(*remain, text + g_data_eidx, strlen(text) - g_data_eidx);
2331 SLOG(LOG_DEBUG, TAG_VCCMD, "[REGEX] There is no data in the text");
2334 SLOG(LOG_DEBUG, TAG_VCCMD, "====");
2335 SLOG(LOG_DEBUG, TAG_VCCMD, "");
2337 return VC_ERROR_NONE;