-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathCSeq.cpp
More file actions
89 lines (74 loc) · 2.09 KB
/
CSeq.cpp
File metadata and controls
89 lines (74 loc) · 2.09 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
#include "CSeq.hpp"
#include <boost/regex.hpp>
#include <sstream>
namespace Sip {
CSeq::CSeq( const SipHeaderValue& srhv ) throw( CSeqException )
{
this->ParseCSeq( srhv.Value() );
}
CSeq::CSeq ( int sequence, SipRequest::REQUEST_METHOD rm ) throw( CSeqException )
{
m_requestMethod = rm;
m_sequence = sequence;
try
{
m_requestMethodString = RequestTypes.ReverseGet( rm );
}
catch ( LookupTableException& e )
{
throw CSeqException( "CSeq::CSeq - Invalid request method" );
}
}
CSeq::CSeq()
{
//Stub
}
string CSeq::ToString() const throw()
{
std::ostringstream cseqAsStringBuilder;
string upperRequestMethodString = this->m_requestMethodString; //because some phones can be picky...
transform( upperRequestMethodString.begin(), upperRequestMethodString.end(), upperRequestMethodString.begin(), (int(*)(int))toupper ); //go uppercase
cseqAsStringBuilder << m_sequence << ' ' << upperRequestMethodString;
return cseqAsStringBuilder.str();
}
void CSeq::ParseCSeq( const string& rawValue ) throw( CSeqException )
{
// [seq] [RM]
boost::regex expression( "(.*?)\\s+(.*)" );
boost::cmatch matches;
if ( boost::regex_match( rawValue.c_str(), matches, expression ) )
{
m_sequence = atoi( string( matches[1].first, matches[1].second ).c_str() );
if (m_sequence == 0 || m_sequence < 0 ) //Or just <1...
throw CSeqException( string( "Invalid CSeq: " ) + rawValue );
m_requestMethodString = string( matches[2].first, matches[2].second );
try
{
m_requestMethod = RequestTypes.GetCase( m_requestMethodString );
}
catch ( LookupTableException& e )
{
throw CSeqException( string( "Request method not supported: " ) + m_requestMethodString );
}
}
else
throw CSeqException( string( "Invalid CSeq: " ) + rawValue );
}
int CSeq::Sequence() const throw()
{
return m_sequence;
}
SipRequest::REQUEST_METHOD CSeq::RequestMethod() const throw()
{
return m_requestMethod;
}
string CSeq::RequestMethodAsString() const throw()
{
return RequestTypes.ReverseGet( m_requestMethod );
}
CSeq& CSeq::Increment() throw()
{
m_sequence++;
return *this;
}
}; //namespace Sip