Headers
From reSIProcate
SipMessage Headers
A detailed listing of the supported headers and their storage/parser type is here.
SipMessage has an array of built in headers and a list of unknown/extension headers. In either case, the header value or values are accessed with the overloaded header method and a header access token.
std::cerr << msg->header(h_To).uri().host() << std::endl;
The header access token is also used to check for the existence of a header:
if (msg->exists(h_Routes))
{
....
The header acesss token is also used to remove a header. It is not an error to remove a header that is not present in the message.
msg->remove(h_Warnings);
The header method will create a header value if the request header is not present in the message and the message is not const. So headers can be added to non-const messages simply by accessing the header.
msg->header(h_To) = NameAddr("Joe <joseph@example.com>");
If the message is const, accessing a header that is not present in the message will raise a SipMessage::Exception. Often, a SIP element will check if the header exists before accessing it rather than handle the exception.
Some headers have multiple values. The values of a multi-valued header are maintained in a container class named after the type contained. For example, msg->header(h_Contacts) returns a reference to NameAddrs. The containers have STL container syntax.
for (NameAddrs::const_iterator i = msg->header(h_Contacts).begin(); i != msg->header(h_Contacts.end(); ++i)
{
const NameAddr& na = *i;
...;
Multi-valued header values correspond to comma separated values with one header or multiple header lines each with their own header. When serialized to the wire, multiple values are emitted comma separated.