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.

163 lines
5.3 KiB

  1. //+---------------------------------------------------------------------------
  2. //
  3. // Copyright (C) 1996, Microsoft Corporation.
  4. //
  5. // File: wqlocale.cxx
  6. //
  7. // Contents: WEB Query locale parsers
  8. //
  9. // History: 96/May/2 DwightKr Created
  10. //
  11. //----------------------------------------------------------------------------
  12. #include <pch.cxx>
  13. #pragma hdrstop
  14. //+---------------------------------------------------------------------------
  15. //
  16. // Function: GetBrowserLCID - public
  17. //
  18. // Synposis: Determines the locale from the browser's HTTP_ACCEPT_LANGUAGE
  19. // Note that the browser may not send a language, in which case
  20. // we will default to the web servers default language.
  21. //
  22. // Arguments: [webServer] the web service which can return the environment
  23. // variable HTTP_ACCEPT_LANGUAGE.
  24. // [wcsHttpLanguage] - buffer to accept the language
  25. //
  26. // History: 20-Jan-96 DwightKr Created
  27. // 11-Jun-97 KyleP Initialize ccHttpLanguage!
  28. //
  29. //----------------------------------------------------------------------------
  30. LCID GetBrowserLCID( CWebServer & webServer, XArray<WCHAR> & wcsHttpLanguage )
  31. {
  32. //
  33. // Don't look it up twice!
  34. //
  35. if ( webServer.IsLCIDValid() )
  36. {
  37. wcsHttpLanguage.Init( webServer.LocaleSize() );
  38. RtlCopyMemory( wcsHttpLanguage.GetPointer(),
  39. webServer.GetLocale(),
  40. webServer.LocaleSize() * sizeof(WCHAR) );
  41. return webServer.GetLCID();
  42. }
  43. //
  44. // Try the hard way...
  45. //
  46. CHAR aszHttpLanguage[512];
  47. ULONG ccHttpLanguage = sizeof(aszHttpLanguage);
  48. if ( !webServer.GetCGIVariable( "HTTP_ACCEPT_LANGUAGE",
  49. aszHttpLanguage,
  50. &ccHttpLanguage) )
  51. {
  52. ciGibDebugOut(( DEB_ITRACE,
  53. "GetBrowserLCID: HTTP_ACCEPT_LANGAUGE was not set in the environment; using lcid=0x%x\n",
  54. GetSystemDefaultLCID() ));
  55. LCID locale = GetSystemDefaultLCID();
  56. WCHAR wcsLocale[100];
  57. GetStringFromLCID( locale, wcsLocale );
  58. ULONG cwcLocale = wcslen(wcsLocale) + 1;
  59. wcsHttpLanguage.Init( cwcLocale );
  60. RtlCopyMemory( wcsHttpLanguage.GetPointer(),
  61. wcsLocale,
  62. cwcLocale*sizeof(WCHAR) );
  63. webServer.SetLCID( locale, wcsLocale, cwcLocale );
  64. return locale;
  65. }
  66. //
  67. // Use the system's ANSI code page here since we're trying to figure
  68. // out which code page to use. The default code page is likely
  69. // correct since all of the locale names are simple strings containing
  70. // only characters A-Z.
  71. //
  72. unsigned cwcLocale = MultiByteToXArrayWideChar( (BYTE const *) aszHttpLanguage,
  73. ccHttpLanguage,
  74. GetACP(),
  75. wcsHttpLanguage );
  76. LCID lcid = GetLCIDFromString( wcsHttpLanguage.GetPointer() );
  77. if ( InvalidLCID == lcid )
  78. lcid = GetSystemDefaultLCID();
  79. webServer.SetLCID( lcid,
  80. wcsHttpLanguage.GetPointer(),
  81. cwcLocale + 1 );
  82. return lcid;
  83. }
  84. //+---------------------------------------------------------------------------
  85. //
  86. // Function: GetQueryLocale - public
  87. //
  88. // Synposis: Determines the locale in both a string and LCID form
  89. //
  90. // Arguments: [wcsCiLocale] - locale string from a IDQ/IDA file
  91. // [variableSet] - set of replaceable parameters
  92. // [outputFormat] - format for replaceable parameters
  93. // [xLocale] - the string representation of the locale
  94. //
  95. // History: 02-May-96 DwightKr Created
  96. // 11-Jun-97 KyleP Use web server from output format
  97. //
  98. //----------------------------------------------------------------------------
  99. LCID GetQueryLocale( WCHAR const * wcsCiLocale,
  100. CVariableSet & variableSet,
  101. COutputFormat & outputFormat,
  102. XArray<WCHAR> & xLocale )
  103. {
  104. ULONG cwcLocale;
  105. WCHAR * wcsLocale = ReplaceParameters( wcsCiLocale,
  106. variableSet,
  107. outputFormat,
  108. cwcLocale );
  109. LCID locale = InvalidLCID;
  110. //
  111. // If a locale was specified by the IDQ file, load its numeric
  112. // representation here.
  113. //
  114. if ( 0 != wcsLocale )
  115. {
  116. xLocale.Set( cwcLocale+1, wcsLocale );
  117. locale = GetLCIDFromString( xLocale.GetPointer() );
  118. if ( InvalidLCID == locale )
  119. {
  120. delete xLocale.Acquire();
  121. outputFormat.LoadNumberFormatInfo( GetBrowserLCID( outputFormat, xLocale ) );
  122. THROW( CIDQException(MSG_CI_IDQ_INVALID_LOCALE, 0) );
  123. }
  124. }
  125. else
  126. {
  127. //
  128. // If no locale was found in the IDQ file read the locale from
  129. // the browser. If the browser did not specify a locale, we'll
  130. // use the system's locale.
  131. //
  132. locale = GetBrowserLCID( outputFormat, xLocale );
  133. }
  134. return locale;
  135. }