-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathSipMessage.hpp
More file actions
165 lines (137 loc) · 5.08 KB
/
SipMessage.hpp
File metadata and controls
165 lines (137 loc) · 5.08 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
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
#ifndef SIPMESSAGE_HPP
#define SIPMESSAGE_HPP
#include <string>
#include <queue>
#include "SipHeader.hpp"
#include "SipHeaderValue.hpp"
namespace Sip {
/**
* \class SipMessageException
* \brief standard exception class for SipMessage
*/
class SipMessageException : public std::exception
{
public:
SipMessageException ( std::string what ) throw() : m_s ( what ) {};
~SipMessageException () throw() {}
const char * what() const throw() { return m_s.c_str(); }
private:
std::string m_s;
};
using std::string;
using std::queue;
/**
* \class SipMessage
* \brief The basic pattern for SIP datagrams.
*/
class SipMessage
{
public:
enum MESSAGE_TYPE
{
MT_UNDEFINED,
MT_REQUEST,
MT_RESPONSE
};
SipMessage( MESSAGE_TYPE type ) throw() : Type( type ), m_hasBody( false ) {}
virtual ~SipMessage() {}
/**
* Returns a vector<SipHeaderValue> corresponding to the header key
* @param key The header key. For example, 'via'
* @return vector<SipHeaderValue>
* @throw SipMessageException if key doesn't exist. See HasHeader()
*/
const vector<SipHeaderValue>& GetHeaderValues ( const string& headerName ) const throw ( SipMessageException );
/**
* Allows you to enumerate all headers
* @return A const reference to the vector of SipHeader's
*/
const vector<SipHeader>& GetAllHeaders() const throw();
/**
* Returns the message body, if there is one->messageQueue.push_back( message );
* @return A const reference to the message body
* @throw SipMessageException is there isn't a body to get
*/
const string& GetMessageBody() const throw( SipMessageException );
string& ModifyMessageBody() throw ( SipMessageException );
/**
* Does a specific SIP header exist
* @param key Header in question. Remember, it's all lcase.
* @return True if header exists, false otherwise.
*/
bool HasHeader ( const string& headerName ) const throw();
/**
* Does message have a non-zero body
* @return True if body exists, false otherwise
*/
bool HasMessageBody ( ) const throw();
/**
* Sets the message body, and the Content-Type and Content-Length fields
*/
void SetMessageBody ( const string& body, const string& rtpMap ) throw( SipMessageException );
/**
* Returns an reference to a header so it's values may be modified. If header doesn't exist, it is added.
* @param headerName The header to modify
* @return A reference to the vector<SipHeaderValue> indicated by the header.
*/
vector<SipHeaderValue>& ModifyHeader( const string& headerName);
/**
* Replaces or sets a header referenced with the values given
* @param headerName The name of the header to add/replace
* @param values The value(s) to go along with it
*/
void SetHeader( const string& headerName, const vector<SipHeaderValue>& values ) throw();
void SetHeader( const string& headerName, const string& value ) throw();
void SetHeader( const string& headerName, const SipHeaderValue& value ) throw();
/**
* @brief Adds to or sets a header with the given vector<SipHeaderValue>
*
* @param headerName
* @param
*/
void PushHeader( const string& headerName, const vector<SipHeaderValue>& values ) throw();
void PushHeader( const string& headerName, const string& value ) throw();
void PushHeader( const string& headerName, const SipHeaderValue& value ) throw();
/**
* @brief Deletes a header
*
* @headerName A string representing the header name. Case insensitive matching is performed.
*/
void DeleteHeader( const string& headerName ) throw();
string ToString() const;
const string& GetOriginalRawMessage() const;
//
// UTILITY
//
MESSAGE_TYPE Type;
protected:
/**
* Adds one or more values, given a header name, to SipMessage::m_headers
* @param headerName The name of the header
* @param rawString The raw string containing values in the following format: value(tags)*,value(tags)*,...
* @note SipMessage::FillTags is used internal after the comma seperated values are split up
* @warning If commas are used for anything but seperating values, the logic will be broken.
*/
void ProcessSipHeaderValues ( const string& headerName, string& rawString ) throw ( SipMessageException );
/**
* Populates m_headers and messageBody (Content-Length header indicates last header line, RFC 3261 7.5)
* @param start The character folloing the end of the start-line and it's CR/LF
* @param end The end of the entire message
*/
void ProcessSipMessage( string::const_iterator start, string::const_iterator end ) throw( SipMessageException );
/**
* transforms any message header name into it's lower-case, long variant
* @param headerName The header name to be cleaned up
* @return The massaged, or 'cleaned' header name
*/
string MassageHeaderKey ( string headerName ) const throw();
string messageBody, rawMessage;
string m_recvAddress;
bool m_hasBody, m_hasRecvAddress;
vector<SipHeader> m_headers;
private:
static void CSVSeperate( const string& rawString, queue<string>& elements );
SipMessage() {}
};
}; //namespace Sip
#endif //SIPMESSAGE_HPP