Commit cf1c15bb authored by urbant's avatar urbant
Browse files

absoluteURI moved to UserInfo

support for multiple occurrences of the contact field
parent 4c91ece9
Loading
Loading
Loading
Loading
+44 −35
Original line number Diff line number Diff line
@@ -218,19 +218,25 @@ void SipUrl::PreDecodeField (int id, Buffer& buffer) throw (DecodeError)
		reg_colon.AssertMatch(buffer, this);
		buffer.SetPosition(buffer.GetPosition() + 8);
		pszScheme = Get_scheme().GetValue();
		SetHypFieldIsPresent (id,  0);
		// user-info is not decoded in case of absoluteURI
		if (is_sip_scheme(pszScheme) &&	reg_userinfo.Match (buffer)) {
		if (is_sip_scheme(pszScheme)) {
			if (reg_userinfo.Match (buffer)) {
				SetHypFieldIsPresent (id,  1);
				SetHypFieldLength (id, reg_userinfo.GetMatchedLength() - 8);
			}
		} 
		// telephone numbers are decoded to the userInfo field
		else if (is_tel_scheme(pszScheme)){
			reg_phone.AssertMatch(buffer, this);
			SetHypFieldIsPresent (id,  1);
			SetHypFieldLength (id, reg_phone.GetMatchedLength());
		}
		else {
			SetHypFieldIsPresent (id,  0);
		else { // absoluteURI
			if (reg_absolute_uri.Match (buffer)) {
				SetHypFieldIsPresent (id,  1);
				SetHypFieldLength(id, reg_absolute_uri.GetMatchedLength());
			}
		}
		break;

@@ -249,15 +255,8 @@ void SipUrl::PreDecodeField (int id, Buffer& buffer) throw (DecodeError)
			} else {
				SetHypFieldIsPresent (id,  0);
			}
		} else if (is_tel_scheme(pszScheme)) {
		} else { // tel or absoluteURI
			SetHypFieldIsPresent(id, 0);
		} else { // absoluteURI
			if (reg_absolute_uri.Match (buffer)) {
				SetHypFieldIsPresent (id,  1);
				SetHypFieldLength(id, reg_absolute_uri.GetMatchedLength());
			} else {
				SetHypFieldIsPresent (id,  0);
			}
		}
		break;

@@ -293,16 +292,31 @@ void SipUrl::PreDecodeField (int id, Buffer& buffer) throw (DecodeError)

void UserInfo::PreDecodeField (int id, Buffer& buffer) throw (DecodeError)
{
	static Regex reg_username ("^([" SIPCHARS_UNRESERVED SIPCHARS_USER_UNRESERVED "]|" SIPREG_ESCAPED ")+:");
	static Regex reg_username ("^([" SIPCHARS_UNRESERVED SIPCHARS_USER_UNRESERVED "]|" SIPREG_ESCAPED ")+");
	static Regex reg_colon ("^[:]");
	static Regex reg_password ("^([&=+$," SIPCHARS_UNRESERVED "]|" SIPREG_ESCAPED ")*");
	static Regex reg_absolute_uri ("^" SIPREG_ABSOLUTE_URI);

	// absoluteURI is mapped into SipUrl.userInfo.userOrTelephoneSubscriber and requires special handling
	Variable* parent = GetParent();
	bool bRequestUri = false;
	if (parent != NULL) {
		const char * pszParName = parent->GetTypeName();
		if (strcmp(pszParName, "SipUrl") == 0) {
			SipUrl * pSipUrl = dynamic_cast<SipUrl*>(parent);
			const char * pszScheme = pSipUrl->Get_scheme().GetValue();
			bRequestUri = !is_sip_scheme(pszScheme);
		}
	}
	Regex * pRegex;
	switch (id) {
	case id_userOrTelephoneSubscriber:
		if (reg_username.Match (buffer)) {
			SetHypFieldLength (id, reg_username.GetMatchedLength() - 8);
		}
		pRegex = bRequestUri ? &reg_absolute_uri : &reg_username;
		pRegex->AssertMatch (buffer, this);
		SetHypFieldLength(id, pRegex->GetMatchedLength());
		break;
	case id_password:
		if(buffer.GetBitsLeft()) {
		if(!bRequestUri && reg_colon.Match(buffer)) {
			buffer.SetPosition(buffer.GetPosition() + 8);
			SetHypFieldIsPresent (id, 1);
			reg_password.AssertMatch (buffer, this);
@@ -316,29 +330,14 @@ void UserInfo::PreDecodeField (int id, Buffer& buffer) throw (DecodeError)
void HostPort::PreDecodeField (int id, Buffer& buffer) throw (DecodeError)
{
	static Regex reg_host ("^" SIPREG_HOST);
	static Regex reg_absolute_uri ("^" SIPREG_ABSOLUTE_URI);
	static Regex reg_colon ("^:");

	// absoluteURI is mapped into SipUrl.hostPort.host and requires special handling
	Variable* parent = GetParent();
	bool bRequestUri = false;
	if (parent != NULL) {
		const char * pszParName = parent->GetTypeName();
		if (strcmp(pszParName, "SipUrl") == 0) {
			SipUrl * pSipUrl = dynamic_cast<SipUrl*>(parent);
			const char * pszScheme = pSipUrl->Get_scheme().GetValue();
			bRequestUri = !is_sip_scheme(pszScheme);
		}
	}

	Regex * pRegex;
	switch (id) {
	case id_host:
		// host is always present
		SetHypFieldIsPresent(id, 1);
		pRegex = bRequestUri ? &reg_absolute_uri : &reg_host;
		pRegex->AssertMatch (buffer, this);
		SetHypFieldLength(id, pRegex->GetMatchedLength());
		reg_host.AssertMatch (buffer, this);
		SetHypFieldLength(id, reg_host.GetMatchedLength());
		break;

	case id_portField:
@@ -867,13 +866,23 @@ void ContactBody::PreDecode (Buffer& buffer) throw (DecodeError)
{
	static Regex reg_asterisk ("^[*]");
	if (reg_asterisk.Match (buffer)) {
		if (GetChosenId() == id_contactAddresses)
			throw DecodeError (this, "cannot process wildcard; contactAddresses option is already selected");
		SetHypChosenId (id_wildcard);
		SetHypFieldLength(id_wildcard, 8);
	} else {
		if (GetChosenId() == id_wildcard)
			throw DecodeError (this, "cannot process address list; wildcart option is already selected");
		SetHypChosenId (id_contactAddresses);
	}
}

void ContactAddress_List::PreDecode (Buffer& buffer) throw (DecodeError)
{
	SetHypSize (GetSize() + 1);
	SetHypAppend (1);
}

void ContactAddress_List::PostDecodeField (int id, Buffer& buffer) throw (DecodeError)
{
	if (detect_comma (buffer))