Home | Info | Community | Development | myReactOS | Contact Us
ReactOS Development > Doxygenqmgr_main.c
Go to the documentation of this file.
00001 /* 00002 * Main DLL interface to Queue Manager (BITS) 00003 * 00004 * Background Intelligent Transfer Service (BITS) interface. Dll is named 00005 * qmgr for backwards compatibility with early versions of BITS. 00006 * 00007 * Copyright 2007 Google (Roy Shea) 00008 * 00009 * This library is free software; you can redistribute it and/or 00010 * modify it under the terms of the GNU Lesser General Public 00011 * License as published by the Free Software Foundation; either 00012 * version 2.1 of the License, or (at your option) any later version. 00013 * 00014 * This library is distributed in the hope that it will be useful, 00015 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00016 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00017 * Lesser General Public License for more details. 00018 * 00019 * You should have received a copy of the GNU Lesser General Public 00020 * License along with this library; if not, write to the Free Software 00021 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA 00022 */ 00023 00024 #include <stdio.h> 00025 00026 #include "objbase.h" 00027 #include "winuser.h" 00028 #include "winreg.h" 00029 #include "advpub.h" 00030 #include "olectl.h" 00031 #include "winsvc.h" 00032 00033 #include "bits.h" 00034 #include "qmgr.h" 00035 #include "initguid.h" 00036 00037 #include "wine/debug.h" 00038 00039 WINE_DEFAULT_DEBUG_CHANNEL(qmgr); 00040 00041 /* Handle to the base address of this DLL */ 00042 static HINSTANCE hInst; 00043 00044 /* Other GUIDs used by this module */ 00045 DEFINE_GUID(CLSID_BackgroundCopyQMgr, 0x69AD4AEE, 0x51BE, 0x439b, 0xA9,0x2C, 0x86,0xAE,0x49,0x0E,0x8B,0x30); 00046 00047 /* Entry point for DLL */ 00048 BOOL WINAPI DllMain(HINSTANCE hinstDLL, DWORD fdwReason, LPVOID lpvReserved) 00049 { 00050 TRACE("(%p, %d, %p)\n", hinstDLL, fdwReason, lpvReserved); 00051 00052 switch (fdwReason) 00053 { 00054 case DLL_WINE_PREATTACH: 00055 return FALSE; /* prefer native version */ 00056 case DLL_PROCESS_ATTACH: 00057 DisableThreadLibraryCalls(hinstDLL); 00058 hInst = hinstDLL; 00059 break; 00060 case DLL_PROCESS_DETACH: 00061 break; 00062 } 00063 00064 return TRUE; 00065 } 00066 00067 static HRESULT init_register_strtable(STRTABLEA *strtable) 00068 { 00069 #define CLSID_EXPANSION_ENTRY(id) { "CLSID_" #id, &CLSID_ ## id } 00070 static const struct { 00071 const char *name; 00072 const CLSID *clsid; 00073 } expns[] = { 00074 CLSID_EXPANSION_ENTRY(BackgroundCopyQMgr), 00075 CLSID_EXPANSION_ENTRY(BackgroundCopyManager) 00076 }; 00077 #undef CLSID_EXPANSION_ENTRY 00078 static STRENTRYA pse[sizeof expns / sizeof expns[0]]; 00079 DWORD i; 00080 00081 strtable->cEntries = sizeof pse / sizeof pse[0]; 00082 strtable->pse = pse; 00083 for (i = 0; i < strtable->cEntries; i++) { 00084 static const char dummy_sample[] = "{12345678-1234-1234-1234-123456789012}"; 00085 const CLSID *clsid = expns[i].clsid; 00086 pse[i].pszName = qmgr_strdup(expns[i].name); 00087 pse[i].pszValue = HeapAlloc(GetProcessHeap(), 0, sizeof dummy_sample); 00088 if (!pse[i].pszName || !pse[i].pszValue) 00089 return E_OUTOFMEMORY; 00090 sprintf(pse[i].pszValue, "{%08X-%04X-%04X-%02X%02X-%02X%02X%02X%02X%02X%02X}", 00091 clsid->Data1, clsid->Data2, clsid->Data3, clsid->Data4[0], 00092 clsid->Data4[1], clsid->Data4[2], clsid->Data4[3], clsid->Data4[4], 00093 clsid->Data4[5], clsid->Data4[6], clsid->Data4[7]); 00094 } 00095 00096 return S_OK; 00097 } 00098 00099 static void cleanup_register_strtable(STRTABLEA *strtable) 00100 { 00101 DWORD i; 00102 for (i = 0; i < strtable->cEntries; i++) { 00103 HeapFree(GetProcessHeap(), 0, strtable->pse[i].pszName); 00104 HeapFree(GetProcessHeap(), 0, strtable->pse[i].pszValue); 00105 if (!strtable->pse[i].pszName || !strtable->pse[i].pszValue) 00106 return; 00107 } 00108 } 00109 00110 static HRESULT register_service(BOOL do_register) 00111 { 00112 static const WCHAR name[] = { 'B','I','T','S', 0 }; 00113 static const WCHAR path[] = { 's','v','c','h','o','s','t','.','e','x','e', 00114 ' ','-','k',' ','n','e','t','s','v','c','s', 0 }; 00115 SC_HANDLE scm, service; 00116 00117 scm = OpenSCManagerW(NULL, NULL, SC_MANAGER_ALL_ACCESS); 00118 if (!scm) 00119 return SELFREG_E_CLASS; 00120 00121 if (do_register) 00122 service = CreateServiceW(scm, name, name, SERVICE_ALL_ACCESS, 00123 SERVICE_WIN32_OWN_PROCESS, 00124 SERVICE_DEMAND_START, SERVICE_ERROR_NORMAL, 00125 path, NULL, NULL, NULL, NULL, NULL); 00126 else 00127 service = OpenServiceW(scm, name, DELETE); 00128 00129 00130 CloseServiceHandle(scm); 00131 if (service) 00132 { 00133 if (!do_register) DeleteService(service); 00134 CloseServiceHandle(service); 00135 } 00136 return S_OK; 00137 } 00138 00139 /* Use an INF file to register or unregister the DLL */ 00140 static HRESULT register_server(BOOL do_register) 00141 { 00142 HRESULT hr; 00143 STRTABLEA strtable; 00144 HMODULE hAdvpack; 00145 HRESULT (WINAPI *pRegInstall)(HMODULE hm, LPCSTR pszSection, const STRTABLEA* pstTable); 00146 static const WCHAR wszAdvpack[] = {'a','d','v','p','a','c','k','.','d','l','l',0}; 00147 00148 TRACE("(%x)\n", do_register); 00149 00150 hr = register_service(do_register); 00151 if (FAILED(hr)) { 00152 ERR("register_service failed: %d\n", GetLastError()); 00153 return hr; 00154 } 00155 00156 hAdvpack = LoadLibraryW(wszAdvpack); 00157 pRegInstall = (void *)GetProcAddress(hAdvpack, "RegInstall"); 00158 00159 hr = init_register_strtable(&strtable); 00160 if (SUCCEEDED(hr)) 00161 hr = pRegInstall(hInst, do_register ? "RegisterDll" : "UnregisterDll", 00162 &strtable); 00163 cleanup_register_strtable(&strtable); 00164 00165 if (FAILED(hr)) 00166 ERR("RegInstall failed: %08x\n", hr); 00167 00168 return hr; 00169 } 00170 00171 HRESULT WINAPI DllRegisterServer(void) 00172 { 00173 return register_server(TRUE); 00174 } 00175 00176 HRESULT WINAPI DllUnregisterServer(void) 00177 { 00178 return register_server(FALSE); 00179 } Generated on Sun May 27 2012 04:25:56 for ReactOS by
1.7.6.1
|