Subversion Repositories userdetect2

Rev

Rev 71 | Blame | Compare with Previous | Last modification | View Log | RSS feed

  1. library DHCP_MAC;
  2.  
  3. uses
  4.   Windows,
  5.   SysUtils,
  6.   Classes,
  7.   UD2_PluginIntf in '..\UD2_PluginIntf.pas',
  8.   UD2_PluginUtils in '..\UD2_PluginUtils.pas',
  9.   UD2_PluginStatus in '..\UD2_PluginStatus.pas',
  10.   NetworkUtils in 'NetworkUtils.pas';
  11.  
  12. {$R *.res}
  13.  
  14. const
  15.   PLUGIN_GUID: TGUID = '{574F8C7F-318E-4FA9-96CE-5A6F1FAE67FD}';
  16.  
  17. function PluginIdentifier: TGUID; cdecl;
  18. begin
  19.   result := PLUGIN_GUID;
  20. end;
  21.  
  22. function IdentificationStringW(lpIdentifier: LPWSTR; cchSize: DWORD): UD2_STATUS; cdecl;
  23. var
  24.   sl, sl2: TStringList;
  25.   i: integer;
  26.   ip, mac: string;
  27.   ec: DWORD;
  28. begin
  29.   try
  30.     sl := TStringList.Create;
  31.     sl2 := TStringList.Create;
  32.     try
  33.       ec := GetDHCPIPAddressList(sl);
  34.       if ec = ERROR_NOT_SUPPORTED then
  35.       begin
  36.         result := UD2_STATUS_NOTAVAIL_OS_NOT_SUPPORTED;
  37.         Exit;
  38.       end
  39.       else if ec <> ERROR_SUCCESS then
  40.       begin
  41.         result := UD2_STATUS_OSError(ec);
  42.         Exit;
  43.       end;
  44.  
  45.       for i := 0 to sl.Count-1 do
  46.       begin
  47.         ip := sl.Strings[i];
  48.         ec := GetMACAddress(ip, mac);
  49.         if ec = ERROR_NOT_SUPPORTED then
  50.         begin
  51.           result := UD2_STATUS_NOTAVAIL_OS_NOT_SUPPORTED;
  52.           Exit;
  53.         end
  54.         else if (ec = S_OK) and
  55.                 (mac <> '') and
  56.                 (sl2.IndexOf(mac) = -1) then
  57.         begin
  58.           sl2.add(mac);
  59.         end;
  60.       end;
  61.       result := UD2_WriteStringListToPointerW(lpIdentifier, cchSize, sl2);
  62.     finally
  63.       sl.Free;
  64.       sl2.Free;
  65.     end;
  66.   except
  67.     on E: Exception do result := UD2_STATUS_HandleException(E);
  68.   end;
  69. end;
  70.  
  71. function PluginNameW(lpPluginName: LPWSTR; cchSize: DWORD; wLangID: LANGID): UD2_STATUS; cdecl;
  72. var
  73.   stPluginName: WideString;
  74.   primaryLangID: Byte;
  75. begin
  76.   primaryLangID := wLangID and $00FF;
  77.   if primaryLangID = LANG_GERMAN then
  78.     stPluginName := 'MAC-Adressen der DHCP-Server'
  79.   else
  80.     stPluginName := 'DHCP MAC addresses';
  81.   result := UD2_WritePascalStringToPointerW(lpPluginName, cchSize, stPluginName);
  82. end;
  83.  
  84. function PluginVendorW(lpPluginVendor: LPWSTR; cchSize: DWORD; wLangID: LANGID): UD2_STATUS; cdecl;
  85. begin
  86.   result := UD2_WritePascalStringToPointerW(lpPluginVendor, cchSize, 'ViaThinkSoft');
  87. end;
  88.  
  89. function PluginVersionW(lpPluginVersion: LPWSTR; cchSize: DWORD; wLangID: LANGID): UD2_STATUS; cdecl;
  90. begin
  91.   result := UD2_WritePascalStringToPointerW(lpPluginVersion, cchSize, '1.0');
  92. end;
  93.  
  94. function IdentificationMethodNameW(lpIdentificationMethodName: LPWSTR; cchSize: DWORD): UD2_STATUS; cdecl;
  95. var
  96.   stIdentificationMethodName: WideString;
  97. begin
  98.   stIdentificationMethodName := 'DHCP_MAC';
  99.   result := UD2_WritePascalStringToPointerW(lpIdentificationMethodName, cchSize, stIdentificationMethodName);
  100. end;
  101.  
  102. function CheckLicense(lpReserved: LPVOID): UD2_STATUS; cdecl;
  103. begin
  104.   result := UD2_STATUS_OK_LICENSED;
  105. end;
  106.  
  107. function DescribeOwnStatusCodeW(lpErrorDescription: LPWSTR; cchSize: DWORD; statusCode: UD2_STATUS; wLangID: LANGID): BOOL; cdecl;
  108. begin
  109.   // This function does not use non-generic status codes
  110.   result := FALSE;
  111. end;
  112.  
  113. exports
  114.   PluginInterfaceID         name mnPluginInterfaceID,
  115.   PluginIdentifier          name mnPluginIdentifier,
  116.   PluginNameW               name mnPluginNameW,
  117.   PluginVendorW             name mnPluginVendorW,
  118.   PluginVersionW            name mnPluginVersionW,
  119.   IdentificationMethodNameW name mnIdentificationMethodNameW,
  120.   IdentificationStringW     name mnIdentificationStringW,
  121.   CheckLicense              name mnCheckLicense,
  122.   DescribeOwnStatusCodeW    name mnDescribeOwnStatusCodeW;
  123.  
  124. end.
  125.