From ba4ff464b3e382cfc0ac2f806f383c11752a8d8c Mon Sep 17 00:00:00 2001 From: Jehan Monnier Date: Fri, 31 Aug 2012 18:17:27 +0200 Subject: [PATCH] add access to country code from iso name --- coreapi/linphonecore_utils.h | 10 +++++++++- coreapi/proxy.c | 24 ++++++++++++++++++------ 2 files changed, 27 insertions(+), 7 deletions(-) diff --git a/coreapi/linphonecore_utils.h b/coreapi/linphonecore_utils.h index bd41ec2b..96438568 100644 --- a/coreapi/linphonecore_utils.h +++ b/coreapi/linphonecore_utils.h @@ -86,7 +86,15 @@ typedef bool_t (*LinphoneCoreIterateHook)(void *data); void linphone_core_add_iterate_hook(LinphoneCore *lc, LinphoneCoreIterateHook hook, void *hook_data); void linphone_core_remove_iterate_hook(LinphoneCore *lc, LinphoneCoreIterateHook hook, void *hook_data); - +/** + * @ingroup misc + *Function to get call country code from ISO 3166-1 alpha-2 code, ex: FR returns 33 + *@param iso country code alpha2 + *@return call country code or -1 if not found + */ +int linphone_dial_plan_lookup_ccc_from_iso(const char* iso); + + #ifdef __cplusplus } #endif diff --git a/coreapi/proxy.c b/coreapi/proxy.c index bb01f14e..47fe08bd 100644 --- a/coreapi/proxy.c +++ b/coreapi/proxy.c @@ -375,21 +375,33 @@ bool_t linphone_proxy_config_get_dial_escape_plus(const LinphoneProxyConfig *cfg */ typedef struct dial_plan{ const char *country; + const char* iso_country_code; /* ISO 3166-1 alpha-2 code, ex: FR for France*/ char ccc[8]; /*country calling code*/ int nnl; /*maximum national number length*/ const char * icp; /*international call prefix, ex: 00 in europe*/ + }dial_plan_t; /* TODO: fill with information for all countries over the world*/ static dial_plan_t const dial_plans[]={ - {"France" , "33" , 9 , "00" }, - {"United States", "1" , 10 , "011" }, - {"Turkey" , "90" , 10 , "00" }, - {"Switzerland" , "41" , 9 , "00" }, - {NULL , "" , 0 , NULL } + {"France" ,"FR" , "33" , 9 , "00" }, + {"United States" ,"US" , "1" , 10 , "011" }, + {"Turkey" ,"TR" , "90" , 10 , "00" }, + {"Switzerland" ,"XK" , "41" , 9 , "00" }, + {NULL ,NULL,"" , 0 , NULL } }; -static dial_plan_t most_common_dialplan={ "generic" , "", 10, "00"}; +static dial_plan_t most_common_dialplan={ "generic" ,"", "", 10, "00"}; + +int linphone_dial_plan_lookup_ccc_from_iso(const char* iso) { + dial_plan_t* dial_plan; + for (dial_plan=(dial_plan_t*)dial_plans; dial_plan->country!=NULL; dial_plan++) { + if (strcmp(iso, dial_plan->iso_country_code)==0) { + return atoi(dial_plan->ccc); + } + } + return -1; +} static void lookup_dial_plan(const char *ccc, dial_plan_t *plan){ int i; -- 2.39.2