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

📄 sipcall.cpp

📁 KphoneSI (kpsi) is a SIP (Session Initiation Protocol) user agent for Linux, with which you can in
💻 CPP
📖 第 1 页 / 共 4 页
字号:
#include <stdio.h>#include <sys/time.h>#include <stdlib.h>#include <qstring.h>#include <qsettings.h>#include "sipuri.h"#include "sipuser.h"#include "sipclient.h"#include "sipmessage.h"#include "siptransaction.h"#include "sipcall.h"#include "../kphone/kstatics.h" SipCallMember::SipCallMember( SipCall *parent, const SipUri &uri ){	if(KStatics::debugLevel>=2) printf(":::::Begin SipCallMember\n");	authstate = authState_Authentication;	callMemberType = unknown;	call = parent;	memberuri = uri;	contacturi = uri;	local = 0;	remote = 0;	localExpiresTime = -1;	state = state_Disconnected;	parent->addMember( this );	timer = new QTimer( this );	connect( timer, SIGNAL( timeout() ), this, SLOT( call_timeout() ) );        holdRefused=false;	statuscode=0;	ourUsername="";	ourPassword="";	nonceCounter=0;	authresponse=QString::null;	proxyauthresponse=QString::null;	challengeCounter = 0;}SipCallMember::~SipCallMember( void ){	delete timer;	if(KStatics::debugLevel>=2) printf(":::::End SipCallMember\n");}void SipCallMember::setContactUri( const SipUri &newcontact ){	contacturi = newcontact;}void SipCallMember::setUri( const SipUri &newuri ){	memberuri = newuri;}// Subscribevoid SipCallMember::requestSubscribe( int expiresTime, const QString &body, const MimeContentType &bodytype ){	callMemberType = Subscribe;	state = state_Idle;	if( expiresTime > 0 ) {		localExpiresTime = expiresTime;		localsessiondesc = body;		localsessiontype = bodytype;	}	sendRequestSubscribe(ourUsername, ourPassword);}void SipCallMember::sendRequestSubscribe( QString username, QString password ){		ourUsername=username;	ourPassword=password;	proxyauthresponse=QString::null;	authresponse=QString::null;	call->transactions.clear();		if( !username.isEmpty() && !password.isEmpty() &&			( authstate == authState_AuthenticationRequired ||			authstate == authState_AuthenticationRequiredWithNewPassword || authstate == SipCallMember::authState_AuthenticationOK ) ) {		if( authtype == DigestAuthenticationRequired ) {			authresponse = Sip::getDigestResponse(				username, password, "SUBSCRIBE", getContactUri().theUri(), proxyauthstr,1 );		} else 	if( authtype == ProxyDigestAuthenticationRequired ) {			proxyauthresponse = Sip::getDigestResponse(				username, password, "SUBSCRIBE", getContactUri().theUri(), proxyauthstr,1 );		} else if( authtype == ProxyBasicAuthenticationRequired ) {			proxyauthresponse = Sip::getBasicResponse( username, password );		}		local = call->newRequest( this, Sip::SUBSCRIBE, localsessiondesc, localsessiontype,			SipUri::null, proxyauthresponse,authresponse, localExpiresTime );	} else {		local = call->newRequest( this, Sip::SUBSCRIBE, 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::requestAuthSubscribe( void ){	challengeCounter++;	statusUpdated( this );    }void SipCallMember::requestClearSubscribe( void ){	localExpiresTime = 0;	call->setCallStatus( SipCall::callDisconneting );	sendRequestSubscribe(ourUsername, ourPassword);}void SipCallMember::handlingSubscribeResponse( 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 ) {			if( call->getCallStatus() == SipCall::callDisconneting ) {				call->setCallStatus( SipCall::callUnconnected );			} else {				call->setCallStatus( SipCall::callInProgress );			}			authstate = authState_AuthenticationOK;			challengeCounter = 0;		} 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;			}			requestAuthSubscribe();			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;			}			requestAuthSubscribe();			return;		}  else if( (local->getStatus().getCode() == 423 ) || (local->getStatus().getCode() == 481 )|| (local->getStatus().getCode() == 489) ) {			challengeCounter = 0;				call->terminateSubscribes(local->getStatus().getCode());				}  else if (local->getStatus().getCode() == 404 ) {			challengeCounter = 0;				call->terminateSubscribes(local->getStatus().getCode());		} else if( local->getStatus().getCode() < 500 ) {			challengeCounter = 0;			if( call->getCallStatus() == SipCall::callInProgress ) {				contactUpdate( false );				call->updateSubscribes();			}		}		challengeCounter = 0;			op = opIdle;		local = 0;			} else {		challengeCounter = 0;		state = state_EarlyDialog;	}}// Notifyvoid SipCallMember::requestRNotify( const QString &body, const MimeContentType &bodytype,QString username, QString password ){	callMemberType = RNotify;	localExpiresTime = -1;	localsessiondesc = body;	localsessiontype = bodytype;	proxyauthresponse=QString::null;	authresponse=QString::null;	call->transactions.clear(); 	if( !username.isEmpty() && !password.isEmpty() &&	    ( authstate == authState_AuthenticationRequired ||	    authstate == authState_AuthenticationRequiredWithNewPassword ) ) {		if( authtype == DigestAuthenticationRequired ) {			authresponse = Sip::getDigestResponse(				username, password, "NOTIFY", getContactUri().theUri(), proxyauthstr );		} else if( authtype == ProxyDigestAuthenticationRequired ) {			proxyauthresponse = Sip::getDigestResponse(				username, password, "NOTIFY", getContactUri().theUri(), proxyauthstr );		} else if( authtype == ProxyBasicAuthenticationRequired ) {			proxyauthresponse = Sip::getBasicResponse( username, password );		}		local = call->newRequest( this, Sip::RNOTIFY, localsessiondesc, localsessiontype,			SipUri::null, proxyauthresponse,authresponse, localExpiresTime );	} else {		local = call->newRequest( this, Sip::RNOTIFY, localsessiondesc, localsessiontype,			SipUri::null, QString::null,QString::null, localExpiresTime );	}	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::requestNotify( const QString &body, const MimeContentType &bodytype ){	callMemberType = Notify;	localExpiresTime = -1;	localsessiondesc = body;	localsessiontype = bodytype;	sendRequestNotify(ourUsername, ourPassword);}void SipCallMember::sendRequestNotify( QString username, QString password ){		ourUsername=username;	ourPassword=password;	proxyauthresponse=QString::null;	authresponse=QString::null;	call->transactions.clear(); 	if( !username.isEmpty() && !password.isEmpty() &&	    ( authstate == authState_AuthenticationRequired ||	    authstate == authState_AuthenticationRequiredWithNewPassword || authstate == SipCallMember::authState_AuthenticationOK  ) ) {		if( authtype == DigestAuthenticationRequired ) {			authresponse = Sip::getDigestResponse(				username, password, "NOTIFY", getContactUri().theUri(), proxyauthstr,1 );		} else if( authtype == ProxyDigestAuthenticationRequired ) {			proxyauthresponse = Sip::getDigestResponse(				username, password, "NOTIFY", getContactUri().theUri(), proxyauthstr,1 );		} else if( authtype == ProxyBasicAuthenticationRequired ) {			proxyauthresponse = Sip::getBasicResponse( username, password );		}		local = call->newRequest( this, Sip::NOTIFY, localsessiondesc, localsessiontype,			SipUri::null, proxyauthresponse, authresponse,localExpiresTime );	} else {		local = call->newRequest( this, Sip::NOTIFY, localsessiondesc, localsessiontype,			SipUri::null, QString::null, QString::null, localExpiresTime );	}	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::requestAuthNotify( void ){	    challengeCounter++;	    statusUpdated( this );}void SipCallMember::requestClearNotify( const  QString &body, const  MimeContentType &bodytype ){	callMemberType = Notify;	localExpiresTime = 0;	localsessiondesc = body;	localsessiontype = bodytype;	sendRequestNotify(ourUsername, ourPassword);}void SipCallMember::handlingNotifyResponse( 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 ) {			call->setCallStatus( SipCall::callInProgress );			local = 0;			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;				}				requestAuthNotify();				return;			} else if( local->getStatus().getCode() == 401) {				challengeCounter = 0;				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;				}				requestAuthNotify();				return;			} else if( local->getStatus().getCode() == 488) {				challengeCounter = 0;			} else if( local->getStatus().getCode() < 500 ) {				challengeCounter = 0;				state = state_Disconnected; statuscode = local->getStatus().getCode();				call->setCallStatus( SipCall::callDead );			}		}		challengeCounter = 0;		op = opIdle;		local = 0;	} else {		state = state_EarlyDialog;		challengeCounter = 0;	}}void SipCallMember::handlingRNotifyResponse( 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 ) {			state = state_r202;			//back to the original type			callMemberType=Invite;			local = 0;			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;				}				requestAuthNotify();				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;				}				requestAuthNotify();				return;			} else if( local->getStatus().getCode() == 488) {			} else if( local->getStatus().getCode() < 500 ) {				state = state_Disconnected; statuscode = local->getStatus().getCode();				call->setCallStatus( SipCall::callDead );			}		}		challengeCounter = 0;		op = opIdle;		local = 0;	} else {		challengeCounter = 0;		state = state_r202;		//back to the original type		callMemberType=Invite;		local = 0;	}		}// Messagevoid SipCallMember::requestMessage( const QString &body, const MimeContentType &bodytype ){	callMemberType = Message;	localsessiondesc = body;	localsessiontype = bodytype;	sendRequestMessage(ourUsername, ourPassword);}void SipCallMember::sendRequestMessage( QString username, QString password ){		ourUsername=username;	ourPassword=password;

⌨️ 快捷键说明

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