Exemplo n.º 1
6
static LinphoneAccountCreatorStatus validate_uri(const char* username, const char* domain, const char* route, const char* display_name) {
	LinphoneAddress* addr;
	LinphoneAccountCreatorStatus status = LinphoneAccountCreatorOK;
	LinphoneProxyConfig* proxy = linphone_proxy_config_new();
	linphone_proxy_config_set_identity(proxy, "sip:[email protected]");

	if (route && linphone_proxy_config_set_route(proxy, route) != 0) {
		status = LinphoneAccountCreatorRouteInvalid;
		goto end;
	}

	if (username) {
		addr = linphone_proxy_config_normalize_sip_uri(proxy, username);
	} else {
		addr = linphone_address_clone(linphone_proxy_config_get_identity_address(proxy));
	}

	if (addr == NULL) {
		status = LinphoneAccountCreatorUsernameInvalid;
		goto end;
	}

	if (domain && linphone_address_set_domain(addr, domain) != 0) {
		status = LinphoneAccountCreatorDomainInvalid;
	}

	if (display_name && (!strlen(display_name) || linphone_address_set_display_name(addr, display_name) != 0)) {
		status = LinphoneAccountCreatorDisplayNameInvalid;
	}
	linphone_address_unref(addr);
end:
	linphone_proxy_config_destroy(proxy);
	return status;
}
Exemplo n.º 2
0
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:[email protected]");

	if (route && linphone_proxy_config_set_route(proxy, route) != 0) {
		linphone_proxy_config_destroy(proxy);
		return LinphoneAccountCreatorRouteInvalid;
	}

	if (username) {
		addr = linphone_proxy_config_normalize_sip_uri(proxy, username);
	} else {
		addr = linphone_address_clone(linphone_proxy_config_get_identity_address(proxy));
	}
	linphone_proxy_config_destroy(proxy);

	if (addr == NULL) {
		return LinphoneAccountCreatorUsernameInvalid;
	}

	if (domain) {
		ms_error("TODO: detect invalid domain");
		linphone_address_set_domain(addr, domain);
	}

	if (display_name) {
		ms_error("TODO: detect invalid display name");
		linphone_address_set_display_name(addr, display_name);
	}

	linphone_address_unref(addr);
	return LinphoneAccountCreatorOk;
}
Exemplo n.º 3
0
static void phone_normalization_with_proxy(void) {
	LinphoneProxyConfig *proxy = linphone_proxy_config_new();
	linphone_proxy_config_set_dial_prefix(proxy, "33");
	BC_ASSERT_STRING_EQUAL(phone_normalization(proxy, "012 3456 789"), "+33123456789");
	BC_ASSERT_STRING_EQUAL(phone_normalization(proxy, "+33123456789"), "+33123456789");
	BC_ASSERT_STRING_EQUAL(phone_normalization(proxy, "+33 0123456789"), "+330123456789");
	BC_ASSERT_STRING_EQUAL(phone_normalization(proxy, "+330012345678"), "+330012345678");
	BC_ASSERT_STRING_EQUAL(phone_normalization(proxy, "+3301 2345678"), "+33012345678");
	BC_ASSERT_STRING_EQUAL(phone_normalization(proxy, "+3301234567891"), "+3301234567891");

	BC_ASSERT_STRING_EQUAL(phone_normalization(proxy, "123456789"), "+33123456789");
	BC_ASSERT_STRING_EQUAL(phone_normalization(proxy, " 0123456789"), "+33123456789");
	BC_ASSERT_STRING_EQUAL(phone_normalization(proxy, "0012345678"), "+12345678");
	BC_ASSERT_STRING_EQUAL(phone_normalization(proxy, "01 2345678"), "+33012345678");
	BC_ASSERT_STRING_EQUAL(phone_normalization(proxy, "01234567891"), "+33234567891"); // invalid phone number (too long)
	BC_ASSERT_PTR_NULL(phone_normalization(proxy, "I_AM_NOT_A_NUMBER")); // invalid phone number

	BC_ASSERT_STRING_EQUAL(phone_normalization(proxy, "+990012345678"), "+990012345678");

	BC_ASSERT_STRING_EQUAL(phone_normalization(proxy, "0952636505"), "+33952636505");
	BC_ASSERT_STRING_EQUAL(phone_normalization(proxy, "09 52 63 65 05"), "+33952636505");
	BC_ASSERT_STRING_EQUAL(phone_normalization(proxy, "09-52-63-65-05"), "+33952636505");
	BC_ASSERT_STRING_EQUAL(phone_normalization(proxy, "+31952636505"), "+31952636505");
	BC_ASSERT_STRING_EQUAL(phone_normalization(proxy, "0033952636505"), "+33952636505");
	BC_ASSERT_STRING_EQUAL(phone_normalization(proxy, "0033952636505"), "+33952636505");
	BC_ASSERT_PTR_NULL(phone_normalization(proxy, "toto"));

	linphone_proxy_config_set_dial_prefix(proxy, "99");
	BC_ASSERT_STRING_EQUAL(phone_normalization(proxy, "0012345678"), "+12345678");

	linphone_proxy_config_destroy(proxy);
}
Exemplo n.º 4
0
LinphoneAccountCreatorStatus linphone_account_creator_set_phone_number(LinphoneAccountCreator *creator, const char *phone_number, const char *country_code) {
	char *normalized_phone_number;
	if (!phone_number || !country_code) {
		if (!phone_number && !country_code) {
			creator->phone_number = NULL;
			return LinphoneAccountCreatorOK;
		} else {
			return LinphoneAccountCreatorPhoneNumberInvalid;
		}
	} else {
		LinphoneProxyConfig *numCfg = linphone_proxy_config_new();
		linphone_proxy_config_set_dial_prefix(numCfg, country_code);
		normalized_phone_number = linphone_proxy_config_normalize_phone_number(numCfg, phone_number);
		linphone_proxy_config_destroy(numCfg);
		if (!normalized_phone_number) {
			return LinphoneAccountCreatorPhoneNumberInvalid;
		}

		// if phone is valid, we lastly want to check that length is OK
		{
			const LinphoneDialPlan* plan = linphone_dial_plan_by_ccc(country_code);
			int size = (int)strlen(phone_number);
			if (size < plan->nnl) {
				return LinphoneAccountCreatorPhoneNumberTooShort;
			} else if (size > plan->nnl + 1) {
				return LinphoneAccountCreatorPhoneNumberTooLong;
			}
		}
	}
	set_string(&creator->phone_number, normalized_phone_number, TRUE);
	ms_free(normalized_phone_number);

	return LinphoneAccountCreatorOK;
}
Exemplo n.º 5
0
static void phone_normalization_with_dial_escape_plus(void){
	LinphoneProxyConfig *proxy = linphone_proxy_config_new();
	linphone_proxy_config_set_dial_prefix(proxy, "33");
	linphone_proxy_config_set_dial_escape_plus(proxy, TRUE);
	BC_ASSERT_STRING_EQUAL(phone_normalization(proxy, "0033952636505"), "0033952636505");
	BC_ASSERT_STRING_EQUAL(phone_normalization(proxy, "0952636505"), "0033952636505");
	BC_ASSERT_STRING_EQUAL(phone_normalization(proxy, "+34952636505"), "0034952636505");
	linphone_proxy_config_destroy(proxy);
}
Exemplo n.º 6
0
void linphone_account_creator_destroy(LinphoneAccountCreator *obj){
	if (obj->username)
		ms_free(obj->username);
	if (obj->password)
		ms_free(obj->password);
	if (obj->domain)
		ms_free(obj->domain);
	if (!obj->succeeded){
		linphone_proxy_config_destroy(sip_setup_context_get_proxy_config(obj->ssctx));
	}
}
Exemplo n.º 7
0
static char* _get_identity(const LinphoneAccountCreator *creator) {
	char *identity = NULL;
	if (creator->username && creator->domain) {
		//we must escape username
		LinphoneProxyConfig* proxy = linphone_proxy_config_new();
		LinphoneAddress* addr;
		linphone_proxy_config_set_identity(proxy, "sip:[email protected]");
		addr = linphone_proxy_config_normalize_sip_uri(proxy, creator->username);
		linphone_address_set_domain(addr, creator->domain);
		identity = linphone_address_as_string(addr);
		linphone_address_destroy(addr);
		linphone_proxy_config_destroy(proxy);
	}
	return identity;
}
Exemplo n.º 8
0
static char* _get_identity(const LinphoneAccountCreator *creator) {
	char *identity = NULL;
	if (creator->username && creator->domain) {
		//we must escape username
		LinphoneProxyConfig* proxy = linphone_proxy_config_new();
		LinphoneAddress* addr;
		// creator->domain may contain some port or some transport (eg. toto.org:443;transport=tcp),
		// we will accept that
		char * tmpidentity = ms_strdup_printf("sip:username@%s", creator->domain);
		linphone_proxy_config_set_identity(proxy, tmpidentity);
		ms_free(tmpidentity);
		addr = linphone_proxy_config_normalize_sip_uri(proxy, creator->username);

		identity = linphone_address_as_string(addr);
		linphone_address_destroy(addr);
		linphone_proxy_config_destroy(proxy);
	}
	return identity;
}
Exemplo n.º 9
0
void linphone_proxy_config_is_server_config_changed_test() {
	LinphoneProxyConfig* proxy_config = linphone_proxy_config_new();

	linphone_proxy_config_done(proxy_config); /*test done without edit*/

	linphone_proxy_config_set_identity(proxy_config,"sip:toto@titi");
	linphone_proxy_config_edit(proxy_config);
	linphone_proxy_config_set_identity(proxy_config,"sips:toto@titi");
	BC_ASSERT_EQUAL(linphone_proxy_config_is_server_config_changed(proxy_config), LinphoneProxyConfigAddressDifferent, int, "%d");

	linphone_proxy_config_set_server_addr(proxy_config,"sip:sip.linphone.org");
	linphone_proxy_config_edit(proxy_config);
	linphone_proxy_config_set_server_addr(proxy_config,"sip:toto.com");
	BC_ASSERT_EQUAL(linphone_proxy_config_is_server_config_changed(proxy_config), LinphoneProxyConfigAddressDifferent, int, "%d");

	linphone_proxy_config_set_server_addr(proxy_config,"sip:sip.linphone.org");
	linphone_proxy_config_edit(proxy_config);
	linphone_proxy_config_set_server_addr(proxy_config,"sip:sip.linphone.org:4444");
	BC_ASSERT_EQUAL(linphone_proxy_config_is_server_config_changed(proxy_config), LinphoneProxyConfigAddressDifferent, int, "%d");

	linphone_proxy_config_set_server_addr(proxy_config,"sip:sip.linphone.org");
	linphone_proxy_config_edit(proxy_config);
	linphone_proxy_config_set_server_addr(proxy_config,"sip:sip.linphone.org;transport=tcp");
	BC_ASSERT_EQUAL(linphone_proxy_config_is_server_config_changed(proxy_config), LinphoneProxyConfigAddressDifferent, int, "%d");

	linphone_proxy_config_set_server_addr(proxy_config,"sip:sip.linphone.org");
	linphone_proxy_config_edit(proxy_config);
	linphone_proxy_config_set_server_addr(proxy_config,"sip:sip.linphone.org;param=blue");
	BC_ASSERT_EQUAL(linphone_proxy_config_is_server_config_changed(proxy_config), LinphoneProxyConfigAddressWeakEqual, int, "%d");


	linphone_proxy_config_edit(proxy_config);
	linphone_proxy_config_set_contact_parameters(proxy_config,"blabla=blue");
	BC_ASSERT_EQUAL(linphone_proxy_config_is_server_config_changed(proxy_config), LinphoneProxyConfigAddressEqual, int, "%d");

	linphone_proxy_config_edit(proxy_config);
	linphone_proxy_config_enable_register(proxy_config,TRUE);
	BC_ASSERT_EQUAL(linphone_proxy_config_is_server_config_changed(proxy_config), LinphoneProxyConfigAddressEqual, int, "%d");

	linphone_proxy_config_destroy(proxy_config);
}