Commit 22339a0b authored by Sylvain Berfini's avatar Sylvain Berfini 🎩

DialPlan is now an hybrid object

parent d8dfb0d9
......@@ -463,15 +463,15 @@ LinphoneAccountCreatorPhoneNumberStatusMask linphone_account_creator_set_phone_n
}
// if phone is valid, we lastly want to check that length is OK in case phone_nunber was normilized
if (strcmp(normalized_phone_number,phone_number) != 0 || phone_number[0] != '+') {
const DialPlan &plan = DialPlan::findByCcc(creator->phone_country_code);
std::shared_ptr<DialPlan> plan = DialPlan::findByCcc(creator->phone_country_code);
int size = (int)strlen(phone_number);
if (plan.isGeneric()) {
if (plan->isGeneric()) {
return_status = LinphoneAccountCreatorPhoneNumberStatusInvalidCountryCode;
}
if (size < plan.getNationalNumberLength() - 1) {
if (size < plan->getNationalNumberLength() - 1) {
return_status += LinphoneAccountCreatorPhoneNumberStatusTooShort;
goto end;
} else if (size > plan.getNationalNumberLength() + 1) {
} else if (size > plan->getNationalNumberLength() + 1) {
return_status += LinphoneAccountCreatorPhoneNumberStatusTooLong;
goto end;
} else if (return_status & LinphoneAccountCreatorPhoneNumberStatusInvalidCountryCode) {
......
......@@ -38,7 +38,6 @@ Copyright (C) 2000 Simon MORLAT (simon.morlat@linphone.org)
#include "linphone/api/c-dial-plan.h"
#include "dial-plan/dial-plan.h"
#include "dial-plan/dial-plan-p.h"
using namespace LinphonePrivate;
......@@ -744,7 +743,7 @@ bool_t linphone_proxy_config_normalize_number(LinphoneProxyConfig *proxy, const
char* linphone_proxy_config_normalize_phone_number(LinphoneProxyConfig *proxy, const char *username) {
LinphoneProxyConfig *tmpproxy = proxy ? proxy : linphone_proxy_config_new();
char* result = NULL;
DialPlan dialplan;
std::shared_ptr<DialPlan> dialplan;
char * nationnal_significant_number = NULL;
int ccc = -1;
......@@ -755,9 +754,9 @@ char* linphone_proxy_config_normalize_phone_number(LinphoneProxyConfig *proxy, c
ccc = DialPlan::lookupCccFromE164(flatten);
if (ccc>-1) { /*e164 like phone number*/
dialplan = DialPlan::findByCcc(ccc);
nationnal_significant_number = strstr(flatten, dialplan.getCountryCallingCode().c_str());
nationnal_significant_number = strstr(flatten, dialplan->getCountryCallingCode().c_str());
if (nationnal_significant_number) {
nationnal_significant_number +=strlen(dialplan.getCountryCallingCode().c_str());
nationnal_significant_number +=strlen(dialplan->getCountryCallingCode().c_str());
}
} else if (flatten[0] =='+') {
ms_message ("Unknown ccc for e164 like number [%s]", flatten);
......@@ -769,14 +768,14 @@ char* linphone_proxy_config_normalize_phone_number(LinphoneProxyConfig *proxy, c
dialplan = DialPlan::MostCommon;
}
if (tmpproxy->dial_prefix){
if (strcmp(tmpproxy->dial_prefix,dialplan.getCountryCallingCode().c_str()) != 0){
if (strcmp(tmpproxy->dial_prefix,dialplan->getCountryCallingCode().c_str()) != 0){
//probably generic dialplan, preserving proxy dial prefix
dialplan.setCountryCallingCode(tmpproxy->dial_prefix);
dialplan->setCountryCallingCode(tmpproxy->dial_prefix);
}
/*it does not make sens to try replace icp with + if we are not sure from the country we are (I.E tmpproxy->dial_prefix==NULL)*/
if (strstr(flatten, dialplan.getInternationalCallPrefix().c_str()) == flatten) {
char *e164 = replace_icp_with_plus(flatten, dialplan.getInternationalCallPrefix().c_str());
if (strstr(flatten, dialplan->getInternationalCallPrefix().c_str()) == flatten) {
char *e164 = replace_icp_with_plus(flatten, dialplan->getInternationalCallPrefix().c_str());
result = linphone_proxy_config_normalize_phone_number(tmpproxy, e164);
ms_free(e164);
goto end;
......@@ -784,23 +783,23 @@ char* linphone_proxy_config_normalize_phone_number(LinphoneProxyConfig *proxy, c
}
nationnal_significant_number=flatten;
}
ms_debug("Using dial plan '%s'",dialplan.getCountry().c_str());
ms_debug("Using dial plan '%s'",dialplan->getCountry().c_str());
/*if proxy has a dial prefix, modify phonenumber accordingly*/
if (dialplan.getCountryCallingCode().c_str()[0]!='\0') {
if (dialplan->getCountryCallingCode().c_str()[0]!='\0') {
/* the number already starts with + or international prefix*/
/*0. keep at most national number significant digits */
char* nationnal_significant_number_start = nationnal_significant_number
+ MAX(0, (int)strlen(nationnal_significant_number)
- (int)dialplan.getNationalNumberLength());
ms_debug("Prefix not present. Keeping at most %d digits: %s", dialplan.getNationalNumberLength(), nationnal_significant_number_start);
- (int)dialplan->getNationalNumberLength());
ms_debug("Prefix not present. Keeping at most %d digits: %s", dialplan->getNationalNumberLength(), nationnal_significant_number_start);
/*1. First prepend international calling prefix or +*/
/*2. Second add prefix*/
/*3. Finally add user digits */
result = ms_strdup_printf("%s%s%s"
, tmpproxy->dial_escape_plus ? dialplan.getInternationalCallPrefix().c_str() : "+"
, dialplan.getCountryCallingCode().c_str()
, tmpproxy->dial_escape_plus ? dialplan->getInternationalCallPrefix().c_str() : "+"
, dialplan->getCountryCallingCode().c_str()
, nationnal_significant_number_start);
ms_debug("Prepended prefix resulted in %s", result);
}
......
......@@ -33,6 +33,16 @@
* @{
*/
/**
* Increases the reference counter of #LinphoneDialPlan objects.
*/
LINPHONE_PUBLIC LinphoneDialPlan *linphone_dial_plan_ref(LinphoneDialPlan *dp);
/**
* Decreases the reference counter of #LinphoneDialPaln objects.
*/
LINPHONE_PUBLIC void linphone_dial_plan_unref(LinphoneDialPlan *dp);
/**
* Returns the country name of the dialplan
* @return the country name
......@@ -87,7 +97,7 @@ LINPHONE_PUBLIC const LinphoneDialPlan* linphone_dial_plan_get_all(void);
/**
* @return \bctbx_list{LinphoneDialPlan} of all known dial plans
**/
LINPHONE_PUBLIC const bctbx_list_t * linphone_dial_plan_get_all_list(void);
LINPHONE_PUBLIC bctbx_list_t * linphone_dial_plan_get_all_list(void);
/**
* Find best match for given CCC
......
......@@ -115,16 +115,6 @@ LINPHONE_PUBLIC void linphone_chat_message_resend_2(LinphoneChatMessage *msg);
*/
LINPHONE_PUBLIC void *linphone_vcard_get_belcard(LinphoneVcard *vcard);
/**
* @brief Increases the reference counter of #LinphoneDialPlan objects.
*/
LINPHONE_PUBLIC LinphoneDialPlan *linphone_dial_plan_ref(LinphoneDialPlan *dp);
/**
* @brief Decreases the reference counter of #LinphoneDialPaln objects.
*/
LINPHONE_PUBLIC void linphone_dial_plan_unref(LinphoneDialPlan *dp);
/**
* @}
*/
......
......@@ -190,7 +190,6 @@ set(LINPHONE_CXX_OBJECTS_PRIVATE_HEADER_FILES
db/main-db-p.h
db/main-db.h
db/session/db-session.h
dial-plan/dial-plan-p.h
dial-plan/dial-plan.h
enums.h
event-log/conference/conference-call-event.h
......
......@@ -26,60 +26,59 @@
// =============================================================================
using namespace std;
using namespace LinphonePrivate;
L_DECLARE_C_CLONABLE_OBJECT_IMPL(DialPlan);
// TODO: Remove me later. Ugly workaround for C++ wrapper.
LinphoneDialPlan *linphone_dial_plan_ref (LinphoneDialPlan *dp) {
DialPlan::toCpp(dp)->ref();
return dp;
}
void linphone_dial_plan_unref (LinphoneDialPlan *) {}
void linphone_dial_plan_unref (LinphoneDialPlan *dp) {
DialPlan::toCpp(dp)->unref();
}
const char *linphone_dial_plan_get_country (const LinphoneDialPlan *dp) {
return L_STRING_TO_C(L_GET_CPP_PTR_FROM_C_OBJECT(dp)->getCountry());
return L_STRING_TO_C(DialPlan::toCpp(dp)->getCountry());
}
const char *linphone_dial_plan_get_iso_country_code (const LinphoneDialPlan *dp) {
return L_STRING_TO_C(L_GET_CPP_PTR_FROM_C_OBJECT(dp)->getIsoCountryCode());
return L_STRING_TO_C(DialPlan::toCpp(dp)->getIsoCountryCode());
}
const char *linphone_dial_plan_get_country_calling_code (const LinphoneDialPlan *dp) {
return L_STRING_TO_C(L_GET_CPP_PTR_FROM_C_OBJECT(dp)->getCountryCallingCode());
return L_STRING_TO_C(DialPlan::toCpp(dp)->getCountryCallingCode());
}
int linphone_dial_plan_get_national_number_length (const LinphoneDialPlan *dp) {
return L_GET_CPP_PTR_FROM_C_OBJECT(dp)->getNationalNumberLength();
return DialPlan::toCpp(dp)->getNationalNumberLength();
}
const char *linphone_dial_plan_get_international_call_prefix (const LinphoneDialPlan *dp) {
return L_STRING_TO_C(L_GET_CPP_PTR_FROM_C_OBJECT(dp)->getInternationalCallPrefix());
return L_STRING_TO_C(DialPlan::toCpp(dp)->getInternationalCallPrefix());
}
int linphone_dial_plan_lookup_ccc_from_e164 (const char *e164) {
return LinphonePrivate::DialPlan::lookupCccFromE164(L_C_TO_STRING(e164));
return DialPlan::lookupCccFromE164(L_C_TO_STRING(e164));
}
int linphone_dial_plan_lookup_ccc_from_iso (const char *iso) {
return LinphonePrivate::DialPlan::lookupCccFromIso(L_C_TO_STRING(iso));
return DialPlan::lookupCccFromIso(L_C_TO_STRING(iso));
}
const LinphoneDialPlan *linphone_dial_plan_by_ccc_as_int (int ccc) {
const LinphonePrivate::DialPlan &dp = LinphonePrivate::DialPlan::findByCcc(ccc);
return L_GET_C_BACK_PTR(&dp);
shared_ptr<DialPlan> dp = DialPlan::findByCcc(ccc);
return dp->toC();
}
const LinphoneDialPlan *linphone_dial_plan_by_ccc (const char *ccc) {
const LinphonePrivate::DialPlan &dp = LinphonePrivate::DialPlan::findByCcc(L_C_TO_STRING(ccc));
return L_GET_C_BACK_PTR(&dp);
shared_ptr<DialPlan> dp = DialPlan::findByCcc(L_C_TO_STRING(ccc));
return dp->toC();
}
const bctbx_list_t *linphone_dial_plan_get_all_list () {
static const list<LinphonePrivate::DialPlan> &dps = LinphonePrivate::DialPlan::getAllDialPlans();
static const bctbx_list_t *list = L_GET_RESOLVED_C_LIST_FROM_CPP_LIST(dps);
return list;
bctbx_list_t *linphone_dial_plan_get_all_list () {
return DialPlan::getCListFromCppList(DialPlan::getAllDialPlans());
}
bool_t linphone_dial_plan_is_generic (const LinphoneDialPlan *ccc) {
return L_GET_CPP_PTR_FROM_C_OBJECT(ccc)->isGeneric();
return DialPlan::toCpp(ccc)->isGeneric();
}
......@@ -38,7 +38,6 @@
F(AbstractChatRoom, ChatRoom) \
F(Core, Core) \
F(Content, Content) \
F(DialPlan, DialPlan) \
F(EventLog, EventLog) \
F(MagicSearch, MagicSearch) \
F(MediaSessionParams, CallParams) \
......
/*
* dial-plan-p.h
* Copyright (C) 2010-2018 Belledonne Communications SARL
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
#ifndef _L_DIAL_PLAN_P_H_
#define _L_DIAL_PLAN_P_H_
#include "dial-plan.h"
#include "object/clonable-object-p.h"
// =============================================================================
LINPHONE_BEGIN_NAMESPACE
class DialPlanPrivate : public ClonableObjectPrivate {
private:
std::string country;
std::string isoCountryCode; // ISO 3166-1 alpha-2 code, ex: FR for France.
std::string countryCallingCode; // Country calling code.
int nationalNumberLength = 0; // Maximum national number length.
std::string internationalCallPrefix; // International call prefix, ex: 00 in europe.
static const std::list<DialPlan> DialPlans;
L_DECLARE_PUBLIC(DialPlan);
};
LINPHONE_END_NAMESPACE
#endif // ifndef _L_DIAL_PLAN_P_H_
This diff is collapsed.
......@@ -22,15 +22,14 @@
#include <list>
#include "object/clonable-object.h"
#include <belle-sip/object++.hh>
#include "linphone/api/c-types.h"
// =============================================================================
LINPHONE_BEGIN_NAMESPACE
class DialPlanPrivate;
class LINPHONE_PUBLIC DialPlan : public ClonableObject {
class DialPlan : public bellesip::HybridObject<LinphoneDialPlan, DialPlan> {
public:
DialPlan (
const std::string &country = "",
......@@ -55,16 +54,22 @@ public:
const std::string &getInternationalCallPrefix () const;
bool isGeneric () const;
static const DialPlan MostCommon;
static const std::shared_ptr<DialPlan> MostCommon;
static int lookupCccFromE164 (const std::string &e164);
static int lookupCccFromIso (const std::string &iso);
static const DialPlan &findByCcc (int ccc);
static const DialPlan &findByCcc (const std::string &ccc);
static const std::list<DialPlan> &getAllDialPlans ();
static std::shared_ptr<DialPlan> findByCcc (int ccc);
static std::shared_ptr<DialPlan> findByCcc (const std::string &ccc);
static const std::list<std::shared_ptr<DialPlan>> &getAllDialPlans ();
private:
L_DECLARE_PRIVATE(DialPlan);
std::string country;
std::string isoCountryCode; // ISO 3166-1 alpha-2 code, ex: FR for France.
std::string countryCallingCode; // Country calling code.
int nationalNumberLength = 0; // Maximum national number length.
std::string internationalCallPrefix; // International call prefix, ex: 00 in europe.
static const std::list<std::shared_ptr<DialPlan>> DialPlans;
};
LINPHONE_END_NAMESPACE
......
......@@ -1537,8 +1537,9 @@ static void echo_canceller_check(void){
}
static void dial_plan(void) {
const bctbx_list_t *it;
for ( it = linphone_dial_plan_get_all_list(); it != NULL; it = it->next) {
bctbx_list_t *dial_plans = linphone_dial_plan_get_all_list();
bctbx_list_t *it;
for (it = dial_plans; it != NULL; it = it->next) {
const LinphoneDialPlan *dialplan = (LinphoneDialPlan *)it->data;
belle_sip_object_remove_from_leak_detector((void*)dialplan);
char *e164 = generate_random_e164_phone_from_dial_plan(dialplan);
......@@ -1554,6 +1555,7 @@ static void dial_plan(void) {
ms_error("cannot generate e164 number for [%s]",linphone_dial_plan_get_country(dialplan));
}
}
bctbx_list_free_with_data(dial_plans, (bctbx_list_free_func)linphone_dial_plan_unref);
}
test_t setup_tests[] = {
TEST_NO_TAG("Version check", linphone_version_test),
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment