kernel32: Move ReadConsole and WriteConsole to kernelbase.
[wine.git] / dlls / wer / main.c
blobad57cbdf40e2eefed06f04588295befcf0e2d9a6
1 /*
2 * Copyright 2010 Louis Lenders
3 * Copyright 2010 Detlef Riekenberg
5 * This library is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU Lesser General Public
7 * License as published by the Free Software Foundation; either
8 * version 2.1 of the License, or (at your option) any later version.
10 * This library is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * Lesser General Public License for more details.
15 * You should have received a copy of the GNU Lesser General Public
16 * License along with this library; if not, write to the Free Software
17 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
20 #include <stdarg.h>
22 #include "windef.h"
23 #include "winbase.h"
24 #include "winreg.h"
25 #include "werapi.h"
26 #include "wine/heap.h"
27 #include "wine/list.h"
28 #include "wine/debug.h"
30 WINE_DEFAULT_DEBUG_CHANNEL(wer);
32 typedef struct {
33 struct list entry;
34 WER_REPORT_INFORMATION info;
35 WER_REPORT_TYPE reporttype;
36 WCHAR eventtype[1];
37 } report_t;
40 static CRITICAL_SECTION report_table_cs;
41 static CRITICAL_SECTION_DEBUG report_table_cs_debug =
43 0, 0, &report_table_cs,
44 { &report_table_cs_debug.ProcessLocksList, &report_table_cs_debug.ProcessLocksList },
45 0, 0, { (DWORD_PTR)(__FILE__ ": report_table_cs") }
47 static CRITICAL_SECTION report_table_cs = { &report_table_cs_debug, -1, 0, 0, 0, 0 };
49 static struct list report_table = LIST_INIT(report_table);
51 static const WCHAR regpath_exclude[] = L"Software\\Microsoft\\Windows Error Reporting\\ExcludedApplications";
53 BOOL WINAPI DllMain(HINSTANCE hinstDLL, DWORD fdwReason, LPVOID lpvReserved)
55 TRACE("(0x%p, %d, %p)\n", hinstDLL, fdwReason, lpvReserved);
57 switch (fdwReason)
59 case DLL_WINE_PREATTACH:
60 return FALSE; /* prefer native version */
61 case DLL_PROCESS_ATTACH:
62 DisableThreadLibraryCalls(hinstDLL);
63 break;
66 return TRUE;
69 /***********************************************************************
70 * WerAddExcludedApplication (wer.@)
72 * Add an application to the user specific or the system wide exclusion list
74 * PARAMS
75 * exeName [i] The application name
76 * allUsers [i] for all users (TRUE) or for the current user (FALSE)
78 * RETURNS
79 * Success: S_OK
80 * Failure: A HRESULT error code
83 HRESULT WINAPI WerAddExcludedApplication(PCWSTR exeName, BOOL allUsers)
85 HKEY hkey;
86 DWORD value = 1;
87 LPWSTR bs;
89 TRACE("(%s, %d)\n",debugstr_w(exeName), allUsers);
90 if (!exeName || !exeName[0])
91 return E_INVALIDARG;
93 bs = wcsrchr(exeName, '\\');
94 if (bs) {
95 bs++; /* skip the backslash */
96 if (!bs[0]) {
97 return E_INVALIDARG;
99 } else
100 bs = (LPWSTR) exeName;
102 if (!RegCreateKeyW(allUsers ? HKEY_LOCAL_MACHINE : HKEY_CURRENT_USER, regpath_exclude, &hkey)) {
103 RegSetValueExW(hkey, bs, 0, REG_DWORD, (LPBYTE)&value, sizeof(DWORD));
104 RegCloseKey(hkey);
105 return S_OK;
107 return E_ACCESSDENIED;
110 /***********************************************************************
111 * WerRemoveExcludedApplication (wer.@)
113 * remove an application from the exclusion list
115 * PARAMS
116 * exeName [i] The application name
117 * allUsers [i] for all users (TRUE) or for the current user (FALSE)
119 * RETURNS
120 * Success: S_OK
121 * Failure: A HRESULT error code
124 HRESULT WINAPI WerRemoveExcludedApplication(PCWSTR exeName, BOOL allUsers)
126 HKEY hkey;
127 LPWSTR bs;
128 LONG lres;
130 TRACE("(%s, %d)\n",debugstr_w(exeName), allUsers);
131 if (!exeName || !exeName[0])
132 return E_INVALIDARG;
134 bs = wcsrchr(exeName, '\\');
135 if (bs) {
136 bs++; /* skip the backslash */
137 if (!bs[0]) {
138 return E_INVALIDARG;
140 } else
141 bs = (LPWSTR) exeName;
143 if (!RegCreateKeyW(allUsers ? HKEY_LOCAL_MACHINE : HKEY_CURRENT_USER, regpath_exclude, &hkey)) {
144 lres = RegDeleteValueW(hkey, bs);
145 RegCloseKey(hkey);
146 return lres ? __HRESULT_FROM_WIN32(ERROR_ENVVAR_NOT_FOUND) : S_OK;
148 return E_ACCESSDENIED;
151 /***********************************************************************
152 * WerReportAddDump (wer.@)
154 * Add a dump of dumpType to hReportHandle.
156 * PARAMS
157 * hReportHandle [i] error reporting handle to add the dump
158 * hProcess [i] handle to the regarding process
159 * hThread [o] handle to the regarding thread
160 * dumpType [i] type of the dump
161 * pExceptionParam [o] pointer to a WER_EXCEPTION_INFORMATION
162 * pDumpCustomOptions [o] pointer to a WER_DUMP_CUSTOM_OPTIONS
163 * dwFlags [i] flag to control the heap dump
165 * RETURNS
166 * Success: S_OK
167 * Failure: A HRESULT error code
170 HRESULT WINAPI WerReportAddDump(HREPORT hReportHandle, HANDLE hProcess, HANDLE hThread,
171 WER_DUMP_TYPE dumpType, PWER_EXCEPTION_INFORMATION pExceptionParam,
172 PWER_DUMP_CUSTOM_OPTIONS pDumpCustomOptions, DWORD dwFlags)
174 FIXME("(%p, %p, %p, %d, %p, %p, %u) :stub\n", hReportHandle, hProcess, hThread, dumpType,
175 pExceptionParam, pDumpCustomOptions, dwFlags);
177 return E_NOTIMPL;
180 /***********************************************************************
181 * WerReportAddFile (wer.@)
183 * Add a file to an error report handle.
185 * PARAMS
186 * hreport [i] error reporting handle to add the file
187 * path [i] path to the file to add
188 * type [i] type of the file to add
189 * flags [i] flags for the file
191 * RETURNS
192 * Success: S_OK
193 * Failure: A HRESULT error code
196 HRESULT WINAPI WerReportAddFile(HREPORT hreport, PCWSTR path, WER_FILE_TYPE type, DWORD flags)
198 FIXME("(%p, %s, %d, 0x%x) :stub\n", hreport, debugstr_w(path), type, flags);
200 return S_OK;
203 /***********************************************************************
204 * WerReportCloseHandle (wer.@)
206 * Close an error reporting handle and free associated resources
208 * PARAMS
209 * hreport [i] error reporting handle to close
211 * RETURNS
212 * Success: S_OK
213 * Failure: A HRESULT error code
216 HRESULT WINAPI WerReportCloseHandle(HREPORT hreport)
218 report_t * report = (report_t *) hreport;
219 report_t * cursor;
220 BOOL found = FALSE;
222 TRACE("(%p)\n", hreport);
223 EnterCriticalSection(&report_table_cs);
224 if (report) {
225 LIST_FOR_EACH_ENTRY(cursor, &report_table, report_t, entry)
227 if (cursor == report) {
228 found = TRUE;
229 list_remove(&report->entry);
230 break;
234 LeaveCriticalSection(&report_table_cs);
235 if (!found)
236 return E_INVALIDARG;
238 heap_free(report);
240 return S_OK;
243 /***********************************************************************
244 * WerReportCreate (wer.@)
246 * Create an error report in memory and return a related HANDLE
248 * PARAMS
249 * eventtype [i] a name for the event type
250 * reporttype [i] what type of report should be created
251 * reportinfo [i] NULL or a ptr to a struct with some detailed information
252 * phandle [o] ptr, where the resulting handle should be saved
254 * RETURNS
255 * Success: S_OK
256 * Failure: A HRESULT error code
258 * NOTES
259 * The event type must be registered at microsoft. Predefined types are
260 * "APPCRASH" as the default on Windows, "Crash32" and "Crash64"
263 HRESULT WINAPI WerReportCreate(PCWSTR eventtype, WER_REPORT_TYPE reporttype, PWER_REPORT_INFORMATION reportinfo, HREPORT *phandle)
265 report_t *report;
267 TRACE("(%s, %d, %p, %p)\n", debugstr_w(eventtype), reporttype, reportinfo, phandle);
268 if (reportinfo) {
269 TRACE(".wzFriendlyEventName: %s\n", debugstr_w(reportinfo->wzFriendlyEventName));
270 TRACE(".wzApplicationName: %s\n", debugstr_w(reportinfo->wzApplicationName));
273 if (phandle) *phandle = NULL;
274 if (!eventtype || !eventtype[0] || !phandle || (reporttype >= WerReportInvalid)) {
275 return E_INVALIDARG;
278 report = heap_alloc_zero(FIELD_OFFSET(report_t, eventtype[lstrlenW(eventtype) + 1]));
279 if (!report)
280 return __HRESULT_FROM_WIN32(ERROR_OUTOFMEMORY);
282 lstrcpyW(report->eventtype, eventtype);
283 report->reporttype = reporttype;
285 if (reportinfo) {
286 report->info = *reportinfo;
287 } else {
288 FIXME("build report information from scratch for %p\n", report);
291 EnterCriticalSection(&report_table_cs);
292 list_add_head(&report_table, &report->entry);
293 LeaveCriticalSection(&report_table_cs);
295 *phandle = report;
296 TRACE("=> %p\n", report);
297 return S_OK;
300 /***********************************************************************
301 * WerReportSetParameter (wer.@)
303 * Set one of 10 parameter / value pairs for a report handle
305 * PARAMS
306 * hreport [i] error reporting handle to add the parameter
307 * id [i] parameter to set (WER_P0 up to WER_P9)
308 * name [i] optional name of the parameter
309 * value [i] value of the parameter
311 * RETURNS
312 * Success: S_OK
313 * Failure: A HRESULT error code
316 HRESULT WINAPI WerReportSetParameter(HREPORT hreport, DWORD id, PCWSTR name, PCWSTR value)
318 FIXME("(%p, %d, %s, %s) :stub\n", hreport, id, debugstr_w(name), debugstr_w(value));
320 return S_OK;
323 /***********************************************************************
324 * WerReportSubmit (wer.@)
326 * Ask the user for permission and send the error report
327 * then kill or restart the application, when requested
329 * PARAMS
330 * hreport [i] error reporting handle to send
331 * consent [i] current transmit permission
332 * flags [i] flag to select dialog, transmission snd restart options
333 * presult [o] ptr, where the transmission result should be saved
335 * RETURNS
336 * Success: S_OK
337 * Failure: A HRESULT error code
340 HRESULT WINAPI WerReportSubmit(HREPORT hreport, WER_CONSENT consent, DWORD flags, PWER_SUBMIT_RESULT presult)
342 FIXME("(%p, %d, 0x%x, %p) :stub\n", hreport, consent, flags, presult);
344 if(!presult)
345 return E_INVALIDARG;
347 *presult = WerDisabled;
348 return S_OK;
351 /***********************************************************************
352 * WerReportSetUIOption (wer.@)
354 HRESULT WINAPI WerReportSetUIOption(HREPORT hreport, WER_REPORT_UI uitype, PCWSTR value)
356 FIXME("(%p, %d, %s) :stub\n", hreport, uitype, debugstr_w(value));
357 return E_NOTIMPL;