|
| 1 | +// Author: Kang Lin <kl222@126.com> |
| 2 | + |
| 3 | +#include <QLoggingCategory> |
| 4 | +#include "ParameterFreeRDPServer.h" |
| 5 | +#include "BackendFreeRDPServer.h" |
| 6 | +#include "Backend.h" |
| 7 | + |
| 8 | +static Q_LOGGING_CATEGORY(log, "FreeRDPServer.Backend") |
| 9 | +CBackendFreeRDPServer::CBackendFreeRDPServer( |
| 10 | + COperateFreeRDPServer* pOperate, bool bStopSignal) |
| 11 | + : CBackendServer(pOperate, bStopSignal) |
| 12 | + , m_pPara(pOperate->GetParameter()) |
| 13 | + , m_pSettings(nullptr) |
| 14 | + , m_pServer(nullptr) |
| 15 | + , m_bServerInit(false) |
| 16 | +{ |
| 17 | + qDebug(log) << Q_FUNC_INFO; |
| 18 | +} |
| 19 | + |
| 20 | +CBackendFreeRDPServer::~CBackendFreeRDPServer() |
| 21 | +{ |
| 22 | + qDebug(log) << Q_FUNC_INFO; |
| 23 | +} |
| 24 | + |
| 25 | +/*! |
| 26 | + * \~chinese 初始化 |
| 27 | + * \return |
| 28 | + * \li OnInitReturnValue::Fail: 错误 |
| 29 | + * \li OnInitReturnValue::Success/OnInitReturnValue::UseOnProcess: 使用 OnProcess() (非 Qt 事件循环) |
| 30 | + * \li OnInitReturnValue::NotUseOnProcess: 不使用 OnProcess() (qt 事件循环) |
| 31 | + * |
| 32 | + * \~english Initialization |
| 33 | + * \return CBackend::OnInitReturnValue |
| 34 | + * \li OnInitReturnValue::Fail: error |
| 35 | + * \li OnInitReturnValue::Success/OnInitReturnValue::UseOnProcess: Use OnProcess() (non-Qt event loop) |
| 36 | + * \li OnInitReturnValue::NotUseOnProcess: Don't use OnProcess() (qt event loop) |
| 37 | + * |
| 38 | + * \~ |
| 39 | + * \see Start() |
| 40 | + */ |
| 41 | +CBackend::OnInitReturnValue CBackendFreeRDPServer::OnInit() |
| 42 | +{ |
| 43 | + shadow_subsystem_set_entry_builtin(NULL); |
| 44 | + |
| 45 | + m_pServer = shadow_server_new(); |
| 46 | + if (!m_pServer) |
| 47 | + { |
| 48 | + qCritical(log) << "Server new failed"; |
| 49 | + return OnInitReturnValue::Fail; |
| 50 | + } |
| 51 | + |
| 52 | + SetParameters(); |
| 53 | + |
| 54 | + int nRet = shadow_server_init(m_pServer); |
| 55 | + if(nRet < 0) |
| 56 | + { |
| 57 | + qCritical(log) << "Server initialization failed:" << nRet; |
| 58 | + return OnInitReturnValue::Fail; |
| 59 | + } |
| 60 | + m_bServerInit = true; |
| 61 | + |
| 62 | + if ((nRet = shadow_server_start(m_pServer)) < 0) |
| 63 | + { |
| 64 | + qCritical(log) << "Failed to start server:" << nRet; |
| 65 | + return OnInitReturnValue::Fail; |
| 66 | + } |
| 67 | + |
| 68 | + // Don't use OnProcess (qt event loop) |
| 69 | + // Because freerdp has new thread process loop |
| 70 | + return OnInitReturnValue::NotUseOnProcess; |
| 71 | +} |
| 72 | + |
| 73 | +int CBackendFreeRDPServer::OnClean() |
| 74 | +{ |
| 75 | + int nRet = 0; |
| 76 | + if(m_pServer) |
| 77 | + { |
| 78 | + if(m_bServerInit) |
| 79 | + shadow_server_uninit(m_pServer); |
| 80 | + shadow_server_free(m_pServer); |
| 81 | + m_pServer = nullptr; |
| 82 | + } |
| 83 | + |
| 84 | + return nRet; |
| 85 | +} |
| 86 | + |
| 87 | +/*! |
| 88 | + * \~chinese 具体操作处理 |
| 89 | + * \return |
| 90 | + * \li >= 0: 继续。再次调用间隔时间,单位毫秒 |
| 91 | + * \li = -1: 停止 |
| 92 | + * \li < -1: 错误代码 |
| 93 | + * |
| 94 | + * \~english Specific operation processing of plug-in |
| 95 | + * \return |
| 96 | + * \li >= 0: continue, Interval call time (msec) |
| 97 | + * \li = -1: stop |
| 98 | + * \li < -1: error code |
| 99 | + * \~ |
| 100 | + * \see Start() slotTimeOut() |
| 101 | + */ |
| 102 | +int CBackendFreeRDPServer::OnProcess() |
| 103 | +{ |
| 104 | + // TODO: add event dispatch (non-Qt event loop) |
| 105 | + |
| 106 | + // TODO: When an error occurs. emit sigStop(); |
| 107 | + |
| 108 | + return 0; |
| 109 | +} |
| 110 | + |
| 111 | +int CBackendFreeRDPServer::SetParameters() |
| 112 | +{ |
| 113 | + m_pSettings = m_pServer->settings; |
| 114 | + m_pSettings->NlaSecurity = m_pPara->getNlaSecurity(); |
| 115 | + m_pSettings->TlsSecurity = m_pPara->getTlsSecurity(); |
| 116 | + m_pSettings->RdpSecurity = m_pPara->getRdpSecurity(); |
| 117 | + m_pSettings->UseRdpSecurityLayer = m_pSettings->RdpSecurity; |
| 118 | + m_pSettings->ExtSecurity = m_pPara->getNlaExtSecurity(); |
| 119 | + if(!m_pPara->getSamFile().isEmpty()) |
| 120 | + freerdp_settings_set_string(m_pSettings, FreeRDP_NtlmSamFile, |
| 121 | + m_pPara->getSamFile().toStdString().c_str()); |
| 122 | + |
| 123 | + m_pServer->authentication = m_pPara->getAuthentication(); |
| 124 | + |
| 125 | + m_pServer->port = m_pPara->m_Net.GetPort(); |
| 126 | + m_pServer->mayView = m_pPara->getMayView(); |
| 127 | + m_pServer->mayInteract = m_pPara->getMayInteract(); |
| 128 | + |
| 129 | + return 0; |
| 130 | +} |
| 131 | + |
| 132 | +void CBackendFreeRDPServer::slotDisconnect(const QString &szIp, const quint16 port) |
| 133 | +{ |
| 134 | + // TODO: Disconnect |
| 135 | +} |
0 commit comments