shell32/tests: Avoid testing that only certain services are requested by IObjectWithS...
[wine.git] / dlls / wer / main.c
blobb40aa1b7625770d80607e3d663b1fd2952fb10b6
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[] =
52 {'S','o','f','t','w','a','r','e','\\',
53 'M','i','c','r','o','s','o','f','t','\\',
54 'W','i','n','d','o','w','s',' ','E','r','r','o','r',' ','R','e','p','o','r','t','i','n','g','\\',
55 'E','x','c','l','u','d','e','d','A','p','p','l','i','c','a','t','i','o','n','s',0};
57 BOOL WINAPI DllMain(HINSTANCE hinstDLL, DWORD fdwReason, LPVOID lpvReserved)
59 TRACE("(0x%p, %d, %p)\n", hinstDLL, fdwReason, lpvReserved);
61 switch (fdwReason)
63 case DLL_WINE_PREATTACH:
64 return FALSE; /* prefer native version */
65 case DLL_PROCESS_ATTACH:
66 DisableThreadLibraryCalls(hinstDLL);
67 break;
70 return TRUE;
73 /***********************************************************************
74 * WerAddExcludedApplication (wer.@)
76 * Add an application to the user specific or the system wide exclusion list
78 * PARAMS
79 * exeName [i] The application name
80 * allUsers [i] for all users (TRUE) or for the current user (FALSE)
82 * RETURNS
83 * Success: S_OK
84 * Failure: A HRESULT error code
87 HRESULT WINAPI WerAddExcludedApplication(PCWSTR exeName, BOOL allUsers)
89 HKEY hkey;
90 DWORD value = 1;
91 LPWSTR bs;
93 TRACE("(%s, %d)\n",debugstr_w(exeName), allUsers);
94 if (!exeName || !exeName[0])
95 return E_INVALIDARG;
97 bs = wcsrchr(exeName, '\\');
98 if (bs) {
99 bs++; /* skip the backslash */
100 if (!bs[0]) {
101 return E_INVALIDARG;
103 } else
104 bs = (LPWSTR) exeName;
106 if (!RegCreateKeyW(allUsers ? HKEY_LOCAL_MACHINE : HKEY_CURRENT_USER, regpath_exclude, &hkey)) {
107 RegSetValueExW(hkey, bs, 0, REG_DWORD, (LPBYTE)&value, sizeof(DWORD));
108 RegCloseKey(hkey);
109 return S_OK;
111 return E_ACCESSDENIED;
114 /***********************************************************************
115 * WerRemoveExcludedApplication (wer.@)
117 * remove an application from the exclusion list
119 * PARAMS
120 * exeName [i] The application name
121 * allUsers [i] for all users (TRUE) or for the current user (FALSE)
123 * RETURNS
124 * Success: S_OK
125 * Failure: A HRESULT error code
128 HRESULT WINAPI WerRemoveExcludedApplication(PCWSTR exeName, BOOL allUsers)
130 HKEY hkey;
131 LPWSTR bs;
132 LONG lres;
134 TRACE("(%s, %d)\n",debugstr_w(exeName), allUsers);
135 if (!exeName || !exeName[0])
136 return E_INVALIDARG;
138 bs = wcsrchr(exeName, '\\');
139 if (bs) {
140 bs++; /* skip the backslash */
141 if (!bs[0]) {
142 return E_INVALIDARG;
144 } else
145 bs = (LPWSTR) exeName;
147 if (!RegCreateKeyW(allUsers ? HKEY_LOCAL_MACHINE : HKEY_CURRENT_USER, regpath_exclude, &hkey)) {
148 lres = RegDeleteValueW(hkey, bs);
149 RegCloseKey(hkey);
150 return lres ? __HRESULT_FROM_WIN32(ERROR_ENVVAR_NOT_FOUND) : S_OK;
152 return E_ACCESSDENIED;
155 /***********************************************************************
156 * WerReportAddDump (wer.@)
158 * Add a dump of dumpType to hReportHandle.
160 * PARAMS
161 * hReportHandle [i] error reporting handle to add the dump
162 * hProcess [i] handle to the regarding process
163 * hThread [o] handle to the regarding thread
164 * dumpType [i] type of the dump
165 * pExceptionParam [o] pointer to a WER_EXCEPTION_INFORMATION
166 * pDumpCustomOptions [o] pointer to a WER_DUMP_CUSTOM_OPTIONS
167 * dwFlags [i] flag to control the heap dump
169 * RETURNS
170 * Success: S_OK
171 * Failure: A HRESULT error code
174 HRESULT WINAPI WerReportAddDump(HREPORT hReportHandle, HANDLE hProcess, HANDLE hThread,
175 WER_DUMP_TYPE dumpType, PWER_EXCEPTION_INFORMATION pExceptionParam,
176 PWER_DUMP_CUSTOM_OPTIONS pDumpCustomOptions, DWORD dwFlags)
178 FIXME("(%p, %p, %p, %d, %p, %p, %u) :stub\n", hReportHandle, hProcess, hThread, dumpType,
179 pExceptionParam, pDumpCustomOptions, dwFlags);
181 return E_NOTIMPL;
184 /***********************************************************************
185 * WerReportAddFile (wer.@)
187 * Add a file to an error report handle.
189 * PARAMS
190 * hreport [i] error reporting handle to add the file
191 * path [i] path to the file to add
192 * type [i] type of the file to add
193 * flags [i] flags for the file
195 * RETURNS
196 * Success: S_OK
197 * Failure: A HRESULT error code
200 HRESULT WINAPI WerReportAddFile(HREPORT hreport, PCWSTR path, WER_FILE_TYPE type, DWORD flags)
202 FIXME("(%p, %s, %d, 0x%x) :stub\n", hreport, debugstr_w(path), type, flags);
204 return S_OK;
207 /***********************************************************************
208 * WerReportCloseHandle (wer.@)
210 * Close an error reporting handle and free associated resources
212 * PARAMS
213 * hreport [i] error reporting handle to close
215 * RETURNS
216 * Success: S_OK
217 * Failure: A HRESULT error code
220 HRESULT WINAPI WerReportCloseHandle(HREPORT hreport)
222 report_t * report = (report_t *) hreport;
223 report_t * cursor;
224 BOOL found = FALSE;
226 TRACE("(%p)\n", hreport);
227 EnterCriticalSection(&report_table_cs);
228 if (report) {
229 LIST_FOR_EACH_ENTRY(cursor, &report_table, report_t, entry)
231 if (cursor == report) {
232 found = TRUE;
233 list_remove(&report->entry);
234 break;
238 LeaveCriticalSection(&report_table_cs);
239 if (!found)
240 return E_INVALIDARG;
242 heap_free(report);
244 return S_OK;
247 /***********************************************************************
248 * WerReportCreate (wer.@)
250 * Create an error report in memory and return a related HANDLE
252 * PARAMS
253 * eventtype [i] a name for the event type
254 * reporttype [i] what type of report should be created
255 * reportinfo [i] NULL or a ptr to a struct with some detailed information
256 * phandle [o] ptr, where the resulting handle should be saved
258 * RETURNS
259 * Success: S_OK
260 * Failure: A HRESULT error code
262 * NOTES
263 * The event type must be registered at microsoft. Predefined types are
264 * "APPCRASH" as the default on Windows, "Crash32" and "Crash64"
267 HRESULT WINAPI WerReportCreate(PCWSTR eventtype, WER_REPORT_TYPE reporttype, PWER_REPORT_INFORMATION reportinfo, HREPORT *phandle)
269 report_t *report;
271 TRACE("(%s, %d, %p, %p)\n", debugstr_w(eventtype), reporttype, reportinfo, phandle);
272 if (reportinfo) {
273 TRACE(".wzFriendlyEventName: %s\n", debugstr_w(reportinfo->wzFriendlyEventName));
274 TRACE(".wzApplicationName: %s\n", debugstr_w(reportinfo->wzApplicationName));
277 if (phandle) *phandle = NULL;
278 if (!eventtype || !eventtype[0] || !phandle || (reporttype >= WerReportInvalid)) {
279 return E_INVALIDARG;
282 report = heap_alloc_zero(FIELD_OFFSET(report_t, eventtype[lstrlenW(eventtype) + 1]));
283 if (!report)
284 return __HRESULT_FROM_WIN32(ERROR_OUTOFMEMORY);
286 lstrcpyW(report->eventtype, eventtype);
287 report->reporttype = reporttype;
289 if (reportinfo) {
290 report->info = *reportinfo;
291 } else {
292 FIXME("build report information from scratch for %p\n", report);
295 EnterCriticalSection(&report_table_cs);
296 list_add_head(&report_table, &report->entry);
297 LeaveCriticalSection(&report_table_cs);
299 *phandle = report;
300 TRACE("=> %p\n", report);
301 return S_OK;
304 /***********************************************************************
305 * WerReportSetParameter (wer.@)
307 * Set one of 10 parameter / value pairs for a report handle
309 * PARAMS
310 * hreport [i] error reporting handle to add the parameter
311 * id [i] parameter to set (WER_P0 up to WER_P9)
312 * name [i] optional name of the parameter
313 * value [i] value of the parameter
315 * RETURNS
316 * Success: S_OK
317 * Failure: A HRESULT error code
320 HRESULT WINAPI WerReportSetParameter(HREPORT hreport, DWORD id, PCWSTR name, PCWSTR value)
322 FIXME("(%p, %d, %s, %s) :stub\n", hreport, id, debugstr_w(name), debugstr_w(value));
324 return S_OK;
327 /***********************************************************************
328 * WerReportSubmit (wer.@)
330 * Ask the user for permission and send the error report
331 * then kill or restart the application, when requested
333 * PARAMS
334 * hreport [i] error reporting handle to send
335 * consent [i] current transmit permission
336 * flags [i] flag to select dialog, transmission snd restart options
337 * presult [o] ptr, where the transmission result should be saved
339 * RETURNS
340 * Success: S_OK
341 * Failure: A HRESULT error code
344 HRESULT WINAPI WerReportSubmit(HREPORT hreport, WER_CONSENT consent, DWORD flags, PWER_SUBMIT_RESULT presult)
346 FIXME("(%p, %d, 0x%x, %p) :stub\n", hreport, consent, flags, presult);
348 if(!presult)
349 return E_INVALIDARG;
351 *presult = WerDisabled;
352 return S_OK;
355 /***********************************************************************
356 * WerReportSetUIOption (wer.@)
358 HRESULT WINAPI WerReportSetUIOption(HREPORT hreport, WER_REPORT_UI uitype, PCWSTR value)
360 FIXME("(%p, %d, %s) :stub\n", hreport, uitype, debugstr_w(value));
361 return E_NOTIMPL;