ReactOS  0.4.14-dev-293-g2b39b42
netcfg_iface.c
Go to the documentation of this file.
1 #include "precomp.h"
2 
3 typedef struct
4 {
5  const INetCfg * lpVtbl;
6  const INetCfgLock * lpVtblLock;
7  const INetCfgPnpReconfigCallback *lpVtblPnpReconfigCallback;
16 
17 static __inline LPINetCfgImpl impl_from_INetCfgLock(INetCfgLock *iface)
18 {
19  return (INetCfgImpl*)((char *)iface - FIELD_OFFSET(INetCfgImpl, lpVtblLock));
20 }
21 
22 static __inline LPINetCfgImpl impl_from_INetCfgPnpReconfigCallback(INetCfgPnpReconfigCallback *iface)
23 {
24  return (INetCfgImpl*)((char *)iface - FIELD_OFFSET(INetCfgImpl, lpVtblPnpReconfigCallback));
25 }
26 
27 
28 HRESULT
29 WINAPI
31  INetCfgLock * iface,
32  REFIID iid,
33  LPVOID * ppvObj)
34 {
36  return INetCfg_QueryInterface((INetCfg*)This, iid, ppvObj);
37 }
38 
39 
40 ULONG
41 WINAPI
43  INetCfgLock * iface)
44 {
46 
47  return INetCfg_AddRef((INetCfg*)This);
48 }
49 
50 ULONG
51 WINAPI
53  INetCfgLock * iface)
54 {
56  return INetCfg_Release((INetCfg*)This);
57 }
58 
59 HRESULT
60 WINAPI
62  INetCfgLock * iface,
63  DWORD cmsTimeout,
64  LPCWSTR pszwClientDescription,
65  LPWSTR *ppszwClientDescription)
66 {
67  DWORD dwResult;
68  HKEY hKey;
69  WCHAR szValue[100];
71 
72  if (This->bInitialized)
74 
75  dwResult = WaitForSingleObject(This->hMutex, cmsTimeout);
76  if (dwResult == WAIT_TIMEOUT)
77  {
78  if (ppszwClientDescription)
79  {
80  if (RegOpenKeyExW(HKEY_LOCAL_MACHINE, L"SYSTEM\\CurrentControlSet\\Control\\Network\\NetCfgLockHolder", 0, KEY_READ, &hKey) == ERROR_SUCCESS)
81  {
82  dwResult = sizeof(szValue);
83  if (RegQueryValueExW(hKey, NULL, NULL, NULL, (LPBYTE)szValue, &dwResult) == ERROR_SUCCESS)
84  {
85  szValue[(sizeof(szValue)/sizeof(WCHAR))-1] = L'\0';
86  *ppszwClientDescription = CoTaskMemAlloc((wcslen(szValue)+1) * sizeof(WCHAR));
87  if (*ppszwClientDescription)
88  wcscpy(*ppszwClientDescription, szValue);
89  }
90  RegCloseKey(hKey);
91  }
92  }
93  return S_FALSE;
94  }
95  else if (dwResult == WAIT_OBJECT_0)
96  {
97  if (RegCreateKeyExW(HKEY_LOCAL_MACHINE, L"SYSTEM\\CurrentControlSet\\Control\\Network\\NetCfgLockHolder", 0, NULL, 0, KEY_WRITE, NULL, &hKey, NULL) == ERROR_SUCCESS)
98  {
99  RegSetValueExW(hKey, NULL, 0, REG_SZ, (LPBYTE)pszwClientDescription, (wcslen(pszwClientDescription)+1) * sizeof(WCHAR));
100  RegCloseKey(hKey);
101  }
102  return S_OK;
103  }
104 
105  return E_FAIL;
106 }
107 
108 HRESULT
109 WINAPI
111  INetCfgLock * iface)
112 {
114 
115  if (This->bInitialized)
117 
118 
119  if (ReleaseMutex(This->hMutex))
120  return S_OK;
121  else
122  return S_FALSE;
123 }
124 
125 HRESULT
126 WINAPI
128  INetCfgLock * iface,
129  LPWSTR *ppszwClientDescription)
130 {
131  HKEY hKey;
132  WCHAR szValue[100];
133  DWORD dwSize, dwType;
134  HRESULT hr;
135 
136  if (RegOpenKeyExW(HKEY_LOCAL_MACHINE, L"SYSTEM\\CurrentControlSet\\Control\\Network\\NetCfgLockHolder", 0, KEY_READ, &hKey) != ERROR_SUCCESS)
137  return S_FALSE;
138 
139  dwSize = sizeof(szValue);
140  if (RegQueryValueExW(hKey, NULL, NULL, &dwType, (LPBYTE)szValue, &dwSize) == ERROR_SUCCESS && dwType == REG_SZ)
141  {
142  hr = S_OK;
143  szValue[(sizeof(szValue)/sizeof(WCHAR))-1] = L'\0';
144  *ppszwClientDescription = CoTaskMemAlloc((wcslen(szValue)+1) * sizeof(WCHAR));
145  if (*ppszwClientDescription)
146  wcscpy(*ppszwClientDescription, szValue);
147  else
148  hr = E_OUTOFMEMORY;
149  }
150  else
151  {
152  hr = E_FAIL;
153  }
154  RegCloseKey(hKey);
155  return hr;
156 }
157 
158 static const INetCfgLockVtbl vt_NetCfgLock =
159 {
166 };
167 
168 /***************************************************************
169  * INetCfgPnpReconfigCallback
170  */
171 
172 HRESULT
173 WINAPI
175  INetCfgPnpReconfigCallback * iface,
176  REFIID iid,
177  LPVOID * ppvObj)
178 {
180  return INetCfg_QueryInterface((INetCfg*)This, iid, ppvObj);
181 }
182 
183 ULONG
184 WINAPI
186  INetCfgPnpReconfigCallback * iface)
187 {
189 
190  return INetCfg_AddRef((INetCfg*)This);
191 }
192 
193 ULONG
194 WINAPI
196  INetCfgPnpReconfigCallback * iface)
197 {
199  return INetCfg_Release((INetCfg*)This);
200 }
201 
202 HRESULT
203 WINAPI
205  INetCfgPnpReconfigCallback * iface,
207  LPCWSTR pszwUpper,
208  LPCWSTR pszwLower,
209  PVOID pvData,
210  DWORD dwSizeOfData)
211 {
212  /* FIXME */
213  return E_NOTIMPL;
214 }
215 
216 static const INetCfgPnpReconfigCallbackVtbl vt_NetCfgPnpReconfigCallback =
217 {
222 };
223 
224 
225 /***************************************************************
226  * INetCfg
227  */
228 
229 HRESULT
231  NetCfgComponentItem *Item)
232 {
233  WCHAR szBuffer[200];
234  HKEY hKey;
235  DWORD dwType, dwSize;
236 
237  if (Item == NULL || Item->szBindName == NULL)
238  return S_OK;
239 
240  wcscpy(szBuffer, L"SYSTEM\\CurrentControlSet\\Services\\");
241  wcscat(szBuffer, Item->szBindName);
242  wcscat(szBuffer, L"\\Linkage");
243 
244  if (RegOpenKeyExW(HKEY_LOCAL_MACHINE, szBuffer, 0, KEY_READ, &hKey) == ERROR_SUCCESS)
245  {
246  dwSize = 0;
247  RegQueryValueExW(hKey, L"Bind", NULL, &dwType, NULL, &dwSize);
248 
249  if (dwSize != 0)
250  {
252  if (Item->pszBinding == NULL)
253  return E_OUTOFMEMORY;
254 
255  RegQueryValueExW(hKey, L"Bind", NULL, &dwType, (LPBYTE)Item->pszBinding, &dwSize);
256  }
257 
258  RegCloseKey(hKey);
259  }
260 
261  return S_OK;
262 }
263 
264 HRESULT
266 {
267  DWORD dwIndex = 0;
268  DWORD dwSize;
269  DWORD dwType;
270  WCHAR szName[100];
271  WCHAR szText[100];
272  HKEY hSubKey, hNDIKey;
273  NetCfgComponentItem * pLast = NULL, *pCurrent;
274 
275  *pHead = NULL;
276  do
277  {
278  szText[0] = L'\0';
279 
280  dwSize = sizeof(szName)/sizeof(WCHAR);
281  if (RegEnumKeyExW(hKey, dwIndex++, szName, &dwSize, NULL, NULL, NULL, NULL) == ERROR_SUCCESS)
282  {
283  pCurrent = CoTaskMemAlloc(sizeof(NetCfgComponentItem));
284  if (!pCurrent)
285  return E_OUTOFMEMORY;
286 
287  ZeroMemory(pCurrent, sizeof(NetCfgComponentItem));
288  CopyMemory(&pCurrent->ClassGUID, pGuid, sizeof(GUID));
289 
290  if (FAILED(CLSIDFromString(szName, &pCurrent->InstanceId)))
291  {
293  //CoTaskMemFree(pCurrent);
294  //return E_FAIL;
295  }
296  if (RegOpenKeyExW(hKey, szName, 0, KEY_READ, &hSubKey) == ERROR_SUCCESS)
297  {
298  /* retrieve Characteristics */
299  dwSize = sizeof(DWORD);
300 
301  RegQueryValueExW(hSubKey, L"Characteristics", NULL, &dwType, (LPBYTE)&pCurrent->dwCharacteristics, &dwSize);
302  if (dwType != REG_DWORD)
303  pCurrent->dwCharacteristics = 0;
304 
305  /* retrieve ComponentId */
306  dwSize = sizeof(szText);
307  if (RegQueryValueExW(hSubKey, L"ComponentId", NULL, &dwType, (LPBYTE)szText, &dwSize) == ERROR_SUCCESS)
308  {
309  if (dwType == REG_SZ)
310  {
311  szText[(sizeof(szText)/sizeof(WCHAR))-1] = L'\0';
312  pCurrent->szId = CoTaskMemAlloc((wcslen(szText)+1)* sizeof(WCHAR));
313  if (pCurrent->szId)
314  wcscpy(pCurrent->szId, szText);
315  }
316  }
317 
318  /* retrieve Description */
319  dwSize = sizeof(szText);
320  if (RegQueryValueExW(hSubKey, L"Description", NULL, &dwType, (LPBYTE)szText, &dwSize) == ERROR_SUCCESS)
321  {
322  if (dwType == REG_SZ)
323  {
324  szText[(sizeof(szText)/sizeof(WCHAR))-1] = L'\0';
325  pCurrent->szDisplayName = CoTaskMemAlloc((wcslen(szText)+1)* sizeof(WCHAR));
326  if (pCurrent->szDisplayName)
327  wcscpy(pCurrent->szDisplayName, szText);
328  }
329  }
330 
331  if (RegOpenKeyExW(hSubKey, L"NDI", 0, KEY_READ, &hNDIKey) == ERROR_SUCCESS)
332  {
333  /* retrieve HelpText */
334  dwSize = sizeof(szText);
335  if (RegQueryValueExW(hNDIKey, L"HelpText", NULL, &dwType, (LPBYTE)szText, &dwSize) == ERROR_SUCCESS)
336  {
337  if (dwType == REG_SZ)
338  {
339  szText[(sizeof(szText)/sizeof(WCHAR))-1] = L'\0';
340  pCurrent->szHelpText = CoTaskMemAlloc((wcslen(szText)+1)* sizeof(WCHAR));
341  if (pCurrent->szHelpText)
342  wcscpy(pCurrent->szHelpText, szText);
343  }
344  }
345 
346  /* retrieve Service */
347  dwSize = sizeof(szText);
348  if (RegQueryValueExW(hNDIKey, L"Service", NULL, &dwType, (LPBYTE)szText, &dwSize) == ERROR_SUCCESS)
349  {
350  if (dwType == REG_SZ)
351  {
352  szText[(sizeof(szText)/sizeof(WCHAR))-1] = L'\0';
353  pCurrent->szBindName = CoTaskMemAlloc((wcslen(szText)+1)* sizeof(WCHAR));
354  if (pCurrent->szBindName)
355  wcscpy(pCurrent->szBindName, szText);
356  }
357  }
358  RegCloseKey(hNDIKey);
359  }
360  RegCloseKey(hSubKey);
361 
362  ReadBindingString(pCurrent);
363 
364  if (!pLast)
365  *pHead = pCurrent;
366  else
367  pLast->pNext = pCurrent;
368 
369  pLast = pCurrent;
370  }
371  }
372  else
373  break;
374 
375  }while(TRUE);
376  return S_OK;
377 }
378 
379 
380 
381 HRESULT
383  const GUID *pGuid, NetCfgComponentItem ** pHead)
384 {
385  HKEY hKey;
386  LPOLESTR pszGuid;
387  HRESULT hr;
388  WCHAR szName[150];
389 
390  hr = StringFromCLSID(pGuid, &pszGuid);
391  if (SUCCEEDED(hr))
392  {
393  swprintf(szName, L"SYSTEM\\CurrentControlSet\\Control\\Network\\%s", pszGuid);
395  {
396  hr = EnumClientServiceProtocol(hKey, pGuid, pHead);
397  RegCloseKey(hKey);
398  }
399  CoTaskMemFree(pszGuid);
400  }
401  return hr;
402 }
403 
404 HRESULT
406 {
407  DWORD dwSize, dwIndex;
408  HDEVINFO hInfo;
409  SP_DEVINFO_DATA DevInfo;
410  HKEY hKey;
411  WCHAR szNetCfg[50];
412  WCHAR szAdapterNetCfg[MAX_DEVICE_ID_LEN];
413  WCHAR szDetail[200] = L"SYSTEM\\CurrentControlSet\\Control\\Class\\";
414  WCHAR szName[130] = L"SYSTEM\\CurrentControlSet\\Control\\Network\\{4D36E972-E325-11CE-BFC1-08002BE10318}\\";
415  NetCfgComponentItem * pLast = NULL, *pCurrent;
416 
417  hInfo = SetupDiGetClassDevs(&GUID_DEVCLASS_NET, NULL, NULL, DIGCF_PRESENT );
418  if (!hInfo)
419  {
420  return E_FAIL;
421  }
422 
423  dwIndex = 0;
424  do
425  {
426  ZeroMemory(&DevInfo, sizeof(SP_DEVINFO_DATA));
427  DevInfo.cbSize = sizeof(DevInfo);
428 
429  /* get device info */
430  if (!SetupDiEnumDeviceInfo(hInfo, dwIndex++, &DevInfo))
431  break;
432 
433  /* get device software registry path */
434  if (!SetupDiGetDeviceRegistryPropertyW(hInfo, &DevInfo, SPDRP_DRIVER, NULL, (LPBYTE)&szDetail[39], sizeof(szDetail)/sizeof(WCHAR) - 40, &dwSize))
435  break;
436 
437  /* open device registry key */
438  if (RegOpenKeyExW(HKEY_LOCAL_MACHINE, szDetail, 0, KEY_READ, &hKey) != ERROR_SUCCESS)
439  break;
440 
441  /* query NetCfgInstanceId for current device */
442  dwSize = sizeof(szNetCfg);
443  if (RegQueryValueExW(hKey, L"NetCfgInstanceId", NULL, NULL, (LPBYTE)szNetCfg, &dwSize) != ERROR_SUCCESS)
444  {
445  RegCloseKey(hKey);
446  break;
447  }
448 
449  /* allocate new INetConnectionItem */
450  pCurrent = CoTaskMemAlloc(sizeof(NetCfgComponentItem));
451  if (!pCurrent)
452  break;
453 
454  ZeroMemory(pCurrent, sizeof(NetCfgComponentItem));
455  CopyMemory(&pCurrent->ClassGUID, &GUID_DEVCLASS_NET, sizeof(GUID));
456  CLSIDFromString(szNetCfg, &pCurrent->InstanceId); //FIXME
457 
458  /* set bind name */
459  pCurrent->szBindName = CoTaskMemAlloc((wcslen(szNetCfg)+1) *sizeof(WCHAR));
460  if (pCurrent->szBindName)
461  wcscpy(pCurrent->szBindName, szNetCfg);
462 
463  /* retrieve ComponentId */
464  dwSize = sizeof(szAdapterNetCfg);
465  if (RegQueryValueExW(hKey, L"ComponentId", NULL, NULL, (LPBYTE)szAdapterNetCfg, &dwSize) == ERROR_SUCCESS)
466  {
467  pCurrent->szId = CoTaskMemAlloc((wcslen(szAdapterNetCfg)+1) * sizeof(WCHAR));
468  if (pCurrent->szId)
469  wcscpy(pCurrent->szId, szAdapterNetCfg);
470  }
471  /* set INetCfgComponent::GetDisplayName */
472  dwSize = sizeof(szAdapterNetCfg);
473  if (RegQueryValueExW(hKey, L"DriverDesc", NULL, NULL, (LPBYTE)szAdapterNetCfg, &dwSize) == ERROR_SUCCESS)
474  {
475  pCurrent->szDisplayName = CoTaskMemAlloc((wcslen(szAdapterNetCfg)+1) * sizeof(WCHAR));
476  if (pCurrent->szDisplayName)
477  wcscpy(pCurrent->szDisplayName, szAdapterNetCfg);
478  }
479 
480  RegCloseKey(hKey);
481  /* open network connections details */
482  wcscpy(&szName[80], szNetCfg);
483  wcscpy(&szName[118], L"\\Connection");
484 
486  {
487  /* retrieve pnp instance id */
488  dwSize = sizeof(szAdapterNetCfg);
489  if (RegQueryValueExW(hKey, L"PnpInstanceID", NULL, NULL, (LPBYTE)szAdapterNetCfg, &dwSize) == ERROR_SUCCESS)
490  {
491  pCurrent->szNodeId = CoTaskMemAlloc((wcslen(szAdapterNetCfg)+1) * sizeof(WCHAR));
492  if (pCurrent->szNodeId)
493  wcscpy(pCurrent->szNodeId, szAdapterNetCfg);
494  }
495  RegCloseKey(hKey);
496  }
497 
498  if (SetupDiGetDeviceRegistryPropertyW(hInfo, &DevInfo, SPDRP_DEVICEDESC, NULL, (PBYTE)szNetCfg, sizeof(szNetCfg)/sizeof(WCHAR), &dwSize))
499  {
500  szNetCfg[(sizeof(szNetCfg)/sizeof(WCHAR))-1] = L'\0';
501  pCurrent->szDisplayName = CoTaskMemAlloc((wcslen(szNetCfg)+1) * sizeof(WCHAR));
502  if (pCurrent->szDisplayName)
503  wcscpy(pCurrent->szDisplayName, szNetCfg);
504  }
505 
506  if (pLast)
507  pLast->pNext = pCurrent;
508  else
509  *pHead = pCurrent;
510 
511  pLast = pCurrent;
512 
513  }while(TRUE);
514 
516  return NOERROR;
517 }
518 
519 
520 HRESULT
522  NetCfgComponentItem * pHead,
523  LPCWSTR pszwComponentId,
524  INetCfgComponent **pComponent,
525  INetCfg * iface)
526 {
527  while(pHead)
528  {
529  if (!_wcsicmp(pHead->szId, pszwComponentId))
530  {
531  return INetCfgComponent_Constructor(NULL, &IID_INetCfgComponent, (LPVOID*)pComponent, pHead, iface);
532  }
533  pHead = pHead->pNext;
534  }
535  return S_FALSE;
536 }
537 
538 
539 
540 HRESULT
541 WINAPI
543  INetCfg * iface,
544  REFIID iid,
545  LPVOID * ppvObj)
546 {
547  INetCfgImpl * This = (INetCfgImpl*)iface;
548  *ppvObj = NULL;
549 
550  if (IsEqualIID (iid, &IID_IUnknown) ||
551  IsEqualIID (iid, &IID_INetCfg))
552  {
553  *ppvObj = This;
554  INetCfg_AddRef(iface);
555  return S_OK;
556  }
557  else if (IsEqualIID (iid, &IID_INetCfgLock))
558  {
559  if (This->bInitialized)
561 
562  *ppvObj = (LPVOID)&This->lpVtblLock;
563  This->hMutex = CreateMutexW(NULL, FALSE, L"NetCfgLock");
564 
565  INetCfgLock_AddRef(iface);
566  return S_OK;
567  }
569  {
570  if (This->bInitialized)
572 
573  *ppvObj = (LPVOID)&This->lpVtblPnpReconfigCallback;
575  return S_OK;
576  }
577 
578  return E_NOINTERFACE;
579 }
580 
581 ULONG
582 WINAPI
584  INetCfg * iface)
585 {
586  INetCfgImpl * This = (INetCfgImpl*)iface;
587  ULONG refCount = InterlockedIncrement(&This->ref);
588 
589  return refCount;
590 }
591 
592 ULONG
593 WINAPI
595  INetCfg * iface)
596 {
597  INetCfgImpl * This = (INetCfgImpl*)iface;
598  ULONG refCount = InterlockedDecrement(&This->ref);
599 
600  if (!refCount)
601  {
603  }
604  return refCount;
605 }
606 
607 HRESULT
608 WINAPI
610  INetCfg * iface,
611  PVOID pReserved)
612 {
613  HRESULT hr;
614  INetCfgImpl *This = (INetCfgImpl *)iface;
615 
616  if (This->bInitialized)
618 
619  hr = EnumerateNetworkAdapter(&This->pNet);
620  if (FAILED(hr))
621  return hr;
622 
623 
624  hr = EnumerateNetworkComponent(&GUID_DEVCLASS_NETCLIENT, &This->pClient);
625  if (FAILED(hr))
626  return hr;
627 
628  hr = EnumerateNetworkComponent(&GUID_DEVCLASS_NETSERVICE, &This->pService);
629  if (FAILED(hr))
630  return hr;
631 
632 
633  hr = EnumerateNetworkComponent(&GUID_DEVCLASS_NETTRANS, &This->pProtocol);
634  if (FAILED(hr))
635  return hr;
636 
637  This->bInitialized = TRUE;
638  return S_OK;
639 }
640 
641 VOID
643  NetCfgComponentItem *pHead,
644  const CLSID * lpClassGUID,
645  BOOL bApply)
646 {
647  HKEY hKey;
648  WCHAR szName[200];
649  LPOLESTR pszGuid;
650 
651  while(pHead)
652  {
653  if (pHead->bChanged)
654  {
655  if (IsEqualGUID(lpClassGUID, &GUID_DEVCLASS_NET))
656  {
657  if (bApply)
658  {
659  if (StringFromCLSID(&pHead->InstanceId, &pszGuid) == NOERROR)
660  {
661  swprintf(szName, L"SYSTEM\\CurrentControlSet\\Control\\Network\\%s", pszGuid);
662  CoTaskMemFree(pszGuid);
663 
665  {
666  RegSetValueExW(hKey, NULL, 0, REG_SZ, (LPBYTE)pHead->szDisplayName, (wcslen(pHead->szDisplayName)+1) * sizeof(WCHAR));
667  RegCloseKey(hKey);
668  }
669  }
670  }
671  }
672  else if (pHead->pNCCC)
673  {
674  if (bApply)
675  {
677  //FIXME
678  // implement INetCfgPnpReconfigCallback and pass it to
679  //INetCfgComponentControl_ApplyPnpChanges(pHead->pNCCC, NULL);
680  }
681  else
682  {
684  }
685  }
686  }
687  pHead = pHead->pNext;
688  }
689 }
690 
691 VOID
693 {
695  CoTaskMemFree(pItem->szHelpText);
696  CoTaskMemFree(pItem->szId);
697  CoTaskMemFree(pItem->szBindName);
698  CoTaskMemFree(pItem->szNodeId);
699  CoTaskMemFree(pItem->pszBinding);
700  CoTaskMemFree(pItem);
701 }
702 
703 HRESULT
704 WINAPI
706  INetCfg * iface)
707 {
708  INetCfgImpl *This = (INetCfgImpl *)iface;
709  NetCfgComponentItem *pItem;
710 
711  if (!This->bInitialized)
713 
714  /* Free the services */
715  while (This->pService != NULL)
716  {
717  pItem = This->pService;
718  This->pService = pItem->pNext;
719  FreeComponentItem(pItem);
720  }
721 
722  /* Free the clients */
723  while (This->pClient != NULL)
724  {
725  pItem = This->pClient;
726  This->pClient = pItem->pNext;
727  FreeComponentItem(pItem);
728  }
729 
730  /* Free the protocols */
731  while (This->pProtocol != NULL)
732  {
733  pItem = This->pProtocol;
734  This->pProtocol = pItem->pNext;
735  FreeComponentItem(pItem);
736  }
737 
738  /* Free the adapters */
739  while (This->pNet != NULL)
740  {
741  pItem = This->pNet;
742  This->pNet = pItem->pNext;
743  FreeComponentItem(pItem);
744  }
745 
746  This->bInitialized = FALSE;
747 
748  return S_OK;
749 }
750 
751 
752 HRESULT
753 WINAPI
755  INetCfg * iface)
756 {
757  INetCfgImpl *This = (INetCfgImpl *)iface;
758 
759  if (!This->bInitialized)
761 
762  ApplyOrCancelChanges(This->pNet, &GUID_DEVCLASS_NET, TRUE);
763  ApplyOrCancelChanges(This->pClient, &GUID_DEVCLASS_NETCLIENT, TRUE);
764  ApplyOrCancelChanges(This->pService, &GUID_DEVCLASS_NETSERVICE, TRUE);
765  ApplyOrCancelChanges(This->pProtocol, &GUID_DEVCLASS_NETTRANS, TRUE);
766 
767  return S_OK;
768 }
769 
770 HRESULT
771 WINAPI
773  INetCfg * iface)
774 {
775  INetCfgImpl *This = (INetCfgImpl *)iface;
776 
777  if (!This->bInitialized)
779 
780  ApplyOrCancelChanges(This->pClient, &GUID_DEVCLASS_NETCLIENT, FALSE);
781  ApplyOrCancelChanges(This->pService, &GUID_DEVCLASS_NETSERVICE, FALSE);
782  ApplyOrCancelChanges(This->pProtocol, &GUID_DEVCLASS_NETTRANS, FALSE);
783 
784  return S_OK;
785 }
786 
787 HRESULT
788 WINAPI
790  INetCfg * iface,
791  const GUID *pguidClass,
792  IEnumNetCfgComponent **ppenumComponent)
793 {
794  INetCfgImpl *This = (INetCfgImpl *)iface;
795 
796  if (!This->bInitialized)
798 
799  if (IsEqualGUID(&GUID_DEVCLASS_NET, pguidClass))
800  return IEnumNetCfgComponent_Constructor (NULL, &IID_IEnumNetCfgComponent, (LPVOID*)ppenumComponent, This->pNet, iface);
801  else if (IsEqualGUID(&GUID_DEVCLASS_NETCLIENT, pguidClass))
802  return IEnumNetCfgComponent_Constructor (NULL, &IID_IEnumNetCfgComponent, (LPVOID*)ppenumComponent, This->pClient, iface);
803  else if (IsEqualGUID(&GUID_DEVCLASS_NETSERVICE, pguidClass))
804  return IEnumNetCfgComponent_Constructor (NULL, &IID_IEnumNetCfgComponent, (LPVOID*)ppenumComponent, This->pService, iface);
805  else if (IsEqualGUID(&GUID_DEVCLASS_NETTRANS, pguidClass))
806  return IEnumNetCfgComponent_Constructor (NULL, &IID_IEnumNetCfgComponent, (LPVOID*)ppenumComponent, This->pProtocol, iface);
807  else
808  return E_NOINTERFACE;
809 }
810 
811 
812 HRESULT
813 WINAPI
815  INetCfg * iface,
816  LPCWSTR pszwComponentId,
817  INetCfgComponent **pComponent)
818 {
819  HRESULT hr;
820  INetCfgImpl *This = (INetCfgImpl *)iface;
821 
822  if (!This->bInitialized)
824 
825  hr = FindNetworkComponent(This->pClient, pszwComponentId, pComponent, iface);
826  if (hr == S_OK)
827  return hr;
828 
829  hr = FindNetworkComponent(This->pService, pszwComponentId, pComponent, iface);
830  if (hr == S_OK)
831  return hr;
832 
833  hr = FindNetworkComponent(This->pProtocol, pszwComponentId, pComponent, iface);
834  if (hr == S_OK)
835  return hr;
836 
837  return S_FALSE;
838 }
839 
840 HRESULT
841 WINAPI
843  INetCfg * iface,
844  const GUID *pguidClass,
845  REFIID riid,
846  void **ppvObject)
847 {
848  return E_FAIL;
849 }
850 
851 static const INetCfgVtbl vt_NetCfg =
852 {
863 };
864 
866 {
867  INetCfgImpl *This;
868 
869  if (!ppv)
870  return E_POINTER;
871 
872  This = (INetCfgImpl *) CoTaskMemAlloc(sizeof (INetCfgImpl));
873  if (!This)
874  return E_OUTOFMEMORY;
875 
876  This->ref = 1;
877  This->lpVtbl = (const INetCfg*)&vt_NetCfg;
878  This->lpVtblLock = (const INetCfgLock*)&vt_NetCfgLock;
879  This->lpVtblPnpReconfigCallback = (const INetCfgPnpReconfigCallback*)&vt_NetCfgPnpReconfigCallback;
880  This->hMutex = NULL;
881  This->bInitialized = FALSE;
882  This->pNet = NULL;
883  This->pClient = NULL;
884  This->pService = NULL;
885  This->pProtocol = NULL;
886 
887  if (!SUCCEEDED (INetCfg_QueryInterface ((INetCfg*)This, riid, ppv)))
888  {
889  INetCfg_Release((INetCfg*)This);
890  return E_NOINTERFACE;
891  }
892 
893  INetCfg_Release((INetCfg*)This);
894  return S_OK;
895 }
VOID ApplyOrCancelChanges(NetCfgComponentItem *pHead, const CLSID *lpClassGUID, BOOL bApply)
Definition: netcfg_iface.c:642
const INetCfg * lpVtbl
Definition: netcfg_iface.c:5
HRESULT WINAPI INetCfg_fnUninitialize(INetCfg *iface)
Definition: netcfg_iface.c:705
BOOL WINAPI SetupDiEnumDeviceInfo(HDEVINFO devinfo, DWORD index, PSP_DEVINFO_DATA info)
Definition: devinst.c:1792
#define INetCfg_QueryInterface(p, a, b)
Definition: netcfgx.h:287
HRESULT WINAPI INetCfgPnpReconfigCallback_fnQueryInterface(INetCfgPnpReconfigCallback *iface, REFIID iid, LPVOID *ppvObj)
Definition: netcfg_iface.c:174
ULONG WINAPI INetCfg_fnRelease(INetCfg *iface)
Definition: netcfg_iface.c:594
static const INetCfgLockVtbl vt_NetCfgLock
Definition: netcfg_iface.c:158
HRESULT WINAPI INetCfg_fnQueryNetCfgClass(INetCfg *iface, const GUID *pguidClass, REFIID riid, void **ppvObject)
Definition: netcfg_iface.c:842
NetCfgComponentItem * pService
Definition: netcfg_iface.c:12
static __inline LPINetCfgImpl impl_from_INetCfgPnpReconfigCallback(INetCfgPnpReconfigCallback *iface)
Definition: netcfg_iface.c:22
#define REFIID
Definition: guiddef.h:118
#define TRUE
Definition: types.h:120
#define E_NOINTERFACE
Definition: winerror.h:2364
EXTERN_C const IID IID_INetCfgLock
Definition: netcfgx.h:14
VOID FreeComponentItem(NetCfgComponentItem *pItem)
Definition: netcfg_iface.c:692
HRESULT WINAPI INetCfgLock_fnAcquireWriteLock(INetCfgLock *iface, DWORD cmsTimeout, LPCWSTR pszwClientDescription, LPWSTR *ppszwClientDescription)
Definition: netcfg_iface.c:61
HRESULT WINAPI INetCfgLock_fnReleaseWriteLock(INetCfgLock *iface)
Definition: netcfg_iface.c:110
HRESULT EnumClientServiceProtocol(HKEY hKey, const GUID *pGuid, NetCfgComponentItem **pHead)
Definition: netcfg_iface.c:265
HRESULT WINAPI INetCfg_Constructor(IUnknown *pUnkOuter, REFIID riid, LPVOID *ppv)
Definition: netcfg_iface.c:865
NCPNP_RECONFIG_LAYER
Definition: netcfgn.h:4
VOID WINAPI CoTaskMemFree(LPVOID ptr)
Definition: ifs.c:420
#define ERROR_SUCCESS
Definition: deptool.c:10
NetCfgComponentItem * pClient
Definition: netcfg_iface.c:13
HRESULT WINAPI INetCfgLock_fnQueryInterface(INetCfgLock *iface, REFIID iid, LPVOID *ppvObj)
Definition: netcfg_iface.c:30
HRESULT hr
Definition: shlfolder.c:183
const INetCfgLock * lpVtblLock
Definition: netcfg_iface.c:6
const WCHAR * LPCWSTR
Definition: xmlstorage.h:185
#define NOERROR
Definition: winerror.h:2354
#define KEY_READ
Definition: nt_native.h:1023
HRESULT WINAPI IEnumNetCfgComponent_Constructor(IUnknown *pUnkOuter, REFIID riid, LPVOID *ppv, NetCfgComponentItem *pItem, INetCfg *pNCfg)
REFIID riid
Definition: precomp.h:44
ULONG WINAPI INetCfg_fnAddRef(INetCfg *iface)
Definition: netcfg_iface.c:583
REFIID LPVOID * ppv
Definition: atlbase.h:39
BOOL WINAPI SetupDiGetDeviceRegistryPropertyW(HDEVINFO DeviceInfoSet, PSP_DEVINFO_DATA DeviceInfoData, DWORD Property, PDWORD PropertyRegDataType, PBYTE PropertyBuffer, DWORD PropertyBufferSize, PDWORD RequiredSize)
Definition: devinst.c:3229
HRESULT FindNetworkComponent(NetCfgComponentItem *pHead, LPCWSTR pszwComponentId, INetCfgComponent **pComponent, INetCfg *iface)
Definition: netcfg_iface.c:521
ULONG WINAPI INetCfgLock_fnAddRef(INetCfgLock *iface)
Definition: netcfg_iface.c:42
#define ZeroMemory
Definition: winbase.h:1642
#define MAX_DEVICE_ID_LEN
Definition: pnpmgr.c:28
ULONG WINAPI INetCfgPnpReconfigCallback_fnRelease(INetCfgPnpReconfigCallback *iface)
Definition: netcfg_iface.c:195
HRESULT EnumerateNetworkAdapter(NetCfgComponentItem **pHead)
Definition: netcfg_iface.c:405
HRESULT EnumerateNetworkComponent(const GUID *pGuid, NetCfgComponentItem **pHead)
Definition: netcfg_iface.c:382
static LPOLESTR
Definition: stg_prop.c:27
#define E_FAIL
Definition: ddrawi.h:102
HRESULT WINAPI INetCfgPnpReconfigCallback_fnSendPnpReconfig(INetCfgPnpReconfigCallback *iface, NCPNP_RECONFIG_LAYER Layer, LPCWSTR pszwUpper, LPCWSTR pszwLower, PVOID pvData, DWORD dwSizeOfData)
Definition: netcfg_iface.c:204
#define DWORD
Definition: nt_native.h:44
#define NETCFG_E_NOT_INITIALIZED
Definition: netcfgx.h:303
struct INetCfgImpl * LPINetCfgImpl
LONG WINAPI RegCreateKeyExW(_In_ HKEY hKey, _In_ LPCWSTR lpSubKey, _In_ DWORD Reserved, _In_opt_ LPWSTR lpClass, _In_ DWORD dwOptions, _In_ REGSAM samDesired, _In_opt_ LPSECURITY_ATTRIBUTES lpSecurityAttributes, _Out_ PHKEY phkResult, _Out_opt_ LPDWORD lpdwDisposition)
Definition: reg.c:1091
#define INetCfgComponentControl_CancelChanges(p)
Definition: netcfgn.h:54
DWORD WINAPI WaitForSingleObject(IN HANDLE hHandle, IN DWORD dwMilliseconds)
Definition: synch.c:82
LONG WINAPI RegCloseKey(HKEY hKey)
Definition: reg.c:423
unsigned char * LPBYTE
Definition: typedefs.h:52
#define E_OUTOFMEMORY
Definition: ddrawi.h:100
static const WCHAR szText[]
Definition: dialog.c:139
#define INetCfgPnpReconfigCallback_AddRef(p)
Definition: netcfgn.h:24
unsigned int BOOL
Definition: ntddk_ex.h:94
long LONG
Definition: pedump.c:60
#define S_FALSE
Definition: winerror.h:2357
_In_ ULONG _In_opt_ PVOID pvData
Definition: winddi.h:3748
smooth NULL
Definition: ftsmooth.c:416
EXTERN_C const IID IID_INetCfg
Definition: netcfgx.h:300
static const INetCfgVtbl vt_NetCfg
Definition: netcfg_iface.c:851
#define INetCfg_Release(p)
Definition: netcfgx.h:289
EXTERN_C const IID IID_INetCfgComponent
Definition: netcfgx.h:77
#define KEY_WRITE
Definition: nt_native.h:1031
LONG WINAPI RegSetValueExW(_In_ HKEY hKey, _In_ LPCWSTR lpValueName, _In_ DWORD Reserved, _In_ DWORD dwType, _In_ CONST BYTE *lpData, _In_ DWORD cbData)
Definition: reg.c:4895
HRESULT WINAPI INetCfg_fnQueryInterface(INetCfg *iface, REFIID iid, LPVOID *ppvObj)
Definition: netcfg_iface.c:542
#define INetCfgComponentControl_ApplyRegistryChanges(p)
Definition: netcfgn.h:52
#define WAIT_OBJECT_0
Definition: winbase.h:387
static const INetCfgPnpReconfigCallbackVtbl vt_NetCfgPnpReconfigCallback
Definition: netcfg_iface.c:216
LONG WINAPI RegQueryValueExW(_In_ HKEY hkeyorg, _In_ LPCWSTR name, _In_ LPDWORD reserved, _In_ LPDWORD type, _In_ LPBYTE data, _In_ LPDWORD count)
Definition: reg.c:4116
HRESULT WINAPI INetCfg_fnInitialize(INetCfg *iface, PVOID pReserved)
Definition: netcfg_iface.c:609
__wchar_t WCHAR
Definition: xmlstorage.h:180
struct tagNetCfgComponentItem * pNext
Definition: precomp.h:51
LONG HRESULT
Definition: typedefs.h:77
#define INetCfgLock_AddRef(p)
Definition: netcfgx.h:22
const GUID IID_IUnknown
BOOL WINAPI SetupDiDestroyDeviceInfoList(HDEVINFO devinfo)
Definition: devinst.c:2898
#define swprintf(buf, format,...)
Definition: sprintf.c:56
#define WINAPI
Definition: msvc.h:8
#define CopyMemory
Definition: winbase.h:1640
BOOL bInitialized
Definition: netcfg_iface.c:9
unsigned long DWORD
Definition: ntddk_ex.h:95
ULONG WINAPI INetCfgPnpReconfigCallback_fnAddRef(INetCfgPnpReconfigCallback *iface)
Definition: netcfg_iface.c:185
#define LPVOID
Definition: nt_native.h:45
#define WAIT_TIMEOUT
Definition: dderror.h:14
HRESULT WINAPI INetCfg_fnFindComponent(INetCfg *iface, LPCWSTR pszwComponentId, INetCfgComponent **pComponent)
Definition: netcfg_iface.c:814
BOOL WINAPI DECLSPEC_HOTPATCH ReleaseMutex(IN HANDLE hMutex)
Definition: synch.c:618
_CRTIMP wchar_t *__cdecl wcscpy(_Out_writes_z_(_String_length_(_Source)+1) wchar_t *_Dest, _In_z_ const wchar_t *_Source)
HRESULT WINAPI INetCfgComponent_Constructor(IUnknown *pUnkOuter, REFIID riid, LPVOID *ppv, NetCfgComponentItem *pItem, INetCfg *pNCfg)
static const WCHAR L[]
Definition: oid.c:1250
#define InterlockedDecrement
Definition: armddk.h:52
HRESULT WINAPI INetCfgLock_fnIsWriteLocked(INetCfgLock *iface, LPWSTR *ppszwClientDescription)
Definition: netcfg_iface.c:127
#define SetupDiGetClassDevs
Definition: setupapi.h:2588
REFIID LPVOID * ppvObject
Definition: precomp.h:44
#define SPDRP_DEVICEDESC
Definition: setupapi.h:502
#define S_OK
Definition: intsafe.h:59
#define InterlockedIncrement
Definition: armddk.h:53
#define INetCfg_AddRef(p)
Definition: netcfgx.h:288
#define E_NOTIMPL
Definition: ddrawi.h:99
HANDLE hMutex
Definition: netcfg_iface.c:10
EXTERN_C const IID IID_IEnumNetCfgComponent
Definition: netcfgx.h:266
HANDLE WINAPI DECLSPEC_HOTPATCH CreateMutexW(IN LPSECURITY_ATTRIBUTES lpMutexAttributes OPTIONAL, IN BOOL bInitialOwner, IN LPCWSTR lpName OPTIONAL)
Definition: synch.c:576
#define FIELD_OFFSET(t, f)
Definition: typedefs.h:254
_CRTIMP wchar_t *__cdecl wcscat(_Inout_updates_z_(_String_length_(_Dest)+_String_length_(_Source)+1) wchar_t *_Dest, _In_z_ const wchar_t *_Source)
BOOL WINAPI IsEqualGUID(REFGUID rguid1, REFGUID rguid2)
Definition: compobj.c:4112
EXTERN_C const IID IID_INetCfgPnpReconfigCallback
Definition: netcfgn.h:29
static const WCHAR szName[]
Definition: msipriv.h:1194
HRESULT WINAPI INetCfg_fnApply(INetCfg *iface)
Definition: netcfg_iface.c:754
HRESULT WINAPI CLSIDFromString(LPCOLESTR idstr, LPCLSID id)
Definition: compobj.c:2338
unsigned int ULONG
Definition: retypes.h:1
LONG WINAPI RegOpenKeyExW(HKEY hKey, LPCWSTR lpSubKey, DWORD ulOptions, REGSAM samDesired, PHKEY phkResult)
Definition: reg.c:3366
#define NETCFG_E_ALREADY_INITIALIZED
Definition: netcfgx.h:302
HRESULT ReadBindingString(NetCfgComponentItem *Item)
Definition: netcfg_iface.c:230
HRESULT WINAPI INetCfg_fnEnumComponents(INetCfg *iface, const GUID *pguidClass, IEnumNetCfgComponent **ppenumComponent)
Definition: netcfg_iface.c:789
NetCfgComponentItem * pProtocol
Definition: netcfg_iface.c:14
LONG WINAPI RegEnumKeyExW(_In_ HKEY hKey, _In_ DWORD dwIndex, _Out_ LPWSTR lpName, _Inout_ LPDWORD lpcbName, _Reserved_ LPDWORD lpReserved, _Out_opt_ LPWSTR lpClass, _Inout_opt_ LPDWORD lpcbClass, _Out_opt_ PFILETIME lpftLastWriteTime)
Definition: reg.c:2527
NetCfgComponentItem * pNet
Definition: netcfg_iface.c:11
Definition: xml2sdb.h:110
WCHAR * LPWSTR
Definition: xmlstorage.h:184
const INetCfgPnpReconfigCallback * lpVtblPnpReconfigCallback
Definition: netcfg_iface.c:7
#define E_POINTER
Definition: winerror.h:2365
HRESULT WINAPI INetCfg_fnCancel(INetCfg *iface)
Definition: netcfg_iface.c:772
#define REG_DWORD
Definition: sdbapi.c:596
INetCfgComponentControl * pNCCC
Definition: precomp.h:52
BYTE * PBYTE
Definition: pedump.c:66
LPVOID WINAPI CoTaskMemAlloc(SIZE_T size)
Definition: ifs.c:404
size_t __cdecl wcslen(_In_z_ const wchar_t *_Str)
PSDBQUERYRESULT_VISTA PVOID DWORD * dwSize
Definition: env.c:54
#define IsEqualIID(riid1, riid2)
Definition: guiddef.h:95
_Check_return_ _CRTIMP int __cdecl _wcsicmp(_In_z_ const wchar_t *_Str1, _In_z_ const wchar_t *_Str2)
static __inline LPINetCfgImpl impl_from_INetCfgLock(INetCfgLock *iface)
Definition: netcfg_iface.c:17
#define SUCCEEDED(hr)
Definition: intsafe.h:57
#define DIGCF_PRESENT
Definition: setupapi.h:171
#define HKEY_LOCAL_MACHINE
Definition: winreg.h:12
#define SPDRP_DRIVER
Definition: setupapi.h:511
ULONG WINAPI INetCfgLock_fnRelease(INetCfgLock *iface)
Definition: netcfg_iface.c:52
HRESULT WINAPI StringFromCLSID(REFCLSID id, LPOLESTR *idstr)
Definition: compobj.c:2412
#define REG_SZ
Definition: layer.c:22