Leaked source code of windows server 2003
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

346 lines
11 KiB

  1. //+---------------------------------------------------------------------------
  2. //
  3. // Microsoft Windows
  4. // Copyright (C) Microsoft Corporation, 1992 - 1997.
  5. //
  6. // File: fuslogvw.c
  7. //
  8. // Contents:
  9. //
  10. // Classes:
  11. //
  12. // Functions:
  13. //
  14. // History: 25 Mar 97 t-alans (Alan Shi) Created
  15. // 12 Jan 00 AlanShi (Alan Shi) Copied from cdllogvw
  16. // 30 May 00 AlanShi (Alan Shi) Modified to show date/time
  17. //
  18. //----------------------------------------------------------------------------
  19. #include <windows.h>
  20. #include <shlwapi.h>
  21. #include <shellapi.h>
  22. #include <wininet.h>
  23. #include <commctrl.h>
  24. #include "cdlids.h"
  25. #include "wininet.h"
  26. #define NUMBER_OF(x) (sizeof(x)/sizeof((x)[0]))
  27. #define URL_SEARCH_PATTERN "?FusionBindError!name="
  28. #define DELIMITER_CHAR '!'
  29. #define MAX_CACHE_ENTRY_INFO_SIZE 2048
  30. #define MAX_DATE_LEN 64
  31. #define PAD_DIGITS_FOR_STRING(x) (((x) > 9) ? TEXT("") : TEXT("0"))
  32. const char *ppszMonths[] = {"Jan", "Feb", "Mar", "Apr", "May", "Jun",
  33. "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"};
  34. LRESULT CALLBACK DlgProc(HWND, UINT, WPARAM, LPARAM);
  35. void ViewLogEntry(HWND hwnd);
  36. void RefreshLogView(HWND hwnd);
  37. void DeleteLogEntry(HWND hwnd);
  38. void DeleteAllLogs(HWND hwnd);
  39. void FormatDateBuffer(FILETIME *pftLastMod, LPSTR szBuf, int cchBuffer);
  40. void InitListView(HWND hwndLV);
  41. void AddLogItem(HWND hwndLV, LPINTERNET_CACHE_ENTRY_INFO pCacheEntryInfo);
  42. HINSTANCE hInst;
  43. int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance,
  44. PSTR szCmdLine, int iCmdShow)
  45. {
  46. hInst = hInstance;
  47. DialogBox(hInstance, MAKEINTRESOURCE(IDD_CDLLOGVIEW), NULL, DlgProc);
  48. return 0;
  49. }
  50. LRESULT CALLBACK DlgProc(HWND hwnd, UINT iMsg, WPARAM wParam, LPARAM lParam)
  51. {
  52. HWND hwndLV;
  53. LPNMHDR pnmh = NULL;
  54. switch (iMsg) {
  55. case WM_INITDIALOG:
  56. hwndLV = GetDlgItem(hwnd, IDC_LV_LOGMESSAGES);
  57. InitListView(hwndLV);
  58. RefreshLogView(hwnd);
  59. return TRUE;
  60. case WM_COMMAND:
  61. switch (LOWORD(wParam)) {
  62. case IDCANCEL:
  63. EndDialog(hwnd, 0);
  64. break;
  65. case IDC_CB_VIEWLOG:
  66. ViewLogEntry(hwnd);
  67. break;
  68. case IDC_CB_REFRESH:
  69. RefreshLogView(hwnd);
  70. break;
  71. case IDC_CB_DELETE:
  72. DeleteLogEntry(hwnd);
  73. break;
  74. case IDC_CB_DELETE_ALL:
  75. DeleteAllLogs(hwnd);
  76. break;
  77. }
  78. return TRUE;
  79. case WM_NOTIFY:
  80. if (wParam == IDC_LV_LOGMESSAGES) {
  81. pnmh = (LPNMHDR)lParam;
  82. if (pnmh->code == LVN_ITEMACTIVATE) {
  83. // Double click (or otherwise activated)
  84. ViewLogEntry(hwnd);
  85. }
  86. }
  87. return TRUE;
  88. }
  89. return FALSE;
  90. }
  91. void DeleteLogEntry(HWND hwnd)
  92. {
  93. LPINTERNET_CACHE_ENTRY_INFO pCacheEntryInfo = NULL;
  94. DWORD dwBufferSize = MAX_CACHE_ENTRY_INFO_SIZE;
  95. HWND hwndLV;
  96. LRESULT lIndex = 0;
  97. LRESULT lLength = 0;
  98. static char pBuffer[MAX_CACHE_ENTRY_INFO_SIZE];
  99. char szUrl[INTERNET_MAX_URL_LENGTH];
  100. char szBuf[INTERNET_MAX_URL_LENGTH];
  101. hwndLV = GetDlgItem(hwnd, IDC_LV_LOGMESSAGES);
  102. lIndex = ListView_GetSelectionMark(hwndLV);
  103. ListView_GetItemText(hwndLV, lIndex, 0, szBuf, INTERNET_MAX_URL_LENGTH);
  104. //
  105. // Length of URL plus lenght of returned string must still fit in the
  106. // URL buffer
  107. //
  108. if (((NUMBER_OF(URL_SEARCH_PATTERN) - 1) + lstrlen(szBuf)) >= NUMBER_OF(szUrl))
  109. {
  110. return;
  111. }
  112. strncpy(szUrl, URL_SEARCH_PATTERN, NUMBER_OF(szUrl));
  113. strncat(szUrl, szBuf, NUMBER_OF(szUrl) - NUMBER_OF(URL_SEARCH_PATTERN));
  114. pCacheEntryInfo = (LPINTERNET_CACHE_ENTRY_INFO)pBuffer;
  115. dwBufferSize = MAX_CACHE_ENTRY_INFO_SIZE;
  116. if (DeleteUrlCacheEntry(szUrl)) {
  117. RefreshLogView(hwnd);
  118. }
  119. else {
  120. MessageBox(hwnd, "Error: Unable to delete cache file!",
  121. "Log View Error", MB_OK | MB_ICONERROR);
  122. }
  123. }
  124. void DeleteAllLogs(HWND hwnd)
  125. {
  126. HWND hwndLV;
  127. LVITEM lvitem;
  128. char szBuf[INTERNET_MAX_URL_LENGTH];
  129. char szUrl[INTERNET_MAX_URL_LENGTH];
  130. int iCount;
  131. int i;
  132. hwndLV = GetDlgItem(hwnd, IDC_LV_LOGMESSAGES);
  133. memset(&lvitem, 0, sizeof(LVITEM));
  134. lvitem.iSubItem = 0;
  135. lvitem.mask = LVIF_TEXT;
  136. lvitem.cchTextMax = NUMBER_OF(szBuf);
  137. lvitem.pszText = szBuf;
  138. iCount = ListView_GetItemCount(hwndLV);
  139. for (i = 0; i < iCount; i++) {
  140. szBuf[0] = TEXT('\0');
  141. lvitem.iItem = i;
  142. if (ListView_GetItem(hwndLV, &lvitem)) {
  143. if ((NUMBER_OF(URL_SEARCH_PATTERN) + lstrlen(szUrl)) < NUMBER_OF(szUrl)) {
  144. return;
  145. }
  146. strncpy(szUrl, URL_SEARCH_PATTERN, NUMBER_OF(szUrl));
  147. strncat(szUrl, lvitem.pszText, NUMBER_OF(szUrl) - NUMBER_OF(URL_SEARCH_PATTERN));
  148. DeleteUrlCacheEntry(szUrl);
  149. }
  150. }
  151. RefreshLogView(hwnd);
  152. }
  153. void ViewLogEntry(HWND hwnd)
  154. {
  155. LRESULT lIndex = 0;
  156. LRESULT lLength = 0;
  157. HWND hwndLV;
  158. DWORD dwBufferSize = MAX_CACHE_ENTRY_INFO_SIZE;
  159. LPINTERNET_CACHE_ENTRY_INFO pCacheEntryInfo = NULL;
  160. char szUrl[INTERNET_MAX_URL_LENGTH];
  161. char szBuf[INTERNET_MAX_URL_LENGTH];
  162. static char pBuffer[MAX_CACHE_ENTRY_INFO_SIZE];
  163. hwndLV = GetDlgItem(hwnd, IDC_LV_LOGMESSAGES);
  164. lIndex = ListView_GetSelectionMark(hwndLV);
  165. ListView_GetItemText(hwndLV, lIndex, 0, szBuf, INTERNET_MAX_URL_LENGTH);
  166. if ((NUMBER_OF(URL_SEARCH_PATTERN) + lstrlen(szUrl)) > NUMBER_OF(szUrl)) {
  167. return;
  168. }
  169. strncpy(szUrl, URL_SEARCH_PATTERN, NUMBER_OF(szUrl));
  170. strncat(szUrl, szBuf, NUMBER_OF(szUrl) - NUMBER_OF(URL_SEARCH_PATTERN));
  171. pCacheEntryInfo = (LPINTERNET_CACHE_ENTRY_INFO)pBuffer;
  172. dwBufferSize = MAX_CACHE_ENTRY_INFO_SIZE;
  173. if (GetUrlCacheEntryInfo(szUrl, pCacheEntryInfo, &dwBufferSize)) {
  174. if (pCacheEntryInfo->lpszLocalFileName != NULL) {
  175. if (ShellExecute(NULL, "open", pCacheEntryInfo->lpszLocalFileName,
  176. NULL, NULL, SW_SHOWNORMAL ) <= (HINSTANCE)32) {
  177. // ShellExecute returns <= 32 if error occured
  178. MessageBox(hwnd, "Error: Unable to open cache file!",
  179. "Log View Error", MB_OK | MB_ICONERROR);
  180. }
  181. }
  182. else {
  183. MessageBox(hwnd, "Error: No file name available!",
  184. "Log View Error", MB_OK | MB_ICONERROR);
  185. }
  186. }
  187. }
  188. void RefreshLogView(HWND hwnd)
  189. {
  190. HANDLE hUrlCacheEnum;
  191. DWORD dwBufferSize = MAX_CACHE_ENTRY_INFO_SIZE;
  192. LPINTERNET_CACHE_ENTRY_INFO pCacheEntryInfo = NULL;
  193. HWND hwndLV;
  194. static char pBuffer[MAX_CACHE_ENTRY_INFO_SIZE];
  195. hwndLV = GetDlgItem(hwnd, IDC_LV_LOGMESSAGES);
  196. ListView_DeleteAllItems(hwndLV);
  197. pCacheEntryInfo = (LPINTERNET_CACHE_ENTRY_INFO)pBuffer;
  198. hUrlCacheEnum = FindFirstUrlCacheEntry(URL_SEARCH_PATTERN, pCacheEntryInfo,
  199. &dwBufferSize);
  200. if (hUrlCacheEnum != NULL) {
  201. if (pCacheEntryInfo->lpszSourceUrlName != NULL) {
  202. if (StrStrI(pCacheEntryInfo->lpszSourceUrlName, URL_SEARCH_PATTERN)) {
  203. AddLogItem(hwndLV, pCacheEntryInfo);
  204. }
  205. }
  206. dwBufferSize = MAX_CACHE_ENTRY_INFO_SIZE;
  207. while (FindNextUrlCacheEntry(hUrlCacheEnum, pCacheEntryInfo,
  208. &dwBufferSize)) {
  209. if (pCacheEntryInfo->lpszSourceUrlName != NULL) {
  210. if (StrStrI(pCacheEntryInfo->lpszSourceUrlName, URL_SEARCH_PATTERN)) {
  211. AddLogItem(hwndLV, pCacheEntryInfo);
  212. }
  213. }
  214. dwBufferSize = MAX_CACHE_ENTRY_INFO_SIZE;
  215. }
  216. }
  217. }
  218. void AddLogItem(HWND hwndLV, LPINTERNET_CACHE_ENTRY_INFO pCacheEntryInfo)
  219. {
  220. LVITEM lvitem;
  221. static char szBuf[MAX_DATE_LEN];
  222. memset(&lvitem, 0, sizeof(lvitem));
  223. lvitem.mask = LVIF_TEXT;
  224. FormatDateBuffer(&pCacheEntryInfo->LastModifiedTime, szBuf, NUMBER_OF(szBuf));
  225. lvitem.iItem = 0;
  226. lvitem.iSubItem = 0;
  227. lvitem.pszText = pCacheEntryInfo->lpszSourceUrlName + lstrlen(URL_SEARCH_PATTERN);
  228. lvitem.iItem = ListView_InsertItem(hwndLV, &lvitem);
  229. lvitem.iSubItem = 1;
  230. lvitem.pszText = szBuf;
  231. ListView_SetItem(hwndLV, &lvitem);
  232. }
  233. void FormatDateBuffer(FILETIME *pftLastMod, LPSTR szBuf, int chBuffer)
  234. {
  235. SYSTEMTIME systime;
  236. FILETIME ftLocalLastMod;
  237. FileTimeToLocalFileTime(pftLastMod, &ftLocalLastMod);
  238. FileTimeToSystemTime(&ftLocalLastMod, &systime);
  239. wnsprintf(szBuf, chBuffer, "%s%d %s %d @ %s%d:%s%d:%s%d",
  240. PAD_DIGITS_FOR_STRING(systime.wDay), systime.wDay,
  241. ppszMonths[systime.wMonth - 1],
  242. systime.wYear,
  243. PAD_DIGITS_FOR_STRING(systime.wHour), systime.wHour,
  244. PAD_DIGITS_FOR_STRING(systime.wMinute), systime.wMinute,
  245. PAD_DIGITS_FOR_STRING(systime.wSecond), systime.wSecond);
  246. }
  247. void InitListView(HWND hwndLV)
  248. {
  249. LVCOLUMN lvcol;
  250. memset(&lvcol, 0, sizeof(LVCOLUMN));
  251. lvcol.mask = LVCF_TEXT | LVCF_WIDTH;
  252. lvcol.cx = 350;
  253. lvcol.pszText = TEXT("Description");
  254. ListView_InsertColumn(hwndLV, 0, &lvcol);
  255. lvcol.pszText = TEXT("Date/Time");
  256. lvcol.cx = 150;
  257. ListView_InsertColumn(hwndLV, 1, &lvcol);
  258. }
  259. int
  260. _stdcall
  261. ModuleEntry(void)
  262. {
  263. int i;
  264. STARTUPINFO si;
  265. LPTSTR pszCmdLine = GetCommandLine();
  266. si.dwFlags = 0;
  267. GetStartupInfoA(&si);
  268. i = WinMain(GetModuleHandle(NULL),
  269. NULL,
  270. pszCmdLine,
  271. (si.dwFlags & STARTF_USESHOWWINDOW) ? si.wShowWindow : SW_SHOWDEFAULT);
  272. ExitProcess(i);
  273. return i; // We never come here
  274. }