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

📄 rtcoutgoingdlg.cpp

📁 再贡献一份基于osip 协议栈的用户代理
💻 CPP
📖 第 1 页 / 共 5 页
字号:
				rectPos.bottom - RECVVID_BOTTOM
				);
			        
				if(FAILED(hr))
				{
					LOGMSGERROR(_T("IVideoWindow::SetWindowPosition() Failed 0x%x"), hr);
										
					pIMediaEvent->Release();
					pIMediaEvent = NULL;

					return hr;
				} 
        
				hr = m_pIRecvVideo->put_Visible(TRUE);

				if (FAILED(hr))
				{
					LOGMSGERROR(_T("IVideoWindow::put_Visible Failed 0x%x"), hr);
										
					pIMediaEvent->Release();
					pIMediaEvent = NULL;

					return hr;
				}

			}

	}

	else if ( ( lMediaType == RTCMT_VIDEO_RECEIVE) && (EventType == RTCMET_STOPPED))
	{

		//
		// we must put_Visible false and set the owner
		// as null See DShow IVideoWindow SDK 
		// NOTE: should not close window without releasing video 
		// or not removing handler ownership from video window.
		//

		m_pIRecvVideo->put_Visible(FALSE);
		m_pIRecvVideo->put_Owner(NULL);   


		m_pIRecvVideo->Release();
		m_pIRecvVideo = NULL;
		
	}

	else if ( (lMediaType == RTCMT_VIDEO_SEND) &&  (EventType == RTCMET_STARTED))
	{

		   RECT    rectPos;				

		   hr = m_pIRTCClient->get_IVideoWindow(  RTCVD_PREVIEW , &m_pIPrevVideo);

			if (SUCCEEDED(hr))
			{
				CString cstrText;

				hr = m_pIPrevVideo->put_WindowStyle(WS_CHILD | WS_CLIPSIBLINGS);
        
				if(FAILED(hr))
				{
					LOGMSGERROR(_T("IVideoWindow::put_WindowStyle() Failed 0x%x"), hr);
					
					pIMediaEvent->Release();
					pIMediaEvent = NULL;

					return hr;
				}
        
				hr = m_pIPrevVideo->put_Owner((OAHWND) m_hWnd);
        
				if(FAILED(hr))
				{
					
					LOGMSGERROR(_T("IVideoWindow::put_Owner() Failed 0x%x"), hr);
					
					pIMediaEvent->Release();
					pIMediaEvent = NULL;
					return hr;
				}

				GetDlgItem( IDC_VSENDS , &hwdVideoSend );

				::GetClientRect(hwdVideoSend, &rectPos);

		        hr = m_pIPrevVideo->SetWindowPosition(
		        rectPos.left + PREVVID_LEFT,
				rectPos.top  + PREVVID_TOP,
				rectPos.right - PREVVID_RIGHT,
				rectPos.bottom - PREVVID_BOTTOM);

			        
				if(FAILED(hr))
				{
					LOGMSGERROR(_T("IVideoWindow::SetWindowPosition() Failed 0x%x"), hr);
					
					pIMediaEvent->Release();
					pIMediaEvent = NULL;
					return hr;
				} 
        
				hr = m_pIPrevVideo->put_Visible(TRUE);

				if (FAILED(hr))
				{
					LOGMSGERROR(_T("IVideoWindow::put_Visible Failed 0x%x"), hr);
					
					pIMediaEvent->Release();
					pIMediaEvent = NULL;
					return hr;
				}

			}

	}

	else if ( ( lMediaType == RTCMT_VIDEO_SEND) && 
		 (EventType == RTCMET_STOPPED))
	{

		//
		// we must put_Visible false and set the owner
		// as null See DShow IVideoWindow SDK 
		// NOTE: should not close window without releasing video 
		// or not removing handler ownership from video window.
		//

		m_pIPrevVideo->put_Visible(FALSE);
		m_pIPrevVideo->put_Owner(NULL);   

		m_pIPrevVideo->Release();
		m_pIPrevVideo = NULL;

		
	}


	if (NULL != pIMediaEvent)
	{

		pIMediaEvent->Release();
		pIMediaEvent = NULL;

	}

	return hr;
}


/**********************************************************
//@RTCProfileEvent
//
//@Description
//
//  Parser for Profile Event
//
//@Args In:     IDispatch Event Interface
//@Args Out:    HRESULT
//
//
//*********************************************************/
HRESULT CRTCOutgoingDlg::RTCProfileEvent(IDispatch *pIDispatch)
{
	HRESULT               hr            = S_OK;	
	IRTCProfileEvent      *pIProfileEvent = NULL;
//	RTC_PROFILE_EVENT_TYPE EventType;
	long lStatusCode;

	hr = pIDispatch->QueryInterface(IID_IRTCProfileEvent,
									reinterpret_cast<void**> (&pIProfileEvent)
									);

	if ((FAILED(hr)))
	{
		LOGMSGERROR(_T("IDispatch::QueryInterface(IRTCProfileEvent) Failed 0x%x"), 
			hr);
		return hr;
	}
	
	//
	// Getting the Profile
	//

	hr = pIProfileEvent->get_StatusCode(&lStatusCode);

    if (FAILED(hr))
    {
        // get_StatusCode failed
		LOGMSGERROR(_T("RTCProfileEvent get_StatusCode failed 0x%x"), hr);
        return hr;
    }

	hr = lStatusCode;

	if (FAILED(hr))
	{
		// Provisioning failed.
		DoLogOff();
//		OnLoggedOff();
		LOGMSGERROR(_T("Provisioning failed!"));
		return hr;
	}

	// Provisioning was successful.
	// Get the RTC profile object from the event
	IRTCProfile *p = NULL;

	hr = pIProfileEvent->get_Profile(&p);
	if(p)  {
		p->QueryInterface(IID_IRTCProfile, (void **)&m_pProfile);
		SAFE_RELEASE(p); 
		//DEBUG_PRINT(("m_pProfile = %X", m_pProfile));
	} else
		hr = E_NOINTERFACE;

	if (FAILED(hr))
	{
		// get_Profile failed
		//DEBUG_PRINT(("get_Profile failed %x", hr ));
		DoLogOff();
		//OnLoggedOff();
		LOGMSGERROR(_T("Logon failed due to get_Profile failed 0x%x"), hr);
		return hr;
	}
/*
//
// profile debugging
//
BSTR lptstrText; 
lptstrText=NULL;
hr = m_pProfile->get_XML(&lptstrText);
if (FAILED(hr))
{
	LOGMSGERROR(_T("get_ProviderData failed 0x%x"), hr);
	return hr;
} else {
	LOGMSGERROR(lptstrText);
	SysFreeString(lptstrText);
}
*/
	//only supported in RTC1.2
	hr = m_pProfile->put_AllowedAuth(RTCAU_DIGEST);
	if (FAILED(hr))
	{
		LOGMSGERROR(_T("put_AllowedAuth failed 0x%x"), hr);
		return hr;
	}

	CString sipUser, sipDomain, sipPw, sipAor;
	m_editSipUser.GetWindowText(sipUser);
	m_editSipDomain.GetWindowText(sipDomain);
	m_editSipPw.GetWindowText(sipPw);
	sipAor = sipUser + "@" + sipDomain;

	// Update the credentials in the profile
	hr = m_pProfile->SetCredentials(sipAor.AllocSysString(),
		sipUser.AllocSysString(),
		sipPw.AllocSysString());

	hr = DoEnableProfile(TRUE);

	if (NULL != pIProfileEvent)
	{
		pIProfileEvent->Release();
		pIProfileEvent = NULL;

	}
	return hr;
}

/**********************************************************
//@RTCRegistrationStateEvent
//
//@Description
//
//  Parser for Registration State Changed Event
//
//@Args In:     IDispatch Event Interface
//@Args Out:    HRESULT
//
//
//*********************************************************/
HRESULT 
CRTCOutgoingDlg::RTCRegistrationStateEvent(IDispatch *pIDispatch)
{
	HRESULT hr                                  = S_OK;
	IRTCRegistrationStateChangeEvent *pIRegistrationState = NULL;
	RTC_REGISTRATION_STATE RegistrationState;
	long lStatusCode;

	hr = pIDispatch->QueryInterface(IID_IRTCRegistrationStateChangeEvent,
									reinterpret_cast<void**> (&pIRegistrationState)
									);

	if (FAILED(hr))
	{
		LOGMSGERROR(_T("IDispatch::QueryInterface(IRTCSessionRegistrationChangeEvent) Failed 0x%x"), 
			hr);
		return hr;
	}
	

	hr = pIRegistrationState->get_State(&RegistrationState);
	if (FAILED(hr))
	{
		LOGMSGERROR(_T("IRTCRegistrationStateChangeEvent::get_State Failed 0x%x"), hr);
		pIRegistrationState->Release();
		pIRegistrationState = NULL;
		return hr;
	}

    // Get the status code
    hr = pIRegistrationState->get_StatusCode(&lStatusCode);
    if (FAILED(hr))
    {
        // get_StatusCode failed
        LOGMSGERROR(_T("Registration Event - get_StatusCode failed %x"), hr);
        return hr;
    }
    //hr = lStatusCode;

	switch(RegistrationState)
	{
	case RTCRS_NOT_REGISTERED:
		m_editRegisterStatus.SetWindowText(_T("RTCRS_NOT_REGISTERED"));
		break;
	case RTCRS_REGISTERING:
		m_editRegisterStatus.SetWindowText(_T("RTCRS_REGISTERING"));
		break;
	case RTCRS_REGISTERED:
		m_editRegisterStatus.SetWindowText(_T("RTCRS_REGISTERED"));
		m_ctrlEditStatus.SetWindowText(_T(""));
		break;
	case RTCRS_ERROR:
	case RTCRS_REJECTED:
		switch(lStatusCode)
		{
		case RTC_E_STATUS_CLIENT_UNAUTHORIZED: // 401
		{
			// if this event is triggerd, this means that the password supplied to
			// the profile is wrong - so no need to automatically resend the REGISTER request
			// tell the user to correc the password 
			// and delete the profile

			// delete profile
			// todo

			// enable logon button

			StateLogOffIDC(VARIANT_FALSE);
			StateLogOnIDC(VARIANT_TRUE);

			LOGMSGERROR(_T("Logon rejected (401), please check your settings"));
/*			if (m_nLogonAttemptCount < 3) {
				m_nLogonAttemptCount++;

				CString sipUser, sipDomain, sipPw, sipAor;
				m_editSipUser.GetWindowText(sipUser);
				m_editSipDomain.GetWindowText(sipDomain);
				m_editSipPw.GetWindowText(sipPw);
				sipAor = sipUser + "@" + sipDomain;

				// Update the credentials in the profile
				hr = m_pProfile->SetCredentials(sipAor.AllocSysString(),
												sipUser.AllocSysString(),
												sipPw.AllocSysString());

				if (FAILED(hr))
				{	// SetCredentials failed
					LOGMSGERROR(_T("SetCredentials failed %x"), hr );
					return hr;
				}

				// Re-register
				hr = DoEnableProfile(TRUE);

				if (FAILED(hr))
				{	// DoRegister failed
					LOGMSGERROR(_T("DoRegister failed %x"), hr);
					return hr;
				}
			} */
		}
			break;
		case RTC_E_SIP_AUTH_TYPE_NOT_SUPPORTED:
			m_editRegisterStatus.SetWindowText(_T("ERR/REJ-RTC_E_SIP_AUTH_TYPE_NOT_SUPPORTED"));
			DoLogOff();
			break;
		default:
			int const arraysize = 60;
			TCHAR pszDest[arraysize]; 
			size_t cbDest = arraysize * sizeof(TCHAR);
			LPCTSTR pszFormat = _T("RTCRS_ERROR/REJECTED 0x%x - SIP code: %d");
			StringCbPrintf(pszDest, cbDest, pszFormat, lStatusCode, (lStatusCode & 0xFFFF));
			m_editRegisterStatus.SetWindowText(pszDest);
			LOGMSGERROR(pszDest);
			DoLogOff();
			break;
		}
		break;
	case RTCRS_UNREGISTERING:
		m_editRegisterStatus.SetWindowText(_T("RTCRS_UNREGISTERING"));
		break;
	case RTCRS_LOGGED_OFF:
		m_editRegisterStatus.SetWindowText(_T("RTCRS_LOGGED_OFF"));
		// unregister and set buttons
		DoLogOff();
		break;
	case RTCRS_LOCAL_PA_LOGGED_OFF:
		m_editRegisterStatus.SetWindowText(_T("RTCRS_LOCAL_PA_LOGGED_OFF"));
		break;
	case RTCRS_REMOTE_PA_LOGGED_OFF:
		m_editRegisterStatus.SetWindowText(_T("RTCRS_REMOTE_PA_LOGGED_OFF"));
		break;
	default : 
			pIRegistrationState->Release();
			pIRegistrationState = NULL;
			return E_UNEXPECTED;
			break;
	}

	if (NULL != pIRegistrationState)
	{
		pIRegistrationState->Release();
		pIRegistrationState = NULL;
	}	
	return hr;
}

void CRTCOutgoingDlg::OnBnClickedButtonLogon()
{
	// TODO: Add your control notification handler code here
	HRESULT               hr            = S_OK;	
	m_nLogonAttemptCount = 0;

	CString sipUser, sipDomain, sipObp, sipAor;
	m_editSipUser.GetWindowText(sipUser);
	m_editSipDomain.GetWindowText(sipDomain);
	m_editSipObp.GetWindowText(sipObp);
	sipAor = sipUser + "@" + sipDomain;

	m_ctrlEditStatus.SetWindowText(sipAor + "...registering");

	hr = DoGetProfile(	NULL, //authuser
						NULL, //authpassw
						sipAor.AllocSysString(),
						sipObp.AllocSysString(),
						_T("UDP"));

	if (FAILED(hr)) 
	{
		LOGMSGERROR(_T("GetProfile failed!"), hr);
		m_editRegisterStatus.SetWindowText(_T("GetProfile failed ..."));
		return;
	}

	StateLogOffIDC(VARIANT_TRUE);
	StateLogOnIDC(VARIANT_FALSE);

	m_editRegisterStatus.SetWindowText(_T("Waiting for profile ..."));
}

//
// Enable or disable the profile
//
HRESULT CRTCOutgoingDlg::DoEnableProfile(BOOL fEnable)
{
	HRESULT hr;
	// Get the RTC client provisioning interface
    IRTCClientProvisioning2 * pProv = NULL;

    hr = m_pIRTCClient->QueryInterface(
            __uuidof(IRTCClientProvisioning2),
            (void **)&pProv);

    if (FAILED(hr))
    {
        // QueryInterface failed
        LOGMSGERROR(_T("QueryInterface failed %x"), hr );  
        return hr;
    }

	if (fEnable) {
		// Enable the RTC profile object
		m_editRegisterStatus.SetWindowText(_T("Registering (enable profile) ..."));

		hr = pProv->EnableProfile(m_pProfile, 
			RTCRF_REGISTER_INVITE_SESSIONS | 
			RTCRF_REGISTER_MESSAGE_SESSIONS);

		SAFE_RELEASE(pProv);

		if (FAILED(hr))
		{
			// EnableProfile failed
			LOGMSGERROR(_T("EnableProfileEx failed %x"), hr );
			if (hr == RTC_E_CLIENT_NOT_INITIALIZED) {
				LOGMSGERROR(_T("EnableProfileEx failed: RTC_E_UDP_NOT_SUPPORTED"));
			}
			return hr;
		}
	} else {
		// Disable the RTC profile object
		m_editRegisterStatus.SetWindowText(_T("DeRegisterung (disable profile) ..."));

		hr = pProv->DisableProfile(m_pProfile);

		SAFE_RELEASE(pProv);

		if (FAILED(hr))
		{
			// EnableProfile failed
			LOGMSGERROR(_T("EnableProfileEx failed %x"), hr );
			if (hr == RTC_E_CLIENT_NOT_INITIALIZED) {
				LOGMSGERROR(_T("EnableProfileEx failed: RTC_E_UDP_NOT_SUPPORTED"));
			}
			return hr;
		}

		StateLogOffIDC(VARIANT_FALSE);
		StateLogOnIDC(VARIANT_TRUE);
	}

	return hr;    
}

/////////////////////////////////////////////
//
// CRTCWin::DoLogOff
// 

HRESULT CRTCOutgoingDlg::DoLogOff()
{
    HRESULT hr = S_OK;

    if (!m_pProfile)
    {
        // Already logged off
		m_editRegisterStatus.SetWindowText(_T("Already logged off"));
		StateLogOffIDC(VARIANT_FALSE);
		StateLogOnIDC(VARIANT_TRUE);
        return S_OK;
    }

    // Disable profile
    DoEnableProfile(FALSE);

    SAFE_RELEASE(m_pProfile);

    return hr;
}

void CRTCOutgoingDlg::OnBnClickedButtonLogoff()
{
	// TODO: Add your control notification handler code here
	DoLogOff();
}

void CRTCOutgoingDlg::OnBnClickedButtonSkype()
{
	// TODO: Add your control notification handler code here
	CString textString;
	m_editSKYPE.GetWindowText(textString);

	std::wstring convstring (textString);

	static const boost::wregex e(L"callto://[^\\|;:\"'碻 \\\\]+");

	if (boost::regex_match(convstring, e)) {
        ShellExecute(NULL, L"open", textString, NULL, NULL, SW_RESTORE);
	} else {
		MessageBox(_T("Error: Not a valid Skype URI!"),
			_T("ENUM Softphone"));
	}
	return;
}

⌨️ 快捷键说明

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