Example #1
0
BOOL CHPThreadPool::AdjustThreadCount(DWORD dwNewThreadCount)
{
	if(!CheckStarted())
		return FALSE;

	return InternalAdjustThreadCount(dwNewThreadCount);
}
Example #2
0
 std::unique_ptr<Subscription> UaServer::CreateSubscription(unsigned int period, SubscriptionHandler& callback)
 {
   CheckStarted();
   CreateSubscriptionParameters params;
   params.RequestedPublishingInterval = period;
   return std::unique_ptr<Subscription>(new Subscription (Registry->GetServer(), params, callback, Debug));
 }
Example #3
0
 uint32_t UaServer::RegisterNamespace(std::string uri)
 {
   CheckStarted();
   Node namespacearray(Registry->GetServer(), ObjectId::Server_NamespaceArray);
   std::vector<std::string> uris = namespacearray.GetValue().As<std::vector<std::string>>();
   uint32_t index = uris.size();
   uris.push_back(uri);
   namespacearray.SetValue(uris);
   return index;
 }
Example #4
0
// start the download thread
void Download::Start()
{
	if (CheckStarted() || CheckDone())
		return;
	http = http_async_req_start(http, uri.c_str(), postData.c_str(), postData.length(), keepAlive ? 1 : 0);
	// add the necessary headers
	if (userID.length() || userSession.length())
		http_auth_headers(http, userID.c_str(), NULL, userSession.c_str());
	if (postDataBoundary.length())
		http_add_multipart_header(http, postDataBoundary);
	DownloadManager::Ref().Lock();
	downloadStarted = true;
	DownloadManager::Ref().Unlock();
}
Example #5
0
 uint32_t UaServer::GetNamespaceIndex(std::string uri)
 {
   CheckStarted();
   Node namespacearray(Registry->GetServer(), ObjectId::Server_NamespaceArray);
   std::vector<std::string> uris = namespacearray.GetValue().As<std::vector<std::string>>();;
   for ( uint32_t i=0; i<uris.size(); ++i)
   {
     if (uris[i] == uri )
     {
       return i;
     }
   }
   throw(std::runtime_error("Error namespace uri does not exists in server")); 
   //return -1;
 }
Example #6
0
CHPThreadPool::EnSubmitResult CHPThreadPool::DirectSubmit(Fn_TaskProc fnTaskProc, PVOID pvArg, BOOL bFreeArg)
{
	BOOL bLimited = (m_dwMaxQueueSize != 0);

	{
		CMutexLock2 lock(m_mtx);

		if(!CheckStarted())
			return SUBMIT_ERROR;

		if(bLimited && (DWORD)m_lsTasks.size() >= m_dwMaxQueueSize)
			return SUBMIT_FULL;
		else
		{
			TTask* pTask = TTask::Construct(fnTaskProc, pvArg, bFreeArg);

			m_lsTasks.push(pTask);
			m_cv.notify_one();
		}

	}

	return SUBMIT_OK;
}
Example #7
0
void CClientDlg::SendWebSocket()
{
	static LPCSTR CLOSE_FLAG	 = "$close";
	static const BYTE MASK_KEY[] = {0x1, 0x2, 0x3, 0x4};

	USES_CONVERSION;

	if(!CheckStarted(FALSE))
		return;

	CString strBody;
	m_Body.GetWindowText(strBody);

	CStringA strBodyA	= T2A(strBody);
	BYTE* pData			= (BYTE*)(LPCSTR)strBodyA;
	int iLength			= strBodyA.GetLength();
	CONNID dwConnID		= m_pClient->GetConnectionID();

	if(strBodyA.CompareNoCase(CLOSE_FLAG) != 0)
	{
		if(m_pClient->SendWSMessage(TRUE, 0, 0x1, MASK_KEY, pData, iLength))
		{
			CString strContent;
			strContent.Format(_T("[WebSocket] (len: %d)"), iLength);

			::LogSend(dwConnID, strContent);

			BOOL bFinal;
			BYTE iReserved;
			BYTE iOperationCode;
			LPCBYTE lpszMask;
			ULONGLONG ullBodyLen;

			VERIFY(m_pClient->GetWSMessageState(&bFinal, &iReserved, &iOperationCode, &lpszMask, &ullBodyLen, nullptr));

			if(!m_bListener) ::PostOnWSMessageHeader(dwConnID, bFinal, iReserved, iOperationCode, lpszMask, ullBodyLen);

			if(ullBodyLen > 0)
			{
				m_pClient->GetResponseBody((LPCBYTE*)&pData, &iLength);

				if(!m_bListener) ::PostOnWSMessageBody(dwConnID, pData, iLength);
			}

			if(!m_bListener) ::PostOnWSMessageComplete(dwConnID);

			if(iOperationCode == 0x8)
				OnBnClickedStop();
		}
		else
		{
			::LogSendFail(dwConnID, ::GetLastError(), ::GetSocketErrorDesc(SE_DATA_SEND));
			SetAppState(ST_STOPPED);
		}
	}
	else
	{
		if(m_pClient->SendWSMessage(TRUE, 0, 0x8, MASK_KEY, nullptr, 0))
		{
			::LogSend(dwConnID, _T("[WebSocket] (OP: close)"));
		}

		m_Body.SetWindowText(_T(""));

		OnBnClickedStop();
	}

	m_pClient->CleanupRequestResult();
}
Example #8
0
void CClientDlg::SendHttp()
{
	USES_CONVERSION;

	if(!CheckStarted(TRUE))
		return;

	CString strMethod;
	CString strSchema;
	CString strAddress;
	CString strPort;
	CString strPath;

	m_Method.GetWindowText(strMethod);
	m_Schema.GetWindowText(strSchema);
	m_Address.GetWindowText(strAddress);
	m_Port.GetWindowText(strPort);

	if(m_Method.GetCurSel() != 8)
	{
		m_Path.GetWindowText(strPath);
		strPath.Trim();

		if(strPath.IsEmpty() || strPath.GetAt(0) != '/')
			strPath.Insert(0, '/');
	}

	THttpHeaderMap headers;

	int iCount = m_Headers.GetCount();

	for(int i = 0; i < iCount; i++)
	{
		CString strHeader;
		m_Headers.GetText(i, strHeader);

		int j = 0;
		CString strName  = strHeader.Tokenize(_T(": "), j);
		CString strValue = strHeader.Mid(j + 1);

		headers.emplace(THttpHeaderMap::value_type(T2A(strName), T2A(strValue)));
	}

	CStringA strBodyA;
	CStringA strPathA;

	if(m_Method.GetCurSel() <= 2)
	{
		CString strBody;
		m_Body.GetWindowText(strBody);

		strBodyA = T2A(strBody);
	}
	else if(m_Method.GetCurSel() == 8)
	{
		THttpHeaderMapCI it = headers.find("Host");

		if(it != headers.end() && !it->second.IsEmpty())
			strPathA = it->second;
		else
		{
			CString strHost;
			strHost.Format(_T("%s:%s"), strAddress, strPort);
			strPathA = strHost;
		}
	}

	if(strPathA.IsEmpty())
		strPathA = T2A(strPath);

	DWORD dwIndex	= 0;
	DWORD dwSize	= (DWORD)headers.size();
	unique_ptr<THeader[]> szHeaders(new THeader[dwSize]);

	for(THttpHeaderMapCI it = headers.begin(), end = headers.end(); it != end; ++it, ++dwIndex)
	{
		szHeaders[dwIndex].name  = it->first;
		szHeaders[dwIndex].value = it->second;
	}

	CONNID dwConnID = m_pClient->GetConnectionID();

	if(m_pClient->SendRequest(T2A(strMethod), strPathA, szHeaders.get(), dwSize, (const BYTE*)(LPCSTR)strBodyA, strBodyA.GetLength()))
	{
		CString strContent;
		strContent.Format(_T("[%s] %s://%s:%s%s"), strMethod, strSchema, strAddress, strPort, strPath);

		::LogSend(dwConnID, strContent);

		if(!m_bListener)
		{
			CStringA strSummary = GetHeaderSummary(m_pClient.get(), "    ", 0, TRUE);
			::PostOnHeadersComplete(dwConnID, strSummary);
		}

		LPCBYTE pData	= nullptr;
		int iLength		= 0;

		m_pClient->GetResponseBody(&pData, &iLength);

		if(iLength > 0)
		{
			if(!m_bListener) ::PostOnBody(dwConnID, pData, iLength);

			LPCSTR lpszEnc = m_pClient->GetContentEncoding();

			if(lpszEnc && ::StrStrIA(lpszEnc, "gzip"))
			{
				int rs		= 0;
				DWORD dwLen	= ::GZipGuessUncompressBound(pData, iLength);

				if(dwLen == 0 || dwLen > 5 * 1024 * 1024)
					rs = -10;
				else
				{
					CBufferPtr szBuff(dwLen);
					rs = ::GZipUncompress(pData, iLength, szBuff, dwLen);
				}

				if(rs == 0)
					::PostUncompressBody(dwConnID, dwLen);
				else
				{
					::PostUncompressBodyFail(dwConnID, rs);

					if(!m_bListener) ::PostOnMessageComplete(dwConnID);

					OnBnClickedStop();
					return;
				}
			}
		}

		if(!m_bListener) ::PostOnMessageComplete(dwConnID);

		EnHttpUpgradeType enUpgrade = m_pClient->GetUpgradeType();

		if(enUpgrade == HUT_WEB_SOCKET)
		{
			if(!m_bListener) ::PostOnUpgrade(dwConnID, enUpgrade);

			m_bWebSocket = TRUE;
			OnCbnSelchangeMethod();
		}
	}
	else
	{
		::LogSendFail(dwConnID, ::GetLastError(), ::GetSocketErrorDesc(SE_DATA_SEND));
		SetAppState(ST_STOPPED);
	}

	m_pClient->CleanupRequestResult();
}
Example #9
0
 void UaServer::Stop()
 {
   std::cout << "Stopping opcua server application" << std::endl;
   CheckStarted();
   Addons->Stop();
 }
Example #10
0
 Node UaServer::GetNode(const NodeId& nodeid) const
 {
   CheckStarted();
   return Node(Registry->GetServer(), nodeid);
 }