* limitations under the License.
*
*/
-
#ifndef __TIZEN_TELEPHONY_PHONE_NUMBER_UTILS_H__
#define __TIZEN_TELEPHONY_PHONE_NUMBER_UTILS_H__
* @return @c 0 on success,
* otherwise a negative error value
*
- * @retval #PHONE_NUMBER_ERROR_NONE Successful
- * @retval #PHONE_NUMBER_ERROR_OUT_OF_MEMORY Out of memory
- * @retval #PHONE_NUMBER_ERROR_INVALID_PARAMETER Invalid parameter
- * @retval #PHONE_NUMBER_ERROR_FILE_NO_SPACE_ON_DEVICE FS Full
- * @retval #PHONE_NUMBER_ERROR_PERMISSION_DENIED Permission denied
- * @retval #PHONE_NUMBER_ERROR_NOT_SUPPORTED Not supported
- * @retval #PHONE_NUMBER_ERROR_NO_DATA Requested data does not exist
+ * @retval #PHONE_NUMBER_ERROR_NONE Successful
+ * @retval #PHONE_NUMBER_ERROR_OUT_OF_MEMORY Out of memory
+ * @retval #PHONE_NUMBER_ERROR_INVALID_PARAMETER Invalid parameter
+ * @retval #PHONE_NUMBER_ERROR_FILE_NO_SPACE_ON_DEVICE FS Full
+ * @retval #PHONE_NUMBER_ERROR_PERMISSION_DENIED Permission denied
+ * @retval #PHONE_NUMBER_ERROR_NOT_SUPPORTED Not supported
+ * @retval #PHONE_NUMBER_ERROR_NO_DATA Requested data does not exist
*
*/
-int phone_number_get_location_from_number(const char *number, phone_number_region_e region, phone_number_lang_e language, char **location);
+int phone_number_get_location_from_number(const char *number,
+ phone_number_region_e region, phone_number_lang_e language, char **location);
/**
* @brief This function gets the formatted number.
* @return @c 0 on success,
* otherwise a negative error value
*
- * @retval #PHONE_NUMBER_ERROR_NONE Successful
- * @retval #PHONE_NUMBER_ERROR_OUT_OF_MEMORY Out of memory
- * @retval #PHONE_NUMBER_ERROR_INVALID_PARAMETER Invalid parameter
- * @retval #PHONE_NUMBER_ERROR_FILE_NO_SPACE_ON_DEVICE FS Full
- * @retval #PHONE_NUMBER_ERROR_PERMISSION_DENIED Permission denied
- * @retval #PHONE_NUMBER_ERROR_NOT_SUPPORTED Not supported
- * @retval #PHONE_NUMBER_ERROR_NO_DATA Requested data does not exist
+ * @retval #PHONE_NUMBER_ERROR_NONE Successful
+ * @retval #PHONE_NUMBER_ERROR_OUT_OF_MEMORY Out of memory
+ * @retval #PHONE_NUMBER_ERROR_INVALID_PARAMETER Invalid parameter
+ * @retval #PHONE_NUMBER_ERROR_FILE_NO_SPACE_ON_DEVICE FS Full
+ * @retval #PHONE_NUMBER_ERROR_PERMISSION_DENIED Permission denied
+ * @retval #PHONE_NUMBER_ERROR_NOT_SUPPORTED Not supported
+ * @retval #PHONE_NUMBER_ERROR_NO_DATA Requested data does not exist
*
*/
-int phone_number_get_formatted_number(const char *number, phone_number_region_e region, char **formatted_number);
+int phone_number_get_formatted_number(const char *number, phone_number_region_e region,
+ char **formatted_number);
/**
* @}
}
#endif
-#endif // __TIZEN_TELEPHONY_PHONE_NUMBER_UTILS_H__
\ No newline at end of file
+#endif /* __TIZEN_TELEPHONY_PHONE_NUMBER_UTILS_H__ */
* limitations under the License.
*
*/
-
#include <stdio.h>
#include <stdlib.h>
#include <fcntl.h>
int phn_location_find_extra_data(const char *region_str, char **p_location_file)
{
- char *location_file = NULL;
DIR *dirp = NULL;
+ struct dirent **dir_list;
+ char *location_file = NULL;
+
dirp = opendir(PHN_LOCATION_DIR);
if (NULL == dirp) {
ERR("opendir() return NULL");
return PHONE_NUMBER_ERROR_NO_DATA;
}
- struct dirent **dir_list;
+
int count = scandir(PHN_LOCATION_DIR, &dir_list, 0, alphasort);
if (count) {
int idx = 0;
char location_prefix[PHN_STR_SHORT_LEN] = {0};
- snprintf(location_prefix, sizeof(location_prefix), "%s-%s", PHN_LOCATION_FILE_PREFIX, region_str);
+
+ snprintf(location_prefix, sizeof(location_prefix), "%s-%s",
+ PHN_LOCATION_FILE_PREFIX, region_str);
while (idx != count) {
const char *file_name = dir_list[idx]->d_name;
if (0 == strncmp(file_name, location_prefix, strlen(location_prefix))) {
*p_location_file = location_file;
return PHONE_NUMBER_ERROR_NONE;
}
+
return PHONE_NUMBER_ERROR_NO_DATA;
}
phone_number_region_e region, phone_number_lang_e lang, char **p_location)
{
int ret = 0;
- gchar* province_temp = NULL;
- gchar* city_temp = NULL;
- int province_str_len = 0;
int city_str_len = 0;
- const gunichar2 *province_str = NULL;
- const gunichar2 *city_str = NULL;
+ int province_str_len = 0;
+ size_t read_size;
+ gchar *city_temp = NULL;
+ gchar *province_temp = NULL;
const char *real_number = number;
+ const gunichar2 *city_str = NULL;
+ const gunichar2 *province_str = NULL;
+ char file_path[PHN_STR_SHORT_LEN] = {0};
- // support region - CN, support lang - zh,en,ko
- RETVM_IF(region != PHONE_NUMBER_REGION_CHINA, PHONE_NUMBER_ERROR_NOT_SUPPORTED, "Not supported region(%d)", region);
+ /* support region - CN, support lang - zh,en,ko */
+ RETVM_IF(region != PHONE_NUMBER_REGION_CHINA, PHONE_NUMBER_ERROR_NOT_SUPPORTED,
+ "Not supported region(%d)", region);
int lang_index = 0;
switch (lang) {
return PHONE_NUMBER_ERROR_NOT_SUPPORTED;
}
- while (real_number && real_number[0] == '0') {
+ while (real_number && real_number[0] == '0')
real_number++;
- }
- RETVM_IF(NULL == real_number, PHONE_NUMBER_ERROR_INVALID_PARAMETER, "number=%s", number);
+ RETVM_IF(NULL == real_number, PHONE_NUMBER_ERROR_INVALID_PARAMETER, "number=%s",
+ number);
- char file_path[PHN_STR_SHORT_LEN] = {0};
snprintf(file_path, sizeof(file_path), "%s/%s", PHN_LOCATION_DIR, file);
+
int fd = open(file_path, O_RDONLY);
RETVM_IF(fd < 0, PHONE_NUMBER_ERROR_NOT_SUPPORTED, "open() Fail(%d)", errno);
- ret = lseek(fd, sizeof(int), SEEK_CUR); // start_mark
+ ret = lseek(fd, sizeof(int), SEEK_CUR); /* start_mark */
if (ret <= 0) {
ERR("lseek() Fail(%d)", errno);
close(fd);
gunichar2 name3[header.province_name_len[2]/2];
};
- #pragma pack(1)
+#pragma pack(1)
struct phn_telephone_city_info {
gint8 province_index;
gunichar2 city1[header.telephone_city_len[0]/2];
gint16 prefix;
};
- #pragma pack(1)
+#pragma pack(1)
struct phn_mobile_city_info {
gint8 province_index;
gunichar2 city1[header.mobile_city_len[0]/2];
};
struct phn_province_info province_info[header.province_count];
- ret = read(fd, &province_info, sizeof(struct phn_province_info)*header.province_count);
+ ret = read(fd, &province_info,
+ sizeof(struct phn_province_info)*header.province_count);
if (ret <= 0) {
ERR("read() Fail(%d)", errno);
close(fd);
}
struct phn_telephone_city_info telephone_city_info[header.telephone_city_count];
- ret = read(fd, &telephone_city_info, sizeof(struct phn_telephone_city_info)*header.telephone_city_count);
+ ret = read(fd, &telephone_city_info,
+ sizeof(struct phn_telephone_city_info)*header.telephone_city_count);
if (ret <= 0) {
ERR("read() Fail(%d)", errno);
close(fd);
}
int i;
- for (i=0;i<header.telephone_city_count;i++) {
+ for (i = 0; i < header.telephone_city_count; i++) {
+ gint8 provice_idx;
gint16 prefix = telephone_city_info[i].prefix;
char prefix_str[PHN_STR_SHORT_LEN] = {0};
- snprintf(prefix_str, sizeof(prefix_str), "%u", prefix);
+ snprintf(prefix_str, sizeof(prefix_str), "%u", prefix);
if (0 == strncmp(real_number, prefix_str, strlen(prefix_str))) {
- switch(lang_index) {
+ switch (lang_index) {
case 0:
city_str = telephone_city_info[i].city1;
city_str_len = header.telephone_city_len[0]/2;
break;
}
- if (0 < telephone_city_info[i].province_index && telephone_city_info[i].province_index <= header.province_count) {
- switch(lang_index) {
+ provice_idx = telephone_city_info[i].province_index;
+ if (0 < provice_idx && provice_idx <= header.province_count) {
+ switch (lang_index) {
case 0:
- province_str = province_info[telephone_city_info[i].province_index-1].name1;
+ province_str = province_info[provice_idx-1].name1;
province_str_len = header.province_name_len[0]/2;
break;
case 1:
- province_str = province_info[telephone_city_info[i].province_index-1].name2;
+ province_str = province_info[provice_idx-1].name2;
province_str_len = header.province_name_len[1]/2;
break;
case 2:
- province_str = province_info[telephone_city_info[i].province_index-1].name3;
+ province_str = province_info[provice_idx-1].name3;
province_str_len = header.province_name_len[2]/2;
break;
default:
}
}
- province_temp = g_utf16_to_utf8(province_str, province_str_len, NULL, NULL, NULL);
+ province_temp = g_utf16_to_utf8(province_str, province_str_len, NULL, NULL,
+ NULL);
city_temp = g_utf16_to_utf8(city_str, city_str_len, NULL, NULL, NULL);
if (city_temp && province_temp) {
char *location = calloc(size+3, sizeof(char));
snprintf(location, size+3, "%s, %s", city_temp, province_temp);
*p_location = location;
- }
- else if (city_temp) {
+ } else if (city_temp) {
int size = strlen(city_temp);
char *location = calloc(size+1, sizeof(char));
snprintf(location, size+1, "%s", city_temp);
if (region != PHONE_NUMBER_REGION_CHINA) {
ERR("Invalid region(%d)", region);
return PHONE_NUMBER_ERROR_NO_DATA;
- }
- else if (strlen(number) < PHN_LOCATION_CHINA_MOBILE_NUMBER_MIN_LEN) {
+ } else if (strlen(number) < PHN_LOCATION_CHINA_MOBILE_NUMBER_MIN_LEN) {
ERR("Invalid number(%s)", number);
return PHONE_NUMBER_ERROR_INVALID_PARAMETER;
}
struct phn_mobile_city_info mobile_city_info[header.mobile_city_count];
- ret = read(fd, &mobile_city_info, sizeof(struct phn_mobile_city_info)*header.mobile_city_count);
+ read_size = sizeof(struct phn_mobile_city_info)*header.mobile_city_count;
+ ret = read(fd, &mobile_city_info, read_size);
if (ret <= 0) {
ERR("read() Fail(%d)", errno);
close(fd);
}
gint16 mobile_prefix_info[header.mobile_prefix_index_count];
- ret = read(fd, &mobile_prefix_info, sizeof(gint16)*header.mobile_prefix_index_count);
+ read_size = sizeof(gint16)*header.mobile_prefix_index_count;
+ ret = read(fd, &mobile_prefix_info, read_size);
if (ret <= 0) {
ERR("read() Fail(%d)", errno);
close(fd);
int num_prefix = atoi(num_prefix_str);
int num_suffix = atoi(num_suffix_str);
- for (i=0;i<header.mobile_prefix_index_count;i++) {
+ for (i = 0; i < header.mobile_prefix_index_count; i++) {
if (num_prefix == mobile_prefix_info[i]) {
gint16 mobile_prefix = 0;
- ret = lseek(fd, PHN_LOCATION_CHINA_MOBILE_SUFFIX_OFFSET*sizeof(gint16)*i + num_suffix*sizeof(gint16), SEEK_CUR);
+ ret = lseek(fd, (PHN_LOCATION_CHINA_MOBILE_SUFFIX_OFFSET*sizeof(gint16)*i)
+ + (num_suffix*sizeof(gint16)), SEEK_CUR);
ret = read(fd, &mobile_prefix, sizeof(gint16));
WARN_IF(ret < 0, "read() Fail(%d)", errno);
}
}
- province_temp = g_utf16_to_utf8(province_str, province_str_len, NULL, NULL, NULL);
+ province_temp = g_utf16_to_utf8(province_str, province_str_len, NULL, NULL,
+ NULL);
city_temp = g_utf16_to_utf8(city_str, city_str_len, NULL, NULL, NULL);
if (city_temp && province_temp) {
char *location = calloc(size+3, sizeof(char));
snprintf(location, size+3, "%s, %s", city_temp, province_temp);
*p_location = location;
- }
- else if (city_temp) {
+ } else if (city_temp) {
int size = strlen(city_temp);
char *location = calloc(size+1, sizeof(char));
snprintf(location, size+1, "%s", city_temp);