fix merge duplication
[platform/core/uifw/stt.git] / common / stt_config_parser.c
1 /*
2 *  Copyright (c) 2011-2016 Samsung Electronics Co., Ltd All Rights Reserved
3 *  Licensed under the Apache License, Version 2.0 (the "License");
4 *  you may not use this file except in compliance with the License.
5 *  You may obtain a copy of the License at
6 *  http://www.apache.org/licenses/LICENSE-2.0
7 *  Unless required by applicable law or agreed to in writing, software
8 *  distributed under the License is distributed on an "AS IS" BASIS,
9 *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
10 *  See the License for the specific language governing permissions and
11 *  limitations under the License.
12 */
13
14 #include <dlog.h>
15 #include <sys/stat.h>
16 #include <unistd.h>
17 #include <vconf.h>
18
19 #include "stt_defs.h"
20 #include "stt_config_parser.h"
21
22
23 #define STT_TAG_ENGINE_BASE_TAG         "stt-engine"
24 #define STT_TAG_ENGINE_NAME             "name"
25 #define STT_TAG_ENGINE_ID               "id"
26 #define STT_TAG_ENGINE_SETTING          "setting"
27 #define STT_TAG_ENGINE_AGREEMENT        "agreement"
28 #define STT_TAG_ENGINE_DEFAULT          "default"
29 #define STT_TAG_ENGINE_LANGUAGE_SET     "languages"
30 #define STT_TAG_ENGINE_LANGUAGE         "lang"
31 #define STT_TAG_ENGINE_SILENCE_SUPPORT  "silence-detection-support"
32 #define STT_TAG_ENGINE_CREDENTIAL_NEED  "app-credential-need"
33
34 #define STT_TAG_CONFIG_BASE_TAG         "stt-config"
35 #define STT_TAG_CONFIG_ENGINE_ID        "engine"
36 #define STT_TAG_CONFIG_ENGINE_SETTING   "engine-setting"
37 #define STT_TAG_CONFIG_AUTO_LANGUAGE    "auto"
38 #define STT_TAG_CONFIG_LANGUAGE         "language"
39 #define STT_TAG_CONFIG_SILENCE_DETECTION "silence-detection"
40 #define STT_TAG_CONFIG_CREDENTIAL       "credential"
41
42
43 #define STT_TAG_TIME_BASE_TAG           "stt-time"
44 #define STT_TAG_TIME_INDEX              "index"
45 #define STT_TAG_TIME_COUNT              "count"
46 #define STT_TAG_TIME_TIME_INFO          "time-info"
47 #define STT_TAG_TIME_TEXT               "text-info"
48 #define STT_TAG_TIME_START              "start"
49 #define STT_TAG_TIME_END                "end"
50
51
52 static xmlDocPtr g_config_doc = NULL;
53
54 static int __stt_parser_get_base_node_from_config(xmlDocPtr config_doc, xmlNodePtr* node_ptr, const char* base_tag)
55 {
56         xmlNodePtr cur = xmlDocGetRootElement(config_doc);
57         if (cur == NULL) {
58                 //LCOV_EXCL_START
59                 SLOG(LOG_ERROR, TAG_STTCONFIG, "[ERROR] Empty document");
60                 return -1;
61                 //LCOV_EXCL_STOP
62         }
63
64         if (xmlStrcmp(cur->name, (const xmlChar *)base_tag)) {
65                 //LCOV_EXCL_START
66                 SLOG(LOG_ERROR, TAG_STTCONFIG, "[ERROR] The wrong type, root node is NOT %s", base_tag);
67                 return -1;
68                 //LCOV_EXCL_STOP
69         }
70
71         cur = cur->xmlChildrenNode;
72         if (cur == NULL) {
73                 //LCOV_EXCL_START
74                 SLOG(LOG_ERROR, TAG_STTCONFIG, "[ERROR] Empty document");
75                 return -1;
76                 //LCOV_EXCL_STOP
77         }
78         *node_ptr = cur;
79         return 0;
80 }
81
82 int stt_parser_get_engine_info(const char* path, stt_engine_info_s** engine_info)
83 {
84         if (NULL == path || NULL == engine_info) {
85                 SLOG(LOG_ERROR, TAG_STTCONFIG, "[ERROR] Input parameter is NULL"); //LCOV_EXCL_LINE
86                 return -1;
87         }
88
89         xmlDocPtr doc = NULL;
90         xmlNodePtr cur = NULL;
91         xmlChar *key;
92
93         doc = xmlParseFile(path);
94         if (doc == NULL) {
95                 return -1;
96         }
97
98         if (0 != __stt_parser_get_base_node_from_config(doc, &cur, STT_TAG_ENGINE_BASE_TAG)) {
99                 SLOG(LOG_ERROR, TAG_STTCONFIG, "[ERROR] Fail to get base node from config");
100                 xmlFreeDoc(doc);
101                 return -1;
102         }
103
104         /* alloc engine info */
105         stt_engine_info_s* temp;
106         temp = (stt_engine_info_s*)calloc(1, sizeof(stt_engine_info_s));
107         if (NULL == temp) {
108                 //LCOV_EXCL_START
109                 xmlFreeDoc(doc);
110                 SLOG(LOG_ERROR, TAG_STTCONFIG, "[ERROR] Fail to allocate memory");
111                 return -1;
112                 //LCOV_EXCL_STOP
113         }
114
115         temp->name = NULL;
116         temp->uuid = NULL;
117         temp->setting = NULL;
118         temp->agreement = NULL;
119         temp->default_lang = NULL;
120         temp->languages = NULL;
121         temp->support_silence_detection = false;
122         temp->need_credential = false;
123
124         bool is_default_lang_set = false;
125
126         while (cur != NULL) {
127                 if (0 == xmlStrcmp(cur->name, (const xmlChar *)STT_TAG_ENGINE_NAME)) {
128                         key = xmlNodeGetContent(cur);
129                         if (NULL != key) {
130                                 /* SLOG(LOG_DEBUG, TAG_STTCONFIG, "Engine name : %s", (char *)key); */
131                                 if (NULL != temp->name) free(temp->name);
132                                 temp->name = strdup((char*)key);
133                                 xmlFree(key);
134                         } else {
135                                 SLOG(LOG_ERROR, TAG_STTCONFIG, "[ERROR] <%s> has no content", STT_TAG_ENGINE_NAME); //LCOV_EXCL_LINE
136                         }
137                 } else if (0 == xmlStrcmp(cur->name, (const xmlChar *)STT_TAG_ENGINE_ID)) {
138                         key = xmlNodeGetContent(cur);
139                         if (NULL != key) {
140                                 /* SLOG(LOG_DEBUG, TAG_STTCONFIG, "Engine uuid : %s", (char *)key); */
141                                 if (NULL != temp->uuid) free(temp->uuid);
142                                 temp->uuid = strdup((char*)key);
143                                 xmlFree(key);
144                         } else {
145                                 SLOG(LOG_ERROR, TAG_STTCONFIG, "[ERROR] <%s> has no content", STT_TAG_ENGINE_ID); //LCOV_EXCL_LINE
146                         }
147                 } else if (0 == xmlStrcmp(cur->name, (const xmlChar *)STT_TAG_ENGINE_SETTING)) {
148                         key = xmlNodeGetContent(cur);
149                         if (NULL != key) {
150                                 SLOG(LOG_DEBUG, TAG_STTCONFIG, "Engine setting : %s", (char *)key);
151                                 if (NULL != temp->setting)      free(temp->setting);
152                                 temp->setting = strdup((char*)key);
153                                 xmlFree(key);
154                         } else {
155                                 SLOG(LOG_ERROR, TAG_STTCONFIG, "[ERROR] <%s> has no content", STT_TAG_ENGINE_SETTING); //LCOV_EXCL_LINE
156                         }
157                 } else if (0 == xmlStrcmp(cur->name, (const xmlChar *)STT_TAG_ENGINE_AGREEMENT)) {
158                         key = xmlNodeGetContent(cur);
159                         if (NULL != key) {
160                                 SLOG(LOG_DEBUG, TAG_STTCONFIG, "Engine agreement : %s", (char *)key);
161                                 if (NULL != temp->agreement)    free(temp->agreement);
162                                 temp->agreement = strdup((char*)key);
163                                 xmlFree(key);
164                         } else {
165                                 SLOG(LOG_ERROR, TAG_STTCONFIG, "[ERROR] <%s> has no content", STT_TAG_ENGINE_AGREEMENT); //LCOV_EXCL_LINE
166                         }
167                 } else if (0 == xmlStrcmp(cur->name, (const xmlChar *)STT_TAG_ENGINE_DEFAULT)) {
168                         key = xmlNodeGetContent(cur);
169                         if (NULL != key) {
170                                 SLOG(LOG_DEBUG, TAG_STTCONFIG, "Engine agreement : %s", (char *)key);
171                                 if (NULL != temp->default_lang) free(temp->default_lang);
172                                 temp->default_lang = strdup((char*)key);
173
174                                 is_default_lang_set = true;
175                                 xmlFree(key);
176                         } else {
177                                 SLOG(LOG_ERROR, TAG_STTCONFIG, "[ERROR] <%s> has no content", STT_TAG_ENGINE_DEFAULT);
178                         }
179                 } else if (0 == xmlStrcmp(cur->name, (const xmlChar *)STT_TAG_ENGINE_LANGUAGE_SET)) {
180                         xmlNodePtr lang_node = NULL;
181                         char* temp_lang = NULL;
182
183                         lang_node = cur->xmlChildrenNode;
184
185                         while (lang_node != NULL) {
186                                 if (0 == xmlStrcmp(lang_node->name, (const xmlChar *)STT_TAG_ENGINE_LANGUAGE)) {
187                                         key = xmlNodeGetContent(lang_node);
188                                         if (NULL != key) {
189                                                 /* SLOG(LOG_DEBUG, TAG_STTCONFIG, "language : %s", (char *)key); */
190                                                 temp_lang = strdup((char*)key);
191                                                 temp->languages = g_slist_append(temp->languages, temp_lang);
192
193                                                 if (false == is_default_lang_set) {
194                                                         if (NULL != temp->default_lang) free(temp->default_lang);
195                                                         temp->default_lang = strdup((char*)key);
196
197                                                         is_default_lang_set = true;
198                                                 }
199                                                 xmlFree(key);
200                                         } else {
201                                                 SLOG(LOG_ERROR, TAG_STTCONFIG, "[ERROR] <%s> has no content", STT_TAG_ENGINE_LANGUAGE); //LCOV_EXCL_LINE
202                                         }
203                                 }
204
205                                 lang_node = lang_node->next;
206                         }
207                 } else if (0 == xmlStrcmp(cur->name, (const xmlChar *)STT_TAG_ENGINE_SILENCE_SUPPORT)) {
208                         key = xmlNodeGetContent(cur);
209                         if (NULL != key) {
210                                 /*SLOG(LOG_DEBUG, TAG_STTCONFIG, "silence-detection-support : %s", (char *)key); */
211
212                                 if (0 == xmlStrcmp(key, (const xmlChar *)"true"))
213                                         temp->support_silence_detection = true;
214                                 else
215                                         temp->support_silence_detection = false;
216
217                                 xmlFree(key);
218                         } else {
219                                 SLOG(LOG_ERROR, TAG_STTCONFIG, "[ERROR] <%s> has no content", STT_TAG_ENGINE_SILENCE_SUPPORT); //LCOV_EXCL_LINE
220                         }
221                 } else if (0 == xmlStrcmp(cur->name, (const xmlChar *)STT_TAG_ENGINE_CREDENTIAL_NEED)) {
222                         key = xmlNodeGetContent(cur);
223                         if (NULL != key) {
224                                 //SLOG(LOG_DEBUG, TAG_STTCONFIG, "app-credential-need : %s", (char *)key);
225
226                                 if (0 == xmlStrcmp(key, (const xmlChar *)"true"))
227                                         temp->need_credential = true;
228                                 else
229                                         temp->need_credential = false;
230
231                                 xmlFree(key);
232                         } else {
233                                 SLOG(LOG_ERROR, TAG_STTCONFIG, "[ERROR] <%s> has no content", STT_TAG_ENGINE_CREDENTIAL_NEED);
234                         }
235                 } else {
236
237                 }
238
239                 cur = cur->next;
240         }
241
242         xmlFreeDoc(doc);
243
244         if (NULL == temp->name || NULL == temp->uuid) {
245                 /* Invalid engine */
246                 SLOG(LOG_ERROR, TAG_STTCONFIG, "[ERROR] Invalid engine : %s", path);
247                 stt_parser_free_engine_info(temp);
248                 return -1;
249         }
250
251         *engine_info = temp;
252
253         return 0;
254 }
255
256 int stt_parser_free_engine_info(stt_engine_info_s* engine_info)
257 {
258         if (NULL == engine_info) {
259                 SLOG(LOG_ERROR, TAG_STTCONFIG, "[ERROR] Input parameter is NULL"); //LCOV_EXCL_LINE
260                 return -1;
261         }
262
263         if (NULL != engine_info->name)          free(engine_info->name);
264         if (NULL != engine_info->uuid)          free(engine_info->uuid);
265         if (NULL != engine_info->setting)       free(engine_info->setting);
266         if (NULL != engine_info->agreement)     free(engine_info->agreement);
267
268         int count = g_slist_length(engine_info->languages);
269
270         int i ;
271         char *temp_lang;
272
273         for (i = 0; i < count ; i++) {
274                 temp_lang = g_slist_nth_data(engine_info->languages, 0);
275
276                 if (NULL != temp_lang) {
277                         engine_info->languages = g_slist_remove(engine_info->languages, temp_lang);
278
279                         if (NULL != temp_lang)
280                                 free(temp_lang);
281                 }
282         }
283
284         if (NULL != engine_info)        free(engine_info);
285
286         return 0;
287 }
288
289 //LCOV_EXCL_START
290 int stt_parser_print_engine_info(stt_engine_info_s* engine_info)
291 {
292         if (NULL == engine_info)
293                 return -1;
294
295         SLOG(LOG_DEBUG, TAG_STTCONFIG, "== get engine info ==");
296         SLOG(LOG_DEBUG, TAG_STTCONFIG, " name : %s", engine_info->name);
297         SLOG(LOG_DEBUG, TAG_STTCONFIG, " id   : %s", engine_info->uuid);
298         if (NULL != engine_info->setting)       SLOG(LOG_DEBUG, TAG_STTCONFIG, " setting : %s", engine_info->setting);
299
300         SLOG(LOG_DEBUG, TAG_STTCONFIG, " languages");
301         GSList *iter = NULL;
302         char* lang;
303         if (g_slist_length(engine_info->languages) > 0) {
304                 /* Get a first item */
305                 iter = g_slist_nth(engine_info->languages, 0);
306
307                 int i = 1;
308                 while (NULL != iter) {
309                         /*Get handle data from list*/
310                         lang = iter->data;
311
312                         SLOG(LOG_DEBUG, TAG_STTCONFIG, "  [%dth] %s", i, lang);
313
314                         /*Get next item*/
315                         iter = g_slist_next(iter);
316                         i++;
317                 }
318         } else {
319                 SLOG(LOG_ERROR, TAG_STTCONFIG, "  language is NONE");
320         }
321         SLOG(LOG_DEBUG, TAG_STTCONFIG, " silence support : %s", engine_info->support_silence_detection ? "true" : "false");
322         SLOG(LOG_DEBUG, TAG_STTCONFIG, " credential need : %s", engine_info->need_credential ? "true" : "false");
323         SLOG(LOG_DEBUG, TAG_STTCONFIG, "=====================");
324
325         return 0;
326 }
327 //LCOV_EXCL_STOP
328
329 int stt_parser_load_config(stt_config_s** config_info)
330 {
331         if (NULL == config_info) {
332                 SLOG(LOG_ERROR, TAG_STTCONFIG, "[ERROR] Input parameter is NULL"); //LCOV_EXCL_LINE
333                 return -1;
334         }
335
336         xmlDocPtr doc = NULL;
337         xmlNodePtr cur = NULL;
338         xmlChar *key;
339         bool is_default_open = false;
340
341         if (0 != access(STT_CONFIG, F_OK)) {
342                 doc = xmlParseFile(STT_DEFAULT_CONFIG);
343                 if (doc == NULL) {
344                         SLOG(LOG_ERROR, TAG_STTCONFIG, "[ERROR] Fail to parse file error : %s", STT_DEFAULT_CONFIG); //LCOV_EXCL_LINE
345                         xmlCleanupParser();
346                         return -1;
347                 }
348                 is_default_open = true;
349         } else {
350                 int retry_count = 0;
351
352                 while (NULL == doc) {
353                         doc = xmlParseFile(STT_CONFIG);
354                         if (NULL != doc) {
355                                 break;
356                         }
357                         retry_count++;
358                         usleep(10000);
359
360                         if (STT_RETRY_COUNT == retry_count) {
361                                 SLOG(LOG_ERROR, TAG_STTCONFIG, "[ERROR] Fail to parse file error : %s", STT_CONFIG);
362                                 SLOG(LOG_ERROR, TAG_STTCONFIG, "[ERROR] Remove the file");
363                                 remove(STT_CONFIG);
364
365                                 doc = xmlParseFile(STT_DEFAULT_CONFIG);
366                                 if (NULL == doc) {
367                                         SLOG(LOG_ERROR, TAG_STTCONFIG, "[ERROR] Fail to parse file error : %s", STT_DEFAULT_CONFIG);
368                                         xmlCleanupParser();
369                                         return -1;
370                                 }
371                                 is_default_open = true;
372                                 break;
373                         }
374                 }
375         }
376
377         if (0 != __stt_parser_get_base_node_from_config(doc, &cur, STT_TAG_CONFIG_BASE_TAG)) {
378                 SLOG(LOG_ERROR, TAG_STTCONFIG, "[ERROR] Fail to get base node from config");
379                 xmlFreeDoc(doc);
380                 return -1;
381         }
382
383         /* alloc engine info */
384         stt_config_s* temp;
385         temp = (stt_config_s*)calloc(1, sizeof(stt_config_s));
386         if (NULL == temp) {
387                 xmlFreeDoc(doc);
388                 SLOG(LOG_ERROR, TAG_STTCONFIG, "[ERROR] Fail to allocate memory"); //LCOV_EXCL_LINE
389                 return -1;
390         }
391
392         temp->engine_id = NULL;
393         temp->setting = NULL;
394         temp->language = NULL;
395
396         while (cur != NULL) {
397                 if (0 == xmlStrcmp(cur->name, (const xmlChar *)STT_TAG_CONFIG_ENGINE_ID)) {
398                         key = xmlNodeGetContent(cur);
399                         if (NULL != key) {
400                                 /*SLOG(LOG_DEBUG, TAG_STTCONFIG, "Engine id : %s", (char *)key); */
401                                 if (NULL != temp->engine_id)    free(temp->engine_id);
402                                 temp->engine_id = strdup((char*)key);
403                                 xmlFree(key);
404                         } else {
405                                 SLOG(LOG_ERROR, TAG_STTCONFIG, "[ERROR] engine id is NULL"); //LCOV_EXCL_LINE
406                         }
407                 } else if (0 == xmlStrcmp(cur->name, (const xmlChar *)STT_TAG_CONFIG_ENGINE_SETTING)) {
408                         key = xmlNodeGetContent(cur);
409                         if (NULL != key) {
410                                 /*SLOG(LOG_DEBUG, TAG_STTCONFIG, "Setting path : %s", (char *)key); */
411                                 if (NULL != temp->setting)      free(temp->setting);
412                                 temp->setting = strdup((char*)key);
413                                 xmlFree(key);
414                         } else {
415                                 SLOG(LOG_ERROR, TAG_STTCONFIG, "[ERROR] setting path is NULL"); //LCOV_EXCL_LINE
416                         }
417
418                 } else if (0 == xmlStrcmp(cur->name, (const xmlChar *)STT_TAG_CONFIG_AUTO_LANGUAGE)) {
419                         key = xmlNodeGetContent(cur);
420                         if (NULL != key) {
421                                 /*SLOG(LOG_DEBUG, TAG_STTCONFIG, "Auto language : %s", (char *)key); */
422
423                                 if (0 == xmlStrcmp(key, (const xmlChar *)"on")) {
424                                         temp->auto_lang = true;
425                                 } else if (0 == xmlStrcmp(key, (const xmlChar *)"off")) {
426                                         temp->auto_lang = false;
427                                 } else {
428                                         SLOG(LOG_ERROR, TAG_STTCONFIG, "Auto voice is wrong"); //LCOV_EXCL_LINE
429                                         temp->auto_lang = true;
430                                 }
431
432                                 xmlFree(key);
433                         } else {
434                                 SLOG(LOG_ERROR, TAG_STTCONFIG, "[ERROR] auto language is NULL"); //LCOV_EXCL_LINE
435                         }
436                 } else if (0 == xmlStrcmp(cur->name, (const xmlChar *)STT_TAG_CONFIG_LANGUAGE)) {
437                         key = xmlNodeGetContent(cur);
438                         if (NULL != key) {
439                                 /*SLOG(LOG_DEBUG, TAG_STTCONFIG, "language : %s", (char *)key); */
440                                 if (NULL != temp->language)     free(temp->language);
441                                 temp->language = strdup((char*)key);
442                                 xmlFree(key);
443                         } else {
444                                 SLOG(LOG_ERROR, TAG_STTCONFIG, "[ERROR] language is NULL"); //LCOV_EXCL_LINE
445                         }
446                 } else if (0 == xmlStrcmp(cur->name, (const xmlChar *)STT_TAG_CONFIG_SILENCE_DETECTION)) {
447                         key = xmlNodeGetContent(cur);
448                         if (NULL != key) {
449                                 /*SLOG(LOG_DEBUG, TAG_STTCONFIG, "silence-detection : %s", (char *)key); */
450
451                                 if (0 == xmlStrcmp(key, (const xmlChar *)"on"))
452                                         temp->silence_detection = true;
453                                 else
454                                         temp->silence_detection = false;
455
456                                 xmlFree(key);
457                         } else {
458                                 SLOG(LOG_ERROR, TAG_STTCONFIG, "[ERROR] silence-detection is NULL"); //LCOV_EXCL_LINE
459                         }
460                 } else if (0 == xmlStrcmp(cur->name, (const xmlChar *)STT_TAG_CONFIG_CREDENTIAL)) {
461                         key = xmlNodeGetContent(cur);
462                         if (NULL != key) {
463                                 //SLOG(LOG_DEBUG, TAG_STTCONFIG, "credential : %s", (char *)key);
464
465                                 if (0 == xmlStrcmp(key, (const xmlChar *)"true"))
466                                         temp->credential = true;
467                                 else
468                                         temp->credential = false;
469
470                                 xmlFree(key);
471                         } else {
472                                 SLOG(LOG_ERROR, TAG_STTCONFIG, "[ERROR] credential is NULL"); //LCOV_EXCL_LINE
473                         }
474                 } else {
475
476                 }
477
478                 cur = cur->next;
479         }
480
481         *config_info = temp;
482         g_config_doc = doc;
483
484         if (is_default_open) {
485                 int retry_count = 0;
486                 int ret = -1;
487                 do {
488                         ret = xmlSaveFile(STT_CONFIG, g_config_doc);
489                         if (0 < ret)
490                                 break;
491                         retry_count++;
492                         usleep(10000);
493
494                         if (STT_RETRY_COUNT == retry_count) {
495                                 SLOG(LOG_ERROR, TAG_STTCONFIG, "[ERROR] Save result : %d", ret);
496                                 return -1;
497                         }
498                 } while (0 != ret);
499
500                 /* Set mode */
501                 if (0 > chmod(STT_CONFIG, 0600)) {
502                         SLOG(LOG_ERROR, TAG_STTCONFIG, "[ERROR] Fail to change file mode : %d", ret);
503                 }
504
505                 /* Set owner */
506                 if (0 > chown(STT_CONFIG, 5000, 5000)) {
507                         SLOG(LOG_ERROR, TAG_STTCONFIG, "[ERROR] Fail to change file owner : %d", ret);
508                 }
509                 SLOG(LOG_DEBUG, TAG_STTCONFIG, "Default config is changed : pid(%d)", getpid());
510         }
511
512         return 0;
513 }
514
515 int stt_parser_unload_config(stt_config_s* config_info)
516 {
517         if (NULL != g_config_doc) {
518                 xmlFreeDoc(g_config_doc);
519                 g_config_doc = NULL;
520         }
521         if (NULL != config_info) {
522                 if (NULL != config_info->engine_id) {
523                         free(config_info->engine_id);
524                         config_info->engine_id = NULL;
525                 }
526                 if (NULL != config_info->setting) {
527                         free(config_info->setting);
528                         config_info->setting = NULL;
529                 }
530                 if (NULL != config_info->language) {
531                         free(config_info->language);
532                         config_info->language = NULL;
533                 }
534
535                 free(config_info);
536         }
537
538         return 0;
539 }
540
541 int stt_parser_set_engine(const char* engine_id, const char* setting, const char* language, bool silence, bool credential)
542 {
543         if (NULL == g_config_doc || NULL == engine_id)
544                 return -1;
545
546         xmlNodePtr cur = NULL;
547         if (0 != __stt_parser_get_base_node_from_config(g_config_doc, &cur, STT_TAG_CONFIG_BASE_TAG)) {
548                 SLOG(LOG_ERROR, TAG_STTCONFIG, "[ERROR] Fail to get base node from config");
549                 return -1;
550         }
551
552         while (cur != NULL) {
553                 if (0 == xmlStrcmp(cur->name, (const xmlChar *)STT_TAG_CONFIG_ENGINE_ID)) {
554                         xmlNodeSetContent(cur, (const xmlChar *)engine_id);
555                 }
556
557                 if (0 == xmlStrcmp(cur->name, (const xmlChar *)STT_TAG_CONFIG_LANGUAGE)) {
558                         xmlNodeSetContent(cur, (const xmlChar *)language);
559                 }
560
561                 if (0 == xmlStrcmp(cur->name, (const xmlChar *)STT_TAG_CONFIG_ENGINE_SETTING)) {
562                         xmlNodeSetContent(cur, (const xmlChar *)setting);
563                 }
564
565                 if (0 == xmlStrcmp(cur->name, (const xmlChar *)STT_TAG_CONFIG_SILENCE_DETECTION)) {
566                         if (true == silence)
567                                 xmlNodeSetContent(cur, (const xmlChar *)"on");
568                         else
569                                 xmlNodeSetContent(cur, (const xmlChar *)"off");
570                 }
571
572                 if (0 == xmlStrcmp(cur->name, (const xmlChar *)STT_TAG_CONFIG_CREDENTIAL)) {
573                         if (true == credential)
574                                 xmlNodeSetContent(cur, (const xmlChar *)"true");
575                         else
576                                 xmlNodeSetContent(cur, (const xmlChar *)"false");
577                 }
578
579                 cur = cur->next;
580         }
581
582         int ret = xmlSaveFile(STT_CONFIG, g_config_doc);
583         SLOG(LOG_DEBUG, TAG_STTCONFIG, "Save result : %d", ret);
584
585         return 0;
586 }
587
588 int stt_parser_set_language(const char* language)
589 {
590         if (NULL == g_config_doc || NULL == language)
591                 return -1;
592
593         xmlNodePtr cur = NULL;
594         if (0 != __stt_parser_get_base_node_from_config(g_config_doc, &cur, STT_TAG_CONFIG_BASE_TAG)) {
595                 SLOG(LOG_ERROR, TAG_STTCONFIG, "[ERROR] Fail to get base node from config");
596                 return -1;
597         }
598
599         while (cur != NULL) {
600                 if (0 == xmlStrcmp(cur->name, (const xmlChar *)STT_TAG_CONFIG_LANGUAGE)) {
601                         xmlNodeSetContent(cur, (const xmlChar *)language);
602                 }
603
604                 cur = cur->next;
605         }
606
607         int ret = xmlSaveFile(STT_CONFIG, g_config_doc);
608         SLOG(LOG_DEBUG, TAG_STTCONFIG, "Save result : %d", ret);
609
610
611         return 0;
612 }
613
614 //LCOV_EXCL_START
615 int stt_parser_set_auto_lang(bool value)
616 {
617         if (NULL == g_config_doc)
618                 return -1;
619
620         xmlNodePtr cur = NULL;
621         if (0 != __stt_parser_get_base_node_from_config(g_config_doc, &cur, STT_TAG_CONFIG_BASE_TAG)) {
622                 SLOG(LOG_ERROR, TAG_STTCONFIG, "[ERROR] Fail to get base node from config");
623                 return -1;
624         }
625
626         while (cur != NULL) {
627                 if (0 == xmlStrcmp(cur->name, (const xmlChar *)STT_TAG_CONFIG_AUTO_LANGUAGE)) {
628                         if (true == value) {
629                                 xmlNodeSetContent(cur, (const xmlChar *)"on");
630                         } else if (false == value) {
631                                 xmlNodeSetContent(cur, (const xmlChar *)"off");
632                         } else {
633                                 SLOG(LOG_ERROR, TAG_STTCONFIG, "[ERROR] The wrong value of auto voice");
634                                 return -1;
635                         }
636                         break;
637                 }
638                 cur = cur->next;
639         }
640
641         int ret = xmlSaveFile(STT_CONFIG, g_config_doc);
642         SLOG(LOG_DEBUG, TAG_STTCONFIG, "Save result : %d", ret);
643
644         return 0;
645 }
646
647 int stt_parser_set_silence_detection(bool value)
648 {
649         if (NULL == g_config_doc)
650                 return -1;
651
652         xmlNodePtr cur = NULL;
653         if (0 != __stt_parser_get_base_node_from_config(g_config_doc, &cur, STT_TAG_CONFIG_BASE_TAG)) {
654                 SLOG(LOG_ERROR, TAG_STTCONFIG, "[ERROR] Fail to get base node from config");
655                 return -1;
656         }
657
658         while (cur != NULL) {
659                 if (0 == xmlStrcmp(cur->name, (const xmlChar *)STT_TAG_CONFIG_SILENCE_DETECTION)) {
660                         if (true == value)
661                                 xmlNodeSetContent(cur, (const xmlChar *)"on");
662                         else
663                                 xmlNodeSetContent(cur, (const xmlChar *)"off");
664                 }
665
666                 cur = cur->next;
667         }
668
669         int ret = xmlSaveFile(STT_CONFIG, g_config_doc);
670         SLOG(LOG_DEBUG, TAG_STTCONFIG, "Save result : %d", ret);
671
672         return 0;
673 }
674 //LCOV_EXCL_STOP
675
676 int stt_parser_find_config_changed(char** engine, char** setting, int* auto_lang, char** language, int* silence, int* credential)
677 {
678         if (NULL == engine || NULL == language || NULL == silence || NULL == credential) {
679                 SLOG(LOG_ERROR, TAG_STTCONFIG, "[ERROR] Input parameter is NULL"); //LCOV_EXCL_LINE
680                 return -1;
681         }
682
683         xmlDocPtr doc = NULL;
684         xmlNodePtr cur_new = NULL;
685         xmlNodePtr cur_old = NULL;
686
687         xmlChar *key_new;
688         xmlChar *key_old;
689
690         doc = xmlParseFile(STT_CONFIG);
691         if (doc == NULL) {
692                 SLOG(LOG_ERROR, TAG_STTCONFIG, "[ERROR] Fail to parse file error : %s", STT_CONFIG);
693                 return -1;
694         }
695
696         cur_new = xmlDocGetRootElement(doc);
697         cur_old = xmlDocGetRootElement(g_config_doc);
698         if (cur_new == NULL || cur_old == NULL) {
699                 //LCOV_EXCL_START
700                 SLOG(LOG_ERROR, TAG_STTCONFIG, "[ERROR] Empty document");
701                 xmlFreeDoc(doc);
702                 return -1;
703                 //LCOV_EXCL_STOP
704         }
705
706         if (xmlStrcmp(cur_new->name, (const xmlChar*)STT_TAG_CONFIG_BASE_TAG) || xmlStrcmp(cur_old->name, (const xmlChar*)STT_TAG_CONFIG_BASE_TAG)) {
707                 //LCOV_EXCL_START
708                 SLOG(LOG_ERROR, TAG_STTCONFIG, "[ERROR] The wrong type, root node is NOT %s", STT_TAG_CONFIG_BASE_TAG);
709                 xmlFreeDoc(doc);
710                 return -1;
711                 //LCOV_EXCL_STOP
712         }
713
714         cur_new = cur_new->xmlChildrenNode;
715         cur_old = cur_old->xmlChildrenNode;
716         if (cur_new == NULL || cur_old == NULL) {
717                 //LCOV_EXCL_START
718                 SLOG(LOG_ERROR, TAG_STTCONFIG, "[ERROR] Empty document");
719                 xmlFreeDoc(doc);
720                 return -1;
721                 //LCOV_EXCL_STOP
722         }
723
724         *engine = NULL;
725         *setting = NULL;
726         *language = NULL;
727
728         while (cur_new != NULL && cur_old != NULL) {
729                 if (0 == xmlStrcmp(cur_new->name, (const xmlChar*)STT_TAG_CONFIG_ENGINE_ID)) {
730                         if (0 == xmlStrcmp(cur_old->name, (const xmlChar*)STT_TAG_CONFIG_ENGINE_ID)) {
731                                 key_old = xmlNodeGetContent(cur_old);
732                                 if (NULL != key_old) {
733                                         key_new = xmlNodeGetContent(cur_new);
734                                         if (NULL != key_new) {
735                                                 if (0 != xmlStrcmp(key_old, key_new)) {
736                                                         SLOG(LOG_DEBUG, TAG_STTCONFIG, "Old engine id(%s), New engine(%s)", (char*)key_old, (char*)key_new);
737                                                         if (NULL != *engine)    free(*engine);
738                                                         *engine = strdup((char*)key_new);
739                                                 }
740                                                 xmlFree(key_new);
741                                         }
742                                         xmlFree(key_old);
743                                 }
744                         } else {
745                                 SLOG(LOG_ERROR, TAG_STTCONFIG, "[ERROR] Old config and new config are different"); //LCOV_EXCL_LINE
746                         }
747                 } else if (0 == xmlStrcmp(cur_new->name, (const xmlChar*)STT_TAG_CONFIG_ENGINE_SETTING)) {
748                         if (0 == xmlStrcmp(cur_old->name, (const xmlChar*)STT_TAG_CONFIG_ENGINE_SETTING)) {
749                                 key_old = xmlNodeGetContent(cur_old);
750                                 if (NULL != key_old) {
751                                         key_new = xmlNodeGetContent(cur_new);
752                                         if (NULL != key_new) {
753                                                 if (0 != xmlStrcmp(key_old, key_new)) {
754                                                         SLOG(LOG_DEBUG, TAG_STTCONFIG, "Old engine setting(%s), New engine setting(%s)", (char*)key_old, (char*)key_new); //LCOV_EXCL_LINE
755                                                         if (NULL != *setting)   free(*setting);
756                                                         *setting = strdup((char*)key_new);
757                                                 }
758                                                 xmlFree(key_new);
759                                         }
760                                         xmlFree(key_old);
761                                 }
762                         } else {
763                                 SLOG(LOG_ERROR, TAG_STTCONFIG, "[ERROR] Old config and new config are different"); //LCOV_EXCL_LINE
764                         }
765                 } else if (0 == xmlStrcmp(cur_new->name, (const xmlChar*)STT_TAG_CONFIG_AUTO_LANGUAGE)) {
766                         if (0 == xmlStrcmp(cur_old->name, (const xmlChar*)STT_TAG_CONFIG_AUTO_LANGUAGE)) {
767                                 key_old = xmlNodeGetContent(cur_old);
768                                 if (NULL != key_old) {
769                                         key_new = xmlNodeGetContent(cur_new);
770                                         if (NULL != key_new) {
771                                                 if (0 != xmlStrcmp(key_old, key_new)) {
772                                                         SLOG(LOG_DEBUG, TAG_STTCONFIG, "Old auto lang(%s), New auto lang(%s)", (char*)key_old, (char*)key_new); //LCOV_EXCL_LINE
773                                                         if (0 == xmlStrcmp((const xmlChar*)"on", key_new)) {
774                                                                 *auto_lang = (int)true;
775                                                         } else {
776                                                                 *auto_lang = (int)false;
777                                                         }
778                                                 }
779
780                                                 xmlFree(key_new);
781                                         }
782                                         xmlFree(key_old);
783                                 }
784                         } else {
785                                 SLOG(LOG_ERROR, TAG_STTCONFIG, "[ERROR] old config and new config are different"); //LCOV_EXCL_LINE
786                         }
787                 } else if (0 == xmlStrcmp(cur_new->name, (const xmlChar*)STT_TAG_CONFIG_LANGUAGE)) {
788                         if (0 == xmlStrcmp(cur_old->name, (const xmlChar*)STT_TAG_CONFIG_LANGUAGE)) {
789                                 key_old = xmlNodeGetContent(cur_old);
790                                 if (NULL != key_old) {
791                                         key_new = xmlNodeGetContent(cur_new);
792                                         if (NULL != key_new) {
793                                                 if (0 != xmlStrcmp(key_old, key_new)) {
794                                                         SLOG(LOG_DEBUG, TAG_STTCONFIG, "Old language(%s), New language(%s)", (char*)key_old, (char*)key_new); //LCOV_EXCL_LINE
795                                                         if (NULL != *language)  free(*language);
796                                                         *language = strdup((char*)key_new);
797                                                 }
798                                                 xmlFree(key_new);
799                                         }
800                                         xmlFree(key_old);
801                                 }
802                         } else {
803                                 SLOG(LOG_ERROR, TAG_STTCONFIG, "[ERROR] old config and new config are different"); //LCOV_EXCL_LINE
804                         }
805                 } else if (0 == xmlStrcmp(cur_new->name, (const xmlChar*)STT_TAG_CONFIG_SILENCE_DETECTION)) {
806                         if (0 == xmlStrcmp(cur_old->name, (const xmlChar*)STT_TAG_CONFIG_SILENCE_DETECTION)) {
807                                 key_old = xmlNodeGetContent(cur_old);
808                                 if (NULL != key_old) {
809                                         key_new = xmlNodeGetContent(cur_new);
810                                         if (NULL != key_new) {
811                                                 if (0 != xmlStrcmp(key_old, key_new)) {
812                                                         SLOG(LOG_DEBUG, TAG_STTCONFIG, "Old silence(%s), New silence(%s)", (char*)key_old, (char*)key_new); //LCOV_EXCL_LINE
813                                                         if (0 == xmlStrcmp(key_new, (const xmlChar*)"on")) {
814                                                                 *silence = 1;
815                                                         } else {
816                                                                 *silence = 0;
817                                                         }
818                                                 }
819
820                                                 xmlFree(key_new);
821                                         }
822                                         xmlFree(key_old);
823                                 }
824                         } else {
825                                 SLOG(LOG_ERROR, TAG_STTCONFIG, "[ERROR] old config and new config are different"); //LCOV_EXCL_LINE
826                         }
827                 } else if (0 == xmlStrcmp(cur_new->name, (const xmlChar*)STT_TAG_CONFIG_CREDENTIAL)) {
828                         if (0 == xmlStrcmp(cur_old->name, (const xmlChar*)STT_TAG_CONFIG_CREDENTIAL)) {
829                                 key_old = xmlNodeGetContent(cur_old);
830                                 if (NULL != key_old) {
831                                         key_new = xmlNodeGetContent(cur_new);
832                                         if (NULL != key_new) {
833                                                 if (0 != xmlStrcmp(key_old, key_new)) {
834                                                         SLOG(LOG_DEBUG, TAG_STTCONFIG, "Old credential(%s), New credential(%s)", (char*)key_old, (char*)key_new); //LCOV_EXCL_LINE
835                                                         if (0 == xmlStrcmp(key_new, (const xmlChar*)"true")) {
836                                                                 *credential = 1;
837                                                         } else {
838                                                                 *credential = 0;
839                                                         }
840                                                 }
841                                                 xmlFree(key_new);
842                                         }
843                                         xmlFree(key_old);
844                                 }
845                         } else {
846                                 SLOG(LOG_ERROR, TAG_STTCONFIG, "[ERROR] old config and new config are different"); //LCOV_EXCL_LINE
847                         }
848
849                 } else {
850
851                 }
852
853                 cur_new = cur_new->next;
854                 cur_old = cur_old->next;
855         }
856
857         xmlFreeDoc(g_config_doc);
858         g_config_doc = doc;
859
860         return 0;
861 }
862
863 /**
864 * time function
865 */
866 //LCOV_EXCL_START
867 int stt_parser_set_time_info(GSList* time_list)
868 {
869         if (0 == g_slist_length(time_list)) {
870                 SLOG(LOG_WARN, TAG_STTCONFIG, "[WARNING] There is no time info to save");
871                 return -1;
872         }
873
874         if (-1 == remove(STT_TIME_INFO_PATH)) {
875                 SLOG(LOG_WARN, TAG_STTCONFIG, "[PLAYER WARNING] Fail to remove file(%s)", STT_TIME_INFO_PATH);
876         }
877
878         xmlDocPtr doc = NULL;
879         xmlNodePtr cur = NULL;
880
881         doc = xmlNewDoc((const xmlChar*)"1.0");
882         if (doc == NULL) {
883                 SLOG(LOG_ERROR, TAG_STTCONFIG, "[ERROR] Fail to make new doc");
884                 return -1;
885         }
886
887         cur = xmlNewNode(NULL, (const xmlChar*)STT_TAG_TIME_BASE_TAG);
888         xmlDocSetRootElement(doc, cur);
889
890         xmlNodePtr inode = NULL;
891         GSList *iter = NULL;
892         stt_result_time_info_s *data = NULL;
893         char temp_str[256];
894
895         snprintf(temp_str, 256, "%d", g_slist_length(time_list));
896
897         inode = xmlNewNode(NULL, (const xmlChar*)STT_TAG_TIME_INDEX);
898         xmlNewProp(inode, (const xmlChar*)STT_TAG_TIME_COUNT, (const xmlChar*)temp_str);
899         xmlAddChild(cur, inode);
900
901         /* Get a first item */
902         iter = g_slist_nth(time_list, 0);
903         while (NULL != iter) {
904                 data = iter->data;
905
906                 if (NULL == data) {
907                         SLOG(LOG_DEBUG, TAG_STTCONFIG, "data is NULL");
908                         continue;
909                 }
910
911                 xmlNodePtr temp_node = NULL;
912
913                 SECURE_SLOG(LOG_DEBUG, TAG_STTCONFIG, "[%d] i(%d) t(%s) s(%ld) e(%ld)",
914                         data->index, data->event, data->text, data->start_time, data->end_time);
915
916                 temp_node = xmlNewNode(NULL, (const xmlChar*)STT_TAG_TIME_TEXT);
917                 xmlNodeSetContent(temp_node, (const xmlChar*)data->text);
918                 xmlAddChild(inode, temp_node);
919
920                 temp_node = xmlNewNode(NULL, (const xmlChar*)STT_TAG_TIME_START);
921                 snprintf(temp_str, 256, "%ld", data->start_time);
922                 xmlNodeSetContent(temp_node, (const xmlChar*)temp_str);
923                 xmlAddChild(inode, temp_node);
924
925                 temp_node = xmlNewNode(NULL, (const xmlChar*)STT_TAG_TIME_END);
926                 snprintf(temp_str, 256, "%ld", data->end_time);
927                 xmlNodeSetContent(temp_node, (const xmlChar*)temp_str);
928                 xmlAddChild(inode, temp_node);
929
930                 /*Get next item*/
931                 iter = g_slist_next(iter);
932         }
933
934         int ret = xmlSaveFormatFile(STT_TIME_INFO_PATH, doc, 1);
935         SLOG(LOG_DEBUG, TAG_STTCONFIG, "Save result : %d", ret);
936
937         xmlFreeDoc(doc);
938         return 0;
939 }
940 //LCOV_EXCL_STOP
941
942 void __stt_parser_time_info_free(void* data)
943 {
944         stt_result_time_info_s* time_info = (stt_result_time_info_s*)data;
945
946         if (NULL != time_info) {
947                 if (NULL != time_info->text) {
948                         free(time_info->text);
949                         time_info->text = NULL;
950                 }
951
952                 free(time_info);
953         }
954 }
955
956 int stt_parser_get_time_info(GSList** time_list)
957 {
958         if (NULL == time_list) {
959                 SLOG(LOG_ERROR, TAG_STTCONFIG, "Invalid parameter : text is NULL"); //LCOV_EXCL_LINE
960                 return -1;
961         }
962
963         xmlDocPtr doc = NULL;
964         xmlNodePtr cur = NULL;
965
966         doc = xmlParseFile(STT_TIME_INFO_PATH);
967         if (doc == NULL) {
968                 SLOG(LOG_WARN, TAG_STTCONFIG, "[WARNING] File is not exist"); //LCOV_EXCL_LINE
969                 return -1;
970         }
971
972         if (0 != __stt_parser_get_base_node_from_config(doc, &cur, STT_TAG_TIME_BASE_TAG)) {
973                 SLOG(LOG_ERROR, TAG_STTCONFIG, "[ERROR] Fail to get base node from config");
974                 xmlFreeDoc(doc);
975                 return -1;
976         }
977
978         /* alloc time info */
979         GSList *temp_time_list = NULL;
980         xmlChar *key = NULL;
981         int index = 0;
982
983         while (cur != NULL) {
984                 if (0 == xmlStrcmp(cur->name, (const xmlChar *)STT_TAG_TIME_INDEX)) {
985                         key = xmlGetProp(cur, (const xmlChar*)STT_TAG_TIME_COUNT);
986                         if (NULL == key) {
987                                 SLOG(LOG_ERROR, TAG_STTCONFIG, "[ERROR] <%s> has no content", STT_TAG_TIME_COUNT); //LCOV_EXCL_LINE
988
989                                 if (NULL != temp_time_list) {
990                                         g_slist_free_full(temp_time_list, __stt_parser_time_info_free);
991                                         temp_time_list = NULL;
992                                 }
993                                 xmlFreeDoc(doc);
994                                 return -1;
995                         }
996
997                         SLOG(LOG_DEBUG, TAG_STTCONFIG, "Count : %s", (char *)key);
998
999                         /* Get time count */
1000                         int count = 0;
1001                         count = atoi((char*)key);
1002                         xmlFree(key);
1003
1004                         if (count <= 0) {
1005                                 SLOG(LOG_ERROR, TAG_STTCONFIG, "[ERROR] count is invalid : %d", count); //LCOV_EXCL_LINE
1006                                 break;
1007                         }
1008
1009                         xmlNodePtr time_node = NULL;
1010                         time_node = cur->xmlChildrenNode;
1011
1012                         int i = 0;
1013                         for (i = 0; i < count; i++) {
1014                                 /* text */
1015                                 time_node = time_node->next;
1016
1017                                 stt_result_time_info_s* temp_info;
1018                                 temp_info = (stt_result_time_info_s*)calloc(1, sizeof(stt_result_time_info_s));
1019
1020                                 if (NULL == temp_info) {
1021                                         SLOG(LOG_ERROR, TAG_STTCONFIG, "[ERROR] Memory alloc error!!"); //LCOV_EXCL_LINE
1022
1023                                         if (NULL != temp_time_list) {
1024                                                 g_slist_free_full(temp_time_list, __stt_parser_time_info_free);
1025                                                 temp_time_list = NULL;
1026                                         }
1027                                         xmlFreeDoc(doc);
1028                                         return -1;
1029                                 }
1030
1031                                 temp_info->index = index;
1032                                 SLOG(LOG_DEBUG, TAG_STTCONFIG, "index : %d", temp_info->index);
1033
1034                                 if (0 == i)             temp_info->event = 0;
1035                                 else if (count -1 == i) temp_info->event = 2;
1036                                 else                    temp_info->event = 1;
1037
1038                                 if (0 == xmlStrcmp(time_node->name, (const xmlChar *)STT_TAG_TIME_TEXT)) {
1039                                         key = xmlNodeGetContent(time_node);
1040                                         if (NULL != key) {
1041                                                 SLOG(LOG_DEBUG, TAG_STTCONFIG, "text : %s", (char *)key); //LCOV_EXCL_LINE
1042                                                 temp_info->text = strdup((char*)key);
1043                                                 xmlFree(key);
1044                                         } else {
1045                                                 SLOG(LOG_ERROR, TAG_STTCONFIG, "[ERROR] <%s> has no content", STT_TAG_TIME_TEXT); //LCOV_EXCL_LINE
1046                                                 free(temp_info);
1047                                                 break;
1048                                         }
1049                                 }
1050
1051                                 /* text */
1052                                 time_node = time_node->next;
1053                                 time_node = time_node->next;
1054
1055                                 if (0 == xmlStrcmp(time_node->name, (const xmlChar *)STT_TAG_TIME_START)) {
1056                                         key = xmlNodeGetContent(time_node);
1057                                         if (NULL != key) {
1058                                                 SLOG(LOG_DEBUG, TAG_STTCONFIG, "Start time : %s", (char *)key); //LCOV_EXCL_LINE
1059                                                 temp_info->start_time = atoi((char*)key);
1060                                                 xmlFree(key);
1061                                         } else {
1062                                                 SLOG(LOG_ERROR, TAG_STTCONFIG, "[ERROR] <%s> has no content", STT_TAG_TIME_START); //LCOV_EXCL_LINE
1063                                                 if (NULL != temp_info->text)    free(temp_info->text);
1064                                                 free(temp_info);
1065                                                 break;
1066                                         }
1067                                 }
1068
1069                                 /* text */
1070                                 time_node = time_node->next;
1071                                 time_node = time_node->next;
1072
1073                                 if (0 == xmlStrcmp(time_node->name, (const xmlChar *)STT_TAG_TIME_END)) {
1074                                         key = xmlNodeGetContent(time_node);
1075                                         if (NULL != key) {
1076                                                 SLOG(LOG_DEBUG, TAG_STTCONFIG, "End time : %s", (char *)key); //LCOV_EXCL_LINE
1077                                                 temp_info->end_time = atoi((char*)key);
1078                                                 xmlFree(key);
1079                                         } else {
1080                                                 SLOG(LOG_ERROR, TAG_STTCONFIG, "[ERROR] <%s> has no content", STT_TAG_TIME_END); //LCOV_EXCL_LINE
1081                                                 if (NULL != temp_info->text)    free(temp_info->text);
1082                                                 free(temp_info);
1083                                                 break;
1084                                         }
1085                                 }
1086
1087                                 time_node = time_node->next;
1088
1089                                 temp_time_list = g_slist_append(temp_time_list, temp_info);
1090                         } /* for */
1091                         index++;
1092                 } /* if */
1093                 cur = cur->next;
1094         }
1095
1096         xmlFreeDoc(doc);
1097
1098         *time_list = temp_time_list;
1099
1100         return 0;
1101 }
1102
1103 int stt_parser_clear_time_info()
1104 {
1105         if (-1 == remove(STT_TIME_INFO_PATH)) {
1106                 /* SLOG(LOG_WARN, TAG_STTCONFIG, "[PLAYER WARNING] Fail to remove file(%s)", STT_TIME_INFO_PATH); */
1107         }
1108
1109         return 0;
1110 }