ReactOS Fundraising Campaign 2012
 
€ 4,410 / € 30,000

Information | Donate

Home | Info | Community | Development | myReactOS | Contact Us

  1. Home
  2. Community
  3. Development
  4. myReactOS
  5. Fundraiser 2012

  1. Main Page
  2. Alphabetical List
  3. Data Structures
  4. Directories
  5. File List
  6. Data Fields
  7. Globals
  8. Related Pages

ReactOS Development > Doxygen

main.c
Go to the documentation of this file.
00001 /*
00002  * Copyright 2010 Louis Lenders
00003  * Copyright 2010 Detlef Riekenberg
00004  *
00005  * This library is free software; you can redistribute it and/or
00006  * modify it under the terms of the GNU Lesser General Public
00007  * License as published by the Free Software Foundation; either
00008  * version 2.1 of the License, or (at your option) any later version.
00009  *
00010  * This library is distributed in the hope that it will be useful,
00011  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00012  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00013  * Lesser General Public License for more details.
00014  *
00015  * You should have received a copy of the GNU Lesser General Public
00016  * License along with this library; if not, write to the Free Software
00017  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
00018  */
00019 
00020 #include "config.h"
00021 
00022 #include <stdarg.h>
00023 
00024 #include "windef.h"
00025 #include "winbase.h"
00026 #include "winreg.h"
00027 #include "werapi.h"
00028 #include "wine/list.h"
00029 #include "wine/unicode.h"
00030 #include "wine/debug.h"
00031 
00032 WINE_DEFAULT_DEBUG_CHANNEL(wer);
00033 
00034 typedef struct {
00035     struct list entry;
00036     WER_REPORT_INFORMATION info;
00037     WER_REPORT_TYPE reporttype;
00038     WCHAR eventtype[1];
00039 } report_t;
00040 
00041 
00042 static CRITICAL_SECTION report_table_cs;
00043 static CRITICAL_SECTION_DEBUG report_table_cs_debug =
00044 {
00045     0, 0, &report_table_cs,
00046     { &report_table_cs_debug.ProcessLocksList, &report_table_cs_debug.ProcessLocksList },
00047       0, 0, { (DWORD_PTR)(__FILE__ ": report_table_cs") }
00048 };
00049 static CRITICAL_SECTION report_table_cs = { &report_table_cs_debug, -1, 0, 0, 0, 0 };
00050 
00051 static struct list report_table = LIST_INIT(report_table);
00052 
00053 static WCHAR regpath_exclude[] = {'S','o','f','t','w','a','r','e','\\',
00054                                   'M','i','c','r','o','s','o','f','t','\\',
00055                                   'W','i','n','d','o','w','s',' ','E','r','r','o','r',' ','R','e','p','o','r','t','i','n','g','\\',
00056                                   'E','x','c','l','u','d','e','d','A','p','p','l','i','c','a','t','i','o','n','s',0};
00057 
00058 /***********************************************************************
00059  * Memory alloccation helper
00060  */
00061 
00062 static inline void * __WINE_ALLOC_SIZE(1) heap_alloc_zero(size_t len)
00063 {
00064     return HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, len);
00065 }
00066 
00067 static inline BOOL heap_free(void *mem)
00068 {
00069     return HeapFree(GetProcessHeap(), 0, mem);
00070 }
00071 
00072 BOOL WINAPI DllMain(HINSTANCE hinstDLL, DWORD fdwReason, LPVOID lpvReserved)
00073 {
00074     TRACE("(0x%p, %d, %p)\n", hinstDLL, fdwReason, lpvReserved);
00075 
00076     switch (fdwReason)
00077     {
00078         case DLL_WINE_PREATTACH:
00079             return FALSE;    /* prefer native version */
00080         case DLL_PROCESS_ATTACH:
00081             DisableThreadLibraryCalls(hinstDLL);
00082             break;
00083         case DLL_PROCESS_DETACH:
00084             break;
00085     }
00086 
00087     return TRUE;
00088 }
00089 
00090 /***********************************************************************
00091  * WerAddExcludedApplication (wer.@)
00092  *
00093  * Add an application to the user specific or the system wide exclusion list
00094  *
00095  * PARAMS
00096  *  exeName  [i] The application name
00097  *  allUsers [i] for all users (TRUE) or for the current user (FALSE)
00098  *
00099  * RETURNS
00100  *  Success: S_OK
00101  *  Faulure: A HRESULT error code
00102  *
00103  */
00104 HRESULT WINAPI WerAddExcludedApplication(PCWSTR exeName, BOOL allUsers)
00105 {
00106     HKEY hkey;
00107     DWORD value = 1;
00108     LPWSTR bs;
00109 
00110     TRACE("(%s, %d)\n",debugstr_w(exeName), allUsers);
00111     if (!exeName || !exeName[0])
00112         return E_INVALIDARG;
00113 
00114     bs = strrchrW(exeName, '\\');
00115     if (bs) {
00116         bs++;   /* skip the backslash */
00117         if (!bs[0]) {
00118             return E_INVALIDARG;
00119         }
00120     } else
00121         bs = (LPWSTR) exeName;
00122 
00123     if (!RegCreateKeyW(allUsers ? HKEY_LOCAL_MACHINE : HKEY_CURRENT_USER, regpath_exclude, &hkey)) {
00124         RegSetValueExW(hkey, bs, 0, REG_DWORD, (LPBYTE)&value, sizeof(DWORD));
00125         RegCloseKey(hkey);
00126         return S_OK;
00127     }
00128     return E_ACCESSDENIED;
00129 }
00130 
00131 /***********************************************************************
00132  * WerRemoveExcludedApplication (wer.@)
00133  *
00134  * remove an application from the exclusion list
00135  *
00136  * PARAMS
00137  *  exeName  [i] The application name
00138  *  allUsers [i] for all users (TRUE) or for the current user (FALSE)
00139  *
00140  * RETURNS
00141  *  Success: S_OK
00142  *  Faulure: A HRESULT error code
00143  *
00144  */
00145 HRESULT WINAPI WerRemoveExcludedApplication(PCWSTR exeName, BOOL allUsers)
00146 {
00147     HKEY hkey;
00148     LPWSTR bs;
00149     LONG lres;
00150 
00151     TRACE("(%s, %d)\n",debugstr_w(exeName), allUsers);
00152     if (!exeName || !exeName[0])
00153         return E_INVALIDARG;
00154 
00155     bs = strrchrW(exeName, '\\');
00156     if (bs) {
00157         bs++;   /* skip the backslash */
00158         if (!bs[0]) {
00159             return E_INVALIDARG;
00160         }
00161     } else
00162         bs = (LPWSTR) exeName;
00163 
00164     if (!RegCreateKeyW(allUsers ? HKEY_LOCAL_MACHINE : HKEY_CURRENT_USER, regpath_exclude, &hkey)) {
00165         lres = RegDeleteValueW(hkey, bs);
00166         RegCloseKey(hkey);
00167         return lres ? __HRESULT_FROM_WIN32(ERROR_ENVVAR_NOT_FOUND) : S_OK;
00168     }
00169     return E_ACCESSDENIED;
00170 }
00171 
00172 /***********************************************************************
00173  * WerReportCloseHandle (wer.@)
00174  *
00175  * Close an error reporting handle and free associated resources
00176  *
00177  * PARAMS
00178  *  hreport [i] error reporting handle to close
00179  *
00180  * RETURNS
00181  *  Success: S_OK
00182  *  Failure: A HRESULT error code
00183  *
00184  */
00185 HRESULT WINAPI WerReportCloseHandle(HREPORT hreport)
00186 {
00187     report_t * report = (report_t *) hreport;
00188     report_t * cursor;
00189     BOOL found = FALSE;
00190 
00191     TRACE("(%p)\n", hreport);
00192     EnterCriticalSection(&report_table_cs);
00193     if (report) {
00194         LIST_FOR_EACH_ENTRY(cursor, &report_table, report_t, entry)
00195         {
00196             if (cursor == report) {
00197                 found = TRUE;
00198                 list_remove(&report->entry);
00199                 break;
00200             }
00201         }
00202     }
00203     LeaveCriticalSection(&report_table_cs);
00204     if (!found)
00205         return E_INVALIDARG;
00206 
00207     heap_free(report);
00208 
00209     return S_OK;
00210 }
00211 
00212 /***********************************************************************
00213  * WerReportCreate (wer.@)
00214  *
00215  * Create an error report in memory and return a related HANDLE
00216  *
00217  * PARAMS
00218  *  eventtype  [i] a name for the event type
00219  *  reporttype [i] what type of report should be created
00220  *  reportinfo [i] NULL or a ptr to a struct with some detailed information
00221  *  phandle    [o] ptr, where the resulting handle should be saved
00222  *
00223  * RETURNS
00224  *  Success: S_OK
00225  *  Failure: A HRESULT error code
00226  *
00227  * NOTES
00228  *  The event type must be registered at microsoft. Predefined types are
00229  *  "APPCRASH" as the default on Windows, "Crash32" and "Crash64"
00230  *
00231  */
00232 HRESULT WINAPI WerReportCreate(PCWSTR eventtype, WER_REPORT_TYPE reporttype, PWER_REPORT_INFORMATION reportinfo, HREPORT *phandle)
00233 {
00234     report_t *report;
00235     DWORD len;
00236 
00237     TRACE("(%s, %d, %p, %p)\n", debugstr_w(eventtype), reporttype, reportinfo, phandle);
00238     if (reportinfo) {
00239         TRACE(".wzFriendlyEventName: %s\n", debugstr_w(reportinfo->wzFriendlyEventName));
00240         TRACE(".wzApplicationName: %s\n", debugstr_w(reportinfo->wzApplicationName));
00241     }
00242 
00243     if (phandle)  *phandle = NULL;
00244     if (!eventtype || !eventtype[0] || !phandle) {
00245         return E_INVALIDARG;
00246     }
00247 
00248     len = lstrlenW(eventtype) + 1;
00249 
00250     report = heap_alloc_zero(len * sizeof(WCHAR) + sizeof(report_t));
00251     if (!report)
00252         return __HRESULT_FROM_WIN32(ERROR_OUTOFMEMORY);
00253 
00254     lstrcpyW(report->eventtype, eventtype);
00255     report->reporttype = reporttype;
00256 
00257     if (reportinfo) {
00258         report->info = *reportinfo;
00259     } else {
00260         FIXME("build report information from scratch for %p\n", report);
00261     }
00262 
00263     EnterCriticalSection(&report_table_cs);
00264     list_add_head(&report_table, &report->entry);
00265     LeaveCriticalSection(&report_table_cs);
00266 
00267     *phandle = report;
00268     TRACE("=> %p\n", report);
00269     return S_OK;
00270 }
00271 
00272 /***********************************************************************
00273  * WerReportSetParameter (wer.@)
00274  *
00275  * Set one of 10 parameter / value pairs for a report handle
00276  *
00277  * PARAMS
00278  *  hreport [i] error reporting handle to add the parameter
00279  *  id      [i] parameter to set (WER_P0 upto WER_P9)
00280  *  name    [i] optional name of the parameter
00281  *  value   [i] value of the parameter
00282  *
00283  * RETURNS
00284  *  Success: S_OK
00285  *  Failure: A HRESULT error code
00286  *
00287  */
00288 HRESULT WINAPI WerReportSetParameter(HREPORT hreport, DWORD id, PCWSTR name, PCWSTR value)
00289 {
00290     FIXME("(%p, %d, %s, %s) :stub\n", hreport, id, debugstr_w(name), debugstr_w(value));
00291 
00292     return E_NOTIMPL;
00293 }
00294 
00295 /***********************************************************************
00296  * WerReportSubmit (wer.@)
00297  *
00298  * Ask the user for permission and send the error report
00299  * then kill or restart the application, when requested
00300  *
00301  * PARAMS
00302  *  hreport [i] error reporting handle to send
00303  *  consent [i] current transmit permission
00304  *  flags   [i] flag to select dialog, transmission snd restart options
00305  *  presult [o] ptr, where the transmission result should be saved
00306  *
00307  * RETURNS
00308  *  Success: S_OK
00309  *  Failure: A HRESULT error code
00310  *
00311  */
00312 HRESULT WINAPI WerReportSubmit(HREPORT hreport, WER_CONSENT consent, DWORD flags, PWER_SUBMIT_RESULT presult)
00313 {
00314     FIXME("(%p, %d, 0x%x, %p) :stub\n", hreport, consent, flags, presult);
00315 
00316     if(!presult)
00317         return E_INVALIDARG;
00318 
00319     *presult = WerDisabled;
00320     return E_NOTIMPL;
00321 }

Generated on Sun May 27 2012 04:16:43 for ReactOS by doxygen 1.7.6.1

ReactOS is a registered trademark or a trademark of ReactOS Foundation in the United States and other countries.