Make TIZEN 2.0
[apps/home/call.git] / call-engine / core / vc-core-util.c
1 /*
2  * Copyright 2012  Samsung Electronics Co., Ltd
3  *
4  * Licensed under the Flora License, Version 1.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.tizenopensource.org/license
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16
17 #include <stdbool.h>
18 #include <assert.h>
19 #include "vc-core-engine.h"
20 #include "vc-core-util.h"
21 #include "vc-core-callagent.h"
22 #include "vc-core-callmanager.h"
23
24 #include <sys/time.h>
25 #include <sys/times.h>
26 #include <unistd.h>
27 #include <pmapi.h>
28
29 #include <unicode/uloc.h>
30 #include <unicode/udat.h>
31 #include <unicode/udatpg.h>
32 #include <unicode/ustring.h>
33
34 #include "appcore-common.h"
35
36 #define CALL_VODAFONEUK_CLI_SHOW_ID "1470"
37 #define CALL_COMMON_CLI_SHOW_ID "*31#"
38 #define CALL_COMMON_CLI_HIDE_ID "#31#"
39
40 #define ASCII_0         48
41 #define ASCII_9         57
42 #define ASCII_A         65
43 #define ASCII_D         68
44 #define ASCII_STAR      42
45 #define ASCII_HASH      35
46 #define ASCII_P         80
47 #define ASCII_p         112
48 #define ASCII_COMMA     44
49 #define ASCII_W                         87
50 #define ASCII_w                         119
51 #define ASCII_SEMI_COLON        59
52
53 #define EIGTH_BIT       0x80
54 #define SEVENTH_BIT 0x40
55 #define SIXTH_BIT       0x20
56 #define FIFTH_BIT       0x10
57 #define FOURTH_BIT      0x08
58 #define THIRD_BIT       0x04
59 #define SECOND_BIT      0x02
60 #define FIRST_BIT       0x01
61
62 #define CALLVC_MIN(x, y) ((x) <= (y) ? (x) : (y))
63 #define ISUSSDDIGIT(X) ((X >= '2') && (X <= '9'))
64 #define ISDIGIT(X) ((X >= '0') && (X <= '9'))
65 #define ISSSDIGITINCALL(X) ((X >= '7') && (X <= '9'))
66 #define IS1CHARUSSDDIGIT(X) ((X >= '1') && (X <= '9'))
67
68 #define DATE_FORMAT_1 "EEMMMddyyyy"     /* Thu Aug 23 2001 */
69 #define TIME_12_TYPE "hma"      /* 7:58 AM */
70 #define TIME_24_TYPE "HHmm"     /* 19:58 */
71
72 /**
73  * This function publishes the event of a given publish type
74  *
75  * @return              Returns TRUE on success and FALSE on failure
76  * @param[in]           src             Telehone number from which call number needd to be parsed
77  * @param[out]          dst             Pointer to the buffer to store the parsed number
78  */
79 gboolean _vc_core_util_remove_invalid_chars(const char *src, char *dst)
80 {
81         VOICECALL_RETURN_FALSE_IF_FAIL((src != NULL));
82         VOICECALL_RETURN_FALSE_IF_FAIL((dst != NULL));
83
84         CALL_ENG_DEBUG(ENG_DEBUG, "Source phone number - %s", src);
85         int i = 0;
86         int j = 0;
87         int nSrc = 0;
88
89         nSrc = strlen(src);
90         CALL_ENG_DEBUG(ENG_DEBUG, "source String len - %d", nSrc);
91
92         for (i = 0; i < nSrc; ++i) {
93                 switch (src[i]) {
94                 case '(':
95                         {
96                                 if (src[i + 1] == '0')
97                                         ++i;
98                                 break;
99                         }
100
101                 case ')':
102                 case '-':
103                 case ' ':
104                 case '/':
105                         {
106                                 break;
107                         }
108
109                 default:
110                         {
111                                 dst[j++] = src[i];
112                                 break;
113                         }
114                 }
115                 if (j > 40) {
116                         break;
117                 }
118         }
119
120         dst[j] = '\0';
121         CALL_ENG_DEBUG(ENG_DEBUG, "Destination phone number - %s", dst);
122
123         return TRUE;
124 }
125
126 /**
127  * This function publishes the event of a given publish type
128  *
129  * @return              Returns TRUE on success and FALSE on failure
130  * @param[in]           pszTelNumber            Telehone number from which call number nned to be extracted
131  * @param[out]  pBuffer                 Pointer to the buffer to store the extracted number
132  * @param[in]           nBufSize                        Size of input buffer
133  */
134 gboolean _vc_core_util_extract_call_number(const char *pszTelNumber, char *pBuffer, const int nBufSize)
135 {
136         char *pszNum = NULL;
137         char *pst = NULL;
138
139         VOICECALL_RETURN_FALSE_IF_FAIL((pBuffer != NULL));
140         VOICECALL_RETURN_FALSE_IF_FAIL((pszTelNumber != NULL));
141
142         CALL_ENG_DEBUG(ENG_DEBUG, "number = %s..", pszTelNumber);
143
144         memset(pBuffer, 0, nBufSize);
145
146         if ((strncmp(pszTelNumber, CALL_COMMON_CLI_SHOW_ID, 4) == 0) || (strncmp(pszTelNumber, CALL_COMMON_CLI_HIDE_ID, 4) == 0))
147                 pszNum = (char *)pszTelNumber + 4;
148         else
149                 pszNum = (char *)pszTelNumber;
150
151         pst = pszNum;
152         while (*pst != '\0') {
153                 if (*pst == 'P' || *pst == 'p' || *pst == ',' || *pst == 'W' || *pst == 'w' || *pst == ';') {
154                         break;
155                 }
156                 pst++;
157         }
158
159         if (strlen(pst) == 0) {
160                 if (strlen(pszNum) == 0)
161                         return FALSE;
162                 _vc_core_util_strcpy(pBuffer, nBufSize, pszNum);
163         } else {
164                 if (pst == pszNum)
165                         return FALSE;
166
167                 _vc_core_util_strcpy(pBuffer, min((((int)pst - (int)pszNum) + 1), (nBufSize)), pszNum);
168         }
169         return TRUE;
170 }
171
172 gboolean _vc_core_util_extract_call_number_without_cli(const char *pszTelNumber, char *pBuffer, const int nBufSize)
173 {
174         char *pszNum = NULL;
175         char *pst = NULL;
176
177         VOICECALL_RETURN_FALSE_IF_FAIL((pszTelNumber != NULL));
178         VOICECALL_RETURN_FALSE_IF_FAIL((pBuffer != NULL));
179
180         CALL_ENG_DEBUG(ENG_DEBUG, "number = %s..", pszTelNumber);
181
182         memset(pBuffer, 0, nBufSize);
183         pszNum = (char *)pszTelNumber;
184         pst = pszNum;
185         while (*pst != '\0') {
186                 if (*pst == 'P' || *pst == 'p' || *pst == ',' || *pst == 'W' || *pst == 'w' || *pst == ';') {
187                         break;
188                 }
189                 pst++;
190         }
191         if (strlen(pst) == 0) {
192                 if (strlen(pszNum) == 0)
193                         return FALSE;
194                 _vc_core_util_strcpy(pBuffer, nBufSize, pszNum);
195         } else {
196                 if (pst == pszNum)
197                         return FALSE;
198
199                 _vc_core_util_strcpy(pBuffer, min((((int)pst - (int)pszNum) + 1), (nBufSize)), pszNum);
200         }
201         return TRUE;
202 }
203
204 /**
205 * This function checks the validity of the given string for SS string
206  *
207 * @return               Returns SS_SI_FORMAT_INVALID - if the string is invalid ss string, SS_SI_FORMAT_VALID - if valid
208 * @param[in]    pinput_string   string to be verified
209  */
210 call_vc_ss_si_format _vc_core_util_check_si_format(const char *pinput_string)
211 {
212         int index = 0, pos = 1, cnt = 0;
213         VOICECALL_RETURN_VALUE_IF_FAIL((pinput_string != NULL), SS_SI_FORMAT_INVALID);
214
215         if ((pinput_string[1] == '*') || (pinput_string[1] == '#'))
216                 pos = 2;
217
218         index = pos;
219
220         while (cnt < 1) {
221                 if (pinput_string[index++] == '*')
222                         cnt++;
223
224                 if (index >= strlen(pinput_string + pos)) {
225                         CALL_ENG_DEBUG(ENG_DEBUG, "valid ss format...");
226                         return SS_SI_FORMAT_VALID;
227                 }
228         }
229
230         return SS_SI_FORMAT_VALID;
231 }
232
233 gboolean _vc_core_util_get_mcc(unsigned long *mcc)
234 {
235         int ret = 0;
236         int plmn_value = 0;
237
238         VOICECALL_RETURN_FALSE_IF_FAIL((mcc != NULL));
239
240         ret = vconf_get_int(VCONFKEY_TELEPHONY_PLMN, &plmn_value);
241         if (0 == ret) {
242                 char mcc_value[4];
243                 char plmn_string[10];
244
245                 CALL_ENG_DEBUG(ENG_DEBUG, "plmn_value = [%d]", plmn_value);
246
247                 memset(plmn_string, 0, sizeof(plmn_string));
248                 memset(mcc_value, 0, sizeof(mcc_value));
249
250                 snprintf(plmn_string, 10, "%d", plmn_value);
251
252                 /*First 3 digits of plmn value constitutes the mcc value */
253                 _vc_core_util_strcpy(mcc_value, 4, plmn_string);
254                 *mcc = (unsigned long)atoi(mcc_value);
255         } else {
256                 CALL_ENG_DEBUG(ENG_ERR, "vconf_get_int failed..[%d]", ret);
257                 *mcc = CALL_NETWORK_MCC_UK;
258         }
259         CALL_ENG_DEBUG(ENG_DEBUG, "mcc = %ld", *mcc);
260
261         return TRUE;
262 }
263
264 gboolean _vc_core_util_get_mnc(unsigned long *mnc)
265 {
266         int ret = 0;
267         int plmn_value = 0;
268
269         VOICECALL_RETURN_FALSE_IF_FAIL((mnc != NULL));
270
271         ret = vconf_get_int(VCONFKEY_TELEPHONY_PLMN, &plmn_value);
272         if (0 == ret) {
273                 char mnc_value[4];
274                 char plmn_string[10];
275
276                 CALL_ENG_DEBUG(ENG_DEBUG, "plmn_value = [%d]", plmn_value);
277
278                 memset(plmn_string, 0, sizeof(plmn_string));
279                 memset(mnc_value, 0, sizeof(mnc_value));
280
281                 snprintf(plmn_string, 10, "%d", plmn_value);
282
283                 /* 4~6th digits of plmn value constitutes the mnc value */
284                 _vc_core_util_strcpy(mnc_value, 4, &plmn_string[3]);
285                 *mnc = (unsigned long)atoi(mnc_value);
286         } else {
287                 CALL_ENG_DEBUG(ENG_ERR, "vconf_get_int failed..[%d]", ret);
288                 *mnc = CALL_NETWORK_MNC_01;
289         }
290         CALL_ENG_DEBUG(ENG_DEBUG, "mnc = %ld", *mnc);
291
292         return TRUE;
293 }
294
295 /**
296  * This function checks whether the given number is SS string or not
297  *
298  * @return              TRUE if the number is SS string, FALSE otherwise
299  * @param[in]           pNumber         number to be verified
300  */
301 gboolean _vc_core_util_check_ss_string(const char *pNumber)
302 {
303         int len;
304         VOICECALL_RETURN_FALSE_IF_FAIL(pNumber != NULL);
305         CALL_ENG_DEBUG(ENG_DEBUG, "pNumber(%s)", pNumber);
306
307         len = strlen(pNumber);
308
309         if (len > 3) {
310                 if (pNumber[len - 1] == '#') {
311                         if (pNumber[0] == '*' || pNumber[0] == '#') {
312                                 return TRUE;
313                         }
314                 } else {
315                         /*
316                          * '*31#', '#31#' -> launch CISS
317                          * '*31#nn..', '#31#nn...' -> launch Voice-call
318                          */
319                         if (strncmp(pNumber, CALL_COMMON_CLI_SHOW_ID, 4) == 0 || strncmp(pNumber, CALL_COMMON_CLI_HIDE_ID, 4) == 0) {
320                                 if (len > 4)
321                                         return FALSE;
322                                 return TRUE;
323                         }
324                 }
325         }
326
327         if ((len == 2) && (ISUSSDDIGIT(pNumber[0]) && ISDIGIT(pNumber[1]))) {
328                 CALL_ENG_DEBUG(ENG_DEBUG, "USSD string");
329                 return TRUE;
330         }
331
332         if ((len == 1) && (IS1CHARUSSDDIGIT(pNumber[0]))) {
333                 CALL_ENG_DEBUG(ENG_DEBUG, "1 character USSD string");
334                 return TRUE;
335         }
336
337         return FALSE;
338 }
339
340 /**
341  * This function checks whether the given number is in CALL SS string or not
342  *
343  * @return              TRUE if the number is in call SS string, FALSE otherwise
344  * @param[in]           pNumber         number to be verified
345  */
346 gboolean _vc_core_util_check_incall_ss_string(const char *number)
347 {
348         int len;
349         int num_int;
350         VOICECALL_RETURN_FALSE_IF_FAIL(number != NULL);
351         CALL_ENG_DEBUG(ENG_DEBUG, "number(%s)", number);
352
353         len = strlen(number);
354         if (len > 2 || len < 1)
355                 return FALSE;
356
357         if (number[0] > '6')
358                 return FALSE;
359
360         if (len == 1) {
361                 /* 0 ~ 4 */
362                 if (number[0] >= '0' && number[0] <= '4')
363                         return TRUE;
364         } else {
365                 /* 11 ~ 17, 21 ~ 27 */
366                 num_int = atoi(number);
367
368                 if (num_int >= 11 && num_int <= 17)
369                         return TRUE;
370                 if (num_int >= 21 && num_int <= 27)
371                         return TRUE;
372         }
373
374         return FALSE;
375 }
376
377 /**
378 * This function extracts the dtmf number from the given telephone number
379 *
380 * @param[in]      tel_number            source telephone number
381 * @param[out] dtmf_number               extracted dtmf number
382 * @param[out] dtmf_buf_len              size of dtmf number buffer
383 */
384 gboolean _vc_core_util_extract_dtmf_number(const char *tel_number, char *dtmf_number, const int dtmf_buf_len)
385 {
386         char *pst;
387         VOICECALL_RETURN_FALSE_IF_FAIL(tel_number != NULL);
388         VOICECALL_RETURN_FALSE_IF_FAIL(dtmf_number != NULL);
389
390         memset(dtmf_number, 0, dtmf_buf_len);
391
392         pst = (char *)tel_number;
393         while (*pst != '\0') {
394 #ifdef  WDIAL_SEND_DTMF
395                 if (*pst == 'P' || *pst == 'p' || *pst == ',' || *pst == 'W' || *pst == 'w' || *pst == ';') {
396 #else
397                 if (*pst == 'P' || *pst == 'p' || *pst == ',') {
398 #endif
399                         break;
400                 }
401                 pst++;
402         }
403
404         if (strlen(pst) == 0) {
405                 return FALSE;
406         } else {
407                 if (pst == tel_number)
408                         return FALSE;
409                 strncpy(dtmf_number, pst, CALLVC_MIN((int)strlen(pst), (dtmf_buf_len-1)));
410         }
411         return TRUE;
412 }
413
414 /**
415 * This function checks whether the given number ia a valid dtmf number or not
416 *
417 * @return               TRUE if the number can be used for sending dtmf , FALSE otherwise
418 * @param[in]            pnumber         number to be verified
419 */
420 gboolean _vc_core_util_isvalid_dtmf_number(char *pnumber)
421 {
422         int len = 0;
423         VOICECALL_RETURN_FALSE_IF_FAIL(pnumber != NULL);
424
425         CALL_ENG_DEBUG(ENG_DEBUG, "_vc_core_util_isvalid_dtmf_number.. entering");
426
427         if (NULL == pnumber || (len = strlen(pnumber)) <= 0) {
428                 return FALSE;
429         }
430
431         CALL_ENG_DEBUG(ENG_DEBUG, "Length = %d", len);
432         while (len > 0) {
433                 if (IS_DIGIT(pnumber[len - 1]) || (pnumber[len - 1] >= ASCII_A && pnumber[len - 1] <= ASCII_D) || (pnumber[len - 1] == ASCII_STAR || pnumber[len - 1] == ASCII_HASH)) {
434                         return TRUE;
435                 }
436                 len--;
437         }
438         return FALSE;
439 }
440
441 /**
442 * This function checks whether the given number ia a valid dtmf number or not
443 *
444 * @return               TRUE if the number can be used for sending dtmf , FALSE otherwise
445 * @param[in]            pnumber         number to be verified
446 */
447 gboolean _vc_core_util_isvalid_full_dtmf_number(char *pnumber)
448 {
449         int len = 0;
450         VOICECALL_RETURN_FALSE_IF_FAIL(pnumber != NULL);
451
452         CALL_ENG_DEBUG(ENG_DEBUG, "_vc_core_util_isvalid_dtmf_number.. entering");
453
454         if (NULL == pnumber || (len = strlen(pnumber)) <= 0) {
455                 return FALSE;
456         }
457
458         CALL_ENG_DEBUG(ENG_DEBUG, "Length = %d", len);
459         while (len > 0) {
460                 if (!(IS_DIGIT(pnumber[len - 1]) || (pnumber[len - 1] >= ASCII_A && pnumber[len - 1] <= ASCII_D) || \
461                                 (pnumber[len - 1] == ASCII_STAR || pnumber[len - 1] == ASCII_HASH) || \
462                                 (pnumber[len - 1] == ASCII_P || pnumber[len - 1] == ASCII_p || pnumber[len - 1] == ASCII_COMMA) || \
463                                 (pnumber[len - 1] == ASCII_W || pnumber[len - 1] == ASCII_w || pnumber[len - 1] == ASCII_SEMI_COLON))) {
464                         CALL_ENG_DEBUG(ENG_DEBUG, "invalid character encountered...");
465                         return FALSE;
466                 }
467                 len--;
468         }
469         CALL_ENG_DEBUG(ENG_DEBUG, "Fully valid DTMF string..");
470         return TRUE;
471 }
472
473 /**
474 * This function checks the validity of the given telephone number
475 *
476 * @return               TRUE if the given number is valid telephone number, FALSE otherwise
477 * @param[in]            ptel_number     telephone number to be verified
478 */
479 gboolean _vc_core_util_isvalid_telephone_number(char *ptel_number)
480 {
481         int len = 0;
482         int i = 0;
483         VOICECALL_RETURN_FALSE_IF_FAIL(ptel_number != NULL);
484
485         if (ptel_number != NULL) {
486                 char call_number[VC_PHONE_NUMBER_LENGTH_MAX] = { 0, };
487
488                 /* Function Test SLP-Call-0250 fixed.
489                  * If user Input "*" or "#" and then make a call,
490                  * the device should alert you that the phone number is incorrect.
491                  */
492                 /*if ((strlen(ptel_number) == 1) && ((strcmp(ptel_number, "*") == 0) ||(strcmp(ptel_number, "#") == 0))) */
493                 /* 1 digit number -> wrong number popup */
494                 if (strlen(ptel_number) == 1) {
495                         CALL_ENG_DEBUG(ENG_DEBUG, "It is wrong number.(1 digit number)");
496                         return FALSE;
497                 }
498                 /*end */
499
500                 /*To avoid checking *31# and #31# */
501                 if (_vc_core_util_extract_call_number(ptel_number, call_number, sizeof(call_number)) == FALSE) {
502                         CALL_ENG_DEBUG(ENG_DEBUG, "No proper number = %s", ptel_number);
503                         return FALSE;
504                 }
505
506                 len = strlen(call_number);
507                 for (i = 0; i < len; i++) {
508                         /*'+' should be allowed only as first digit of the dialling number */
509                         if (i >= 1 && call_number[i] == '+') {
510                                 return FALSE;
511                         }
512
513                         if (!IS_DIGIT(call_number[i]) && call_number[i] != '+' && call_number[i] != ASCII_STAR && call_number[i] != ASCII_HASH && call_number[i] != 'P' && call_number[i] != 'p' && call_number[i] != ',') {
514                                 return FALSE;
515                         }
516                 }
517                 return TRUE;
518         }
519         return FALSE;
520 }
521
522 gboolean _vc_core_util_check_gcf_status(void)
523 {
524         gboolean bgcf_status = FALSE;
525         int ret = -1;
526
527         ret = vconf_get_int(VCONFKEY_ADMIN_GCF_TEST, &bgcf_status);
528         if (0 == ret) {
529                 CALL_ENG_DEBUG(ENG_DEBUG, "bgcf_status = [%d]", bgcf_status);
530         } else {
531                 CALL_ENG_DEBUG(ENG_ERR, "vconf_get_int failed..[%d]", ret);
532         }
533
534         return bgcf_status;
535 }
536
537 gboolean _vc_core_util_check_zuhause_status(void)
538 {
539         int isZuhauseArea = 0;
540         int ret = -1;
541
542         ret = vconf_get_int(VCONFKEY_TELEPHONY_ZONE_ZUHAUSE, &isZuhauseArea);
543         if (0 == ret) {
544                 CALL_ENG_DEBUG(ENG_DEBUG, "isZuhauseArea = [%d]", isZuhauseArea);
545         } else {
546                 CALL_ENG_DEBUG(ENG_ERR, "vconf_get_int failed..[%d]", ret);
547         }
548
549         if (isZuhauseArea == 0) {
550                 /*Not in a zuhause area.. */
551                 return FALSE;
552         } else {
553                 /*in a zuhause area.. */
554                 return TRUE;
555         }
556 }
557
558 /*********************************************************************/
559 gboolean _vc_core_util_set_call_status(int call_status)
560 {
561         CALL_ENG_DEBUG(ENG_DEBUG, "call_status = [%d]", call_status);
562
563         if (vconf_set_int(VCONFKEY_CALL_STATE, call_status)) {
564                 CALL_ENG_DEBUG(ENG_DEBUG, "vconf_set_int failed.");
565                 return FALSE;
566         }
567         return TRUE;
568 }
569
570 gboolean _vc_core_util_set_call_volume(int vol_level)
571 {
572         CALL_ENG_DEBUG(ENG_DEBUG, "vol_level = [%d]", vol_level);
573
574         if (vconf_set_int(VCONFKEY_CALL_VOLUME_LEVEL, vol_level)) {
575                 CALL_ENG_DEBUG(ENG_WARN, "vconf_set_int failed.");
576                 return FALSE;
577         }
578         return TRUE;
579 }
580
581 int _vc_core_util_get_call_volume(void)
582 {
583         int vol_level = 0;
584
585         if (vconf_get_int(VCONFKEY_CALL_VOLUME_LEVEL, &vol_level)) {
586                 CALL_ENG_DEBUG(ENG_WARN, "vconf_set_int failed.");
587         }
588
589         CALL_ENG_DEBUG(ENG_DEBUG, "vol_level(%d)", vol_level);
590         return vol_level;
591 }
592
593 gboolean _vc_core_util_check_video_call_status(void)
594 {
595         int call_status = 0;
596         int ret = -1;
597
598         ret = vconf_get_int(VCONFKEY_CALL_STATE, &call_status);
599         if (0 == ret) {
600                 CALL_ENG_DEBUG(ENG_DEBUG, "call_status = [%d]", call_status);
601                 if (call_status == VCONFKEY_CALL_VIDEO_CONNECTING || call_status == VCONFKEY_CALL_VIDEO_ACTIVE) {
602                         return TRUE;
603                 }
604         } else {
605                 CALL_ENG_DEBUG(ENG_ERR, "vconf_get_int failed..[%d]", ret);
606         }
607         return FALSE;
608 }
609
610 gboolean _vc_core_util_get_SAP_status()
611 {
612         int bt_status = VCONFKEY_BT_DEVICE_NONE;
613         gboolean ret = FALSE;
614
615         ret = vconf_get_int(VCONFKEY_BT_DEVICE, &bt_status);
616         if (0 == ret) {
617                 CALL_ENG_DEBUG(ENG_DEBUG, "bt_status = [0x%x]", bt_status);
618         } else {
619                 CALL_ENG_DEBUG(ENG_ERR, "vconf_get_int failed..[%d]", ret);
620         }
621
622         if (bt_status == VCONFKEY_BT_DEVICE_SAP_CONNECTED) {
623                 return TRUE;
624         } else {
625                 return FALSE;
626         }
627 }
628
629 void _vc_core_util_get_cug_info(voicecall_setup_info_t *psetupcall_info)
630 {
631         VOICECALL_RETURN_IF_FAIL(psetupcall_info != NULL);
632         voicecall_cug_info_t *pcug_info = NULL;
633         /*int error_code = -1; */
634
635         pcug_info = (voicecall_cug_info_t *) &psetupcall_info->cug_info;
636
637         /*Get the CUG Information from the Settings */
638         memset(&psetupcall_info->cug_info, 0, sizeof(voicecall_cug_info_t));
639         pcug_info->bcug_used = 0;
640 }
641
642 void _vc_core_util_get_identity_mode(voicecall_setup_info_t *psetupcall_info)
643 {
644         int id_mode = 0;        /*0 - default, 1-show, 2-hide */
645         int ret = -1;
646         VOICECALL_RETURN_IF_FAIL(psetupcall_info != NULL);
647
648         ret = vconf_get_int(VCONFKEY_CISSAPPL_SHOW_MY_NUMBER_INT, &id_mode);
649         if (0 == ret) {
650                 CALL_ENG_DEBUG(ENG_DEBUG, "id_mode = [%d]", id_mode);
651                 psetupcall_info->identity_mode = id_mode;
652         } else {
653                 CALL_ENG_DEBUG(ENG_ERR, "vconf_get_int failed..[%d]", ret);
654                 psetupcall_info->identity_mode = 0;
655         }
656 }
657
658 gboolean _vc_core_util_is_offline_mode(void)
659 {
660         gboolean bstatus = -1;
661
662         if (vconf_get_bool(VCONFKEY_SETAPPL_FLIGHT_MODE_BOOL, &bstatus)) {
663                 CALL_ENG_DEBUG(ENG_ERR, "vconf_get_bool failed.");
664                 return FALSE;
665         }
666         CALL_ENG_DEBUG(ENG_DEBUG, "bstatus:[%d]", bstatus);
667
668         return bstatus;
669 }
670
671 gboolean _vc_core_util_is_pwlock(void)
672 {
673         int pwlock_state = -1;
674
675         if (vconf_get_int(VCONFKEY_PWLOCK_STATE, &pwlock_state)) {
676                 CALL_ENG_DEBUG(ENG_ERR, "vconf_get_int failed.");
677                 return FALSE;
678         }
679         CALL_ENG_DEBUG(ENG_DEBUG, "pwlock_state:[%d]", pwlock_state);
680         if ((pwlock_state == VCONFKEY_PWLOCK_BOOTING_LOCK) || (pwlock_state == VCONFKEY_PWLOCK_RUNNING_LOCK)) {
681                 return TRUE;
682         } else {
683                 return FALSE;
684         }
685 }
686
687 gboolean _vc_core_util_get_nw_status(int *network_status)
688 {
689         int svc_type = -1;
690         gboolean ret = FALSE;
691         VOICECALL_RETURN_FALSE_IF_FAIL(network_status != NULL);
692
693         ret = vconf_get_int(VCONFKEY_TELEPHONY_SVCTYPE, &svc_type);
694         if (0 == ret) {
695                 CALL_ENG_DEBUG(ENG_DEBUG, "svc_type = [%d]", svc_type);
696                 *network_status = svc_type;
697                 return TRUE;
698         } else {
699                 CALL_ENG_DEBUG(ENG_ERR, "vconf_get_int failed..[%d]", ret);
700                 return FALSE;
701         }
702 }
703
704 /* Function Definitions */
705 /**
706  * This function copies the source string to the target string according to the size of the destination string
707  *
708  * @return              Returns newly copied string on success or NULL on failure
709  * @param[out]  pbuffer         Target Buffer
710  * @param[in]           buf_count       Size of Target Buffer
711  * @param[in]           pstring         Source String
712  */
713 gboolean _vc_core_util_strcpy(char *pbuffer, int buf_count, const char *pstring)
714 {
715         VOICECALL_RETURN_FALSE_IF_FAIL(pbuffer != NULL);
716         VOICECALL_RETURN_FALSE_IF_FAIL(pstring != NULL);
717
718         if (buf_count == 0) {
719                 CALL_ENG_DEBUG(ENG_DEBUG, "buf_count is zero!!");
720                 return FALSE;
721         }
722 #ifdef _NO_USE_STRCPY_
723         if ((buf_count - 1) >= (int)strlen(pstring)) {
724                 strcpy(pbuffer, pstring);
725         } else {
726                 CALL_ENG_DEBUG(ENG_DEBUG, "pbuffer size is smaller than pstring!!");
727                 strncpy(pbuffer, pstring, (buf_count - 1));
728                 pbuffer[buf_count - 1] = '\0';
729         }
730 #else
731         strncpy(pbuffer, pstring, (buf_count - 1));
732         pbuffer[buf_count - 1] = '\0';
733 #endif
734         return TRUE;
735 }
736
737 /**
738  * This function make the date and time string
739  *
740  * @return              Returns newly copied string on success or NULL on failure
741  * @param[out]  pbuffer         Target Buffer
742  * @param[in]           time    time
743  */
744 char *_vc_core_util_get_date_time(time_t time)
745 {
746         UDate date;
747         const char *locale = uloc_getDefault();
748         UErrorCode status = U_ZERO_ERROR;
749         UDateTimePatternGenerator *generator;
750         UDateFormat *formatter;
751         UChar bestPattern[64] = { '\0', };
752         UChar formatted[64] = { '\0', };
753         char bestPatternString[128] = { '\0', };
754         char formattedString[128] = { '\0', };
755         int32_t bestPatternCapacity, formattedCapacity;
756         int32_t bestPatternLength, formattedLength;
757         char skeleton[128] = { '\0', };
758         UChar customSkeleton[64] = { '\0', };
759         enum appcore_time_format time_format;
760
761         appcore_get_timeformat(&time_format);
762
763         switch (time_format) {
764         case APPCORE_TIME_FORMAT_12:
765                 snprintf(skeleton, sizeof(skeleton), "%s%s", DATE_FORMAT_1, TIME_12_TYPE);
766                 break;
767         case APPCORE_TIME_FORMAT_24:
768                 snprintf(skeleton, sizeof(skeleton), "%s%s", DATE_FORMAT_1, TIME_24_TYPE);
769                 break;
770         case APPCORE_TIME_FORMAT_UNKNOWN:
771         default:
772                 snprintf(skeleton, sizeof(skeleton), "%s%s", DATE_FORMAT_1, TIME_24_TYPE);
773                 break;
774         }
775
776         u_uastrncpy(customSkeleton, skeleton, strlen(skeleton));
777
778         generator = udatpg_open(locale, &status);
779         bestPatternCapacity = (int32_t) (sizeof(bestPattern) / sizeof((bestPattern)[0]));
780
781         bestPatternLength = udatpg_getBestPattern(generator, customSkeleton, u_strlen(customSkeleton), bestPattern, bestPatternCapacity, &status);
782         u_austrncpy(bestPatternString, bestPattern, 128);
783
784         CALL_ENG_DEBUG(ENG_DEBUG, "BestPattern(%s)", bestPatternString);
785
786         date = (UDate) time * 1000;
787
788         formatter = udat_open(UDAT_IGNORE, UDAT_IGNORE, locale, NULL, -1, bestPattern, -1, &status);
789
790         /* UDAT_IGNORE Passed so that our best pattern is used in generating pattern */
791         formattedCapacity = (int32_t) (sizeof(formatted) / sizeof((formatted)[0]));
792         formattedLength = udat_format(formatter, date, formatted, formattedCapacity, NULL, &status);
793         u_austrncpy(formattedString, formatted, 128);
794         udatpg_close(generator);
795         udat_close(formatter);
796
797         CALL_ENG_DEBUG(ENG_DEBUG, "DATE & TIME(%s)", formattedString);
798         return g_strdup(formattedString);
799 }
800
801 gboolean _vc_core_util_phonelock_status(void)
802 {
803         gboolean b_phonelock = FALSE;
804         if (!vconf_get_bool(VCONFKEY_SETAPPL_STATE_POWER_ON_LOCK_BOOL, &b_phonelock)) {
805                 CALL_ENG_DEBUG(ENG_DEBUG, "b_phonelock:[%d]", b_phonelock);
806                 return b_phonelock;
807         } else {
808                 CALL_ENG_DEBUG(ENG_DEBUG, "get VCONFKEY_SETAPPL_STATE_POWER_ON_LOCK_BOOL failed..");
809                 return FALSE;
810         }
811 }
812
813 void _vc_core_util_download_test_call(char *result)
814 {
815         int ret;
816         FILE *d_call_test = NULL;
817         char string[20] = { };
818
819         VOICECALL_RETURN_IF_FAIL(result != NULL);
820
821         /*create string */
822         snprintf(string, sizeof(string), "/tmp/%s", result);
823
824         d_call_test = fopen(string, "w");
825         if (d_call_test == NULL) {
826                 CALL_ENG_DEBUG(ENG_DEBUG, "FAIL:fopen(%s)", string);
827                 return;
828         }
829         /*ret = fwrite("\0", sizeof(char), 1, d_call_test); */
830         /*CALL_ENG_DEBUG(ENG_DEBUG,"Result:fwrite(%d)", ret); */
831
832         ret = fclose(d_call_test);
833         CALL_ENG_DEBUG(ENG_DEBUG, "Result:fwrite(%d)", ret);
834         if (ret != 0) {
835                 CALL_ENG_DEBUG(ENG_DEBUG, "FAIL:fclose");
836                 return;
837         }
838
839 }