📄 siprequest.cxx
字号:
/* Copyright (C) 2005 Mikael Magnusson, Erik Eliasson This library is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation; either version 2.1 of the License, or (at your option) any later version. This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. You should have received a copy of the GNU Lesser General Public License along with this library; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA*//* * Author(s): Mikael Magnusson <mikma@users.sourceforge.net> * Erik Eliasson <eliasson@it.kth.se>*//* Name * SipRequest.cxx * Author * Mikael Magnusson, mikma@users.sourceforge.net * Erik Eliasson, eliasson@it.kth.se * Purpose * Any SIP request request to libmsip*/#include<config.h>#include<libmsip/SipStack.h>#include<libmsip/SipRequest.h>#include<libmsip/SipException.h>#include<libmsip/SipCommandDispatcher.h>#include<libmsip/SipMessageContentIM.h>#include<libmsip/SipHeader.h>#include<libmsip/SipHeaderRoute.h>#include<libmsip/SipHeaderEvent.h>#include<libmsip/SipHeaderFrom.h>#include<libmsip/SipHeaderTo.h>#include<libmsip/SipHeaderCallID.h>#include<libmsip/SipHeaderCSeq.h>#include<libmsip/SipHeaderMaxForwards.h>#include<libmsip/SipHeaderUserAgent.h>#include<libmsip/SipHeaderProxyAuthorization.h>#include<libmsip/SipHeaderAccept.h>#include<libmsip/SipHeaderContact.h>#include<libmsip/SipHeaderReferTo.h>#include<libmsip/SipHeaderSupported.h>using namespace std;MRef<SipRequest*> SipRequest::createSipMessageAck(string branch, MRef<SipMessage*> pack, string to_tel_no, bool provisional){ string method; if (provisional){ method = "PRACK"; }else{ method = "ACK"; } MRef<SipRequest*> req = new SipRequest(branch, method); req->setUri(to_tel_no); req->addHeader(new SipHeader(new SipHeaderValueMaxForwards(70))); int noHeaders = pack->getNoHeaders(); for (int32_t i=0; i< noHeaders; i++){ //FIX: deep copy? MRef<SipHeader *> header = pack->getHeaderNo(i); int headerType = header->getType(); switch (headerType){ case SIP_HEADER_TYPE_CSEQ: ((SipHeaderValueCSeq*) *(header->getHeaderValue(0)))->setMethod(method); case SIP_HEADER_TYPE_FROM: case SIP_HEADER_TYPE_TO: case SIP_HEADER_TYPE_CALLID: req->addHeader(header); break; } } return req;}MRef<SipRequest*> SipRequest::createSipMessageBye(string branch, string callId, string target, string to_uri, string from_uri, int32_t seq_no){ MRef<SipRequest*> req = new SipRequest(branch, "BYE"); req->setUri(target); req->addHeader(new SipHeader(new SipHeaderValueMaxForwards(70))); SipUri from(from_uri); req->addHeader(new SipHeader(new SipHeaderValueFrom(from))); SipUri to(to_uri); req->addHeader(new SipHeader(new SipHeaderValueTo(to))); req->addHeader(new SipHeader(new SipHeaderValueCSeq("BYE", seq_no))); req->addHeader(new SipHeader(new SipHeaderValueCallID(callId))); return req;}MRef<SipRequest*> SipRequest::createSipMessageCancel(string branch, MRef<SipRequest*> inv, string to_uri ){ MRef<SipRequest*> req = new SipRequest(branch, "CANCEL"); req->setUri(to_uri); req->addHeader(new SipHeader( new SipHeaderValueMaxForwards(70))); MRef<SipHeader *> header; int noHeaders = inv->getNoHeaders(); for (int32_t i=0; i< noHeaders; i++){ header = inv->getHeaderNo(i); int type = header->getType(); bool add=false; switch (type){ case SIP_HEADER_TYPE_FROM: add=true; break; case SIP_HEADER_TYPE_TO: add=true; break; case SIP_HEADER_TYPE_CSEQ: ((SipHeaderValueCSeq*)*(header->getHeaderValue(0)))->setCSeq( ((SipHeaderValueCSeq *)*(header->getHeaderValue(0)))->getCSeq() ); ((SipHeaderValueCSeq*)*(header->getHeaderValue(0)))->setMethod("CANCEL"); add=true; break; case SIP_HEADER_TYPE_CALLID: add=true; break; } if (add){ req->addHeader(header); } } return req;}MRef<SipRequest*> SipRequest::createSipMessageIMMessage(string branch, string callId, std::string toUri, const SipUri& fromUri, int32_t seqNo, string msg){ MRef<SipRequest*> req = new SipRequest(branch, "MESSAGE"); req->setUri(toUri); req->addDefaultHeaders(fromUri,toUri,"MESSAGE",seqNo,callId); req->addHeader(new SipHeader(new SipHeaderValueUserAgent(HEADER_USER_AGENT_DEFAULT))); req->setContent(new SipMessageContentIM(msg)); return req;}static void addHeaders( MRef<SipRequest*> req, const string &call_id, const string &tel_no, //FIXME: Send uris as const SipURI& const string &proxyAddr, int32_t proxyPort, const string &localAddr, int32_t localSipPort, const string &from_tel_no, int32_t seq_no, const string &username, const string &nonce, const string &realm, const string &password, const string &transport, MRef<SipStack*> stack ){ req->setUri(tel_no); MRef<SipHeader*> hdr; SipUri fromUri(from_tel_no); req->addHeader(new SipHeader( new SipHeaderValueFrom(fromUri) ) ); SipUri toUri(tel_no); req->addHeader(new SipHeader( new SipHeaderValueTo(toUri) )); req->addHeader(new SipHeader(new SipHeaderValueCallID(call_id)) ); SipUri uri; uri.setParams(tel_no,proxyAddr,"",proxyPort); if ( username.length()>0 || nonce.length()>0 || realm.length()>0 ){ req->addHeader(new SipHeader( new SipHeaderValueProxyAuthorization("INVITE",tel_no,realm, nonce, uri, username, password,"DIGEST") ) ); } req->addHeader(new SipHeader(new SipHeaderValueCSeq("INVITE",seq_no))); req->addHeader(new SipHeader(new SipHeaderValueContact(from_tel_no, localAddr, localSipPort,"",transport))); req->addHeader(new SipHeader(new SipHeaderValueUserAgent(HEADER_USER_AGENT_DEFAULT))); if (stack){ req->addHeader(new SipHeader(new SipHeaderValueSupported(stack->getAllSupportedExtensionsStr()))); }}MRef<SipRequest*> SipRequest::createSipMessageInvite(const string &branch, const string &call_id, const string &tel_no, const string &proxyAddr, int32_t proxyPort, const string &localAddr, int32_t localSipPort, const string &from_tel_no, int32_t seq_no, const string &transport, MRef<SipStack*> stack ){ MRef<SipRequest*> req = new SipRequest(branch,"INVITE"); addHeaders(req, call_id, tel_no, proxyAddr, proxyPort, localAddr, localSipPort, from_tel_no, seq_no, "","","","",transport, stack); return req;}MRef<SipRequest*> SipRequest::createSipMessageInvite(const string &branch, const string &call_id, const string &tel_no, const string &proxyAddr, int32_t proxyPort, const string &localAddr, int32_t localSipPort, const string &from_tel_no, int32_t seq_no, const string &username, const string &nonce, const string &realm, const string &password, const string &transport, MRef<SipStack*> stack){ MRef<SipRequest*> req = new SipRequest(branch, "INVITE"); addHeaders(req, call_id, tel_no, proxyAddr, proxyPort, localAddr, localSipPort, from_tel_no, seq_no, username, nonce, realm, password, transport,stack); return req;}MRef<SipRequest*> SipRequest::createSipMessageNotify(string branch, string callId, const SipUri& toUri, const SipUri& fromUri, int32_t seqNo ){ MRef<SipRequest*> req = new SipRequest(branch, "NOTIFY"); req->setUri(toUri.getString()); req->addDefaultHeaders(fromUri, toUri,"NOTIFY",seqNo,callId); req->addHeader(new SipHeader(new SipHeaderValueUserAgent(HEADER_USER_AGENT_DEFAULT))); req->addHeader(new SipHeader(new SipHeaderValueEvent("presence"))); return req;}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -