Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
BC
public
liblinphone
Commits
5b5bdb71
Commit
5b5bdb71
authored
Nov 18, 2019
by
Sylvain Berfini
🐮
Browse files
Fixes for account creator
parent
8f5cba14
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
113 additions
and
38 deletions
+113
-38
coreapi/account_creator.c
coreapi/account_creator.c
+104
-35
coreapi/lpconfig.c
coreapi/lpconfig.c
+3
-3
tester/account_creator_tester.c
tester/account_creator_tester.c
+6
-0
No files found.
coreapi/account_creator.c
View file @
5b5bdb71
...
...
@@ -49,7 +49,9 @@ BELLE_SIP_INSTANCIATE_VPTR(LinphoneAccountCreatorCbs, belle_sip_object_t,
static
const
char
*
_get_domain
(
LinphoneAccountCreator
*
creator
)
{
if
(
creator
->
domain
)
return
creator
->
domain
;
return
linphone_proxy_config_get_domain
(
creator
->
proxy_cfg
);
else
if
(
creator
->
proxy_cfg
)
return
linphone_proxy_config_get_domain
(
creator
->
proxy_cfg
);
return
NULL
;
}
static
const
char
*
ha1_for_passwd
(
const
char
*
username
,
const
char
*
realm
,
const
char
*
passwd
,
const
char
*
algo
)
{
...
...
@@ -354,9 +356,6 @@ BELLE_SIP_INSTANCIATE_VPTR(LinphoneAccountCreator, belle_sip_object_t,
LinphoneAccountCreator
*
_linphone_account_creator_new
(
LinphoneCore
*
core
,
const
char
*
xmlrpc_url
)
{
LinphoneAccountCreator
*
creator
;
const
char
*
domain
=
lp_config_get_string
(
core
->
config
,
"assistant"
,
"domain"
,
NULL
);
const
char
*
algorithm
=
lp_config_get_string
(
core
->
config
,
"assistant"
,
"algorithm"
,
NULL
);
creator
=
belle_sip_object_new
(
LinphoneAccountCreator
);
creator
->
service
=
linphone_core_get_account_creator_service
(
core
);
linphone_account_creator_service_ref
(
creator
->
service
);
...
...
@@ -365,13 +364,6 @@ LinphoneAccountCreator * _linphone_account_creator_new(LinphoneCore *core, const
creator
->
transport
=
LinphoneTransportTcp
;
creator
->
xmlrpc_session
=
(
xmlrpc_url
)
?
linphone_xml_rpc_session_new
(
core
,
xmlrpc_url
)
:
NULL
;
if
(
domain
)
{
linphone_account_creator_set_domain
(
creator
,
domain
);
}
if
(
algorithm
)
{
linphone_account_creator_set_algorithm
(
creator
,
algorithm
);
}
creator
->
set_as_default
=
TRUE
;
creator
->
proxy_cfg
=
linphone_core_create_proxy_config
(
core
);
...
...
@@ -381,6 +373,21 @@ LinphoneAccountCreator * _linphone_account_creator_new(LinphoneCore *core, const
return
creator
;
}
static
void
fill_domain_and_algorithm_if_needed
(
LinphoneAccountCreator
*
creator
)
{
if
(
creator
->
domain
==
NULL
)
{
const
char
*
domain
=
lp_config_get_string
(
linphone_core_get_config
(
creator
->
core
),
"assistant"
,
"domain"
,
NULL
);
if
(
domain
)
{
linphone_account_creator_set_domain
(
creator
,
domain
);
}
}
if
(
creator
->
algorithm
==
NULL
)
{
const
char
*
algorithm
=
lp_config_get_string
(
linphone_core_get_config
(
creator
->
core
),
"assistant"
,
"algorithm"
,
NULL
);
if
(
algorithm
)
{
linphone_account_creator_set_algorithm
(
creator
,
algorithm
);
}
}
}
LinphoneAccountCreator
*
linphone_account_creator_new
(
LinphoneCore
*
core
,
const
char
*
xmlrpc_url
)
{
return
_linphone_account_creator_new
(
core
,
xmlrpc_url
);
}
...
...
@@ -397,6 +404,7 @@ void linphone_account_creator_reset(LinphoneAccountCreator *creator) {
resetField
(
&
creator
->
activation_code
);
resetField
(
&
creator
->
domain
);
resetField
(
&
creator
->
route
);
resetField
(
&
creator
->
algorithm
);
if
(
creator
->
proxy_cfg
)
{
linphone_proxy_config_unref
(
creator
->
proxy_cfg
);
...
...
@@ -436,10 +444,10 @@ void linphone_account_creator_set_proxy_config(LinphoneAccountCreator *creator,
}
LinphoneAccountCreatorUsernameStatus
linphone_account_creator_set_username
(
LinphoneAccountCreator
*
creator
,
const
char
*
username
)
{
int
min_length
=
lp_config_get_int
(
creator
->
core
->
config
,
"assistant"
,
"username_min_length"
,
-
1
);
int
max_length
=
lp_config_get_int
(
creator
->
core
->
config
,
"assistant"
,
"username_max_length"
,
-
1
);
bool_t
use_phone_number
=
!!
lp_config_get_int
(
creator
->
core
->
config
,
"assistant"
,
"use_phone_number"
,
0
);
const
char
*
regex
=
lp_config_get_string
(
creator
->
core
->
config
,
"assistant"
,
"username_regex"
,
0
);
int
min_length
=
lp_config_get_int
(
linphone_core_get_config
(
creator
->
core
)
,
"assistant"
,
"username_min_length"
,
-
1
);
int
max_length
=
lp_config_get_int
(
linphone_core_get_config
(
creator
->
core
)
,
"assistant"
,
"username_max_length"
,
-
1
);
bool_t
use_phone_number
=
!!
lp_config_get_int
(
linphone_core_get_config
(
creator
->
core
)
,
"assistant"
,
"use_phone_number"
,
0
);
const
char
*
regex
=
lp_config_get_string
(
linphone_core_get_config
(
creator
->
core
)
,
"assistant"
,
"username_regex"
,
0
);
if
(
!
username
)
{
resetField
(
&
creator
->
username
);
return
LinphoneAccountCreatorUsernameStatusOk
;
...
...
@@ -475,13 +483,18 @@ LinphoneAccountCreatorPhoneNumberStatusMask linphone_account_creator_set_phone_n
return
(
LinphoneAccountCreatorPhoneNumberStatusMask
)
LinphoneAccountCreatorPhoneNumberStatusInvalid
;
}
}
else
{
if
(
strlen
(
country_code
)
==
0
||
strcmp
(
country_code
,
"+"
)
==
0
)
return
LinphoneAccountCreatorPhoneNumberStatusInvalidCountryCode
;
if
(
!
creator
->
proxy_cfg
)
creator
->
proxy_cfg
=
linphone_core_create_proxy_config
(
creator
->
core
);
LinphoneProxyConfig
*
numCfg
=
creator
->
proxy_cfg
;
creator
->
phone_country_code
=
ms_strdup
(
country_code
[
0
]
==
'+'
?
&
country_code
[
1
]
:
country_code
);
linphone_proxy_config_set_dial_prefix
(
numCfg
,
creator
->
phone_country_code
);
normalized_phone_number
=
linphone_proxy_config_normalize_phone_number
(
numCfg
,
phone_number
);
if
(
!
normalized_phone_number
)
{
return
LinphoneAccountCreatorPhoneNumberStatusInvalid
;
}
// 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
]
!=
'+'
)
{
std
::
shared_ptr
<
DialPlan
>
plan
=
DialPlan
::
findByCcc
(
creator
->
phone_country_code
);
...
...
@@ -490,10 +503,10 @@ LinphoneAccountCreatorPhoneNumberStatusMask linphone_account_creator_set_phone_n
return_status
=
LinphoneAccountCreatorPhoneNumberStatusInvalidCountryCode
;
}
if
(
size
<
plan
->
getNationalNumberLength
()
-
1
)
{
return_status
+
=
LinphoneAccountCreatorPhoneNumberStatusTooShort
;
return_status
=
LinphoneAccountCreatorPhoneNumberStatusTooShort
;
goto
end
;
}
else
if
(
size
>
plan
->
getNationalNumberLength
()
+
1
)
{
return_status
+
=
LinphoneAccountCreatorPhoneNumberStatusTooLong
;
return_status
=
LinphoneAccountCreatorPhoneNumberStatusTooLong
;
goto
end
;
}
else
if
(
return_status
&
LinphoneAccountCreatorPhoneNumberStatusInvalidCountryCode
)
{
goto
end
;
...
...
@@ -512,8 +525,8 @@ const char * linphone_account_creator_get_phone_number(const LinphoneAccountCrea
}
LinphoneAccountCreatorPasswordStatus
linphone_account_creator_set_password
(
LinphoneAccountCreator
*
creator
,
const
char
*
password
)
{
int
min_length
=
lp_config_get_int
(
creator
->
core
->
config
,
"assistant"
,
"password_min_length"
,
-
1
);
int
max_length
=
lp_config_get_int
(
creator
->
core
->
config
,
"assistant"
,
"password_max_length"
,
-
1
);
int
min_length
=
lp_config_get_int
(
linphone_core_get_config
(
creator
->
core
)
,
"assistant"
,
"password_min_length"
,
-
1
);
int
max_length
=
lp_config_get_int
(
linphone_core_get_config
(
creator
->
core
)
,
"assistant"
,
"password_max_length"
,
-
1
);
if
(
!
password
)
{
resetField
(
&
creator
->
password
);
return
LinphoneAccountCreatorPasswordStatusTooShort
;
...
...
@@ -623,6 +636,7 @@ LinphoneTransportType linphone_account_creator_get_transport(const LinphoneAccou
}
LinphoneAccountCreatorStatus
linphone_account_creator_set_route
(
LinphoneAccountCreator
*
creator
,
const
char
*
route
)
{
if
(
!
creator
->
proxy_cfg
)
creator
->
proxy_cfg
=
linphone_core_create_proxy_config
(
creator
->
core
);
if
(
!
route
||
linphone_proxy_config_set_route
(
creator
->
proxy_cfg
,
route
)
!=
0
)
return
LinphoneAccountCreatorStatusRequestFailed
;
...
...
@@ -741,16 +755,19 @@ LinphoneAccountCreatorStatus linphone_account_creator_login_linphone_account(Lin
LinphoneAccountCreatorStatus
linphone_account_creator_constructor_linphone
(
LinphoneAccountCreator
*
creator
)
{
LinphoneAddress
*
addr
;
const
char
*
identity
=
lp_config_get_default_string
(
creator
->
core
->
config
,
"proxy"
,
"reg_identity"
,
NULL
);
const
char
*
proxy
=
lp_config_get_default_string
(
creator
->
core
->
config
,
"proxy"
,
"reg_proxy"
,
NULL
);
const
char
*
route
=
lp_config_get_default_string
(
creator
->
core
->
config
,
"proxy"
,
"reg_route"
,
NULL
);
const
char
*
realm
=
lp_config_get_default_string
(
creator
->
core
->
config
,
"proxy"
,
"realm"
,
NULL
);
const
char
*
identity
=
lp_config_get_default_string
(
linphone_core_get_config
(
creator
->
core
),
"proxy"
,
"reg_identity"
,
NULL
);
const
char
*
proxy
=
lp_config_get_default_string
(
linphone_core_get_config
(
creator
->
core
),
"proxy"
,
"reg_proxy"
,
NULL
);
const
char
*
route
=
lp_config_get_default_string
(
linphone_core_get_config
(
creator
->
core
),
"proxy"
,
"reg_route"
,
NULL
);
const
char
*
realm
=
lp_config_get_default_string
(
linphone_core_get_config
(
creator
->
core
),
"proxy"
,
"realm"
,
NULL
);
if
(
!
creator
->
proxy_cfg
)
creator
->
proxy_cfg
=
linphone_core_create_proxy_config
(
creator
->
core
);
linphone_proxy_config_set_realm
(
creator
->
proxy_cfg
,
realm
?
realm
:
"sip.linphone.org"
);
linphone_proxy_config_set_route
(
creator
->
proxy_cfg
,
route
?
route
:
"sip.linphone.org"
);
linphone_proxy_config_set_server_addr
(
creator
->
proxy_cfg
,
proxy
?
proxy
:
"sip.linphone.org"
);
addr
=
linphone_address_new
(
identity
?
identity
:
"sip:username@sip.linphone.org"
);
linphone_proxy_config_set_identity_address
(
creator
->
proxy_cfg
,
addr
);
linphone_address_unref
(
addr
);
return
LinphoneAccountCreatorStatusRequestOk
;
}
...
...
@@ -758,6 +775,7 @@ LinphoneAccountCreatorStatus linphone_account_creator_constructor_linphone(Linph
static
void
_is_account_exist_response_cb
(
LinphoneXmlRpcRequest
*
request
)
{
LinphoneAccountCreator
*
creator
=
(
LinphoneAccountCreator
*
)
linphone_xml_rpc_request_get_user_data
(
request
);
LinphoneAccountCreatorStatus
status
=
LinphoneAccountCreatorStatusRequestFailed
;
const
char
*
resp
=
linphone_xml_rpc_request_get_string_response
(
request
);
if
(
linphone_xml_rpc_request_get_status
(
request
)
==
LinphoneXmlRpcStatusOk
)
{
status
=
(
strcmp
(
resp
,
"ERROR_ACCOUNT_DOESNT_EXIST"
)
==
0
)
?
LinphoneAccountCreatorStatusAccountNotExist
:
(
...
...
@@ -767,6 +785,7 @@ static void _is_account_exist_response_cb(LinphoneXmlRpcRequest *request) {
set_string
(
&
creator
->
phone_number
,
resp
,
FALSE
);
}
}
if
(
creator
->
cbs
->
is_account_exist_response_cb
!=
NULL
)
{
creator
->
cbs
->
is_account_exist_response_cb
(
creator
,
status
,
resp
);
}
...
...
@@ -783,6 +802,7 @@ LinphoneAccountCreatorStatus linphone_account_creator_is_account_exist_linphone(
return
LinphoneAccountCreatorStatusMissingArguments
;
}
fill_domain_and_algorithm_if_needed
(
creator
);
if
(
creator
->
xmlrpc_session
)
{
ms_debug
(
"Account creator: is_account_exist (%s=%s, domain=%s)"
,
(
creator
->
username
)
?
"username"
:
"phone number"
,
...
...
@@ -806,6 +826,7 @@ LinphoneAccountCreatorStatus linphone_account_creator_is_account_exist_linphone(
static
void
_create_account_cb_custom
(
LinphoneXmlRpcRequest
*
request
)
{
LinphoneAccountCreator
*
creator
=
(
LinphoneAccountCreator
*
)
linphone_xml_rpc_request_get_user_data
(
request
);
LinphoneAccountCreatorStatus
status
=
LinphoneAccountCreatorStatusRequestFailed
;
const
char
*
resp
=
linphone_xml_rpc_request_get_string_response
(
request
);
if
(
linphone_xml_rpc_request_get_status
(
request
)
==
LinphoneXmlRpcStatusOk
)
{
status
=
(
strcmp
(
resp
,
"OK"
)
==
0
)
?
LinphoneAccountCreatorStatusAccountCreated
...
...
@@ -816,6 +837,7 @@ static void _create_account_cb_custom(LinphoneXmlRpcRequest *request) {
:
(
strcmp
(
resp
,
"ERROR_ALGO_NOT_SUPPORTED"
)
==
0
)
?
LinphoneAccountCreatorStatusAlgoNotSupported
:
LinphoneAccountCreatorStatusAccountNotCreated
;
}
if
(
creator
->
cbs
->
create_account_response_cb
!=
NULL
)
{
creator
->
cbs
->
create_account_response_cb
(
creator
,
status
,
resp
);
}
...
...
@@ -870,7 +892,9 @@ static LinphoneXmlRpcRequest * _create_account_with_email_custom(LinphoneAccount
LinphoneAccountCreatorStatus
linphone_account_creator_create_account_linphone
(
LinphoneAccountCreator
*
creator
)
{
LinphoneXmlRpcRequest
*
request
=
NULL
;
fill_domain_and_algorithm_if_needed
(
creator
);
char
*
identity
=
_get_identity
(
creator
);
if
(
!
identity
||
(
!
(
request
=
_create_account_with_phone_custom
(
creator
))
&&
!
(
request
=
_create_account_with_email_custom
(
creator
))))
{
if
(
creator
->
cbs
->
create_account_response_cb
!=
NULL
)
{
...
...
@@ -889,6 +913,7 @@ LinphoneAccountCreatorStatus linphone_account_creator_create_account_linphone(Li
ms_free
(
identity
);
return
LinphoneAccountCreatorStatusRequestOk
;
}
ms_free
(
identity
);
return
LinphoneAccountCreatorStatusRequestFailed
;
}
...
...
@@ -896,6 +921,7 @@ LinphoneAccountCreatorStatus linphone_account_creator_create_account_linphone(Li
static
void
_delete_linphone_account_response_cb
(
LinphoneXmlRpcRequest
*
request
)
{
LinphoneAccountCreator
*
creator
=
(
LinphoneAccountCreator
*
)
linphone_xml_rpc_request_get_user_data
(
request
);
LinphoneAccountCreatorStatus
status
=
LinphoneAccountCreatorStatusRequestFailed
;
const
char
*
resp
=
linphone_xml_rpc_request_get_string_response
(
request
);
if
(
linphone_xml_rpc_request_get_status
(
request
)
==
LinphoneXmlRpcStatusOk
)
{
status
=
(
strcmp
(
resp
,
"OK"
)
==
0
)
?
LinphoneAccountCreatorStatusAccountCreated
...
...
@@ -905,6 +931,7 @@ static void _delete_linphone_account_response_cb(LinphoneXmlRpcRequest *request)
:
(
strstr
(
resp
,
"ERROR_"
)
==
0
)
?
LinphoneAccountCreatorStatusRequestFailed
:
LinphoneAccountCreatorStatusAccountNotCreated
;
}
if
(
creator
->
cbs
->
delete_account_response_cb
!=
NULL
)
{
creator
->
cbs
->
delete_account_response_cb
(
creator
,
status
,
resp
);
}
...
...
@@ -912,7 +939,7 @@ static void _delete_linphone_account_response_cb(LinphoneXmlRpcRequest *request)
}
LinphoneAccountCreatorStatus
linphone_account_creator_delete_account_linphone
(
LinphoneAccountCreator
*
creator
)
{
if
((
!
creator
->
username
&&
!
creator
->
phone_number
)
||
!
creator
->
password
)
{
if
((
!
creator
->
username
&&
!
creator
->
phone_number
)
||
!
creator
->
password
||
!
creator
->
proxy_cfg
)
{
if
(
creator
->
cbs
->
delete_account_response_cb
!=
NULL
)
{
creator
->
cbs
->
delete_account_response_cb
(
creator
,
LinphoneAccountCreatorStatusMissingArguments
,
"Missing required parameters"
);
}
...
...
@@ -920,6 +947,7 @@ LinphoneAccountCreatorStatus linphone_account_creator_delete_account_linphone(Li
return
LinphoneAccountCreatorStatusMissingArguments
;
}
fill_domain_and_algorithm_if_needed
(
creator
);
ms_debug
(
"Account creator: delete_account (username=%s, password=%s, domain=%s, algo=%s)"
,
creator
->
username
,
creator
->
password
,
...
...
@@ -949,14 +977,16 @@ static void _login_account_confirmation_key_cb_custom(LinphoneXmlRpcRequest *req
if
(
linphone_xml_rpc_request_get_status
(
request
)
==
LinphoneXmlRpcStatusFailed
)
{
const
char
*
resp
=
linphone_xml_rpc_request_get_string_response
(
request
);
if
(
strcmp
(
resp
,
"ERROR_ACCOUNT_DOESNT_EXIST"
)
==
0
)
{
status
=
LinphoneAccountCreatorStatusAccountNotExist
;
}
else
if
(
strcmp
(
resp
,
"ERROR_KEY_DOESNT_MATCH"
)
==
0
)
{
status
=
LinphoneAccountCreatorStatusWrongActivationCode
;
}
else
if
(
strcmp
(
resp
,
"ERROR_ALGO_NOT_SUPPORTED"
)
==
0
)
{
status
=
LinphoneAccountCreatorStatusAlgoNotSupported
;
}
else
{
status
=
LinphoneAccountCreatorStatusUnexpectedError
;
if
(
resp
!=
NULL
)
{
if
(
strcmp
(
resp
,
"ERROR_ACCOUNT_DOESNT_EXIST"
)
==
0
)
{
status
=
LinphoneAccountCreatorStatusAccountNotExist
;
}
else
if
(
strcmp
(
resp
,
"ERROR_KEY_DOESNT_MATCH"
)
==
0
)
{
status
=
LinphoneAccountCreatorStatusWrongActivationCode
;
}
else
if
(
strcmp
(
resp
,
"ERROR_ALGO_NOT_SUPPORTED"
)
==
0
)
{
status
=
LinphoneAccountCreatorStatusAlgoNotSupported
;
}
else
{
status
=
LinphoneAccountCreatorStatusUnexpectedError
;
}
}
}
else
if
(
linphone_xml_rpc_request_get_status
(
request
)
==
LinphoneXmlRpcStatusOk
)
{
status
=
LinphoneAccountCreatorStatusRequestOk
;
...
...
@@ -1003,6 +1033,7 @@ LinphoneAccountCreatorStatus linphone_account_creator_login_linphone_account_lin
return
LinphoneAccountCreatorStatusMissingArguments
;
}
fill_domain_and_algorithm_if_needed
(
creator
);
if
(
creator
->
xmlrpc_session
)
{
ms_debug
(
"Account creator: recover_account_from_confirmation_key (username=%s, activation code=%s, domain=%s, algo=%s)"
,
creator
->
username
?
creator
->
username
:
creator
->
phone_number
,
...
...
@@ -1021,12 +1052,14 @@ LinphoneAccountCreatorStatus linphone_account_creator_login_linphone_account_lin
linphone_xml_rpc_request_unref
(
request
);
return
LinphoneAccountCreatorStatusRequestOk
;
}
return
LinphoneAccountCreatorStatusRequestFailed
;
}
static
void
_activate_account_cb_custom
(
LinphoneXmlRpcRequest
*
request
)
{
LinphoneAccountCreator
*
creator
=
(
LinphoneAccountCreator
*
)
linphone_xml_rpc_request_get_user_data
(
request
);
LinphoneAccountCreatorStatus
status
=
LinphoneAccountCreatorStatusRequestFailed
;
const
char
*
resp
=
linphone_xml_rpc_request_get_string_response
(
request
);
if
(
linphone_xml_rpc_request_get_status
(
request
)
==
LinphoneXmlRpcStatusOk
)
{
if
(
strcmp
(
resp
,
"ERROR_ACCOUNT_ALREADY_ACTIVATED"
)
==
0
)
{
...
...
@@ -1044,6 +1077,7 @@ static void _activate_account_cb_custom(LinphoneXmlRpcRequest *request) {
set_string
(
&
creator
->
ha1
,
resp
,
FALSE
);
}
}
if
(
creator
->
cbs
->
activate_account_response_cb
!=
NULL
)
{
creator
->
cbs
->
activate_account_response_cb
(
creator
,
status
,
resp
);
}
...
...
@@ -1060,6 +1094,7 @@ LinphoneAccountCreatorStatus linphone_account_creator_activate_account_linphone(
return
LinphoneAccountCreatorStatusMissingArguments
;
}
fill_domain_and_algorithm_if_needed
(
creator
);
if
(
creator
->
xmlrpc_session
)
{
ms_debug
(
"Account creator: activate_account_phone (phone number=%s, username=%s, activation code=%s, domain=%s, algo=%s)"
,
creator
->
phone_number
,
...
...
@@ -1080,6 +1115,7 @@ LinphoneAccountCreatorStatus linphone_account_creator_activate_account_linphone(
linphone_xml_rpc_request_unref
(
request
);
return
LinphoneAccountCreatorStatusRequestOk
;
}
return
LinphoneAccountCreatorStatusRequestFailed
;
}
...
...
@@ -1093,6 +1129,7 @@ LinphoneAccountCreatorStatus linphone_account_creator_activate_email_account_lin
return
LinphoneAccountCreatorStatusMissingArguments
;
}
fill_domain_and_algorithm_if_needed
(
creator
);
if
(
creator
->
xmlrpc_session
)
{
ms_debug
(
"Account creator: activate_account_email (username=%s, activation code=%s, domain=%s, algo=%s)"
,
creator
->
username
,
...
...
@@ -1111,12 +1148,14 @@ LinphoneAccountCreatorStatus linphone_account_creator_activate_email_account_lin
linphone_xml_rpc_request_unref
(
request
);
return
LinphoneAccountCreatorStatusRequestOk
;
}
return
LinphoneAccountCreatorStatusRequestFailed
;
}
static
void
get_linphone_confirmation_key_response_cb
(
LinphoneXmlRpcRequest
*
request
)
{
LinphoneAccountCreator
*
creator
=
(
LinphoneAccountCreator
*
)
linphone_xml_rpc_request_get_user_data
(
request
);
LinphoneAccountCreatorStatus
status
=
LinphoneAccountCreatorStatusRequestFailed
;
const
char
*
resp
=
linphone_xml_rpc_request_get_string_response
(
request
);
if
(
linphone_xml_rpc_request_get_status
(
request
)
==
LinphoneXmlRpcStatusOk
)
{
if
(
strcmp
(
resp
,
"ERROR_USERNAME_PARAMETER_NOT_FOUND"
)
==
0
)
{
...
...
@@ -1132,6 +1171,7 @@ static void get_linphone_confirmation_key_response_cb(LinphoneXmlRpcRequest *req
set_string
(
&
creator
->
activation_code
,
resp
,
FALSE
);
}
}
if
(
creator
->
cbs
->
confirmation_key_response_cb
!=
NULL
)
{
creator
->
cbs
->
confirmation_key_response_cb
(
creator
,
status
,
resp
);
}
...
...
@@ -1139,7 +1179,7 @@ static void get_linphone_confirmation_key_response_cb(LinphoneXmlRpcRequest *req
}
LinphoneAccountCreatorStatus
linphone_account_creator_get_confirmation_key_linphone
(
LinphoneAccountCreator
*
creator
)
{
if
(
!
creator
->
username
||
!
creator
->
password
)
{
if
(
!
creator
->
username
||
!
creator
->
password
||
!
creator
->
proxy_cfg
)
{
if
(
creator
->
cbs
->
confirmation_key_response_cb
!=
NULL
)
{
creator
->
cbs
->
confirmation_key_response_cb
(
creator
,
LinphoneAccountCreatorStatusMissingArguments
,
"Missing required parameters"
);
}
...
...
@@ -1147,6 +1187,7 @@ LinphoneAccountCreatorStatus linphone_account_creator_get_confirmation_key_linph
return
LinphoneAccountCreatorStatusMissingArguments
;
}
fill_domain_and_algorithm_if_needed
(
creator
);
ms_debug
(
"Account creator: confirmation_key (username=%s, password=%s, domain=%s, algo=%s)"
,
creator
->
username
,
creator
->
password
,
...
...
@@ -1170,10 +1211,12 @@ LinphoneAccountCreatorStatus linphone_account_creator_get_confirmation_key_linph
static
void
_is_account_activated_cb_custom
(
LinphoneXmlRpcRequest
*
request
)
{
LinphoneAccountCreator
*
creator
=
(
LinphoneAccountCreator
*
)
linphone_xml_rpc_request_get_user_data
(
request
);
LinphoneAccountCreatorStatus
status
=
LinphoneAccountCreatorStatusRequestFailed
;
const
char
*
resp
=
linphone_xml_rpc_request_get_string_response
(
request
);
if
(
linphone_xml_rpc_request_get_status
(
request
)
==
LinphoneXmlRpcStatusOk
)
{
status
=
(
strcmp
(
resp
,
"OK"
)
==
0
)
?
LinphoneAccountCreatorStatusAccountActivated
:
LinphoneAccountCreatorStatusAccountNotActivated
;
}
if
(
creator
->
cbs
->
is_account_activated_response_cb
!=
NULL
)
{
creator
->
cbs
->
is_account_activated_response_cb
(
creator
,
status
,
resp
);
}
...
...
@@ -1191,6 +1234,7 @@ LinphoneAccountCreatorStatus linphone_account_creator_is_account_activated_linph
return
LinphoneAccountCreatorStatusMissingArguments
;
}
fill_domain_and_algorithm_if_needed
(
creator
);
if
(
creator
->
xmlrpc_session
)
{
ms_debug
(
"Account creator: is_account_activated (username=%s, domain=%s, algo=%s)"
,
creator
->
username
?
creator
->
username
:
creator
->
phone_number
,
...
...
@@ -1208,6 +1252,7 @@ LinphoneAccountCreatorStatus linphone_account_creator_is_account_activated_linph
ms_free
(
identity
);
return
LinphoneAccountCreatorStatusRequestOk
;
}
ms_free
(
identity
);
return
LinphoneAccountCreatorStatusRequestFailed
;
}
...
...
@@ -1218,12 +1263,14 @@ LinphoneAccountCreatorStatus linphone_account_creator_is_account_activated_linph
static
void
_is_phone_number_used_cb_custom
(
LinphoneXmlRpcRequest
*
request
)
{
LinphoneAccountCreator
*
creator
=
(
LinphoneAccountCreator
*
)
linphone_xml_rpc_request_get_user_data
(
request
);
LinphoneAccountCreatorStatus
status
=
LinphoneAccountCreatorStatusRequestFailed
;
const
char
*
resp
=
linphone_xml_rpc_request_get_string_response
(
request
);
if
(
linphone_xml_rpc_request_get_status
(
request
)
==
LinphoneXmlRpcStatusOk
)
{
status
=
(
strcmp
(
resp
,
"OK_ACCOUNT"
)
==
0
)
?
LinphoneAccountCreatorStatusAliasIsAccount
:
(
strcmp
(
resp
,
"OK_ALIAS"
)
==
0
)
?
LinphoneAccountCreatorStatusAliasExist
:
LinphoneAccountCreatorStatusAliasNotExist
;
}
if
(
creator
->
cbs
->
is_alias_used_response_cb
!=
NULL
)
{
creator
->
cbs
->
is_alias_used_response_cb
(
creator
,
status
,
resp
);
}
...
...
@@ -1241,6 +1288,7 @@ LinphoneAccountCreatorStatus linphone_account_creator_is_phone_number_used_linph
return
LinphoneAccountCreatorStatusMissingArguments
;
}
fill_domain_and_algorithm_if_needed
(
creator
);
if
(
creator
->
xmlrpc_session
)
{
ms_debug
(
"Account creator: is_phone_number_used (phone number=%s, domain=%s)"
,
creator
->
phone_number
,
...
...
@@ -1256,6 +1304,7 @@ LinphoneAccountCreatorStatus linphone_account_creator_is_phone_number_used_linph
ms_free
(
identity
);
return
LinphoneAccountCreatorStatusRequestOk
;
}
ms_free
(
identity
);
return
LinphoneAccountCreatorStatusRequestFailed
;
}
...
...
@@ -1266,12 +1315,14 @@ LinphoneAccountCreatorStatus linphone_account_creator_is_phone_number_used_linph
static
void
_link_phone_number_with_account_cb_custom
(
LinphoneXmlRpcRequest
*
request
)
{
LinphoneAccountCreator
*
creator
=
(
LinphoneAccountCreator
*
)
linphone_xml_rpc_request_get_user_data
(
request
);
LinphoneAccountCreatorStatus
status
=
LinphoneAccountCreatorStatusRequestFailed
;
const
char
*
resp
=
linphone_xml_rpc_request_get_string_response
(
request
);
status
=
(
strcmp
(
resp
,
"OK"
)
==
0
)
?
LinphoneAccountCreatorStatusRequestOk
const
char
*
resp
=
linphone_xml_rpc_request_get_string_response
(
request
);
if
(
linphone_xml_rpc_request_get_status
(
request
)
==
LinphoneXmlRpcStatusOk
)
{
status
=
(
strcmp
(
resp
,
"OK"
)
==
0
)
?
LinphoneAccountCreatorStatusRequestOk
:
(
strcmp
(
resp
,
"ERROR_CANNOT_SEND_SMS"
)
==
0
)
?
LinphoneAccountCreatorStatusPhoneNumberInvalid
:
(
strcmp
(
resp
,
"ERROR_MAX_SMS_EXCEEDED"
)
==
0
)
?
LinphoneAccountCreatorStatusPhoneNumberOverused
:
LinphoneAccountCreatorStatusAccountNotLinked
;
}
if
(
creator
->
cbs
->
link_account_response_cb
!=
NULL
)
{
creator
->
cbs
->
link_account_response_cb
(
creator
,
status
,
resp
);
...
...
@@ -1289,6 +1340,7 @@ LinphoneAccountCreatorStatus linphone_account_creator_link_phone_number_with_acc
return
LinphoneAccountCreatorStatusMissingArguments
;
}
fill_domain_and_algorithm_if_needed
(
creator
);
if
(
creator
->
xmlrpc_session
)
{
ms_debug
(
"Account creator: link_phone_number_with_account (phone number=%s, username=%s, domain=%s, language=%s)"
,
creator
->
phone_number
,
...
...
@@ -1307,18 +1359,21 @@ LinphoneAccountCreatorStatus linphone_account_creator_link_phone_number_with_acc
linphone_xml_rpc_request_unref
(
request
);
return
LinphoneAccountCreatorStatusRequestOk
;
}
return
LinphoneAccountCreatorStatusRequestFailed
;
}
static
void
_get_phone_number_for_account_cb_custom
(
LinphoneXmlRpcRequest
*
request
)
{
LinphoneAccountCreator
*
creator
=
(
LinphoneAccountCreator
*
)
linphone_xml_rpc_request_get_user_data
(
request
);
LinphoneAccountCreatorStatus
status
=
LinphoneAccountCreatorStatusRequestFailed
;
const
char
*
resp
=
linphone_xml_rpc_request_get_string_response
(
request
);
if
(
linphone_xml_rpc_request_get_status
(
request
)
==
LinphoneXmlRpcStatusOk
)
{
status
=
(
strcmp
(
resp
,
"ERROR_USERNAME_PARAMETER_NOT_FOUND"
)
==
0
||
strcmp
(
resp
,
"ERROR_ACCOUNT_DOESNT_EXIST"
)
==
0
||
strcmp
(
resp
,
"ERROR_ALIAS_DOESNT_EXIST"
)
==
0
)
?
LinphoneAccountCreatorStatusAccountNotLinked
:
LinphoneAccountCreatorStatusAccountLinked
;
}
if
(
creator
->
cbs
->
is_account_linked_response_cb
!=
NULL
)
{
creator
->
cbs
->
is_account_linked_response_cb
(
creator
,
status
,
resp
);
}
...
...
@@ -1335,6 +1390,7 @@ LinphoneAccountCreatorStatus linphone_account_creator_is_account_linked_linphone
return
LinphoneAccountCreatorStatusMissingArguments
;
}
fill_domain_and_algorithm_if_needed
(
creator
);
if
(
creator
->
xmlrpc_session
)
{
ms_debug
(
"Account creator: is_account_linked (username=%s, domain=%s)"
,
creator
->
username
,
...
...
@@ -1349,6 +1405,7 @@ LinphoneAccountCreatorStatus linphone_account_creator_is_account_linked_linphone
linphone_xml_rpc_request_unref
(
request
);
return
LinphoneAccountCreatorStatusRequestOk
;
}
return
LinphoneAccountCreatorStatusRequestFailed
;
}
/****************** END OF LINK PHONE NUMBER WITH ACCOUNT SECTION *************/
...
...
@@ -1357,10 +1414,12 @@ LinphoneAccountCreatorStatus linphone_account_creator_is_account_linked_linphone
static
void
_activate_phone_number_link_cb_custom
(
LinphoneXmlRpcRequest
*
request
)
{
LinphoneAccountCreator
*
creator
=
(
LinphoneAccountCreator
*
)
linphone_xml_rpc_request_get_user_data
(
request
);
LinphoneAccountCreatorStatus
status
=
LinphoneAccountCreatorStatusRequestFailed
;
const
char
*
resp
=
linphone_xml_rpc_request_get_string_response
(
request
);
if
(
linphone_xml_rpc_request_get_status
(
request
)
==
LinphoneXmlRpcStatusOk
)
{
status
=
(
strstr
(
resp
,
"ERROR_"
)
==
resp
)
?
LinphoneAccountCreatorStatusAccountNotActivated
:
LinphoneAccountCreatorStatusAccountActivated
;
}
if
(
creator
->
cbs
->
activate_alias_response_cb
!=
NULL
)
{
creator
->
cbs
->
activate_alias_response_cb
(
creator
,
status
,
resp
);
}
...
...
@@ -1377,6 +1436,7 @@ LinphoneAccountCreatorStatus linphone_account_creator_activate_phone_number_link
return
LinphoneAccountCreatorStatusMissingArguments
;
}
fill_domain_and_algorithm_if_needed
(
creator
);
if
(
creator
->
xmlrpc_session
)
{
ms_debug
(
"Account creator: activate_phone_number_link (phone number=%s, username=%s, activation code=%s, domain=%s, algo=%s)"
,
creator
->
phone_number
,
...
...
@@ -1398,6 +1458,7 @@ LinphoneAccountCreatorStatus linphone_account_creator_activate_phone_number_link
linphone_xml_rpc_request_unref
(
request
);
return
LinphoneAccountCreatorStatusRequestOk
;
}
return
LinphoneAccountCreatorStatusRequestFailed
;
}
/****************** END OF ACTIVE PHONE NUMBER LINK **************************/
...
...
@@ -1406,6 +1467,7 @@ LinphoneAccountCreatorStatus linphone_account_creator_activate_phone_number_link
static
void
_recover_phone_account_cb_custom
(
LinphoneXmlRpcRequest
*
request
)
{
LinphoneAccountCreator
*
creator
=
(
LinphoneAccountCreator
*
)
linphone_xml_rpc_request_get_user_data
(
request
);
LinphoneAccountCreatorStatus
status
=
LinphoneAccountCreatorStatusRequestFailed
;
const
char
*
resp
=
linphone_xml_rpc_request_get_string_response
(
request
);
if
(
linphone_xml_rpc_request_get_status
(
request
)
==
LinphoneXmlRpcStatusOk
)
{
if
(
strstr
(
resp
,
"ERROR_"
)
==
resp
)
{
...
...
@@ -1418,6 +1480,7 @@ static void _recover_phone_account_cb_custom(LinphoneXmlRpcRequest *request) {
set_string
(
&
creator
->
username
,
resp
,
FALSE
);
}
}
if
(
creator
->
cbs
->
recover_account_response_cb
!=
NULL
)
{
creator
->
cbs
->
recover_account_response_cb
(
creator
,
status
,
resp
);
}
...
...
@@ -1434,6 +1497,7 @@ LinphoneAccountCreatorStatus linphone_account_creator_recover_phone_account_linp
return
LinphoneAccountCreatorStatusMissingArguments
;
}
fill_domain_and_algorithm_if_needed
(
creator
);
if
(
creator
->
xmlrpc_session
)
{
ms_debug
(
"Account creator: recover_phone_account (phone number=%s, domain=%s, language=%s)"
,
creator
->
phone_number
,
...
...
@@ -1450,6 +1514,7 @@ LinphoneAccountCreatorStatus linphone_account_creator_recover_phone_account_linp
linphone_xml_rpc_request_unref
(
request
);
return
LinphoneAccountCreatorStatusRequestOk
;
}
return
LinphoneAccountCreatorStatusRequestFailed
;
}
/****************** END OF ACTIVE PHONE NUMBER LINK **************************/
...
...
@@ -1458,6 +1523,7 @@ LinphoneAccountCreatorStatus linphone_account_creator_recover_phone_account_linp
static
void
_password_updated_cb_custom
(
LinphoneXmlRpcRequest
*
request
)
{
LinphoneAccountCreator
*
creator
=
(
LinphoneAccountCreator
*
)
linphone_xml_rpc_request_get_user_data
(
request
);
LinphoneAccountCreatorStatus
status
=
LinphoneAccountCreatorStatusRequestFailed
;
const
char
*
resp
=
linphone_xml_rpc_request_get_string_response
(
request
);
if
(
linphone_xml_rpc_request_get_status
(
request
)
==
LinphoneXmlRpcStatusOk
)
{
if
(
strcmp
(
resp
,
"OK"
)
==
0
)
{
...
...
@@ -1470,6 +1536,7 @@ static void _password_updated_cb_custom(LinphoneXmlRpcRequest *request) {
status
=
LinphoneAccountCreatorStatusServerError
;
}
}
if
(
creator
->
cbs
->
update_account_response_cb
!=
NULL
)
{
creator
->
cbs
->
update_account_response_cb
(
creator
,
status
,
resp
);
}
...
...
@@ -1494,6 +1561,7 @@ LinphoneAccountCreatorStatus linphone_account_creator_update_password_linphone(L
}
bctbx_free
(
identity
);
fill_domain_and_algorithm_if_needed
(
creator
);
if
(
creator
->
xmlrpc_session
)
{
const
char
*
username
=
creator
->
username
?
creator
->
username
:
creator
->
phone_number
;
char
*
ha1
=
bctbx_strdup
(
creator
->
ha1
?
creator
->
ha1
:
ha1_for_passwd
(
username
,
_get_domain
(
creator
),
creator
->
password
,
creator
->
algorithm
));
...
...
@@ -1520,6 +1588,7 @@ LinphoneAccountCreatorStatus linphone_account_creator_update_password_linphone(L
return
LinphoneAccountCreatorStatusRequestOk
;
}
return
LinphoneAccountCreatorStatusRequestFailed
;
}
/****************** END OF UPDATE ACCOUNT **************************/
...
...
coreapi/lpconfig.c
View file @
5b5bdb71
...
...
@@ -219,9 +219,9 @@ static int is_a_comment(const char *str){
LpSection
*
linphone_config_find_section
(
const
LpConfig
*
lpconfig
,
const
char
*
name
){
LpSection
*
sec
;
bctbx_list_t
*
elem
;
bctbx_list_t
*
elem
=
lpconfig
->
sections
;
/*printf("Looking for section %s\n",name);*/
for
(
elem
=
lpconfig
->
sections
;
elem
!=
NULL
;
elem
=
bctbx_list_next
(
elem
)){
for
(;
elem
!=
NULL
;
elem
=
bctbx_list_next
(
elem
)){
sec
=
(
LpSection
*
)
elem
->
data
;
if
(
strcmp
(
sec
->
name
,
name
)
==
0
){
/*printf("Section %s found\n",name);*/
...
...
@@ -752,7 +752,7 @@ bool_t linphone_config_get_skip_flag_for_section(const LpConfig *lpconfig, const
}
void
linphone_config_set_string
(
LpConfig
*
lpconfig
,
const
char
*
section
,
const
char
*
key
,
const
char
*
value
){
LpItem
*
item
;
LpItem
*
item
;
LpSection
*
sec
=
linphone_config_find_section
(
lpconfig
,
section
);
if
(
sec
!=
NULL
){
item
=
lp_section_find_item
(
sec
,
key
);
...
...
tester/account_creator_tester.c
View file @
5b5bdb71
...
...
@@ -304,6 +304,12 @@ static void local_country_code_invalid(void) {
LinphoneAccountCreatorPhoneNumberStatus
,
"%i"
);
BC_ASSERT_EQUAL
(
linphone_account_creator_set_phone_number
(
creator
,
"0123"
,
"+"
)
&
LinphoneAccountCreatorPhoneNumberStatusInvalidCountryCode
,
LinphoneAccountCreatorPhoneNumberStatusInvalidCountryCode
,
LinphoneAccountCreatorPhoneNumberStatus
,
"%i"
);
linphone_account_creator_unref
(
creator
);
linphone_core_manager_destroy
(
marie
);
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment