Пример #1
0
/// Builds a default header if it doesn't exist.
void SIPPacket::EnsureHeader(){
	if (header.Size() != 0)
		return;
	// Assign default-sender if not done already.
	if (sender == NULL)
		SetSender(defaultSender);
	// Build it.
	BuildHeader();
}
Пример #2
0
INode::INode(const StringRef& name/*=StringRef::Empty*/, const IEventArg& e /*= IEventArg::Empty*/)
	:IRenderable(name), DefaultRunnable(RunningState::None)
{
	Start();
	SetSender(this);
}
Пример #3
0
cyDraw::cyDraw(plKey sender, plKey recvr)
{
    SetSender(sender);
    AddRecvr(recvr);
    fNetForce = false;
}
Пример #4
0
// =============================================================================================================================================================
/// Default contructor that builds a header using relevant data from the packet to which it is replying.
SIPReplyPacket::SIPReplyPacket(SIPPacket * packetToReply, int type)
: SIPPacket(type){
	SetSender(defaultSender);
	assert(defaultSender);
	cSeq = packetToReply->cSeq;
}
Пример #5
0
// Ref: http://tools.ietf.org/html/rfc3261#section-24
// Builds the header using the previously set parameters. Call this again if you change any of them!
void SIPPacket::BuildHeader(){
	// Make sure body is set before calculating header-parameters!
	if (!bodySet){
		std::cout<< "ERROR: Body not set before calling SIPPacket::BuildHeader! Fix this, yo.";
		assert(bodySet);	
	}
	// Set default sender (us) if no sender already specified.
	if (!sender)
		sender = defaultSender;
	if (!senderSet){
		SetSender(sender);
	}
	if (!recipientSet){
		SetRecipient(recipient);
	}
	header.Clear();
	String typeName = PacketTypeName();
	switch(type){
		case SIP_REGISTER:
		case SIP_INFO:
		case SIP_INVITE:
		case SIP_BYE:
		case SIP_ACK:
		case SIP_CANCEL:
		case SIP_OPTIONS:
		case SIP_SUBSCRIBE:
		case SIP_NOTIFY:
			header.Add(typeName+" sip:"+recipientAddress+" SIP/"+SIPVersion);
			break;
		case SIP_OK:
		case SIP_BAD_REQUEST:
			header.Add("SIP/"+String(SIPVersion)+" "+typeName);
			break;
		default:
			std::cout<<"Unrecognized packet type: "<<type<<" typeName: "<<typeName;
			assert(false && "Unrecognized packet-type when setting first row in SIP message header. Add a new case for it?");
			break;
	}
	String toString = "To: "+recipientData;
	/// Only do this if the recipient is known.
	SIPSessionData * recipientSessionData = NULL;
	if (recipient){
		recipientSessionData = (SIPSessionData*)recipient->GetSessionData(SessionType::SIP);
		if (recipientSessionData->theirTag.Length()){
			toString.Add(";tag="+recipientSessionData->theirTag);
		}
	}
	header.Add(toString);
	String senderString = "From: "+senderData;
	if (recipientSessionData){
		if (recipientSessionData->ourTag.Length()){
			senderString.Add(";tag="+recipientSessionData->ourTag);
		}
	}
	header.Add(senderString);
	// TODO: Add Call-ID ?
	// Add CSeq
	if (cSeq.Length())
		header.Add("CSeq: "+cSeq);
	// Script-type, for Subscribe messages
	if (event.Length()){
		header.Add("Script: "+event);
	}
	// TODO: Add Contact
	if (expirationTime >= 0)
		header.Add("Expires: "+String::ToString(expirationTime));
	int bodyLength = BodyLength();
	if (bodyLength > 0){
		if (!contentType.Length())
			contentType = "application/customP2PMediaProtocol";
		header.Add("Content-Type: "+contentType);
	}
	header.Add("Content-Length: "+String::ToString(bodyLength));
	headerSet = true;
}