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.

179 lines
5.5 KiB

  1. // apgtsmfc.cpp
  2. // Equivalents of Global Afx MFC functions.
  3. // Use the real MFC functions if you can.
  4. #include "stdafx.h"
  5. #include "apgtsmfc.h"
  6. #include "apgtsassert.h"
  7. #include "CharConv.h"
  8. #include <stdio.h> // Needed for sprintf
  9. extern HANDLE ghModule;
  10. // This is not the name of any MFC Afx function
  11. // This loads a string from the resource file. It is here as a basis for CString::LoadString().
  12. // INPUT nID - resource ID of a string resource?
  13. // INPUT/OUTPUT lpszBuf - on input, points to a buffer. On output, that buffer contains ???
  14. // INPUT nMaxBuf - size of lpszBuf
  15. int AfxLoadString(UINT nID, LPTSTR lpszBuf, UINT nMaxBuf)
  16. {
  17. // convert integer value to a resource type compatible with Win32 resource-management
  18. // fns. (used in place of a string containing the name of the resource.)
  19. // >>> Why rightshift and add 1? (Ignore in V3.0 because this is if'd out, anyway)
  20. LPCTSTR lpszName = MAKEINTRESOURCE((nID>>4)+1);
  21. HINSTANCE hInst;
  22. int nLen = 0;
  23. // Only works from the main module.
  24. hInst = AfxGetResourceHandle();
  25. if (::FindResource(hInst, lpszName, RT_STRING) != NULL)
  26. nLen = ::LoadString(hInst, nID, lpszBuf, nMaxBuf);
  27. return nLen;
  28. }
  29. // Return HINSTANCE handle where the default resources of the application are loaded.
  30. HINSTANCE AfxGetResourceHandle()
  31. {
  32. return (HINSTANCE) ghModule;
  33. }
  34. #if 0
  35. // We've removed this because we are not using string resources. If we revive
  36. // string resources, we must revive this function.
  37. // INPUT/OUTPUT &rString�-��CString object (remember, not MFC CString). On return, will
  38. // contain the resultant string after the substitution is performed.
  39. // INPUT nIDS�- resource ID of template string on which the substitution will be performed.
  40. // INPUT *lpsz1�-�In the MFC AfxFormatString1, a string that will replace the format
  41. // characters "%1" in the template string. In our version, will perform only a single
  42. // replacement & will replace '%' followed by _any_ character.
  43. // Will be a mess if rString as pased in does not contain such an instance.
  44. void AfxFormatString1(CString& rString, UINT nIDS, LPCTSTR lpsz1)
  45. {
  46. CString str;
  47. str.LoadString(nIDS);
  48. int iInsert = str.Find('%', -1);
  49. rString = str.Left(iInsert);
  50. rString += lpsz1;
  51. rString += str.Right(str.GetLength() - iInsert - 2);
  52. return;
  53. }
  54. #endif
  55. #if 0
  56. // We've removed this because we are not using string resources. If we revive
  57. // string resources, we must revive this function.
  58. // Like AfxFormatString1, but also has an input lpsz2 to replace the format characters "%2.
  59. // In our version, will perform only a single replacement by lpsz1 and a single replacement
  60. // by lpsz2, & rather than look for "%1" and "%2" will replace the first 2 instances of
  61. // '%' followed by _any_ character.
  62. // Will be a mess if rString as pased in does not contain 2 such instances.
  63. void AfxFormatString2(CString& rString, UINT nIDS, LPCTSTR lpsz1,
  64. LPCTSTR lpsz2)
  65. {
  66. int iFirst;
  67. int iSecond;
  68. CString str;
  69. str.LoadString(nIDS);
  70. iFirst = str.Find('%', -1);
  71. rString = str.Left(iFirst);
  72. rString += lpsz1;
  73. iSecond = str.Find(_T('%'), iFirst);
  74. rString += str.Mid(iFirst + 2, iSecond - (iFirst + 2) );
  75. rString += lpsz2;
  76. rString += str.Right(str.GetLength() - iSecond - 2);
  77. return;
  78. }
  79. #endif
  80. // Utilize this namespace for non-class related functions.
  81. namespace APGTS_nmspace
  82. {
  83. // function of convenience - has nothing to do with MFC
  84. bool GetServerVariable(CAbstractECB *pECB, LPCSTR var_name, CString& out)
  85. {
  86. char buf[256] = {0}; // 256 should cover all cases
  87. DWORD size = sizeof(buf)/sizeof(buf[0]);
  88. if (pECB->GetServerVariable(var_name, buf, &size))
  89. {
  90. out = (LPCTSTR)buf;
  91. return true;
  92. }
  93. return false;
  94. }
  95. // >>> $MAINT - It would be preferable to use standardized encode-decoding logic rather
  96. // than maintaining this custom code. RAB-19990921.
  97. // V3.2
  98. // Utility function to URL encode cookies.
  99. // char, not TCHAR: cookie is always ASCII.
  100. void CookieEncodeURL( CString& strURL )
  101. {
  102. CString strTemp;
  103. int nURLpos;
  104. char cCurByte;
  105. for (nURLpos= 0; nURLpos < strURL.GetLength(); nURLpos++)
  106. {
  107. cCurByte= strURL[ nURLpos ];
  108. if (isalnum( cCurByte ))
  109. strTemp+= strURL.Mid( nURLpos, 1 );
  110. else if (cCurByte == _T(' '))
  111. strTemp+= _T("+");
  112. else if ((cCurByte == _T('=')) || (cCurByte == _T('&'))) // Skip over name-pair delimiters.
  113. strTemp+= strURL.Mid( nURLpos, 1 );
  114. else if ((cCurByte == _T('+')) || (cCurByte == _T('%'))) // Skip over previously encoded characters.
  115. strTemp+= strURL.Mid( nURLpos, 1 );
  116. else
  117. {
  118. // Encode all other characters.
  119. char szBuff[5];
  120. sprintf( szBuff, _T("%%%02X"), (unsigned char) cCurByte );
  121. strTemp+= szBuff;
  122. }
  123. }
  124. strURL= strTemp;
  125. return;
  126. }
  127. // Utility function to URL decode cookies.
  128. // char, not TCHAR: cookie is always ASCII.
  129. void CookieDecodeURL( CString& strURL )
  130. {
  131. CString strTemp;
  132. int nURLpos;
  133. char cCurByte;
  134. for (nURLpos= 0; nURLpos < strURL.GetLength(); nURLpos++)
  135. {
  136. cCurByte= strURL[ nURLpos ];
  137. if (cCurByte == _T('+'))
  138. strTemp+= _T(" ");
  139. else if (cCurByte == _T('%'))
  140. {
  141. // Decode URL encoded characters.
  142. char szBuff[3];
  143. int nVal;
  144. szBuff[ 0 ]= strURL[ ++nURLpos ];
  145. szBuff[ 1 ]= strURL[ ++nURLpos ];
  146. szBuff[ 2 ]= '\0';
  147. sscanf( szBuff, "%02x", &nVal );
  148. sprintf( szBuff, "%c", nVal );
  149. strTemp+= szBuff;
  150. }
  151. else
  152. strTemp+= strURL.Mid( nURLpos, 1 );
  153. }
  154. strURL= strTemp;
  155. return;
  156. }
  157. }