Commit 668dc9b6 authored by Sylvain Berfini's avatar Sylvain Berfini 🎩

Started new DialPlan object, still a few compilation issues

parent a7adfbda
......@@ -22,6 +22,7 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
#include "linphone/lpconfig.h"
#include "c-wrapper/c-wrapper.h"
#include "linphone/api/c-dial-plan.h"
#if !_WIN32
#include "regex.h"
......@@ -402,10 +403,10 @@ LinphoneAccountCreatorPhoneNumberStatusMask linphone_account_creator_set_phone_n
if (linphone_dial_plan_is_generic(plan)) {
return_status = LinphoneAccountCreatorPhoneNumberStatusInvalidCountryCode;
}
if (size < plan->nnl - 1) {
if (size < linphone_dial_plan_get_national_number_length(plan) - 1) {
return_status += LinphoneAccountCreatorPhoneNumberStatusTooShort;
goto end;
} else if (size > plan->nnl + 1) {
} else if (size > linphone_dial_plan_get_national_number_length(plan) + 1) {
return_status += LinphoneAccountCreatorPhoneNumberStatusTooLong;
goto end;
} else if (return_status & LinphoneAccountCreatorPhoneNumberStatusInvalidCountryCode) {
......
This diff is collapsed.
......@@ -32,6 +32,7 @@ Copyright (C) 2000 Simon MORLAT (simon.morlat@linphone.org)
// For migration purpose.
#include "address/address-p.h"
#include "c-wrapper/c-wrapper.h"
#include "linphone/api/c-dial-plan.h"
using namespace LinphonePrivate;
......@@ -646,7 +647,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;
LinphoneDialPlan dialplan = {0};
const LinphoneDialPlan *dialplan;
char * nationnal_significant_number = NULL;
int ccc = -1;
......@@ -656,24 +657,24 @@ char* linphone_proxy_config_normalize_phone_number(LinphoneProxyConfig *proxy, c
ccc = linphone_dial_plan_lookup_ccc_from_e164(flatten);
if (ccc>-1) { /*e164 like phone number*/
dialplan = *linphone_dial_plan_by_ccc_as_int(ccc);
nationnal_significant_number = strstr(flatten, dialplan.ccc);
dialplan = linphone_dial_plan_by_ccc_as_int(ccc);
nationnal_significant_number = strstr(flatten, linphone_dial_plan_get_country_calling_code(dialplan));
if (nationnal_significant_number) {
nationnal_significant_number +=strlen(dialplan.ccc);
nationnal_significant_number +=strlen(linphone_dial_plan_get_country_calling_code(dialplan));
}
} else if (flatten[0] =='+') {
ms_message ("Unknown ccc for e164 like number [%s]", flatten);
goto end;
} else {
dialplan = *linphone_dial_plan_by_ccc(tmpproxy->dial_prefix); //copy dial plan;
dialplan = linphone_dial_plan_by_ccc(tmpproxy->dial_prefix); //copy dial plan;
if (tmpproxy->dial_prefix){
if (strcmp(tmpproxy->dial_prefix,dialplan.ccc) != 0){
/*if (strcmp(tmpproxy->dial_prefix,linphone_dial_plan_get_country_calling_code(dialplan)) != 0){
//probably generic dialplan, preserving proxy dial prefix
strncpy(dialplan.ccc,tmpproxy->dial_prefix,sizeof(dialplan.ccc));
}
strncpy(linphone_dial_plan_get_country_calling_code(dialplan),tmpproxy->dial_prefix,sizeof(linphone_dial_plan_get_country_calling_code(dialplan)));
}*/
/*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.icp)==flatten) {
char *e164 = replace_icp_with_plus(flatten,dialplan.icp);
if (strstr(flatten,linphone_dial_plan_get_international_call_prefix(dialplan))==flatten) {
char *e164 = replace_icp_with_plus(flatten,linphone_dial_plan_get_iso_country_code(dialplan));
result = linphone_proxy_config_normalize_phone_number(tmpproxy,e164);
ms_free(e164);
goto end;
......@@ -682,23 +683,23 @@ char* linphone_proxy_config_normalize_phone_number(LinphoneProxyConfig *proxy, c
}
nationnal_significant_number=flatten;
}
ms_debug("Using dial plan '%s'",dialplan.country);
ms_debug("Using dial plan '%s'",linphone_dial_plan_get_country(dialplan));
/*if proxy has a dial prefix, modify phonenumber accordingly*/
if (dialplan.ccc[0]!='\0') {
if (linphone_dial_plan_get_country_calling_code(dialplan)[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.nnl);
ms_debug("Prefix not present. Keeping at most %d digits: %s", dialplan.nnl, nationnal_significant_number_start);
- (int)linphone_dial_plan_get_national_number_length(dialplan));
ms_debug("Prefix not present. Keeping at most %d digits: %s", linphone_dial_plan_get_national_number_length(dialplan), 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.icp : "+"
, dialplan.ccc
, tmpproxy->dial_escape_plus ? linphone_dial_plan_get_international_call_prefix(dialplan) : "+"
, linphone_dial_plan_get_country_calling_code(dialplan)
, nationnal_significant_number_start);
ms_debug("Prepended prefix resulted in %s", result);
}
......
......@@ -84,6 +84,7 @@ set(C_API_HEADER_FILES
c-chat-message-cbs.h
c-chat-room.h
c-chat-room-cbs.h
c-dial-plan.h
c-event-log.h
c-participant.h
c-types.h
......
/*
* c-dial-plan.h
* Copyright (C) 2010-2017 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 _C_DIAL_PLAN_H_
#define _C_DIAL_PLAN_H_
#include "linphone/api/c-types.h"
// =============================================================================
#ifdef __cplusplus
extern "C" {
#endif // ifdef __cplusplus
/**
* @addtogroup misc
* @{
*/
LINPHONE_PUBLIC const char * linphone_dial_plan_get_country(const LinphoneDialPlan *dp);
LINPHONE_PUBLIC const char * linphone_dial_plan_get_iso_country_code(const LinphoneDialPlan *dp);
LINPHONE_PUBLIC const char * linphone_dial_plan_get_country_calling_code(const LinphoneDialPlan *dp);
LINPHONE_PUBLIC int linphone_dial_plan_get_national_number_length(const LinphoneDialPlan *dp);
LINPHONE_PUBLIC const char * linphone_dial_plan_get_international_call_prefix(const LinphoneDialPlan *dp);
/**
*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
*/
LINPHONE_PUBLIC int linphone_dial_plan_lookup_ccc_from_iso(const char* iso);
/**
*Function to get call country code from an e164 number, ex: +33952650121 will return 33
*@param e164 phone number
*@return call country code or -1 if not found
*/
LINPHONE_PUBLIC int linphone_dial_plan_lookup_ccc_from_e164(const char* e164);
/**
* Return NULL-terminated array of all known dial plans
* @deprecated use linphone_dial_plan_get_all_list instead
**/
LINPHONE_PUBLIC const LinphoneDialPlan* linphone_dial_plan_get_all(void);
/**
* @return {\bctbx_list const LinphoneDialPlan*} of all known dial plans
**/
LINPHONE_PUBLIC const bctbx_list_t * linphone_dial_plan_get_all_list();
/**
* Find best match for given CCC
* @return Return matching dial plan, or a generic one if none found
**/
LINPHONE_PUBLIC const LinphoneDialPlan* linphone_dial_plan_by_ccc(const char *ccc);
/**
* Find best match for given CCC
* @return Return matching dial plan, or a generic one if none found
**/
LINPHONE_PUBLIC const LinphoneDialPlan* linphone_dial_plan_by_ccc_as_int(int ccc);
/**
* Return if given plan is generic
**/
LINPHONE_PUBLIC bool_t linphone_dial_plan_is_generic(const LinphoneDialPlan *ccc);
/**
* @}
*/
#ifdef __cplusplus
}
#endif // ifdef __cplusplus
#endif // ifndef _C_DIAL_PLAN_H_
......@@ -117,6 +117,12 @@ typedef struct _LinphoneChatMessageCbs LinphoneChatMessageCbs;
**/
typedef struct _LinphoneParticipant LinphoneParticipant;
/**
* Represents a dial plan
* @ingroup misc
**/
typedef struct _LinphoneDialPlan LinphoneDialPlan;
// -----------------------------------------------------------------------------
// EventLog.
// -----------------------------------------------------------------------------
......
......@@ -87,51 +87,6 @@ void linphone_core_add_iterate_hook(LinphoneCore *lc, LinphoneCoreIterateHook ho
void linphone_core_remove_iterate_hook(LinphoneCore *lc, LinphoneCoreIterateHook hook, void *hook_data);
typedef struct _LinphoneDialPlan {
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*/
} LinphoneDialPlan;
/**
* @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
*/
LINPHONE_PUBLIC int linphone_dial_plan_lookup_ccc_from_iso(const char* iso);
/**
* @ingroup misc
*Function to get call country code from an e164 number, ex: +33952650121 will return 33
*@param e164 phone number
*@return call country code or -1 if not found
*/
LINPHONE_PUBLIC int linphone_dial_plan_lookup_ccc_from_e164(const char* e164);
/**
* Return NULL-terminated array of all known dial plans
**/
LINPHONE_PUBLIC const LinphoneDialPlan* linphone_dial_plan_get_all(void);
/**
* Find best match for given CCC
* @return Return matching dial plan, or a generic one if none found
**/
LINPHONE_PUBLIC const LinphoneDialPlan* linphone_dial_plan_by_ccc(const char *ccc);
/**
* Find best match for given CCC
* @return Return matching dial plan, or a generic one if none found
**/
LINPHONE_PUBLIC const LinphoneDialPlan* linphone_dial_plan_by_ccc_as_int(int ccc);
/**
* Return if given plan is generic
**/
LINPHONE_PUBLIC bool_t linphone_dial_plan_is_generic(const LinphoneDialPlan *ccc);
#ifdef __cplusplus
}
#endif
......
......@@ -86,6 +86,8 @@ set(LINPHONE_CXX_OBJECTS_PRIVATE_HEADER_FILES
db/session/db-session-p.h
db/session/db-session-provider.h
db/session/db-session.h
dial-plan/dial-plan-p.h
dial-plan/dial-plan.h
enums.h
event-log/call-event.h
event-log/chat-message-event.h
......@@ -124,6 +126,7 @@ set(LINPHONE_CXX_OBJECTS_SOURCE_FILES
c-wrapper/api/c-chat-message.cpp
c-wrapper/api/c-chat-room-cbs.cpp
c-wrapper/api/c-chat-room.cpp
c-wrapper/api/c-dial-plan.cpp
c-wrapper/api/c-event-log.cpp
c-wrapper/api/c-participant.cpp
c-wrapper/internal/c-sal.cpp
......@@ -162,6 +165,7 @@ set(LINPHONE_CXX_OBJECTS_SOURCE_FILES
db/main-db.cpp
db/session/db-session-provider.cpp
db/session/db-session.cpp
dial-plan/dial-plan.cpp
event-log/call-event.cpp
event-log/chat-message-event.cpp
event-log/conference-event.cpp
......
/*
* c-dial-plan.cpp
* Copyright (C) 2010-2017 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.
*/
#include "linphone/api/c-dial-plan.h"
#include "linphone/wrapper_utils.h"
#include "c-wrapper/c-wrapper.h"
#include "dial-plan/dial-plan.h"
// =============================================================================
using namespace std;
L_DECLARE_C_OBJECT_IMPL(DialPlan);
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 NULL;
}
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 NULL;
}
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 NULL;
}
int linphone_dial_plan_get_national_number_length(const LinphoneDialPlan *dp) {
//return L_GET_CPP_PTR_FROM_C_OBJECT(dp).getNationalNumberLength();
return -1;
}
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 NULL;
}
int linphone_dial_plan_lookup_ccc_from_e164(const char* e164) {
return LinphonePrivate::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));
}
const LinphoneDialPlan* linphone_dial_plan_by_ccc_as_int(int ccc) {
//LinphonePrivate::DialPlan dp = LinphonePrivate::DialPlan::findByCccAsInt(ccc);
//return L_GET_C_BACK_PTR();
return NULL; //TODO
}
const LinphoneDialPlan* linphone_dial_plan_by_ccc(const char *ccc) {
//LinphonePrivate::DialPlan dp = LinphonePrivate::DialPlan::findByCcc(L_C_TO_STRING(ccc));
//return L_GET_C_BACK_PTR();
return NULL; //TODO
}
const LinphoneDialPlan* linphone_dial_plan_get_all() {
return NULL; //TODO
}
const bctbx_list_t * linphone_dial_plan_get_all_list() {
//const list<DialPlan> dps = LinphonePrivate::DialPlan::getAllDialPlans();
//return L_GET_RESOLVED_C_LIST_FROM_CPP_LIST();
return NULL; //TODO
}
bool_t linphone_dial_plan_is_generic(const LinphoneDialPlan *ccc) {
//return L_GET_CPP_PTR_FROM_C_OBJECT(ccc).isGeneric();
return FALSE;
}
\ No newline at end of file
......@@ -72,6 +72,7 @@ BELLE_SIP_TYPE_ID(LinphoneContactSearch),
BELLE_SIP_TYPE_ID(LinphoneContent),
BELLE_SIP_TYPE_ID(LinphoneCore),
BELLE_SIP_TYPE_ID(LinphoneCoreCbs),
BELLE_SIP_TYPE_ID(LinphoneDialPlan),
BELLE_SIP_TYPE_ID(LinphoneErrorInfo),
BELLE_SIP_TYPE_ID(LinphoneEvent),
BELLE_SIP_TYPE_ID(LinphoneFactory),
......
......@@ -888,7 +888,9 @@ shared_ptr<ChatRoom> MainDb::findChatRoom (const string &peerAddress) const {
void MainDb::cleanHistory (const string &, FilterMask) {}
shared_ptr<ChatRoom> MainDb::findChatRoom (const string &) const {}
shared_ptr<ChatRoom> MainDb::findChatRoom (const string &) const {
return nullptr;
}
bool MainDb::import (Backend, const string &) {
return false;
......
/*
* dial-plan-p.h
* Copyright (C) 2010-2017 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 _DIAL_PLAN_P_H_
#define _DIAL_PLAN_P_H_
#include "dial-plan.h"
#include "object/clonable-object-p.h"
// =============================================================================
LINPHONE_BEGIN_NAMESPACE
class DialPlanPrivate : public ClonableObjectPrivate {
public:
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*/
L_DECLARE_PUBLIC(DialPlan);
};
LINPHONE_END_NAMESPACE
#endif // ifndef _DIAL_PLAN_P_H_
This diff is collapsed.
/*
* dial-plan.h
* Copyright (C) 2010-2017 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 _DIAL_PLAN_H_
#define _DIAL_PLAN_H_
#include <list>
#include "object/clonable-object.h"
// =============================================================================
LINPHONE_BEGIN_NAMESPACE
class DialPlanPrivate;
class LINPHONE_PUBLIC DialPlan : public ClonableObject {
public:
DialPlan (const std::string &country = "", const std::string &isoCountryCode = "", const std::string &ccc = "", int nnl = 0, const std::string &icp = "");
DialPlan (const DialPlan &src);
~DialPlan ();
DialPlan &operator= (const DialPlan &src);
const std::string& getCountry() const;
const std::string& getIsoCountryCode() const;
const std::string& getCountryCallingCode() const;
int getNationalNumberLength() const;
const std::string& getInternationalCallPrefix() const;
bool isGeneric() const;
static const DialPlan MostCommon;
static int lookupCccFromE164(std::string e164);
static int lookupCccFromIso(std::string iso);
static const DialPlan& findByCccAsInt(int ccc);
static const DialPlan& findByCcc(const std::string& ccc);
static const std::list<DialPlan>& getAllDialPlans();
private:
static std::list<DialPlan> const DialPlans;
L_DECLARE_PRIVATE(DialPlan);
};
LINPHONE_END_NAMESPACE
#endif // ifndef _DIAL_PLAN_H_
......@@ -231,9 +231,6 @@ eval "$SED_START 's/enableDownloadOpenH264(/OpenH264DownloadHelper.enableDownloa
#DialPlan
#LinphoneBuffer
#Call.zoomVideo()
#Factory.instance().setLogCollectionPath(getFilesDir().getAbsolutePath());
#Factory.instance().enableLogCollection(isDebugEnabled);
#Factory.instance().setDebugMode(isDebugEnabled, getString(R.string.app_name));
#AccountCreator.updatePassword
#Android specifics not wrapped automatically
......@@ -264,3 +261,6 @@ eval "$SED_START 's/enableDownloadOpenH264(/OpenH264DownloadHelper.enableDownloa
#Core.setCpuCount() => Not needed anymore, can be removed
#AccountCreator.getPrefix => linphone_dial_plan_lookup_ccc_from_e164
#ProxyConfig.lookupCCCFromIso=> linphone_dial_plan_lookup_ccc_from_iso
#Factory.instance().setLogCollectionPath(getFilesDir().getAbsolutePath()); => Core.setLogCollectionPath
#Factory.instance().enableLogCollection(isDebugEnabled); => COre.enableLogCollection
#Factory.instance().setDebugMode(isDebugEnabled, getString(R.string.app_name)); => Core.setLogLevelMask
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