// DicomNetSink.cpp : implementation file // #include "stdafx.h" #include "dclient.h" #include "DicomNetSink.h" #include "dclientDlg.h" extern CDclientApp theApp; #ifdef _DEBUG #define new DEBUG_NEW #undef THIS_FILE static char THIS_FILE[] = __FILE__; #endif ///////////////////////////////////////////////////////////////////////////// // CDicomNetSink IMPLEMENT_DYNCREATE(CDicomNetSink, CCmdTarget) CDicomNetSink::CDicomNetSink() { EnableAutomation(); m_bSCU=TRUE; m_pDlg=NULL; } CDicomNetSink::~CDicomNetSink() { } void CDicomNetSink::OnFinalRelease() { // When the last reference for an automation object is released // OnFinalRelease is called. The base class will automatically // deletes the object. Add additional cleanup required for your // object before calling the base class. CCmdTarget::OnFinalRelease(); } BEGIN_MESSAGE_MAP(CDicomNetSink, CCmdTarget) //{{AFX_MSG_MAP(CDicomNetSink) // NOTE - the ClassWizard will add and remove mapping macros here. //}}AFX_MSG_MAP END_MESSAGE_MAP() BEGIN_DISPATCH_MAP(CDicomNetSink, CCmdTarget) //{{AFX_DISPATCH_MAP(CDicomNetSink) // NOTE - the ClassWizard will add and remove mapping macros here. DISP_FUNCTION_ID(CDicomNetSink,"NetConnect",1,OnNetConnect,VT_EMPTY,VTS_I4 VTS_I4) DISP_FUNCTION_ID(CDicomNetSink,"NetAccept",2,OnNetAccept,VT_EMPTY,VTS_I4) DISP_FUNCTION_ID(CDicomNetSink,"NetClose",3,OnNetClose,VT_EMPTY,VTS_I4 VTS_I4 VTS_I4) DISP_FUNCTION_ID(CDicomNetSink,"NetReceive",4,OnNetReceive,VT_EMPTY,VTS_I4 VTS_I4 VTS_I2 VTS_VARIANT VTS_I4) DISP_FUNCTION_ID(CDicomNetSink,"NetSend",5,OnNetSend,VT_EMPTY,VTS_I4 VTS_I4 VTS_I2 VTS_I4) DISP_FUNCTION_ID(CDicomNetSink,"NetReceiveAssociateRequest",6,OnNetReceiveAssociateRequest,VT_EMPTY,VTS_I4 VTS_I4) DISP_FUNCTION_ID(CDicomNetSink,"NetReceiveAssociateAccept",7,OnNetReceiveAssociateAccept,VT_EMPTY,VTS_I4 VTS_I4) DISP_FUNCTION_ID(CDicomNetSink,"NetReceiveAssociateReject",8,OnNetReceiveAssociateReject,VT_EMPTY,VTS_I4 VTS_I2 VTS_I2 VTS_I2) DISP_FUNCTION_ID(CDicomNetSink,"NetReceiveData",9,OnNetReceiveData,VT_EMPTY,VTS_I4 VTS_I2 VTS_I4 VTS_I4) DISP_FUNCTION_ID(CDicomNetSink,"NetReceiveReleaseRequest",10,OnNetReceiveReleaseRequest,VT_EMPTY,VTS_I4) DISP_FUNCTION_ID(CDicomNetSink,"NetReceiveReleaseResponse",11,OnNetReceiveReleaseResponse,VT_EMPTY,VTS_I4) DISP_FUNCTION_ID(CDicomNetSink,"NetReceiveAbort",12,OnNetReceiveAbort,VT_EMPTY,VTS_I4 VTS_I2 VTS_I2) DISP_FUNCTION_ID(CDicomNetSink,"NetReceiveCStoreRequest",13,OnNetReceiveCStoreRequest,VT_EMPTY,VTS_I4 VTS_I2 VTS_I2 VTS_BSTR VTS_BSTR VTS_I2 VTS_BSTR VTS_I2 VTS_I4) DISP_FUNCTION_ID(CDicomNetSink,"NetReceiveCStoreResponse",14,OnNetReceiveCStoreResponse,VT_EMPTY,VTS_I4 VTS_I2 VTS_I2 VTS_BSTR VTS_BSTR VTS_I4) DISP_FUNCTION_ID(CDicomNetSink,"NetReceiveCFindResponse",16,OnNetReceiveCFindResponse,VT_EMPTY,VTS_I4 VTS_I2 VTS_I2 VTS_BSTR VTS_I4 VTS_I4) DISP_FUNCTION_ID(CDicomNetSink,"NetReceiveCMoveResponse",20,OnNetReceiveCMoveResponse,VT_EMPTY,VTS_I4 VTS_I2 VTS_I2 VTS_BSTR VTS_I4 VTS_I2 VTS_I2 VTS_I2 VTS_I2 VTS_I4) DISP_FUNCTION_ID(CDicomNetSink,"NetReceiveCEchoRequest",22,OnNetReceiveCEchoRequest,VT_EMPTY,VTS_I4 VTS_I2 VTS_I2 VTS_BSTR) DISP_FUNCTION_ID(CDicomNetSink,"NetReceiveCEchoResponse",23,OnNetReceiveCEchoResponse,VT_EMPTY,VTS_I4 VTS_I2 VTS_I2 VTS_BSTR VTS_I4) DISP_FUNCTION_ID(CDicomNetSink,"NetExternalAuthenticateISCL",37,OnNetExternalAuthenticateISCL,VT_EMPTY,VTS_I4 VTS_VARIANT VTS_VARIANT VTS_VARIANT) DISP_FUNCTION_ID(CDicomNetSink,"NetGetChallengeISCL",38,OnNetGetChallengeISCL,VT_EMPTY,VTS_I4 VTS_VARIANT VTS_VARIANT) DISP_FUNCTION_ID(CDicomNetSink,"NetInternalAuthenticateISCL",39,OnNetInternalAuthenticateISCL,VT_EMPTY,VTS_I4 VTS_VARIANT VTS_VARIANT VTS_VARIANT) DISP_FUNCTION_ID(CDicomNetSink,"NetSecureLinkReady",40,OnNetSecureLinkReady,VT_EMPTY,VTS_I4 VTS_I4) DISP_FUNCTION_ID(CDicomNetSink,"SSLPrivateKeyPasswordEvent", 43, OnSSLPrivateKeyPasswordEvent, VT_EMPTY, VTS_I4 VTS_I4) //}}AFX_DISPATCH_MAP END_DISPATCH_MAP() // Note: we add support for IID_IDicomNetSink to support typesafe binding // from VBA. This IID must match the GUID that is attached to the // dispinterface in the .ODL file. // {3D7CCE5E-5DEE-4F97-B906-2ED34B33FB3F} static const IID IID_IDicomNetSink = { 0x3d7cce5e, 0x5dee, 0x4f97, { 0xb9, 0x6, 0x2e, 0xd3, 0x4b, 0x33, 0xfb, 0x3f } }; BEGIN_INTERFACE_MAP(CDicomNetSink, CCmdTarget) INTERFACE_PART(CDicomNetSink, DIID__LEADDicomNetEvents, Dispatch) END_INTERFACE_MAP() ///////////////////////////////////////////////////////////////////////////// // CDicomNetSink message handlers void CDicomNetSink::OnNetConnect(long hNet, long nStatus) { CString szOut; m_pDlg->StopStatusBar("Ready"); szOut.Format("Connect - Status=%d", nStatus); m_pDlg->RecordMessage(FALSE, szOut, FALSE, NULL); if(nStatus == 0) { m_pDlg->m_ResultsList.AddString("Connection Accepted - " + m_pDlg->m_pLEADDicomNet1->GetPeerAddress(hNet)); } else { m_pDlg->MessageBox("Connect Failed!", "Error", MB_OK); szOut.Format("Connection Failed! - Status=%d", nStatus); m_pDlg->m_ResultsList.AddString(szOut); return; } if(m_pDlg->m_pLEADDicomNet1->GetNetworkSecurityMode() == DICOM_SECURE_NONE) OnNetSecureLinkReady(hNet, nStatus); } void CDicomNetSink::OnNetClose(long hNet, long nStatus, long hPeer) { if(m_bSCU) { m_pDlg->StopStatusBar("Ready"); m_pDlg->RecordMessage(FALSE, "Close", FALSE, NULL); m_pDlg->m_ResultsList.AddString("Connection Closed - " + m_pDlg->m_pLEADDicomNet1->GetPeerAddress(hNet)); } else { //remote computer closed the connection //we can now shutdown our server m_pDlg->m_ResultsList.AddString("SCU Connection Closed - " + m_pDlg->m_pLEADDicomNet1->GetPeerAddress(hNet)); m_pDlg->m_ResultsList.AddString("SCP has been shut down"); m_pDlg->m_pLEADDicomNet2->Close(m_pDlg->m_pLEADDicomNet2->GethNet()); m_pDlg->m_pLEADDicomNet2->ShutDown(); } } void CDicomNetSink::OnNetReceive(long hNet, long nStatus, short nType, const VARIANT FAR& pData, long lSize) { CString szOut; m_pDlg->m_lReceived += lSize; szOut.Format("Received: %ld", m_pDlg->m_lReceived); m_pDlg->m_StatusBar.SetText(szOut, 1, 0); szOut.Format("data received - %s Status=%d Type=%d", m_pDlg->m_pLEADDicomNet1->GetPeerAddress(hNet), nStatus, nType); m_pDlg->m_ResultsList.AddString(szOut); } void CDicomNetSink::OnNetSend(long hNet, long nStatus, short nType, long lBytes) { CString szOut; m_pDlg->m_lSent += lBytes; szOut.Format("Sent: %ld", m_pDlg->m_lSent); m_pDlg->m_StatusBar.SetText(szOut, 2, 0); } void CDicomNetSink::OnNetReceiveAssociateAccept(long hNet, long hPDU) { HTREEITEM hParent=NULL; // Server allowed us to Associate // we have received an AssociateAccept m_pDlg->m_ResultsList.AddString("Associate Accept received - " + m_pDlg->m_pLEADDicomNet1->GetPeerAddress(hNet)); // now, display the recieved hPDU hParent = m_pDlg->RecordMessage(FALSE, "Associate Accept", FALSE, NULL); m_pDlg->DisplayAssociate(hPDU, hParent); m_pDlg->StopStatusBar("Ready"); } void CDicomNetSink::OnNetReceiveAssociateReject(long hNet, short nResult, short nSource, short nReason) { CString szOut; HTREEITEM hNewNode=NULL; HTREEITEM hParent=NULL; // we have received an AssociateReject m_pDlg->StopStatusBar("Ready"); m_pDlg->m_ResultsList.AddString("Associate Reject received - " + m_pDlg->m_pLEADDicomNet1->GetPeerAddress(hNet)); // Display the AssociateReject hParent = m_pDlg->RecordMessage(FALSE, "Associate Reject", FALSE, NULL); switch(nResult) { case PDU_REJECT_RESULT_PERMANENT: szOut = "Result: Rejected permanent"; case PDU_REJECT_RESULT_TRANSIENT: szOut = "Result: Rejected transient"; default: szOut.Format("Result Unknown - %d", nResult); } hNewNode = m_pDlg->m_MsgList.InsertItem(szOut, 2, 2, hParent, TVI_LAST); switch(nSource) { case PDU_REJECT_SOURCE_USER: szOut = "Source: Upper Layer service-user"; break; case PDU_REJECT_SOURCE_PROVIDER1: szOut = "Source: Upper Layer service-provider (ASCE related function)"; break; case PDU_REJECT_SOURCE_PROVIDER2: szOut = "Source: Upper Layer service-provider (Presentation related function)"; break; default: szOut.Format("Source Unknown - %d", nSource); break; } hNewNode = m_pDlg->m_MsgList.InsertItem(szOut, 2, 2, hParent, TVI_LAST); switch(nSource) { case PDU_REJECT_SOURCE_USER: switch(nReason) { case PDU_REJECT_REASON_UNKNOWN: szOut = "Reason: No reason given"; break; case PDU_REJECT_REASON_APPLICATION: szOut = "Reason: Application context name not supported"; break; case PDU_REJECT_REASON_CALLING: szOut = "Reason: Calling AE Title not recognized"; break; case PDU_REJECT_REASON_CALLED: szOut = "Reason: Called AE Title not recognized"; break; default: szOut.Format("Reason: Unknown - %d", nReason); break; } break; case PDU_REJECT_SOURCE_PROVIDER1: switch(nReason) { case PDU_REJECT_REASON_UNKNOWN: szOut = "Reason: No reason given"; break; case PDU_REJECT_REASON_VERSION: szOut = "Reason: Protocol version not supported"; break; default: szOut.Format("Reason: Unknown - %d", nReason); break; } break; case PDU_REJECT_SOURCE_PROVIDER2: switch(nReason) { case PDU_REJECT_REASON_CONGESTION: szOut = "Reason: Temporary congestion"; case PDU_REJECT_REASON_LIMIT: szOut = "Reason: Local limit exceeded"; default: szOut.Format("Reason: Unknown - %d", nReason); break; } break; default: szOut.Format("Reason: Unknown - %d", nReason); break; } hNewNode = m_pDlg->m_MsgList.InsertItem(szOut, 2, 2, hParent, TVI_LAST); } void CDicomNetSink::OnNetReceiveReleaseResponse(long hNet) { // Release Response was received m_pDlg->StopStatusBar("Ready"); m_pDlg->m_ResultsList.AddString("Release Response Received - " + m_pDlg->m_pLEADDicomNet1->GetPeerAddress(m_pDlg->m_pLEADDicomNet1->GethNet())); m_pDlg->RecordMessage(FALSE, "Release Response", FALSE, NULL); m_pDlg->RecordMessage(TRUE, "Close", FALSE, NULL); m_pDlg->m_pLEADDicomNet1->Close(m_pDlg->m_pLEADDicomNet1->GethNet()); m_pDlg->m_pLEADDicomNet1->ShutDown(); m_pDlg->m_ResultsList.AddString("Connection Closed"); } void CDicomNetSink::OnNetReceiveAbort(long hNet, short nSource, short nReason) { if(m_bSCU) { CString szOut; HTREEITEM hNewNode=NULL; HTREEITEM hParent=NULL; // we have received an Abort m_pDlg->StopStatusBar("Ready"); m_pDlg->m_ResultsList.AddString("Abort received - " + m_pDlg->m_pLEADDicomNet1->GetPeerAddress(hNet)); hParent = m_pDlg->RecordMessage(FALSE, "Abort", FALSE, NULL); switch(nSource) { case PDU_ABORT_SOURCE_USER: szOut = "Source: Upper Layer service-user"; break; case PDU_ABORT_SOURCE_PROVIDER: szOut = "Source: Upper Layer service-provider"; break; default: szOut.Format("Source: Unknown - %d", nSource); break; } hNewNode = m_pDlg->m_MsgList.InsertItem(szOut, 2, 2, hParent, TVI_LAST); switch(nSource) { case PDU_ABORT_SOURCE_USER: szOut.Format("Reason: Unknown - %d", nReason); break; case PDU_ABORT_SOURCE_PROVIDER: switch(nReason) { case PDU_ABORT_REASON_UNKNOWN: szOut = "Reason: Reason not specified"; break; case PDU_ABORT_REASON_UNRECOGNIZED: szOut = "Reason: Unrecognized PDU"; break; case PDU_ABORT_REASON_UNEXPECTED: szOut = "Reason: Unexpected PDU"; break; case PDU_ABORT_REASON_UNRECOGNIZED_PARAM: szOut = "Reason: Unrecognized PDU parameter"; break; case PDU_ABORT_REASON_UNEXPECTED_PARAM: szOut = "Reason: Unexpected PDU parameter"; break; case PDU_ABORT_REASON_INVALID_PARAM: szOut = "Reason: Invalid PDU parameter value"; break; default: szOut.Format("Reason: Unknown - %d", nReason); break; } default: szOut.Format("Reason: Unknown - %d", nReason); break; } hNewNode = m_pDlg->m_MsgList.InsertItem(szOut, 2, 2, hParent, TVI_LAST); } else { CString szOut; //Abort was received m_pDlg->StopStatusBar("Ready"); m_pDlg->RecordMessage(FALSE, "Abort", FALSE, NULL); szOut.Format("Abort was received - Source: %d Reason: %d - ", nSource, nReason); BSTR bstr = m_pDlg->m_pLEADDicomNet2->GetPeerAddress(hNet); CString cs = bstr; SysFreeString(bstr); m_pDlg->m_ResultsList.AddString(szOut + cs); } } void CDicomNetSink::OnNetReceiveData(long hNet, short nID, long hDicomCS, long hDicomDS) { //we have received a data message //if connection was never Associated, ignore message if(!m_pDlg->m_pLEADDicomNet1->IsAssociated(hNet)) { m_pDlg->m_ResultsList.AddString("Data Message Ignored - " + m_pDlg->m_pLEADDicomNet1->GetPeerAddress(hNet)); return; } m_pDlg->m_ResultsList.AddString("Command Set received - " + m_pDlg->m_pLEADDicomNet1->GetPeerAddress(hNet)); //copy the Command Set m_pDlg->m_pLEADDicomCS->SetCommandSet(hDicomCS); //we will display it in the specific event } void CDicomNetSink::OnNetReceiveCEchoResponse(long hNet, short nPresentationID, short nMessageID, LPCTSTR pszClass, long nStatus) { m_pDlg->StopStatusBar("Ready"); m_pDlg->m_hMsgParent = m_pDlg->RecordMessage(FALSE, "C-ECHO-RSP", FALSE, NULL); m_pDlg->DisplayCommandSet(m_pDlg->m_hMsgParent); } void CDicomNetSink::OnNetReceiveCStoreResponse(long hNet, short nPresentationID, short nMessageID, LPCTSTR pszClass, LPCTSTR pszInstance, long nStatus) { m_pDlg->StopStatusBar("Ready"); m_pDlg->m_hMsgParent = m_pDlg->RecordMessage(FALSE, "C-STORE-RSP", FALSE, NULL); m_pDlg->DisplayCommandSet(m_pDlg->m_hMsgParent); } void CDicomNetSink::OnNetReceiveCFindResponse(long hNet, short nPresentationID, short nMessageID, LPCTSTR pszClass, long nStatus, long hDS) { CString szText; long hKey; HTREEITEM hNodeX=NULL; HTREEITEM hParent=NULL; short nRet; BOOL bDone; bDone = FALSE; hParent = NULL; if (hDS != 0) { switch(m_pDlg->m_nFindType) { case COMMAND_C_FIND_PATIENT_ROOT: case COMMAND_C_FIND_PATIENT_STUDY_ONLY: m_pDlg->m_pReceiveDS->SetCurrentElement(0L); szText = "PATIENT"; break; case COMMAND_C_FIND_STUDY_ROOT: szText = "STUDY"; if(m_pDlg->m_bPatientLevel == FALSE) m_pDlg->m_pReceiveDS->SetCurrentElement(0L); else { if (m_pDlg->m_hKey != 0) { m_pDlg->m_pReceiveDS->SetCurrentElement(m_pDlg->m_hKey); hParent = m_pDlg->m_hParent; } } break; case COMMAND_C_FIND_SERIES: szText = "SERIES"; m_pDlg->m_pReceiveDS->SetCurrentElement(m_pDlg->m_hKey); hParent = m_pDlg->m_hParent; break; case COMMAND_C_FIND_IMAGE: szText = "IMAGE"; m_pDlg->m_pReceiveDS->SetCurrentElement(m_pDlg->m_hKey); hParent = m_pDlg->m_hParent; break; case COMMAND_C_FIND_STUDY: szText = "STUDY"; m_pDlg->m_pReceiveDS->SetCurrentElement(m_pDlg->m_hKey); hParent = m_pDlg->m_hParent; break; } //insert a new key BSTR bstr = szText.AllocSysString(); nRet = m_pDlg->m_pReceiveDS->InsertKey(bstr, FALSE); //insert a new key for the received ds SysFreeString(bstr); //now, insert the data set into that key if (nRet == 0) { IDicomDSElementPtr pCurrentElement = m_pDlg->m_pReceiveDS->GetCurrentElement(); hKey = pCurrentElement->GethElement(); m_pDlg->m_pReceiveDS->InsertDS(hDS, 0); //display the data set m_pDlg->m_pReceiveDS->SetCurrentElement(hKey); nRet = m_pDlg->m_pReceiveDS->MoveChildElement(); if (nRet == 0) { switch(m_pDlg->m_nFindType) { case COMMAND_C_FIND_PATIENT_ROOT: case COMMAND_C_FIND_PATIENT_STUDY_ONLY: nRet = m_pDlg->m_pReceiveDS->FindFirstElement(TAG_PATIENT_NAME, TRUE); if (nRet == 0) { nRet = m_pDlg->m_pReceiveDS->GetStringValue(0, 1); if (nRet == 0) { bDone = TRUE; BSTR bstr = m_pDlg->m_pReceiveDS->GetStringValues(0); CString cs = bstr; SysFreeString(bstr); szText = szText + " - " + cs; } } if (bDone == FALSE) { nRet = m_pDlg->m_pReceiveDS->FindFirstElement(TAG_PATIENT_ID, TRUE); if (nRet == 0) { nRet = m_pDlg->m_pReceiveDS->GetStringValue(0, 1); if (nRet == 0) { BSTR bstr = m_pDlg->m_pReceiveDS->GetStringValues(0); CString cs = bstr; SysFreeString(bstr); szText = szText + " - " + cs; } } } break; case COMMAND_C_FIND_STUDY_ROOT: case COMMAND_C_FIND_STUDY: nRet = m_pDlg->m_pReceiveDS->FindFirstElement(TAG_STUDY_ID, TRUE); if (nRet == 0) { nRet = m_pDlg->m_pReceiveDS->GetStringValue(0, 1); if (nRet == 0) { bDone = TRUE; BSTR bstr = m_pDlg->m_pReceiveDS->GetStringValues(0); CString cs = bstr; SysFreeString(bstr); szText = szText + " - " + cs; } } if (bDone == FALSE) { nRet = m_pDlg->m_pReceiveDS->FindFirstElement(TAG_STUDY_INSTANCE_UID, TRUE); if (nRet == 0) { nRet = m_pDlg->m_pReceiveDS->GetStringValue(0, 1); if (nRet == 0) { bDone = TRUE; BSTR bstr = m_pDlg->m_pReceiveDS->GetStringValues(0); CString cs = bstr; SysFreeString(bstr); szText = szText + " - " + cs; } } } if (bDone == FALSE) { nRet = m_pDlg->m_pReceiveDS->FindFirstElement(TAG_PATIENT_NAME, TRUE); if (nRet == 0) { nRet = m_pDlg->m_pReceiveDS->GetStringValue(0, 1); if (nRet == 0) { bDone = TRUE; BSTR bstr = m_pDlg->m_pReceiveDS->GetStringValues(0); CString cs = bstr; SysFreeString(bstr); szText = szText + " - " + cs; } } } if (bDone == FALSE) { nRet = m_pDlg->m_pReceiveDS->FindFirstElement(TAG_PATIENT_ID, TRUE); if (nRet == 0) { nRet = m_pDlg->m_pReceiveDS->GetStringValue(0, 1); if (nRet == 0) { BSTR bstr = m_pDlg->m_pReceiveDS->GetStringValues(0); CString cs = bstr; SysFreeString(bstr); szText = szText + " - " + cs; } } } break; case COMMAND_C_FIND_SERIES: nRet = m_pDlg->m_pReceiveDS->FindFirstElement(TAG_SERIES_NUMBER, TRUE); if (nRet == 0) { nRet = m_pDlg->m_pReceiveDS->GetConvertValue(); if (nRet == 0) { BSTR bstr = m_pDlg->m_pReceiveDS->GetStringValues(0); CString cs = bstr; SysFreeString(bstr); szText = szText + " - " + cs; } } else { nRet = m_pDlg->m_pReceiveDS->FindFirstElement(TAG_SERIES_INSTANCE_UID, TRUE); if (nRet == 0) { nRet = m_pDlg->m_pReceiveDS->GetStringValue(0, 1); if (nRet == 0) { BSTR bstr = m_pDlg->m_pReceiveDS->GetStringValues(0); CString cs = bstr; SysFreeString(bstr); szText = szText + " - " + cs; } } } break; case COMMAND_C_FIND_IMAGE: nRet = m_pDlg->m_pReceiveDS->FindFirstElement(TAG_INSTANCE_NUMBER, TRUE); if (nRet == 0) { nRet = m_pDlg->m_pReceiveDS->GetConvertValue(); if (nRet == 0) { BSTR bstr = m_pDlg->m_pReceiveDS->GetStringValues(0); CString cs = bstr; SysFreeString(bstr); szText = szText + " - " + cs; } } break; } } if (hParent == NULL) hNodeX = m_pDlg->m_FindResults.InsertItem(szText, 0, 0, TVI_ROOT, TVI_LAST); else hNodeX = m_pDlg->m_FindResults.InsertItem(szText, 0, 0, hParent, TVI_LAST); m_pDlg->m_FindResults.SetItemData(hNodeX, hKey); m_pDlg->m_FindResults.SetItemState(hNodeX, TVIS_BOLD, TVIS_BOLD); if(m_pDlg->m_FindResults.GetParentItem(hNodeX)) { m_pDlg->m_FindResults.SetItemState(m_pDlg->m_FindResults.GetParentItem(hNodeX), 0, TVIS_BOLD); m_pDlg->m_FindResults.Expand(m_pDlg->m_FindResults.GetParentItem(hNodeX), TVE_EXPAND); } } } if(nStatus != COMMAND_STATUS_PENDING) { m_pDlg->StopStatusBar ("Ready"); CString szOut; BSTR bstr = m_pDlg->m_pLEADDicomNet1->GetPeerAddress(hNet); CString cs = bstr; SysFreeString(bstr); szOut.Format("Find Response received - Status: %d - %s", nStatus, cs); m_pDlg->m_ResultsList.AddString(szOut); } m_pDlg->m_hMsgParent = m_pDlg->RecordMessage(FALSE, "C-FIND-RSP", FALSE, NULL); m_pDlg->DisplayCommandSet(m_pDlg->m_hMsgParent); m_pDlg->m_FindResults.RedrawWindow(); } void CDicomNetSink::OnNetReceiveCMoveResponse(long hNet, short nPresentationID, short nMessageID, LPCTSTR pszClass, long nStatus, short nRemaining, short nCompleted, short nFailed, short nWarning, long hDS) { short nRet; CString szOut; if(nRemaining == 0) { m_pDlg->StopStatusBar("Ready"); if(m_pDlg->m_pLEADDicomNet2->GethNet() != 0) { //C-MOVE is complete //we can now shutdown our server m_pDlg->m_ResultsList.AddString("SCU Connection Closed - " + m_pDlg->m_pLEADDicomNet1->GetPeerAddress(hNet)); m_pDlg->m_ResultsList.AddString("SCP has been shut down"); m_pDlg->m_pLEADDicomNet2->Close(m_pDlg->m_pLEADDicomNet2->GethNet()); m_pDlg->m_pLEADDicomNet2->ShutDown(); } } m_pDlg->m_hMsgParent = m_pDlg->RecordMessage(FALSE, "C-MOVE-RSP", FALSE, NULL); m_pDlg->DisplayCommandSet(m_pDlg->m_hMsgParent); if(nStatus == 0xC901) { if(hDS != 0) { m_pDlg->m_pLEADDicomDS2->hDicomDS = hDS; m_pDlg->m_pLEADDicomDS2->MoveFirstElement(FALSE); nRet = m_pDlg->m_pLEADDicomDS2->FindFirstElement(TAG_OFFENDING_ELEMENT, FALSE); if(nRet == 0) { m_pDlg->m_pLEADDicomDS2->GetConvertValue(); BSTR bstr = m_pDlg->m_pLEADDicomDS2->GetStringValues(0); szOut = bstr; SysFreeString(bstr); m_pDlg->m_ResultsList.AddString("C-MOVE-RQ - Offending Element: " + szOut); } } } } void CDicomNetSink::OnNetAccept(long nStatus) { if(!m_bSCU) { CString szOut; long hClient; //accepting the connection attempt m_pDlg->m_pLEADDicomNet2->Accept(); //get the latest client hClient = m_pDlg->m_pLEADDicomNet2->GetClient(m_pDlg->m_pLEADDicomNet2->GethNet(), 0); //display some information about the connection: BSTR bstr = m_pDlg->m_pLEADDicomNet2->GetPeerAddress(hClient); CString cs = bstr; SysFreeString(bstr); szOut = "Peer: " + cs; m_pDlg->m_ResultsList.AddString("SCU Connection Accepted - " + szOut); m_pDlg->RecordMessage(FALSE, "SCU Connection Accepted - " + szOut, FALSE, NULL); } } void CDicomNetSink::OnNetReceiveAssociateRequest(long hNet, long hPDU) { long x; short nID; short nResult; CString szAbstract; CString szTransfer; HTREEITEM hParent=NULL; short nRet; CString szCalled; CString szCalling; //somebody wants to Associate //we have received an AssociateRequest m_pDlg->m_ResultsList.AddString("Associate Request received - " + m_pDlg->m_pLEADDicomNet2->GetPeerAddress(hNet)); hParent = m_pDlg->RecordMessage(FALSE, "Associate Request", FALSE, NULL); //now, display the recieved hPDU m_pDlg->DisplayAssociate(hPDU, hParent); //check the version, if not 1, reject it if(m_pDlg->m_pLEADDicomNet2->GetVersion(hPDU) != 1) { m_pDlg->m_pLEADDicomNet2->SendAssociateReject(hNet, PDU_REJECT_RESULT_PERMANENT, PDU_REJECT_SOURCE_USER, PDU_REJECT_REASON_VERSION); m_pDlg->m_ResultsList.AddString("Associate Reject sent - " + m_pDlg->m_pLEADDicomNet2->GetPeerAddress(hNet)); m_pDlg->RecordMessage(TRUE, "Associate Reject", FALSE, NULL); } else { //send associate accept class back m_pDlg->m_pLEADDicomNet2->CreateAssociate(FALSE); BSTR bstr1 = m_pDlg->m_pLEADDicomNet2->GetCalled(hPDU); BSTR bstr2 = m_pDlg->m_pLEADDicomNet2->GetCalling(hPDU); szCalled = bstr1; szCalling = bstr2; m_pDlg->m_pLEADDicomNet2->SetCalled(m_pDlg->m_pLEADDicomNet2->GethPDU(), bstr1); m_pDlg->m_pLEADDicomNet2->SetCalling(m_pDlg->m_pLEADDicomNet2->GethPDU(), bstr2); SysFreeString(bstr1); SysFreeString(bstr2); m_pDlg->m_pLEADDicomNet2->SetApplication(m_pDlg->m_pLEADDicomNet2->GethPDU(), m_pDlg->m_pLEADDicomNet2->GetApplication(hPDU)); //copy all presenetation objects from received hPDU //also, reply that we only support the first Transfer Syntax from the received hPDU for(x=0; xm_pLEADDicomNet2->GetPresentationCount(hPDU); x++) { nID = m_pDlg->m_pLEADDicomNet2->GetPresentationID(hPDU, x); nResult = PDU_ACCEPT_RESULT_SUCCESS; //I accept everything on this server! BSTR bstr = szAbstract.AllocSysString(); m_pDlg->m_pLEADDicomNet2->AddPresentation(m_pDlg->m_pLEADDicomNet2->GethPDU(), nID, nResult, bstr); SysFreeString(bstr); //This AE will report only supporting the first Transfer syntax szTransfer = UID_EXPLICIT_VR_LITTLE_ENDIAN; //default if(m_pDlg->m_pLEADDicomNet1->GetTransferCount(hPDU, nID) > 0) { BSTR bstr = m_pDlg->m_pLEADDicomNet1->GetTransferSyntax(hPDU, nID, 0); szTransfer = bstr; SysFreeString(bstr); } bstr = szTransfer.AllocSysString(); m_pDlg->m_pLEADDicomNet2->AddTransferSyntax(m_pDlg->m_pLEADDicomNet2->GethPDU(), nID, bstr); SysFreeString(bstr); //enable role select nRet = m_pDlg->m_pLEADDicomNet2->SetRoleSelect(m_pDlg->m_pLEADDicomNet2->GethPDU(), nID, TRUE, PDU_ROLE_SUPPORT, PDU_ROLE_SUPPORT); m_pDlg->m_pLEADDicomNet2->SetPresentationResult(m_pDlg->m_pLEADDicomNet2->GethPDU(), nID, PDU_ACCEPT_RESULT_SUCCESS); } if(m_pDlg->m_pLEADDicomNet2->IsImplementClass(hPDU)) m_pDlg->m_pLEADDicomNet2->SetImplementClass(m_pDlg->m_pLEADDicomNet2->GethPDU(), TRUE, m_pDlg->m_pLEADDicomNet2->GetImplementClass(hPDU)); if(m_pDlg->m_pLEADDicomNet2->IsImplementVersion(hPDU)) m_pDlg->m_pLEADDicomNet2->SetImplementVersion(m_pDlg->m_pLEADDicomNet2->GethPDU(), TRUE, m_pDlg->m_pLEADDicomNet2->GetImplementVersion(hPDU)); m_pDlg->m_pLEADDicomNet2->SendAssociateAccept(hNet); m_pDlg->m_ResultsList.AddString("Associate Accept sent - " + m_pDlg->m_pLEADDicomNet2->GetPeerAddress(hNet)); hParent = m_pDlg->RecordMessage(TRUE, "Associate Accept", FALSE, NULL); m_pDlg->DisplayAssociate(m_pDlg->m_pLEADDicomNet2->GethPDU(), hParent); } } void CDicomNetSink::OnNetReceiveReleaseRequest(long hNet) { CString szOut; //Release Request was received m_pDlg->RecordMessage(FALSE, "Release Request", FALSE, NULL); szOut = "Release Request was received - "; BSTR bstr = m_pDlg->m_pLEADDicomNet2->GetPeerAddress(hNet); CString cs = bstr; SysFreeString(bstr); m_pDlg->m_ResultsList.AddString(szOut + cs); m_pDlg->m_pLEADDicomNet2->SendReleaseResponse(hNet); szOut = "Release Response was sent - "; bstr = m_pDlg->m_pLEADDicomNet2->GetPeerAddress(hNet); cs = bstr; SysFreeString(bstr); m_pDlg->m_ResultsList.AddString(szOut + cs); m_pDlg->RecordMessage(TRUE, "Release Response", FALSE, NULL); } void CDicomNetSink::OnNetReceiveCStoreRequest(long hNet, short nPresentationID, short nMessageID, LPCTSTR pszClass, LPCTSTR pszInstance, short nPriority, LPCTSTR pszMoveAE, short nMoveMessageID, long hDS) { short nRet; CString szReply; CString szName; CString szFile; nRet = COMMAND_STATUS_SUCCESS; m_pDlg->m_hMsgParent = m_pDlg->RecordMessage(FALSE, "C-STORE-RQ", FALSE, NULL); m_pDlg->DisplayCommandSet(m_pDlg->m_hMsgParent); m_pDlg->m_ResultsList.AddString("Store Request Command Set Sent - " + m_pDlg->m_pLEADDicomNet2->GetPeerAddress(hNet)); if(m_pDlg->m_hParent) m_pDlg->m_FindResults.SetItemState(m_pDlg->m_hParent, 0, TVIS_BOLD); //perform the store nRet = m_pDlg->PerformSTORECommand(hDS); //send a response szReply = "Store Response Command Set Sent - "; //use high-level method to send a response m_pDlg->m_pLEADDicomNet2->SendCStoreResponse(hNet, nPresentationID, nMessageID, pszClass, pszInstance, nRet); BSTR bstr = m_pDlg->m_pLEADDicomNet2->GetPeerAddress(hNet); CString cs = bstr; SysFreeString(bstr); m_pDlg->m_ResultsList.AddString(szReply + cs); m_pDlg->RecordMessage(TRUE, "C-STORE-RSP", FALSE, NULL); } void CDicomNetSink::OnNetReceiveCEchoRequest(long hNet, short nPresentationID, short nMessageID, LPCTSTR pszClass) { short nRet; CString szReply; nRet = COMMAND_STATUS_SUCCESS; m_pDlg->m_hMsgParent = m_pDlg->RecordMessage(FALSE, "C-ECHO-RQ", FALSE, NULL); m_pDlg->DisplayCommandSet(m_pDlg->m_hMsgParent); //send a response szReply = "Echo Response Command Set Sent - "; m_pDlg->m_pLEADDicomNet2->SendCEchoResponse(hNet, nPresentationID, nMessageID, pszClass, COMMAND_STATUS_SUCCESS); BSTR bstr = m_pDlg->m_pLEADDicomNet2->GetPeerAddress(hNet); CString cs = bstr; SysFreeString(bstr); m_pDlg->m_ResultsList.AddString(szReply + cs); m_pDlg->RecordMessage(TRUE, "C-ECHO-RSP", FALSE, NULL); } void CDicomNetSink::OnNetExternalAuthenticateISCL(long hNet, VARIANT FAR* nChallenge, VARIANT FAR* nResponse, VARIANT FAR* nParameter) { if(nResponse->cyVal.int64 == nChallenge->cyVal.int64 + 1) m_pDlg->m_pLEADDicomNet1->ISCLChallengeResponseSuccess = TRUE; else m_pDlg->m_pLEADDicomNet1->ISCLChallengeResponseSuccess = FALSE; } void CDicomNetSink::OnNetGetChallengeISCL(long hNet, VARIANT FAR* nChallenge, VARIANT FAR* nParameter) { nChallenge->cyVal.int64 = 0x0123456789ABCDE1; m_pDlg->m_pLEADDicomNet1->ISCLChallengeResponseSuccess = TRUE; } void CDicomNetSink::OnNetInternalAuthenticateISCL(long hNet, VARIANT FAR* nChallenge, VARIANT FAR* nResponse, VARIANT FAR* nParameter) { nResponse->cyVal.int64 = nChallenge->cyVal.int64 + 1; m_pDlg->m_pLEADDicomNet1->ISCLChallengeResponseSuccess = TRUE; } void CDicomNetSink::OnNetSecureLinkReady(long hNet, long nError) { HTREEITEM hParent=NULL; if (nError == 0) { // now, send Associate Request // send the Associate Request to the server hParent = m_pDlg->RecordMessage(TRUE, "Associate Request", FALSE, NULL); BSTR bstr1 = m_pDlg->m_szCalledAE.AllocSysString(); BSTR bstr2 = m_pDlg->m_szCallingAE.AllocSysString(); m_pDlg->m_pLEADDicomNet1->SetCalled(m_pDlg->m_pLEADDicomNet1->GethPDU(), bstr1); m_pDlg->m_pLEADDicomNet1->SetCalling(m_pDlg->m_pLEADDicomNet1->GethPDU(), bstr2); SysFreeString(bstr1); SysFreeString(bstr2); m_pDlg->DisplayAssociate(m_pDlg->m_pLEADDicomNet1->GethPDU(), hParent); m_pDlg->StartStatusBar("Waiting for Associate Accept/Reject..."); m_pDlg->m_pLEADDicomNet1->SendAssociateRequest(hNet); BSTR bstr = m_pDlg->m_pLEADDicomNet1->GetPeerAddress(hNet); CString cs = bstr; SysFreeString(bstr); m_pDlg->m_ResultsList.AddString("Associate Request Sent - " + cs); } else { CString csMsg; csMsg.Format("Error [%d] -- Connect Failed", nError); hParent = m_pDlg->RecordMessage(TRUE, csMsg, FALSE, NULL); m_pDlg->m_ResultsList.AddString(csMsg); } } void CDicomNetSink::OnSSLPrivateKeyPasswordEvent(long hNet, long nFlag) { int nLenPassword; CPasswordDlg dlg; nLenPassword = 0; if ((theApp.m_strPrivateKeyPassword.GetLength() == 0) && (!theApp.m_bValidPrivateKeyPassword) ) { dlg.m_strPassword = "test"; int nRet = dlg.DoModal(); if (nRet == IDOK) theApp.m_strPrivateKeyPassword = dlg.m_strPassword; } if (theApp.m_strPrivateKeyPassword.GetLength() > 0) { _bstr_t bstrPrivateKeyPassword = theApp.m_strPrivateKeyPassword; m_pDlg->m_pLEADDicomNet1->SSLPrivateKeyPassword = bstrPrivateKeyPassword; } }