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

📄 sipcall.cpp

📁 KphoneSI (kpsi) is a SIP (Session Initiation Protocol) user agent for Linux, with which you can in
💻 CPP
📖 第 1 页 / 共 4 页
字号:
	proxyauthresponse=QString::null;	authresponse=QString::null;	if( !username.isEmpty() && !password.isEmpty() &&	    ( authstate == authState_AuthenticationRequired ||	    authstate == authState_AuthenticationRequiredWithNewPassword|| authstate == SipCallMember::authState_AuthenticationOK  ) ) {		if( authtype == DigestAuthenticationRequired ) {			authresponse = Sip::getDigestResponse(				username, password, "MESSAGE", getContactUri().theUri(), proxyauthstr,1 );		} else if( authtype == ProxyDigestAuthenticationRequired ) {			proxyauthresponse = Sip::getDigestResponse(				username, password, "MESSAGE", getContactUri().theUri(), proxyauthstr,1 );		} else if( authtype == ProxyBasicAuthenticationRequired ) {			proxyauthresponse = Sip::getBasicResponse( username, password );		}		local = call->newRequest( this, Sip::MESSAGE, localsessiondesc, localsessiontype,			SipUri::null, proxyauthresponse,authresponse, localExpiresTime );	} else {		local = call->newRequest( this, Sip::MESSAGE, localsessiondesc, localsessiontype,			SipUri::null, QString::null, QString::null, localExpiresTime );	}	if( localExpiresTime > 0 ) {		timer->start( localExpiresTime * 900, TRUE );	}	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::requestAuthMessage( void ){    challengeCounter++;    statusUpdated( this );}void SipCallMember::handlingMessageResponse( void ){	QString authstrtemp;	if( local->wasCancelled() ) {		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;		} 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;				}				requestAuthMessage();				return;			} 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;				}				requestAuthMessage();				return;			} else {				state = state_Disconnected; statuscode = local->getStatus().getCode();				challengeCounter = 0;			}		}		op = opIdle;		local = 0;	} else {		challengeCounter = 0;		state = state_EarlyDialog;	}}// Invitebool  SipCallMember::requestInvite( const QString &body, const MimeContentType &bodytype ){ 	callMemberType = Invite;	localsessiondesc = body;	localsessiontype = bodytype;	state = state_InviteRequested;	return sendRequestInvite(ourUsername, ourPassword);}bool  SipCallMember::requestReInvite( const QString &body, const MimeContentType &bodytype ){ 	callMemberType = Invite;	localsessiondesc = body;	localsessiontype = bodytype;	state =  state_ReInviteRequested;	return sendRequestInvite(ourUsername, ourPassword);}bool SipCallMember::sendRequestInvite( QString username, QString password ){	ourUsername=username;	ourPassword=password;	if( !username.isEmpty() && !password.isEmpty() &&	    ( authstate == authState_AuthenticationRequired || authstate == authState_AuthenticationRequiredWithNewPassword || SipCallMember::authState_AuthenticationOK ) ) {		ourUsername=username;		ourPassword=password;		proxyauthresponse=QString::null;		authresponse=QString::null;		if( authtype == DigestAuthenticationRequired ) {			authresponse = Sip::getDigestResponse(				username, password, "INVITE", getContactUri().theUri(), proxyauthstr,++nonceCounter );		} else if( authtype == ProxyDigestAuthenticationRequired ) {			proxyauthresponse = Sip::getDigestResponse(				username, password, "INVITE", getContactUri().theUri(), proxyauthstr,++nonceCounter );		} else if( authtype == ProxyBasicAuthenticationRequired ) {			proxyauthresponse = Sip::getBasicResponse( username, password );		}		local = call->newRequest( this, Sip::INVITE, localsessiondesc, localsessiontype,			SipUri::null, proxyauthresponse,authresponse, localExpiresTime );	} else {		local = call->newRequest( this, Sip::INVITE, localsessiondesc, localsessiontype,			SipUri::null, QString::null, QString::null,localExpiresTime );	}	if( localExpiresTime > 0 ) {		timer->start( localExpiresTime * 900, TRUE );	}	if( local ) {			op = opRequest;		if( authstate == authState_AuthenticationRequired ||		    authstate == authState_AuthenticationRequiredWithNewPassword ) {			authstate = authState_AuthenticationTryingWithPassword;		} else if( authstate == SipCallMember::authState_AuthenticationOK) {		;		} else {			authstate = authState_AuthenticationTrying;		}		connect( local, SIGNAL( statusUpdated() ), this, SLOT( localStatusUpdated() ) );	} else {	    return false;	}return true;}void SipCallMember::requestAuthInvite( void ){	challengeCounter++;	nonceCounter=0;	statusUpdated( this );}void SipCallMember::handlingInviteResponse( void ){	QString authstrtemp;	if( (state == state_Connected)  || (state == state_RequestingReInvite)){		if( local->getStatus().getCode() >= 200 ) {			if( local->getStatus().getCode() == 200 ) {				statusdesc = "Response: " + local->getStatus().getReasonPhrase();				challengeCounter = 0;				statusUpdated( this );											} else if( local->getStatus().getCode() == 401 ) {				proxyauthstr = local->getFinalWWWAuthString();				authstrtemp = proxyauthstr.lower();				if( authstrtemp.contains( "digest" ) ) {					authtype = DigestAuthenticationRequired;				} else {					authtype = ProxyBasicAuthenticationRequired;				}				requestAuthInvite();				return;						} else if( local->getStatus().getCode() == 407 ) {				proxyauthstr = local->getFinalProxyAuthString();				authstrtemp = proxyauthstr.lower();				if( authstrtemp.contains( "digest" ) ) {					authtype = ProxyDigestAuthenticationRequired;				} else {					authtype = ProxyBasicAuthenticationRequired;				}				requestAuthInvite();				return;						} else {				challengeCounter = 0;				state = state_Disconnected; statuscode = local->getStatus().getCode();				statusdesc = "Response: " + local->getStatus().getReasonPhrase();			}			op = opIdle;			local = 0;		}	} else if( state == state_Disconnecting ) {		if( local->getStatus().getCode() >= 200 ) {						if( local->getStatus().getCode() == 401 ) {				proxyauthstr = local->getFinalWWWAuthString();				authstrtemp = proxyauthstr.lower();				if( authstrtemp.contains( "digest" ) ) {					authtype = DigestAuthenticationRequired;				} else {					authtype = ProxyBasicAuthenticationRequired;				} 				callMemberType = Disc;				authstate=authState_AuthenticationRequired;				requestAuthInvite();				return;						} else if( local->getStatus().getCode() == 407 ) {				proxyauthstr = local->getFinalProxyAuthString();				authstrtemp = proxyauthstr.lower();				if( authstrtemp.contains( "digest" ) ) {					authtype = ProxyDigestAuthenticationRequired;				} else {					authtype = ProxyBasicAuthenticationRequired;				}					authstate=authState_AuthenticationRequired; 				callMemberType = Disc;				requestAuthInvite();				return;			} else {				challengeCounter = 0;				state = state_Disconnected; statuscode = local->getStatus().getCode();				statusdesc = "Response: " + local->getStatus().getReasonPhrase();			}			op = opIdle;			local = 0;		}	} else if( state == state_CancelPending ) {		if( local->getStatus().getCode() == 408 ) {			challengeCounter = 0;			local->stopInviteRep();		} else if( local->getStatus().getCode() == 200 ) {			local = 0;			challengeCounter = 0;			requestDisconnect();		} else if( local->getStatus().getCode() > 100 ) {			challengeCounter = 0;			local->cancelRequest();			local = 0;		}		state = state_Disconnected; statuscode = local->getStatus().getCode();	} else {		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;				call->setCallStatus( SipCall::callInProgress );				state = state_Connected;				statusdesc = "Conn " + local->getStatus().getReasonPhrase();//KFl			} else if( local->getStatus().getCode() < 400 ) {				challengeCounter = 0;				state = state_Redirected ;				statusdesc = "Redir " + local->getStatus().getReasonPhrase();				redirectlist = local->getFinalContactList();			} 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 ) {						authstate = authState_AuthenticationRequiredWithNewPassword;					} else {						authstate = authState_AuthenticationRequired;					}					requestAuthInvite();					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 ) {						authstate = authState_AuthenticationRequiredWithNewPassword;					} else {						authstate = authState_AuthenticationRequired;					}					requestAuthInvite();					return;				} else {					challengeCounter = 0;					state = state_Disconnected;					statuscode = local->getStatus().getCode();					statusdesc = "!!Call Failed: " + local->getStatus().getReasonPhrase();				}			}			op = opIdle;			local = 0;		} else {			statusdesc = local->getStatus().getReasonPhrase();			if( local->getStatus().getCode() != 100 ) {			    challengeCounter = 0;				    state = state_EarlyDialog;			} else if (challengeCounter >5) {			    localStatusUpdated();			}		}	}}void SipCallMember::sendRequestBye( QString username, QString password ) {	if( !username.isEmpty() && !password.isEmpty() && ( authstate == authState_AuthenticationRequired || authstate == authState_AuthenticationRequiredWithNewPassword  || authstate == SipCallMember::authState_AuthenticationOK ) ) {		ourUsername=username;		ourPassword=password;		proxyauthresponse=QString::null;		authresponse=QString::null;		if( authtype == DigestAuthenticationRequired ) {			authresponse = Sip::getDigestResponse(				username, password, "BYE", getContactUri().theUri(), proxyauthstr, ++nonceCounter);		} else if( authtype == ProxyDigestAuthenticationRequired ) {			proxyauthresponse = Sip::getDigestResponse(				username, password, "BYE", getContactUri().theUri(), proxyauthstr, ++nonceCounter);		} else if( authtype == ProxyBasicAuthenticationRequired ) {			proxyauthresponse = Sip::getBasicResponse( username, password );		}		local = call->newRequest( this, Sip::BYE, QString::null,(MimeContentType) 0,			SipUri::null, proxyauthresponse, authresponse,localExpiresTime );	} else {		local = call->newRequest( this, Sip::BYE,QString::null,(MimeContentType) 0,			SipUri::null, QString::null,  QString::null,localExpiresTime );	}	if( localExpiresTime > 0 ) {		timer->start( localExpiresTime * 900, TRUE );	}	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() ) );	} else {	}}// Byevoid SipCallMember::requestDisconnect( void ){	if( local ) {				if( state != state_r202 ) local->cancelRequest();		disconnect( local, 0, this, 0 );	}	state = state_Disconnecting;	statusdesc = "Disconnecting";	sendRequestBye( ourUsername, ourPassword );	/*	local = call->newRequest( this, Sip::BYE );	if( local ) {		connect( local, SIGNAL( statusUpdated() ), this, SLOT( localStatusUpdated() ) );	}	*/	}void SipCallMember::requestRefer( bool shortTr,const SipUri &referto,	const QString &body, const MimeContentType &bodytype ){	if( state == state_Disconnected ) return;	    if(shortTr) {		state = state_Disconnecting;		statusdesc = "Transfering";		local = call->newRequest( this, Sip::REFER, body, bodytype, referto );		connect( local, SIGNAL( statusUpdated() ), this, SLOT( localStatusUpdated() ) );		state = state_Disconnecting;		statusdesc = "Disconnecting";		local = call->newRequest( this, Sip::BYE );		    if( local ) {			connect( local, SIGNAL( statusUpdated() ), this, SLOT( localStatusUpdated() ) );		    } 	    } else {		state = state_r202;		statusdesc = "Transfering";		local = call->newRequest( this, Sip::REFER, body, bodytype, referto );		if( local ) {		    connect( local, SIGNAL( statusUpdated() ), this, SLOT( localStatusUpdated() ) );	    }	}		statusUpdated( this );}/*void SipCallMember::requestOptions( const QString &body, const MimeContentType &bodytype ){	if( local ) {		local->cancelRequest();		disconnect( local, 0, this, 0 );	}	statusdesc = "Querying options";	local = call->newRequest( this, Sip::OPTIONS, body, bodytype );	connect( local, SIGNAL( statusUpdated() ), this, SLOT( localStatusUpdated() ) );	    statusUpdated( this );}*/void SipCallMember::requestOptions( const QString &body, const MimeContentType &bodytype ){	if( local ) {		local->cancelRequest();		disconnect( local, 0, this, 0 );	}	callMemberType = Options;	statusdesc = "Querying options";	localsessiondesc = body;	localsessiontype = bodytype;	statusdesc = "Querying options";

⌨️ 快捷键说明

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