Commit ada704f9 authored by baire's avatar baire
Browse files

replace undisplayable characters with '?' in the payload field

parent a87a8708
Loading
Loading
Loading
Loading
+16 −17
Original line number Diff line number Diff line
@@ -172,6 +172,13 @@ error_malformed:
	throw e;
}

static inline bool asciichar_is_displayable (char c)
{
	if ((c >= 32) && (c<127))
		return true;
	return (c == '\r') | (c == '\n') | (c == '\t') | (c == '%');
}

void normalise_escaped_string (Charstring& cs) throw (DecodeError)
{
	std::string result;
@@ -202,8 +209,7 @@ void normalise_escaped_string (Charstring& cs) throw (DecodeError)
			c = *p;
		}

		if (((c >= 32) && (c<127))
		 | (c == '\r') | (c == '\n') | (c == '\t') | (c == '%'))
		if (asciichar_is_displayable(c))
		{
			// 7-bit character
			result += c;
@@ -2108,6 +2114,14 @@ void msgname::PostDecodeField (int id, Buffer& buffer) throw (DecodeError) \
		} \
		Get_payload().Get_payloadlength().SetValue(buffer.GetLength() / 8); \
		Get_payload().Get_payloadvalue().SetValueBin(buffer.GetValueBin(), buffer.GetLength()); \
 \
		/* replace undisplayable characters with '?' */ \
		Charstring& payload = Get_payload().Get_payloadvalue(); \
		int byte_length = buffer.GetLength() / 8; \
		for (int  i=0 ; i<byte_length ; i++) { \
			if (!asciichar_is_displayable (payload[i])) \
				payload[i] = '?'; \
		} \
		break; \
	} \
}
@@ -2165,21 +2179,6 @@ void MessageBody::PreDecode (Buffer& buffer) throw (DecodeError)
	SetHypChosenId (id_textplain);
}

void Payload::PreDecode(Buffer& buffer) throw (DecodeError)
{
	// FIXME: this is not very clean
	// 	  -> should provide a way to skip a field in the decoder
	int offset=buffer.GetPosition() - Get_payloadlength().GetLength();
	if (offset < 0)
		throw DecodeError (this, "Unable to decode Payload\n");
	buffer.SetPosition(offset);
}

void Payload::PostDecode(Buffer& buffer) throw (DecodeError)
{
	Get_payloadlength().SetValue(Get_payloadvalue().GetLength() / 8);
}

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