use phone_number_get_normalized_number API 78/51178/2
authorGukhwan Cho <gh78.cho@samsung.com>
Thu, 5 Nov 2015 04:46:32 +0000 (13:46 +0900)
committerGukhwan Cho <gh78.cho@samsung.com>
Tue, 17 Nov 2015 07:51:19 +0000 (16:51 +0900)
Change-Id: Ie65a44a605587fe78826402a9a476a24de6e3ba2
Signed-off-by: Gukhwan Cho <gh78.cho@samsung.com>
packaging/contacts-service.spec
schema.sql
server/CMakeLists.txt
server/ctsvc_number_utils.c
server/ctsvc_server_setting.c
server/ctsvc_server_update.c

index fc7c8b1..c0b64af 100644 (file)
@@ -26,6 +26,7 @@ BuildRequires:  pkgconfig(cynara-session)
 BuildRequires:  pkgconfig(cynara-creds-socket)
 BuildRequires:  pkgconfig(capi-system-info)
 BuildRequires:  pkgconfig(icu-uc)
+BuildRequires:  pkgconfig(phonenumber-utils)
 Requires(post): /usr/bin/sqlite3, /bin/chmod, /bin/chown
 Requires(post): /sbin/ldconfig
 Requires(postun): /sbin/ldconfig
index e1fa401..bdcedd2 100755 (executable)
@@ -20,7 +20,7 @@
 
 --PRAGMA journal_mode = PERSIST;
 --PRAGMA journal_mode = TRUNCATE;
-PRAGMA user_version = 101;
+PRAGMA user_version = 102;
 
 CREATE TABLE persons
 (
index 9aa4a70..8c84860 100644 (file)
@@ -161,6 +161,7 @@ pkg_check_modules(ctsvc_server_pkgs REQUIRED
        cynara-session
        cynara-creds-socket
        capi-system-info
+       phonenumber-utils
 )
 
 FOREACH(flag ${ctsvc_server_pkgs_CFLAGS})
index 97f9845..b2403af 100644 (file)
@@ -23,6 +23,7 @@
 #include <TapiUtility.h>
 #include <ITapiNetwork.h>
 #include <sqlite3.h>
+#include <phone_number.h>
 
 #include "contacts.h"
 #include "ctsvc_internal.h"
@@ -753,11 +754,12 @@ static int __ctsvc_number_has_ip_and_cc(const char*number, int len, int *index)
 
 int ctsvc_normalize_number(const char *src, char *dest, int dest_size, bool replace_alphabet)
 {
-       int index;
-       int n;
-       char *cc = NULL;
-       int d_pos = 0;
-       int first_zero = 0;
+       int ret;
+       int d_pos;
+       int s_pos;
+       char *normalized_out = NULL;
+       char temp[dest_size];
+
 
        if (NULL == src) {
                CTS_ERR("The parameter(src) is NULL");
@@ -768,60 +770,27 @@ int ctsvc_normalize_number(const char *src, char *dest, int dest_size, bool repl
        if (d_pos <= 0)
                return d_pos;
 
-       cc = ctsvc_get_network_cc(false);
-       n = __ctsvc_number_has_ip_and_cc(src, d_pos-ctsvc_get_phonenumber_min_match_digit(), &index);
-
-       if (src[0] == '0'   /* remove first '0' */
-                       || (cc && cc[0] == '7' && src[0] == '8'))   /* Russian */
-               first_zero = 1;
-
-       /*
-        * 001 82 10 1234 5678 -> +82 10 1234 5678
-        * +001 82 10 1234 5678 -> +82 10 1234 5678
-        * 82 10 1234 5678 -> +82 10 1234 5678
-        * add '+'
-        * do not append + if the number without cc is too short
-        * cc 010-1234-5678 ==> +cc 010-1234-5678, cc3456 => cc3456
-        */
-       if (CTSVC_IP_CC == n || CTSVC_CC_ONLY == n) {
-               if (d_pos + 1 < dest_size) {
-                       dest[0] = '+';
-                       memcpy(dest+1, src, d_pos+1);
-                       d_pos++;
-                       dest[d_pos] = 0;
-                       return d_pos;
-               }
+       d_pos = 0;
+       s_pos = 0;
+       if (src[s_pos] == '+')
+               temp[d_pos++] = src[s_pos++];
+       while (src[s_pos] != 0) {
+               if (src[s_pos] == '+' || src[s_pos] == ';')
+                       s_pos++;
+               temp[d_pos++] = src[s_pos++];
        }
-       else if (CTSVC_PLUS_ONLY == n || CTSVC_PLUS_CC_ONLY == n
-                || CTSVC_PLUS_IP_ONLY == n || CTSVC_PLUS_IP_CC == n) {
-               if (d_pos < dest_size) {
-                       /* Just copy */
-                       memcpy(dest, src, d_pos+1);
-                       dest[d_pos] = 0;
-                       return d_pos;
-               }
+       temp[d_pos] = 0;
+
+       ret = phone_number_get_normalized_number(temp, &normalized_out);
+       if (PHONE_NUMBER_ERROR_NONE == ret) {
+               d_pos = strlen(normalized_out);
+               memcpy(dest, normalized_out, d_pos+1);
+               free(normalized_out);
        }
-       /* append country code */
-       else {  /* CTSVC_NONE,        invalid case : CTSVC_IP_ONLY */
-               if (cc && ctsvc_get_phonenumber_min_match_digit() <= d_pos) {
-                       /*
-                        * add '+cc'
-                        * do not append cc if the number is too short
-                        * 010-1234-5678 ==> +cc 10-1234-5678, 1234 ==> 1234
-                        * 8 XXX-XXX-XX-XX ===> +7 XXX-XXX-XX-XX
-                        */
-                       if (d_pos + strlen(cc) + 1 < dest_size) {
-                               dest[0] = '+';
-                               memcpy(dest+1, cc, strlen(cc));
-                               memcpy(dest+1+strlen(cc), src+first_zero, d_pos+1-first_zero);
-                               d_pos += (1+strlen(cc));
-                               dest[d_pos] = 0;
-                               return d_pos;
-                       }
-               }
+       else {
+               memcpy(dest, temp, d_pos+1);
        }
 
-       memcpy(dest, src, d_pos+1);
        dest[d_pos] = 0;
 
        return d_pos;
index 535dee5..2d87e05 100644 (file)
@@ -200,6 +200,15 @@ void ctsvc_deregister_vconf(void)
 
 int ctsvc_get_phonenumber_min_match_digit(void)
 {
+       int ret = 0;
+       if (phonenumber_min_match_digit <= 0) {
+               ret = vconf_get_int(CTSVC_VCONF_PHONENUMBER_MIN_MATCH_DIGIT, &phonenumber_min_match_digit);
+               if (ret < 0) {
+                       CTS_ERR("vconf_get_int() Fail(%d)", ret);
+                       phonenumber_min_match_digit = 8;
+               }
+       }
+
        return phonenumber_min_match_digit;
 }
 
index 605cfcc..5599ffc 100644 (file)
@@ -34,7 +34,7 @@
  * You have to update user version schema.sql
  *                     PRAGMA user_version = 100;
  */
-#define CTSVC_SCHEMA_VERSION 101
+#define CTSVC_SCHEMA_VERSION 102
 
 #ifdef ENABLE_LOG_FEATURE
 static int __ctsvc_server_find_person_id_of_phonelog(sqlite3 *__db, char *normal_num,
@@ -155,7 +155,7 @@ static void __ctsvc_server_number_info_update(sqlite3 *__db)
                                sqlite3_bind_text(update_stmt, 1, normal_num, strlen(normal_num), SQLITE_STATIC);
                                ret = ctsvc_get_minmatch_number(normal_num, minmatch, sizeof(minmatch), ctsvc_get_phonenumber_min_match_digit());
                                if (CONTACTS_ERROR_NONE == ret) {
-                                       sqlite3_bind_text(stmt, 3, minmatch, strlen(minmatch), SQLITE_STATIC);
+                                       sqlite3_bind_text(update_stmt, 3, minmatch, strlen(minmatch), SQLITE_STATIC);
                                        find_person_id  = __ctsvc_server_find_person_id_of_phonelog(__db, normal_num, minmatch, person_id, &number_type);
                                }
 
@@ -212,7 +212,7 @@ static void __ctsvc_server_number_info_update(sqlite3 *__db)
                                sqlite3_bind_text(update_stmt, 2, normal_num, strlen(normal_num), SQLITE_STATIC);
                                ret = ctsvc_get_minmatch_number(normal_num, minmatch, sizeof(minmatch), ctsvc_get_phonenumber_min_match_digit());
                                if (CONTACTS_ERROR_NONE == ret)
-                                       ctsvc_stmt_bind_text(stmt, 1, minmatch);
+                                       ctsvc_stmt_bind_text(update_stmt, 1, minmatch);
                        }
                        sqlite3_bind_int(update_stmt, 4, id);
                        ret = sqlite3_step(update_stmt);
@@ -410,6 +410,13 @@ int ctsvc_server_db_update(void)
                old_version = 101;
        }
 
+       if (old_version <= 101) {
+               /* update phonelog, data number value */
+               __ctsvc_server_number_info_update(__db);
+
+               old_version = 102;
+       }
+
        snprintf(query, sizeof(query),
                        "PRAGMA user_version = %d", CTSVC_SCHEMA_VERSION);
        ret = sqlite3_exec(__db, query, NULL, 0, &errmsg);