account creator: detect invalid domain by changing linphone_address_set_*...

account creator: detect invalid domain by changing linphone_address_set_* methods to return -1 in case of error
parent 1e5711f2
......@@ -132,12 +132,12 @@ void linphone_account_creator_set_user_data(LinphoneAccountCreator *creator, voi
static LinphoneAccountCreatorStatus validate_uri(const char* username, const char* domain, const char* route, const char* display_name) {
LinphoneProxyConfig* proxy = linphone_proxy_config_new();
LinphoneAddress* addr;
linphone_proxy_config_set_identity(proxy, "sip:user@domain.com");
LinphoneAccountCreatorStatus status = LinphoneAccountCreatorOK;
linphone_proxy_config_set_identity(proxy, "sip:userame@domain.com");
if (route && linphone_proxy_config_set_route(proxy, route) != 0) {
linphone_proxy_config_destroy(proxy);
return LinphoneAccountCreatorRouteInvalid;
status = LinphoneAccountCreatorRouteInvalid;
goto end;
}
if (username) {
......@@ -145,24 +145,23 @@ static LinphoneAccountCreatorStatus validate_uri(const char* username, const cha
} else {
addr = linphone_address_clone(linphone_proxy_config_get_identity_address(proxy));
}
linphone_proxy_config_destroy(proxy);
if (addr == NULL) {
return LinphoneAccountCreatorUsernameInvalid;
status = LinphoneAccountCreatorUsernameInvalid;
}
if (domain) {
ms_error("TODO: detect invalid domain");
linphone_address_set_domain(addr, domain);
if (domain && linphone_address_set_domain(addr, domain) != 0) {
status = LinphoneAccountCreatorDomainInvalid;
}
if (display_name) {
ms_error("TODO: detect invalid display name");
linphone_address_set_display_name(addr, display_name);
if (display_name && linphone_address_set_display_name(addr, display_name) != 0) {
status = LinphoneAccountCreatorDisplayNameInvalid;
}
linphone_address_unref(addr);
return LinphoneAccountCreatorOK;
end:
linphone_proxy_config_destroy(proxy);
return status;
}
static bool_t is_matching_regex(const char *entry, const char* regex) {
......
......@@ -89,37 +89,51 @@ const char *linphone_address_get_domain(const LinphoneAddress *u){
/**
* Sets the display name.
**/
void linphone_address_set_display_name(LinphoneAddress *u, const char *display_name){
int linphone_address_set_display_name(LinphoneAddress *u, const char *display_name){
sal_address_set_display_name(u,display_name);
return 0;
}
/**
* Sets the username.
**/
void linphone_address_set_username(LinphoneAddress *uri, const char *username){
int linphone_address_set_username(LinphoneAddress *uri, const char *username){
sal_address_set_username(uri,username);
return 0;
}
/**
* Sets the domain.
**/
void linphone_address_set_domain(LinphoneAddress *uri, const char *host){
sal_address_set_domain(uri,host);
int linphone_address_set_domain(LinphoneAddress *uri, const char *host){
if (host) {
char *identity = ms_strdup_printf("sip:%s", host);
LinphoneAddress* test = linphone_address_new(identity);
ms_free(identity);
if (test) {
sal_address_set_domain(uri,host);
linphone_address_destroy(test);
return 0;
}
}
return -1;
}
/**
* Sets the port number.
**/
void linphone_address_set_port(LinphoneAddress *uri, int port){
int linphone_address_set_port(LinphoneAddress *uri, int port){
sal_address_set_port(uri,port);
return 0;
}
/**
* Set a transport.
**/
void linphone_address_set_transport(LinphoneAddress *uri, LinphoneTransportType tp){
int linphone_address_set_transport(LinphoneAddress *uri, LinphoneTransportType tp){
sal_address_set_transport(uri,(SalTransport)tp);
return 0;
}
/**
......
......@@ -436,10 +436,11 @@ LINPHONE_PUBLIC const char *linphone_address_get_display_name(const LinphoneAddr
LINPHONE_PUBLIC const char *linphone_address_get_username(const LinphoneAddress *u);
LINPHONE_PUBLIC const char *linphone_address_get_domain(const LinphoneAddress *u);
LINPHONE_PUBLIC int linphone_address_get_port(const LinphoneAddress *u);
LINPHONE_PUBLIC void linphone_address_set_display_name(LinphoneAddress *u, const char *display_name);
LINPHONE_PUBLIC void linphone_address_set_username(LinphoneAddress *uri, const char *username);
LINPHONE_PUBLIC void linphone_address_set_domain(LinphoneAddress *uri, const char *host);
LINPHONE_PUBLIC void linphone_address_set_port(LinphoneAddress *uri, int port);
LINPHONE_PUBLIC int linphone_address_set_display_name(LinphoneAddress *u, const char *display_name);
LINPHONE_PUBLIC int linphone_address_set_username(LinphoneAddress *uri, const char *username);
LINPHONE_PUBLIC int linphone_address_set_domain(LinphoneAddress *uri, const char *host);
LINPHONE_PUBLIC int linphone_address_set_port(LinphoneAddress *uri, int port);
LINPHONE_PUBLIC int linphone_address_set_transport(LinphoneAddress *uri,LinphoneTransportType type);
/*remove tags, params etc... so that it is displayable to the user*/
LINPHONE_PUBLIC void linphone_address_clean(LinphoneAddress *uri);
LINPHONE_PUBLIC bool_t linphone_address_is_secure(const LinphoneAddress *addr);
......@@ -447,7 +448,6 @@ LINPHONE_PUBLIC bool_t linphone_address_get_secure(const LinphoneAddress *addr);
LINPHONE_PUBLIC void linphone_address_set_secure(LinphoneAddress *addr, bool_t enabled);
LINPHONE_PUBLIC bool_t linphone_address_is_sip(const LinphoneAddress *uri);
LINPHONE_PUBLIC LinphoneTransportType linphone_address_get_transport(const LinphoneAddress *uri);
LINPHONE_PUBLIC void linphone_address_set_transport(LinphoneAddress *uri,LinphoneTransportType type);
LINPHONE_PUBLIC const char *linphone_address_get_method_param(const LinphoneAddress *addr);
LINPHONE_PUBLIC void linphone_address_set_method_param(LinphoneAddress *addr, const char *method);
LINPHONE_PUBLIC char *linphone_address_as_string(const LinphoneAddress *u);
......
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