Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
freebsd
GitHub Repository: freebsd/freebsd-src
Path: blob/main/crypto/krb5/src/windows/leash/LeashDebugWindow.cpp
34889 views
1
// **************************************************************************************
2
// File: LeashDebugWindow.cpp
3
// By: Arthur David Leather
4
// Created: 12/02/98
5
// Copyright @1998 Massachusetts Institute of Technology - All rights reserved.
6
// Description: CPP file for LeashDebugWindow.h. Contains variables and functions
7
// for the Leash Debug Window
8
//
9
// History:
10
//
11
// MM/DD/YY Inits Description of Change
12
// 12/02/98 ADL Original
13
// **************************************************************************************
14
15
16
17
#include "stdafx.h"
18
#include "leash.h"
19
#include "LeashDebugWindow.h"
20
#include "lglobals.h"
21
22
#ifdef _DEBUG
23
#define new DEBUG_NEW
24
#undef THIS_FILE
25
static char THIS_FILE[] = __FILE__;
26
#endif
27
28
/////////////////////////////////////////////////////////////////////////////
29
// CLeashDebugWindow dialog
30
31
32
CLeashDebugWindow::CLeashDebugWindow(CWnd* pParent /*=NULL*/)
33
: CDialog(CLeashDebugWindow::IDD, pParent)
34
{
35
//{{AFX_DATA_INIT(CLeashDebugWindow)
36
//}}AFX_DATA_INIT
37
38
m_pView = NULL;
39
}
40
41
CLeashDebugWindow::CLeashDebugWindow(CFormView* pView)
42
{
43
m_pView = pView;
44
}
45
46
void CLeashDebugWindow::DoDataExchange(CDataExchange* pDX)
47
{
48
CDialog::DoDataExchange(pDX);
49
//{{AFX_DATA_MAP(CLeashDebugWindow)
50
DDX_Control(pDX, IDC_DEBUG_LISTBOX, m_debugListBox);
51
DDX_Control(pDX, IDC_LOG_FILE_LOCATION_TEXT, m_debugFile);
52
//}}AFX_DATA_MAP
53
}
54
55
56
BEGIN_MESSAGE_MAP(CLeashDebugWindow, CDialog)
57
//{{AFX_MSG_MAP(CLeashDebugWindow)
58
ON_WM_SHOWWINDOW()
59
ON_BN_CLICKED(IDC_COPY_TO_CLIPBOARD, OnCopyToClipboard)
60
ON_WM_DESTROY()
61
ON_WM_CLOSE()
62
//}}AFX_MSG_MAP
63
END_MESSAGE_MAP()
64
65
/////////////////////////////////////////////////////////////////////////////
66
// CLeashDebugWindow message handlers
67
68
69
BOOL CLeashDebugWindow::Create(const LPCSTR debugFilePath)
70
{
71
m_debugFilePath = debugFilePath;
72
return CDialog::Create(CLeashDebugWindow::IDD);
73
}
74
75
76
void CLeashDebugWindow::OnCancel()
77
{
78
if (m_pView != NULL)
79
{
80
CWinApp* pApp;
81
pApp = AfxGetApp();
82
pApp->WriteProfileInt("Settings", "DebugWindow", FALSE_FLAG);
83
m_pView->PostMessage(WM_GOODBYE, IDCANCEL); // modeless case
84
//// pset_krb_debug(OFF);
85
//// pset_krb_ap_req_debug(OFF);
86
}
87
else
88
{
89
CDialog::OnCancel(); // modal case
90
}
91
}
92
93
void CLeashDebugWindow::OnOK()
94
{
95
if (m_pView != NULL)
96
{
97
// modeless case
98
UpdateData(TRUE);
99
m_pView->PostMessage(WM_GOODBYE, IDOK);
100
}
101
else
102
{
103
CDialog::OnOK(); // modal case
104
}
105
}
106
107
BOOL CLeashDebugWindow::OnInitDialog()
108
{
109
CDialog::OnInitDialog();
110
111
// Set Debug flags
112
//// pset_krb_debug(ON); //(int)m_debugListBox.GetSafeHwnd()
113
//// pset_krb_ap_req_debug(ON);
114
115
if (*m_debugFilePath != 0)
116
SetDlgItemText(IDC_LOG_FILE_LOCATION_TEXT, m_debugFilePath);
117
else
118
SetDlgItemText(IDC_LOG_FILE_LOCATION_TEXT, "Not Available");
119
120
if (!m_debugListBox.GetCount())
121
GetDlgItem(IDC_COPY_TO_CLIPBOARD)->EnableWindow(FALSE);
122
123
m_CopyButton = FALSE;
124
125
return TRUE; // return TRUE unless you set the focus to a control
126
// EXCEPTION: OCX Property Pages should return FALSE
127
}
128
129
void CLeashDebugWindow::OnShowWindow(BOOL bShow, UINT nStatus)
130
{
131
CDialog::OnShowWindow(bShow, nStatus);
132
}
133
134
void CLeashDebugWindow::OnCopyToClipboard()
135
{
136
if (!OpenClipboard())
137
{
138
MessageBox("Unable to open Clipboard!", "Error", MB_OK);
139
return;
140
}
141
142
EmptyClipboard();
143
144
int maxItems = m_debugListBox.GetCount();
145
const int MAX_MEM = maxItems * 90; // 90 chars per line seems safe like a safe bet
146
147
HGLOBAL hDebugText = GlobalAlloc(GMEM_DDESHARE | GMEM_MOVEABLE, MAX_MEM);
148
if (NULL != hDebugText)
149
{
150
CString listboxItem;
151
LPSTR pDebugText = (LPSTR) GlobalLock(hDebugText);
152
if (!pDebugText)
153
{
154
MessageBox("Unable to write to Clipboard!", "Error", MB_OK);
155
ASSERT(pDebugText);
156
return;
157
}
158
159
*pDebugText = 0;
160
for (int xItem = 0; xItem < maxItems; xItem++)
161
{
162
m_debugListBox.GetText(xItem, listboxItem);
163
strcat(pDebugText, listboxItem);
164
strcat(pDebugText, "\r\n");
165
}
166
167
GlobalUnlock(hDebugText);
168
}
169
170
if (NULL != hDebugText)
171
SetClipboardData(CF_TEXT, hDebugText);
172
173
CloseClipboard();
174
MessageBox("Copy to Clipboard was Successful!\r\n Paste it in your favorite editor.",
175
"Note", MB_OK);
176
}
177
178
BOOL CLeashDebugWindow::PreTranslateMessage(MSG* pMsg)
179
{
180
if (!m_CopyButton && m_debugListBox.GetCount())
181
{
182
m_CopyButton = TRUE;
183
GetDlgItem(IDC_COPY_TO_CLIPBOARD)->EnableWindow(TRUE);
184
}
185
186
return CDialog::PreTranslateMessage(pMsg);
187
}
188
189