Commit e921cc9b authored by urbant's avatar urbant
Browse files

decoding support for RFC 3265 and RFC 3313

parent caf44ff6
Loading
Loading
Loading
Loading
+82 −0
Original line number Diff line number Diff line
@@ -131,6 +131,7 @@ bool is_tel_scheme (const char * pszScheme) {
#define SIPCHARS_TEXT_UTF8CHAR	"\x21-\xFD"
#define SIPREG_ESCAPED	"(%[0-9A-Fa-f]{2})"
#define SIPREG_TOKEN "[" SIPCHARS_ALFANUM ".!%*_+`'~\\-]+"
#define SIPREG_TOKEN_NODOT "[" SIPCHARS_ALFANUM "!%*_+`'~\\-]+"
#define SIPREG_WORD "(?:[][" SIPCHARS_ALFANUM "\\-.!%*_+`'~()<>:\\\\\"/?{}])+"
#define SIPREG_ASCII_WITHOUT_COMMA "[\\x21-\\x2B\\x2D-\\x7E]+"
#define SIPREG_TEXT_UTF8_TRIM	"[\x21-\xFD]([\x21-\xFD]|(" SIPREG_LWS "))*"
@@ -737,6 +738,11 @@ private:
		SIP_HEADER_ADD (WWW-Authenticate,		,	wwwAuthenticate,	WWW_AUTHENTICATE_E);
		SIP_HEADER_ADD (RSeq,		,	rSeq,		RSEQ_E);
		SIP_HEADER_ADD (RAck,		,	rAck,		RACK_E);
		SIP_HEADER_ADD (Allow-Events,	u,	allowEvents,	ALLOW_EVENTS_E);
		SIP_HEADER_ADD (Event,		o,	event,		EVENT_E);
		SIP_HEADER_ADD (Subscription-State,		,	subscriptionState,	SUBSCRIPTION_STATE_E);
		SIP_HEADER_ADD (P-Media-Authorization,	,	pMediaAuthorization,	P_MEDIA_AUTHORIZATION_E);
		
		{
			mEntries.push_back(Entry("", "", MessageHeader::id_undefinedHeader_List, ""));
			Entry& e = *mEntries.rbegin();
@@ -802,6 +808,8 @@ void MessageHeader::PreDecodeField (Buffer& buffer) throw (DecodeError)
			case id_unsupported:
			case id_via:
			case id_warning:
			case id_allowEvents:
			case id_pMediaAuthorization:
			case id_undefinedHeader_List:
				// these fields can appear multiple times
				break;
@@ -2024,4 +2032,78 @@ void RAck::PreDecodeField (int id, Buffer& buffer) throw (DecodeError)
	}
}

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

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

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

void Event::PreDecodeField (int id, Buffer& buffer) throw (DecodeError)
{
	static Regex reg_event ("^" SIPREG_TOKEN);
	static Regex reg_separator ("^" SIPREG_SEMI);

	switch (id) { 
		case id_eventType:
			reg_event.AssertMatch (buffer, this);
			SetHypFieldLength (id, reg_event.GetMatchedLength());
			break;
		case id_eventParams:
			SetHypFieldIsPresent (id, reg_separator.Match (buffer) ? 1 : 0);
			break;
	}
}

void SubscriptionState::PreDecodeField (int id, Buffer& buffer) throw (DecodeError)
{
	static Regex reg_substate ("^" SIPREG_TOKEN);
	static Regex reg_separator ("^" SIPREG_SEMI);

	switch (id) { 
		case id_subState:
			reg_substate.AssertMatch (buffer, this);
			SetHypFieldLength (id, reg_substate.GetMatchedLength());
			break;
		case id_substateParams:
			SetHypFieldIsPresent (id, reg_separator.Match (buffer) ? 1 : 0);
			break;
	}
}

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

void PMediaAuthorization_List::PreDecodeField (int id, Buffer& buffer) throw (DecodeError)
{
	static Regex reg_media_authorization ("^[" SIPCHARS_HEXA "]+");
	reg_media_authorization.AssertMatch (buffer, this);
	SetHypFieldLength (reg_media_authorization.GetMatchedLength());
}

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

}} // namespaces