Leaked source code of windows server 2003
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

115 lines
3.3 KiB

  1. //+---------------------------------------------------------------------------
  2. //
  3. // Copyright (C) 1997, Microsoft Corporation.
  4. //
  5. // File: caturl.cxx
  6. //
  7. // Contents: Functions dealing with catalog URLs
  8. //
  9. // History: 12 Mar 1997 AlanW Created
  10. //
  11. //----------------------------------------------------------------------------
  12. #include <pch.cxx>
  13. #pragma hdrstop
  14. #include <caturl.hxx>
  15. const WCHAR achQueryProtocol[] = L"query:";
  16. const unsigned cchQueryProtocol = (sizeof achQueryProtocol /
  17. sizeof achQueryProtocol[0]) - 1;
  18. //+---------------------------------------------------------------------------
  19. //
  20. // Function: ParseCatalogURL - public
  21. //
  22. // Synopsis: Parse a catalog URL into its machine and catalog components
  23. //
  24. // Arguments: [pwszInput] - the string containing the catalog URL
  25. // [xpCatalog] - pointer where catalog is returned if any
  26. // [xpMachine] - pointer where machine is returned if any
  27. //
  28. // Notes: If there is no machine name specified, the default machine
  29. // name ( "." ) is used.
  30. //
  31. // History: 12 Mar 1997 AlanW Created
  32. //
  33. //----------------------------------------------------------------------------
  34. SCODE ParseCatalogURL( const WCHAR * pwszInput,
  35. XPtrST<WCHAR> & xpCatalog,
  36. XPtrST<WCHAR> & xpMachine )
  37. {
  38. Win4Assert( 0 != pwszInput );
  39. if (_wcsnicmp( pwszInput, achQueryProtocol, cchQueryProtocol ) == 0 )
  40. {
  41. //
  42. // It's in the URL format. Find the machine and catalog.
  43. //
  44. pwszInput += cchQueryProtocol;
  45. if (pwszInput[0] == L'/' && pwszInput[1] == L'/')
  46. {
  47. // Get the machine string and save a copy
  48. pwszInput += 2;
  49. const WCHAR * pwszMachEnd = wcschr( pwszInput, L'/' );
  50. if ( 0 == pwszMachEnd )
  51. pwszMachEnd = pwszInput + wcslen( pwszInput );
  52. WCHAR * pwszTmp = new WCHAR[ (size_t)(pwszMachEnd - pwszInput) + 1 ];
  53. xpMachine.Free();
  54. xpMachine.Set(pwszTmp);
  55. RtlCopyMemory( pwszTmp, pwszInput, (pwszMachEnd-pwszInput) * sizeof (WCHAR) );
  56. pwszTmp[ pwszMachEnd-pwszInput ] = L'\0';
  57. pwszInput = pwszMachEnd;
  58. }
  59. else
  60. {
  61. xpMachine.Free();
  62. }
  63. if (pwszInput[0] == L'/')
  64. pwszInput++;
  65. }
  66. else
  67. {
  68. xpMachine.Free();
  69. }
  70. //
  71. // The rest of the string is just the catalog name.
  72. //
  73. if (pwszInput[0] != L'\0')
  74. {
  75. // Get the catalog string and save a copy
  76. unsigned cch = wcslen( pwszInput );
  77. WCHAR * pwszTmp = new WCHAR[ cch + 1 ];
  78. xpCatalog.Free();
  79. xpCatalog.Set(pwszTmp);
  80. RtlCopyMemory( pwszTmp, pwszInput, cch * sizeof (WCHAR) );
  81. pwszTmp[ cch ] = L'\0';
  82. }
  83. else
  84. {
  85. xpCatalog.Free();
  86. }
  87. //
  88. // If no machine was specified, use the local machine
  89. //
  90. if ( 0 == xpMachine.GetPointer() )
  91. {
  92. ULONG cwc = 1 + wcslen( CATURL_LOCAL_MACHINE );
  93. xpMachine.Set( new WCHAR[ cwc ] );
  94. wcscpy( xpMachine.GetPointer(), CATURL_LOCAL_MACHINE );
  95. }
  96. return S_OK;
  97. }