⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 sipcall.cpp

📁 KphoneSI (kpsi) is a SIP (Session Initiation Protocol) user agent for Linux, with which you can in
💻 CPP
📖 第 1 页 / 共 4 页
字号:
	sendRequestOptions(ourUsername, ourPassword);}void SipCallMember::sendRequestOptions( QString username, QString password ){		ourUsername=username;	ourPassword=password;		//call->transactions.clear();  ?????		if( !username.isEmpty() && !password.isEmpty() &&			( authstate == authState_AuthenticationRequired ||			authstate == authState_AuthenticationRequiredWithNewPassword || authstate == SipCallMember::authState_AuthenticationOK ) ) {		if( authtype == ProxyDigestAuthenticationRequired ) {			proxyauthresponse = Sip::getDigestResponse(				username, password, "OPTIONS", getContactUri().theUri(), proxyauthstr );		} else if( authtype == ProxyBasicAuthenticationRequired ) {			proxyauthresponse = Sip::getBasicResponse( username, password );		}		local = call->newRequest( this, Sip::OPTIONS, localsessiondesc, localsessiontype,			SipUri::null, proxyauthresponse,authresponse, localExpiresTime );	} else {		local = call->newRequest( this, Sip::OPTIONS, localsessiondesc, localsessiontype,			SipUri::null, QString::null,QString::null);	}	if( local ) {		op = opRequest;		if( authstate == authState_AuthenticationRequired ||		    authstate == authState_AuthenticationRequiredWithNewPassword  ) {			authstate = authState_AuthenticationTryingWithPassword;		} else {			authstate = authState_AuthenticationTrying;		}				connect( local, SIGNAL( statusUpdated() ), this, SLOT( localStatusUpdated() ) );	}}void SipCallMember::requestAuthOptions( void ){    challengeCounter++;    statusUpdated( this );}void SipCallMember::handlingOptionsResponse( void ) {	QString authstrtemp;	if( local->wasCancelled() ) {		challengeCounter = 0;			state = state_Disconnected; statuscode = local->getStatus().getCode();		op = opIdle;		local = 0;	} else if( local->getStatus().getCode() >= 200 ) {  // final response		if( local->getStatus().getCode() < 300 ) {			challengeCounter = 0;			if( call->getCallStatus() == SipCall::callDisconneting ) {				call->setCallStatus( SipCall::callUnconnected );			} else {				call->setCallStatus( SipCall::callInProgress );			}			authstate = authState_AuthenticationOK;		} else if( local->getStatus().getCode() == 401) {			proxyauthstr = local->getFinalWWWAuthString();			authstrtemp = proxyauthstr.lower();			if( authstrtemp.contains( "digest" ) ) {				authtype = DigestAuthenticationRequired;			} else {				authtype = ProxyBasicAuthenticationRequired;			}			if( authstate == authState_AuthenticationTryingWithPassword ) {				authstate = authState_AuthenticationRequiredWithNewPassword;			} else {				authstate = authState_AuthenticationRequired;			}			statuscode = local->getStatus().getCode();			requestAuthOptions();			return;		} else if( local->getStatus().getCode() == 407) {			proxyauthstr = local->getFinalProxyAuthString();			authstrtemp = proxyauthstr.lower();			if( authstrtemp.contains( "digest" ) ) {				authtype = ProxyDigestAuthenticationRequired;			} else {				authtype = ProxyBasicAuthenticationRequired;			}			if( authstate == authState_AuthenticationTryingWithPassword ) {				authstate = authState_AuthenticationRequiredWithNewPassword;			} else {				authstate = authState_AuthenticationRequired;			}			statuscode = local->getStatus().getCode();			requestAuthOptions();			return;		} else {			challengeCounter = 0;			op = opIdle;			local = 0;		}	}}void SipCallMember::acceptInvite( const QString &body, const MimeContentType &bodytype ){	if( !remote ) return;	if( body != QString::null ) {		localsessiondesc = body;		localsessiontype = bodytype;	}	remote->sendResponse( SipStatus( 200 ), body, bodytype );	state = state_Connected;	statusdesc = "Conn 200OK";	    statusUpdated( this );	call->setCallStatus( SipCall::callInProgress );}	    void SipCallMember::forwardCall( const QString &body){	QString bodytype = "text/plain";	if( !remote ) return;	if( body != QString::null ) {		localsessiondesc = body;		localsessiontype = bodytype;	}	remote->sendResponseNC( SipStatus( 302 ), body, bodytype );	    statusUpdated( this );}void SipCallMember::refuseInvite( void ){	if( !remote ) return;	remote->sendResponse( SipStatus( 200 ));	    statusUpdated( this );}void SipCallMember::notAcceptableHere( void ){	if( !remote ) return;	remote->sendResponse( SipStatus( 488 ) );	state = state_Disconnected; statuscode = 488;	statusdesc = "Not Acceptable Here";	statusUpdated( this );}void SipCallMember::declineInvite( const QString &body, const MimeContentType &bodytype ){	if( !remote ) return;	remote->sendResponse( SipStatus( 603 ), body, bodytype );	state = state_Disconnected;	statusdesc = "Rejecting call invitation"; statuscode = 603;	    statusUpdated( this );}void SipCallMember::localStatusUpdated( void ){	QString authstrtemp;	MimeContentType mtype;	SipStatus sipstatus;	if(challengeCounter > 5) {		{		    QSettings settings;		    QString p = KStatics::myInd + "Registration/";		    printf(" +----------------------------------------------------------------+\n");		    printf(" |    to many unsuccessfull authentication requests!!!            |\n");		    printf(" |    retry with new authentication username and password, please |\n");		    printf(" +----------------------------------------------------------------+\n");		    settings.writeEntry( p + "Password", "" );		    settings.writeEntry( p + "UserName", "" );		}		exit(-1);	}	if( !local ) {		return;	}	mtype = local->getFinalContentType();	if( mtype == MimeContentType( "application/sdp" ) ) {		sessiondesc = local->getFinalMessageBody();		localsessiontype = mtype;	} else {		recentbody = local->getFinalMessageBody();		recentbodytype = mtype;	}	if( (callMemberType == Invite ) || (callMemberType == Disc) )  {		if(state != state_r202) {		    handlingInviteResponse();		}	} else if( callMemberType == Message ) {		handlingMessageResponse();	} else if( callMemberType == Subscribe ) {		handlingSubscribeResponse();	} else if( callMemberType == Notify ) {		handlingNotifyResponse(); 	} else if( callMemberType == RNotify ) {		handlingRNotifyResponse();	//} else if(call->getCallType() == SipCall::OptionsCall) { 	} else if( callMemberType == Options ) {		handlingOptionsResponse();	} else {		return;	}	    	    statusUpdated( this );}void SipCallMember::incomingTransaction( SipTransaction *newtrans ){	MimeContentType mtype;	remote = newtrans;	if( remote->getRequest()->getMethod() == Sip::INVITE ) {		connect( remote, SIGNAL( statusUpdated() ), this, SLOT( remoteStatusUpdated() ) );		if( state == state_Disconnected ) {			state = state_RequestingInvite;			statusdesc = "Invitation received";			remote->sendResponse( SipStatus( 180 ) );		} else {			state = state_RequestingReInvite;			statusdesc = "Session update requested";		}		mtype = remote->getRequestMessageContentType();		if( mtype == MimeContentType( "application/sdp" ) ) {			sessiontype = mtype;			sessiondesc = remote->getRequestMessageBody();		} else {			recentbodytype = mtype;			recentbody = remote->getRequestMessageBody();		}	} else if( remote->getRequest()->getMethod() == Sip::BYE ) {		state = state_Disconnected;		statusdesc = "Remote end disconnected";statuscode = 487;		call->hideCallWidget();	} else if( remote->getRequest()->getMethod() == Sip::REFER ) {		if( state == state_Refer ) {			return;		}		remote->sendResponse( SipStatus( 202 ) );		state = state_Refer;		statusdesc = "Refer";		redirectlist = SipUriList( remote->getRequest()->getHeaderData( SipHeader::Refer_To ) );	}	    statusUpdated( this );}void SipCallMember::remoteStatusUpdated( void ){	if( state == state_RequestingInvite ) {		if( remote->wasCancelled() ) {			state = state_Disconnected;			statusdesc = "Request cancelled"; statuscode = 487;			statusUpdated( this );		}	}}void SipCallMember::cancelTransaction( void ){	if( local ) {		if( state == state_EarlyDialog ) {			local->cancelRequest();			state = state_Disconnected;		} else {		    local->stopInviteRep();		    state = state_CancelPending;		}	}}QString SipCallMember::getSubject( void ){	return call->getSubject();}void SipCallMember::call_timeout(){	if( call->getCallType() == SipCall::outSubscribeCall ) {	    requestSubscribe();	} else if( call->getCallType() == SipCall::inSubscribeCall ) {		contactUpdate ( false );	};}void SipCallMember::contactUpdate( bool active, QString presence ){	call->setPresenceStatus( presence );	if( active ) {		call->setCallStatus( SipCall::callInProgress );	} else {		if( call->getCallStatus() != SipCall::callDead ) {			call->setCallStatus( SipCall::callUnconnected );		}		memberuri.setTag( QString::null );	}statusUpdated( this );}void SipCallMember::timerStart( int time ){	timer->start( time );}//------------------------------//           SipCall//------------------------------SipCall::SipCall( SipUser *local, const QString &id, SipCall::CallType ctype ){	callstatus = callUnconnected;	if ( id == QString::null ) {		callid = SipMessage::createCallId();	} else {		callid = id;	}	// Remember to nuke all members and transactions	members.setAutoDelete( true );	transactions.setAutoDelete( true );	/** user by SipCall */	struct timeval tv;	gettimeofday( &tv, NULL );	srand( tv.tv_usec );	lastseq = rand() % 8000;	parent = local->parent();	calltype = ctype;	hasroute = false;	localuri = local->getUri();	localuri.generateTag();	parent->addCall( this );	basePresenceStatus = false;	presenceStatus = "offline";	bodyMask = QString::null;	contactstr = "";	refnoti = QString::null;	hasrecordroute = false;	Inumber="0";	onHold = preCall;	noHold=false;	masterHold=false;	activeOnly=false;	useCmdLine=false;	RemoteStart=false;	switchthru=false;	if(KStatics::debugLevel>=2) printf(":::::Begin SipCall\n");	}SipCall::~SipCall( void ){	if(KStatics::debugLevel>=2)printf(":::::End SipCall\n");	parent->deleteCall( this );	transactions.clear();	members.clear();}void SipCall::addMember( SipCallMember *newmember ){	members.append( newmember );}SipTransaction *SipCall::newRequest( SipCallMember *member, Sip::Method meth,	const QString &body, const MimeContentType &bodytype, const SipUri &referto,	const QString &proxyauthentication, const QString &authentication,int expiresTime ){	SipTransaction *trans = new SipTransaction( lastseq++, member, this );	if( trans->sendRequest( meth, body, bodytype, referto, proxyauthentication, authentication, expiresTime ) ) {		transactions.clear();		transactions.append( trans );		// Audit the call		auditCall();		// Return the transaction object for tracking		return trans;	} else {		delete trans;		return 0;	}}//SipTransaction *SipCall::newRegister( const SipUri &registerserver, int expiresTime, const //QString &authentication, const //QString &proxyauthentication, const QString &qvalue, const QString &body, const MimeContentType //&bodytype )SipTransaction *SipCall::newRegister( const SipUri &registerserver, SipCallMember *callMember, int expiresTime, const QString &authentication, const QString &proxyauthentication, const QString &qvalue, const QString &body, const MimeContentType &bodytype ){	transactions.clear();	localuri.setTag( QString::null );		callMember->setUri(localuri);	SipTransaction *trans = new SipTransaction( lastseq++, callMember, this );		//SipTransaction *trans = new SipTransaction( lastseq++, new SipCallMember( this, localuri ), this );	transactions.append( trans );	trans->sendRegister( registerserver, expiresTime, authentication, proxyauthentication, body, bodytype, qvalue );	return trans;}bool SipCall::sendRequest( SipMessage *reqmsg, bool contact, const SipUri &proxy, const QString &branch ){	reqmsg->insertHeader( SipHeader::From, localuri.nameAddr() );	reqmsg->insertHeader( SipHeader::Call_ID, callid );	if( ( reqmsg->getMethod() == Sip::INVITE ) || ( reqmsg->getMethod() == Sip::MSG ) ) {		reqmsg->insertHeader( SipHeader::Subject, getSubject() );	}	if( hasroute ) {		if( route.getHead().uri().contains( ";lr" ) ) {			reqmsg->insertHeader( SipHeader::Route, route.getUriList() );		} else {			reqmsg->setRequestUri( route.getHead() );			SipUriList routewithouthead = route;			routewithouthead.removeHead();			reqmsg->insertHeader( SipHeader::Route, routewithouthead.getUriList() );		}	}	if( parent->getExplicitProxyMode() ) {		if( reqmsg->getMethod() == Sip::REGISTER || reqmsg->getMethod() == Sip::INVITE ||				reqmsg->getMethod() == Sip::SUBSCRIBE || reqmsg->getMethod() == Sip::ACK ) {			if( parent->isLooseRoute() ) {				if( reqmsg->getMethod() == Sip::REGISTER ) {					reqmsg->setRequestUri(						SipUri( reqmsg->getHeaderData( SipHeader::To ) ).getRegisterUri() );				}				reqmsg->insertHeader( SipHeader::Route, parent->getExplicitProxyAddress() );			} else if( parent->isStrictRoute() ) {				if( reqmsg->getMethod() == Sip::REGISTER ) {					reqmsg->insertHeader(						SipHeader::Route, SipUri(						reqmsg->getHeaderData( SipHeader::To ) ).getRouteUri() );				} else {					reqmsg->insertHeader(						SipHeader::Route, "<" + reqmsg->getRequestUri().reqUri() + ">" );				}				reqmsg->setRequestUri( parent->getExplicitProxyAddress() );			} else {				if( reqmsg->getMethod() == Sip::REGISTER ) {					reqmsg->setRequestUri(						SipUri( reqmsg->getHeaderData( SipHeader::To ) ).getRegisterUri() );				}			}		}	}	return parent->sendRequest( reqmsg, contact, proxy, branch );}void SipCall::sendResponse( SipMessage *responsemsg, bool contact ){

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -