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