Commit 3bf58b3b authored by urbant's avatar urbant
Browse files

support for repeated header fields (including authorization)

parent 1ec4cf18
Loading
Loading
Loading
Loading
+155 −51
Original line number Diff line number Diff line
@@ -380,9 +380,31 @@ void AmpersandParam_List::PreDecodeField (int id, Buffer& buffer) throw (DecodeE
		SetHypSize(-2);
}

void CommaParam_List::PreDecode (Buffer& buffer) throw (DecodeError)
{
	Variable* parent = GetParent();
	if (parent != NULL) {		
		const char * pszParName = parent->GetTypeName();
		if (strcmp(pszParName, "Credentials") == 0 ||
			strcmp(pszParName, "AuthenticationInfo") == 0){
			SetHypSize (GetSize() + 1);
			SetHypAppend (1);
		}
	}
}

void CommaParam_List::PreDecodeField (int id, Buffer& buffer) throw (DecodeError)
{
	static Regex reg_content ("^" SIPREG_ASCII_WITHOUT_COMMA);
	if (GetSize() > 0 && !reg_content.Match(buffer)) {
		SetHypSize(-2);	
	}
}

void CommaParam_List::PostDecodeField (int id, Buffer& buffer) throw (DecodeError)
{
	if (detect_comma (buffer))
	static Regex reg_content ("^" SIPREG_ASCII_WITHOUT_COMMA);
	if (detect_comma (buffer) && reg_content.Match (buffer))
		SetHypSize (GetSize() + 1);
	else
		SetHypSize (-2);
@@ -942,7 +964,7 @@ void ReplyTo::PreDecodeField (int id, Buffer& buffer) throw (DecodeError)
void Accept::PreDecodeField (int id, Buffer& buffer) throw (DecodeError){
	static Regex reg_accept_args ("^[^;,\\r\\n]");
	if (id == id_acceptArgs){
		if(reg_accept_args.Match(buffer)) {
		if(reg_accept_args.Match(buffer) || Get_acceptArgs().GetSize() > 0) {
			SetHypFieldIsPresent (id, 1);
		} else if (Get_acceptArgs().GetSize() == 0){
			SetHypFieldIsPresent (id, 0);
@@ -977,9 +999,18 @@ void AcceptBody_List::PreDecode (Buffer& buffer) throw (DecodeError)
	SetHypAppend (1);
}

void AcceptBody_List::PreDecodeField (int id, Buffer& buffer) throw (DecodeError)
{
	static Regex reg_content ("^" SIPREG_ASCII_WITHOUT_COMMA);
	if (GetSize() > 0 && !reg_content.Match(buffer)) {
		SetHypSize(-2);	
	}
}

void AcceptBody_List::PostDecodeField (int id, Buffer& buffer) throw (DecodeError)
{
	if (detect_comma (buffer))
	static Regex reg_content ("^" SIPREG_ASCII_WITHOUT_COMMA);
	if (detect_comma (buffer) && reg_content.Match (buffer))
		SetHypSize (GetSize() + 1);
	else
		SetHypSize (-2);
@@ -988,7 +1019,8 @@ void AcceptBody_List::PostDecodeField (int id, Buffer& buffer) throw (DecodeErro
void AcceptEncoding::PreDecodeField (int id, Buffer& buffer) throw (DecodeError){
	static Regex reg_content_coding ("^[^,\\r\\n]");
	if (id == id_contentCoding){
		if(reg_content_coding.Match(buffer)) {
		if(reg_content_coding.Match(buffer) || 
			Get_contentCoding().GetSize() > 0) {
			SetHypFieldIsPresent (id, 1);
		} else {
			SetHypFieldIsPresent (id, 0);
@@ -999,14 +1031,20 @@ void AcceptEncoding::PreDecodeField (int id, Buffer& buffer) throw (DecodeError)
void ContentCoding_List::PreDecodeField (int id, Buffer& buffer) throw (DecodeError)
{
	static Regex reg_content ("^" SIPREG_ASCII_WITHOUT_COMMA);
	if (GetSize() == 0)
		reg_content.AssertMatch(buffer, this);
	else if (!reg_content.Match(buffer)) {
		SetHypSize(-2);
		return;
	}
	SetHypFieldLength(reg_content.GetMatchedLength());
}


void ContentCoding_List::PostDecodeField (int id, Buffer& buffer) throw (DecodeError)
{
	if (detect_comma (buffer))
	static Regex reg_content ("^" SIPREG_ASCII_WITHOUT_COMMA);
	if (detect_comma (buffer) && reg_content.Match (buffer))
		SetHypSize (GetSize() + 1);
	else
		SetHypSize (-2);
@@ -1015,7 +1053,8 @@ void ContentCoding_List::PostDecodeField (int id, Buffer& buffer) throw (DecodeE
void AcceptLanguage::PreDecodeField (int id, Buffer& buffer) throw (DecodeError){
	static Regex reg_language_body ("^[^;,\\r\\n]");
	if (id == id_languageBody){
		if(reg_language_body.Match(buffer)) {
		if(reg_language_body.Match(buffer) ||
			Get_languageBody().GetSize() > 0) {
			SetHypFieldIsPresent (id, 1);
		} else {
			SetHypFieldIsPresent (id, 0);
@@ -1041,9 +1080,27 @@ void LanguageBody::PreDecodeField (int id, Buffer& buffer) throw (DecodeError)
	}
}

void LanguageBody_List::PreDecode (Buffer& buffer) throw (DecodeError)
{
	// we assume that we are decoding one field at onece 
	// multiple fields are handled by successively decoding
	// the via field several times in MessageHeader
	SetHypSize (GetSize() + 1);
	SetHypAppend (1);
}

void LanguageBody_List::PreDecodeField (int id, Buffer& buffer) throw (DecodeError) {
	static Regex reg_language ("^[^" SIPCHARS_WSP ";,\\r\\n]+");
	if (!reg_language.Match(buffer)) {
		SetHypSize(-2);
		return;
	}
}

void LanguageBody_List::PostDecodeField (int id, Buffer& buffer) throw (DecodeError)
{
	if (detect_comma (buffer))
	static Regex reg_language ("^[^" SIPCHARS_WSP ";,\\r\\n]+");
	if (detect_comma (buffer) && reg_language.Match (buffer))
		SetHypSize (GetSize() + 1);
	else
		SetHypSize (-2);
@@ -1057,7 +1114,7 @@ void MaxForwards::PreDecode (Buffer& buffer) throw (DecodeError)
void AlertInfo::PreDecodeField (int id, Buffer& buffer) throw (DecodeError){
	static Regex reg_alert_info ("^[^;,\\r\\n]");
	if (id == id_alertInfoBody){
		if(reg_alert_info.Match(buffer)) {
		if(reg_alert_info.Match(buffer) || Get_alertInfoBody().GetSize() > 0) {
			SetHypFieldIsPresent (id, 1);
		} else {
			SetHypFieldIsPresent (id, 0);
@@ -1093,6 +1150,15 @@ void AlertInfoBody::PostDecodeField (int id, Buffer& buffer) throw (DecodeError)
	}
}

void AlertInfoBody_List::PreDecode (Buffer& buffer) throw (DecodeError)
{
	// we assume that we are decoding one field at onece 
	// multiple fields are handled by successively decoding
	// the via field several times in MessageHeader
	SetHypSize (GetSize() + 1);
	SetHypAppend (1);
}

void AlertInfoBody_List::PostDecodeField (int id, Buffer& buffer) throw (DecodeError)
{
	if (detect_comma (buffer))
@@ -1104,7 +1170,7 @@ void AlertInfoBody_List::PostDecodeField (int id, Buffer& buffer) throw (DecodeE
void Allow::PreDecodeField (int id, Buffer& buffer) throw (DecodeError){
	static Regex reg_allow ("^[^,\\r\\n]");
	if (id == id_methods){
		if(reg_allow.Match(buffer)) {
		if(reg_allow.Match(buffer) || Get_methods().GetSize() > 0) {
			SetHypFieldIsPresent (id, 1);
		} else {
			SetHypFieldIsPresent (id, 0);
@@ -1112,21 +1178,33 @@ void Allow::PreDecodeField (int id, Buffer& buffer) throw (DecodeError){
	}
}

void Method_List::PreDecodeField (int id, Buffer& buffer) throw (DecodeError)
void Method_List::PreDecode (Buffer& buffer) throw (DecodeError)
{
	static Regex reg_separator ("^" SIPREG_COMMA);
	// we assume that we are decoding one field at onece 
	// multiple fields are handled by successively decoding
	// the via field several times in MessageHeader
	SetHypSize (GetSize() + 1);
	SetHypAppend (1);
}

void Method_List::PreDecodeField (int id, Buffer& buffer) throw (DecodeError) {
	static Regex reg_content ("^" SIPREG_TOKEN);
	
	if (!buffer.GetBitsLeft())
	if (reg_content.Match (buffer)) {
		SetHypFieldLength(reg_content.GetMatchedLength());
	} else {
		SetHypSize(-2);
		return;
	bool bSeparated = reg_separator.Match(buffer);
	if (bSeparated)
		buffer.SetPosition(buffer.GetPosition() + reg_separator.GetMatchedLength());
	} 
}

	if (GetSize() == 0 || bSeparated) {
		reg_content.AssertMatch(buffer, this);
		SetHypFieldLength(reg_content.GetMatchedLength());
	} else
void Method_List::PostDecodeField (int id, Buffer& buffer) throw (DecodeError)
{
	static Regex reg_content ("^" SIPREG_TOKEN);

	if (detect_comma (buffer) && reg_content.Match (buffer))
		SetHypSize (GetSize() + 1);
	else
		SetHypSize (-2);
}

@@ -1134,9 +1212,13 @@ void Credentials::PreDecode (Buffer& buffer) throw (DecodeError)
{
	static Regex reg_digest ("^[Dd][Ii][Gg][Ee][Ss][Tt]" SIPREG_LWS);
	if (reg_digest.Match (buffer)) {
		if (GetChosenId() == id_otherResponse)
			throw DecodeError (this, "cannot process digest credentials; otherResponse option is already selected");
		buffer.SetPosition(buffer.GetPosition() + reg_digest.GetMatchedLength());
		SetHypChosenId (id_digestResponse);		
	} else {
		if (GetChosenId() == id_digestResponse)
			throw DecodeError (this, "cannot process custom credentials; digestResponse option is already selected");
		SetHypChosenId (id_otherResponse);
	}
}
@@ -1165,6 +1247,8 @@ void OtherAuth::PreDecodeField (int id, Buffer& buffer) throw (DecodeError)
		case id_authParams:
			reg_separator.AssertMatch(buffer, this);
			buffer.SetPosition(buffer.GetPosition() + reg_separator.GetMatchedLength());
			Get_authParams().SetHypSize (GetSize() + 1);
			Get_authParams().SetHypAppend (1);
			break;
	}
}
@@ -1234,6 +1318,12 @@ void ContentDisposition::PreDecodeField (int id, Buffer& buffer) throw (DecodeEr
	}
}

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

void LanguageTag_List::PreDecodeField (int id, Buffer& buffer) throw (DecodeError)
{
	static Regex reg_content ("^" SIPREG_ASCII_WITHOUT_COMMA);
@@ -1241,7 +1331,6 @@ void LanguageTag_List::PreDecodeField (int id, Buffer& buffer) throw (DecodeErro
	SetHypFieldLength(reg_content.GetMatchedLength());	
}


void LanguageTag_List::PostDecodeField (int id, Buffer& buffer) throw (DecodeError)
{
	if (detect_comma (buffer))
@@ -1261,7 +1350,7 @@ void Date::PreDecodeField (int id, Buffer& buffer) throw (DecodeError){
void ErrorInfo::PreDecodeField (int id, Buffer& buffer) throw (DecodeError){
	static Regex reg_error_info ("^[^;,\\r\\n]");
	if (id == id_errorInfo){
		if(reg_error_info.Match(buffer)) {
		if(reg_error_info.Match(buffer) || Get_errorInfo().GetSize() > 0) {
			SetHypFieldIsPresent (id, 1);
		} else {
			SetHypFieldIsPresent (id, 0);
@@ -1297,6 +1386,12 @@ void ErrorInfoBody::PostDecodeField (int id, Buffer& buffer) throw (DecodeError)
	}
}

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

void ErrorInfoBody_List::PostDecodeField (int id, Buffer& buffer) throw (DecodeError)
{
	if (detect_comma (buffer))
@@ -1317,6 +1412,12 @@ void Expires::PreDecodeField (int id, Buffer& buffer) throw (DecodeError)
	}
}

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

void CallidString_List::PreDecodeField (int id, Buffer& buffer) throw (DecodeError)
{
	static Regex reg_content ("^" SIPREG_ASCII_WITHOUT_COMMA);
@@ -1636,36 +1737,39 @@ void Payload::PostDecode(Buffer& buffer) throw (DecodeError)
	Get_payloadlength().SetValue(Get_payloadvalue().GetLength() / 8);
}

void OptionTag_List::PreDecodeField(int id, Buffer& buffer) throw (DecodeError)
void OptionTag_List::PreDecode (Buffer& buffer) throw (DecodeError)
{
	static Regex reg_first ("^" SIPREG_TOKEN);
	static Regex reg_next ("^" SIPREG_COMMA "(" SIPREG_TOKEN ")");

	if (id == 0) {
		// first option
		reg_first.AssertMatch(buffer, this);
		SetHypFieldLength(reg_first.GetMatchedLength());
	} else if (reg_next.Match(buffer)) {
		// next options
		reg_next.MoveAt(buffer, 1);
		SetHypFieldLength(reg_next.GetMatchedLength(1));
	} else {
		// end of options
		SetHypSize(-2);
	}
	SetHypSize (GetSize() + 1);
	SetHypAppend (1);
}

void RouteBody_List::PreDecodeField(int id, Buffer& buffer) throw (DecodeError)
void OptionTag_List::PreDecodeField (int id, Buffer& buffer) throw (DecodeError)
{
	static Regex reg_comma ("^,");
	static Regex reg_content ("^" SIPREG_TOKEN);
	reg_content.AssertMatch(buffer, this);
	SetHypFieldLength(reg_content.GetMatchedLength());	
}

	if (id) {
		if (reg_comma.Match(buffer)) {
			reg_comma.MovePast(buffer);
		} else {
void OptionTag_List::PostDecodeField (int id, Buffer& buffer) throw (DecodeError)
{
	if (detect_comma (buffer))
		SetHypSize (GetSize() + 1);
	else
		SetHypSize (-2);
}

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

void RouteBody_List::PostDecodeField (int id, Buffer& buffer) throw (DecodeError)
{
	if (detect_comma (buffer))
		SetHypSize (GetSize() + 1);
	else
		SetHypSize (-2);
}

void RouteBody::PreDecodeField(int id, Buffer& buffer) throw (DecodeError)