Generate the string representing this sip message.
| 187 | |
| 188 | // Generate the string representing this sip message. |
| 189 | string SipMessage::smGenerate() |
| 190 | { |
| 191 | string result; |
| 192 | result.reserve(1000); |
| 193 | char buf[200]; |
| 194 | |
| 195 | // First line. |
| 196 | if (msmCode == 0) { |
| 197 | // It is a request |
| 198 | string uri = this->msmReqUri; // This includes the URI params and headers, if any. |
| 199 | snprintf(buf,200,"%s %s SIP/2.0\r\n", this->msmReqMethod.c_str(), uri.c_str()); |
| 200 | } else { |
| 201 | // It is a reply. |
| 202 | snprintf(buf,200,"SIP/2.0 %u %s\r\n", msmCode, msmReason.c_str()); |
| 203 | } |
| 204 | result.append(buf); |
| 205 | |
| 206 | appendHeader(&result,"To",this->msmTo.value()); |
| 207 | appendHeader(&result,"From",this->msmFrom.value()); |
| 208 | |
| 209 | appendHeader(&result,"Via",this->msmVias); |
| 210 | |
| 211 | appendHeader(&result,"Route",this->msmRoutes); |
| 212 | |
| 213 | appendHeader(&result,"Call-ID",this->msmCallId); |
| 214 | |
| 215 | snprintf(buf,200,"%d %s",msmCSeqNum,msmCSeqMethod.c_str()); |
| 216 | appendHeader(&result,"CSeq",buf); |
| 217 | |
| 218 | if (! msmContactValue.empty()) { appendHeader(&result,"Contact",msmContactValue); } |
| 219 | if (! msmAuthorizationValue.empty()) { appendHeader(&result,"Authorization",msmAuthorizationValue); } |
| 220 | // The WWW-Authenticate header occurs only in inbound replies from the Registrar, so we ignore it here. |
| 221 | |
| 222 | // These are other headers we dont otherwise process. |
| 223 | for (SipParamList::iterator it = msmHeaders.begin(); it != msmHeaders.end(); it++) { |
| 224 | appendHeader(&result,it->mName.c_str(),it->mValue); |
| 225 | } |
| 226 | |
| 227 | static const char* userAgent1 = "OpenBTS " VERSION " Build Date " __DATE__; |
| 228 | const char *userAgent = userAgent1; |
| 229 | appendHeader(&result,"User-Agent",userAgent); |
| 230 | |
| 231 | appendHeader(&result,"Max-Forwards",gConfig.getNum("SIP.MaxForwards")); |
| 232 | |
| 233 | // Create the body, if any. |
| 234 | appendHeader(&result,"Content-Type",msmContentType); |
| 235 | appendHeader(&result,"Content-Length",msmBody.size()); |
| 236 | result.append("\r\n"); |
| 237 | result.append(msmBody); |
| 238 | msmContent = result; |
| 239 | return msmContent; |
| 240 | } |
| 241 | |
| 242 | // Copy the top via from other into this. |
| 243 | void SipMessage::smCopyTopVia(SipMessage *other) |