📄 sipcall.cpp
字号:
#include <stdio.h>#include <sys/time.h>#include "sipuri.h"#include "sipuser.h"#include "sipclient.h"#include "sipmessage.h"#include "siptransaction.h"#include "sipcall.h"SipCallMember::SipCallMember( SipCall *parent, const SipUri &uri ){ 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() ) );}SipCallMember::~SipCallMember( void ){ delete timer;}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();}void SipCallMember::sendRequestSubscribe( QString username, QString password ){ call->transactions.clear(); if( !username.isEmpty() && !password.isEmpty() && ( authstate == authState_AuthenticationRequired || authstate == authState_AuthenticationRequiredWithNewPassword ) ) { if( authtype == ProxyDigestAuthenticationRequired ) { proxyauthresponse = Sip::getDigestResponse( username, password, "SUBSCRIBE", getContactUri().uri(), proxyauthstr ); } else if( authtype == ProxyBasicAuthenticationRequired ) { proxyauthresponse = Sip::getBasicResponse( username, password ); } local = call->newRequest( this, Sip::SUBSCRIBE, localsessiondesc, localsessiontype, SipUri::null, proxyauthresponse, localExpiresTime ); } else { local = call->newRequest( this, Sip::SUBSCRIBE, localsessiondesc, localsessiontype, SipUri::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 ){ statusUpdated( this );}void SipCallMember::requestClearSubscribe( void ){ localExpiresTime = 0; call->setCallStatus( SipCall::callDisconneting ); sendRequestSubscribe();}void SipCallMember::handlingSubscribeResponse( void ){ QString authstrtemp; if( local->wasCancelled() ) { state = state_Disconnected; 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; } else if( local->getStatus().getCode() == 401) { proxyauthstr = local->getFinalWWWAuthString(); 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() == 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() < 500 ) { if( call->getCallStatus() == SipCall::callInProgress ) { contactUpdate( false ); call->updateSubscribes(); } } op = opIdle; local = 0; } else { state = state_EarlyDialog; }}// Notifyvoid SipCallMember::requestNotify( const QString &body, const MimeContentType &bodytype ){ callMemberType = Notify; localExpiresTime = -1; localsessiondesc = body; localsessiontype = bodytype; sendRequestNotify();}void SipCallMember::sendRequestNotify( QString username, QString password ){ call->transactions.clear(); if( !username.isEmpty() && !password.isEmpty() && ( authstate == authState_AuthenticationRequired || authstate == authState_AuthenticationRequiredWithNewPassword ) ) { if( authtype == ProxyDigestAuthenticationRequired ) { proxyauthresponse = Sip::getDigestResponse( username, password, "NOTIFY", getContactUri().uri(), proxyauthstr ); } else if( authtype == ProxyBasicAuthenticationRequired ) { proxyauthresponse = Sip::getBasicResponse( username, password ); } local = call->newRequest( this, Sip::NOTIFY, localsessiondesc, localsessiontype, SipUri::null, proxyauthresponse, localExpiresTime ); } else { local = call->newRequest( this, Sip::NOTIFY, localsessiondesc, localsessiontype, SipUri::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 ){ statusUpdated( this );}void SipCallMember::requestClearNotify( const QString &body, const MimeContentType &bodytype ){ callMemberType = Notify; localExpiresTime = 0; localsessiondesc = body; localsessiontype = bodytype; sendRequestNotify();}void SipCallMember::handlingNotifyResponse( void ){ QString authstrtemp; if( local->wasCancelled() ) { state = state_Disconnected; op = opIdle; local = 0; } else if( local->getStatus().getCode() >= 200 ) { // final response if( local->getStatus().getCode() < 300 ) { call->setCallStatus( SipCall::callInProgress ); local = 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 = ProxyDigestAuthenticationRequired; } 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; call->setCallStatus( SipCall::callDead ); } } op = opIdle; local = 0; } else { state = state_EarlyDialog; }}// Messagevoid SipCallMember::requestMessage( const QString &body, const MimeContentType &bodytype ){ callMemberType = Message; localsessiondesc = body; localsessiontype = bodytype; sendRequestMessage();}void SipCallMember::sendRequestMessage( QString username, QString password ){ if( !username.isEmpty() && !password.isEmpty() && ( authstate == authState_AuthenticationRequired || authstate == authState_AuthenticationRequiredWithNewPassword ) ) { if( authtype == ProxyDigestAuthenticationRequired ) { proxyauthresponse = Sip::getDigestResponse( username, password, "MESSAGE", getContactUri().uri(), proxyauthstr ); } else if( authtype == ProxyBasicAuthenticationRequired ) { proxyauthresponse = Sip::getBasicResponse( username, password ); } local = call->newRequest( this, Sip::MESSAGE, localsessiondesc, localsessiontype, SipUri::null, proxyauthresponse, localExpiresTime ); } else { local = call->newRequest( this, Sip::MESSAGE, localsessiondesc, localsessiontype, SipUri::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 ){ statusUpdated( this );}void SipCallMember::handlingMessageResponse( void ){ QString authstrtemp; if( local->wasCancelled() ) { state = state_Disconnected; op = opIdle; local = 0; } else if( local->getStatus().getCode() >= 200 ) { // final response if( local->getStatus().getCode() < 300 ) { } 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 { state = state_Disconnected; } } op = opIdle; local = 0; } else { state = state_EarlyDialog; }}// Invitevoid SipCallMember::requestInvite( const QString &body, const MimeContentType &bodytype ){ callMemberType = Invite; localsessiondesc = body; localsessiontype = bodytype; state = state_InviteRequested; sendRequestInvite();}void SipCallMember::sendRequestInvite( QString username, QString password ){ if( !username.isEmpty() && !password.isEmpty() && ( authstate == authState_AuthenticationRequired ||
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -