Commit e67640ef authored by baire's avatar baire
Browse files

support for decoding quoted strings

parent ad4875da
Loading
Loading
Loading
Loading
+53 −18
Original line number Diff line number Diff line
@@ -88,7 +88,7 @@ private:
	boost::match_results<iterator>	mResults;
};

void normalise_quoted_string (Charstring& cs) throw (DecodeError)
void normalise_quoted_string (Charstring& cs, bool remove_quotes = false) throw (DecodeError)
{
	std::string result;

@@ -96,13 +96,28 @@ void normalise_quoted_string (Charstring& cs) throw (DecodeError)
	
	const unsigned char* p   = cs.GetValueBin();
	const unsigned char* end = p + (cs.GetLength() / 8);

	if (remove_quotes)
	{
		if ((end - p) < 2)
			goto error_malformed;

		if ((*p++ != '"') | (*--end != '"'))
			goto error_malformed;
	}

	for ( ; p!=end ; p++)
	{
		switch (*p) {
		case '\r':
		case '\r': //LWS
		case '\n':
		case ' ':
		case 0x21:

		case ' ': //WSP
		case '\v':
		case '\t':
		case '\f':

		case 0x21: //!
			// plain text
			result += *p;
			break;
@@ -145,9 +160,15 @@ void normalise_quoted_string (Charstring& cs) throw (DecodeError)
	}

	// replace the string with the quoted string
	{
		Bytestring& bs = cs;
		bs.SetValue (result);
	}
	return;

error_malformed:
	throw DecodeError (&cs, "Malformed quoted string");
}

//WSP: space, htab, vtab, form feed
#define SIPCHARS_WSP		" \t\v\f"
@@ -571,6 +592,18 @@ void GenericParam::PreDecodeField (int id, Buffer& buffer) throw (DecodeError)
	}
}

void GenericParam::PostDecode (Buffer& buffer) throw (DecodeError)
{
	if (IsPresent (id_paramValue))
	{
		Charstring& value = Get_paramValue();

		if (value.GetLength() &&
		    (*value.GetValueBin() == '"'))
				normalise_quoted_string (value, true);
	}
}

void RequestLine::PreDecodeField (int id, Buffer& buffer) throw (DecodeError)
{
	static Regex reg_method ("^" SIPREG_TOKEN);
@@ -1761,14 +1794,18 @@ void NameAddr::PreDecodeField (int id, Buffer& buffer) throw (DecodeError)
	}
}

void NameAddr::PostDecodeField (int id, Buffer& buffer) throw (DecodeError)
void NameAddr::PostDecode (Buffer& buffer) throw (DecodeError)
{
	static Regex reg_raquot ("^>");
	if (id == id_addrSpec)
	{

	reg_raquot.AssertMatch (buffer, this);
	buffer.SetPosition(buffer.GetPosition() + 8);
	remove_whitespace(buffer);
	
	if (IsPresent (id_displayName)) {
		if (Get_displayName().GetLength() &&
		    (*Get_displayName().GetValueBin() == '"'))
			normalise_quoted_string (Get_displayName(), true);
	}
}

@@ -2139,13 +2176,11 @@ void WarningValue::PreDecodeField (int id, Buffer& buffer) throw (DecodeError)
	}
}

void WarningValue::PostDecodeField (int id, Buffer& buffer) throw (DecodeError)
void WarningValue::PostDecode (Buffer& buffer) throw (DecodeError)
{
	switch (id) { 
		case id_WarnText:
	buffer.SetPosition(buffer.GetPosition() + 8); // remove ending quota
			break;
	}

	normalise_quoted_string (Get_WarnText());
}

void WarnAgent::PreDecode (Buffer& buffer) throw (DecodeError)