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.

124 lines
4.2 KiB

  1. //-----------------------------------------------------------------------------
  2. //
  3. //
  4. // File: dsnconv.h
  5. //
  6. // Description: Base classes for DSN resource conversion
  7. //
  8. // Author: Mike Swafford (MikeSwa)
  9. //
  10. // History:
  11. // 10/21/98 - MikeSwa Created
  12. //
  13. // Copyright (C) 1998 Microsoft Corporation
  14. //
  15. //-----------------------------------------------------------------------------
  16. #ifndef __DSNCONV_H__
  17. #define __DSNCONV_H__
  18. //---[ CResourceConversionContext ]----------------------------------------------
  19. //
  20. //
  21. // Description:
  22. // Class used to abstract the various types of content conversion we
  23. // may be forced to do to support charsets other than US-ASCII.
  24. // Hungarian:
  25. // resconv, presconv
  26. //
  27. //-----------------------------------------------------------------------------
  28. class CResourceConversionContext
  29. {
  30. public:
  31. //Used to convert a UNICODE/ASCII resource to DSN body text
  32. //This additional abstraction (UNICODE vs ASCII)
  33. //is require for supporting potential additions like without messing with
  34. //the mainline buffer code
  35. // - guaranteed line length
  36. // - handling special ASCII characters in RFC822 headers
  37. // - Provides single code path for all buffer writes
  38. virtual BOOL fConvertBuffer(
  39. IN BOOL fASCII,
  40. IN PBYTE pbInputBuffer,
  41. IN DWORD cbInputBuffer,
  42. IN PBYTE pbOutputBuffer,
  43. IN DWORD cbOutputBuffer,
  44. OUT DWORD *pcbWritten,
  45. OUT DWORD *pcbRead) = 0;
  46. };
  47. //---[ CDefaultResourceConversionContext ]-------------------------------------
  48. //
  49. //
  50. // Description:
  51. // Default resource conversion object... simple memcpy for base case
  52. // Hungarian:
  53. // defconv, pdefconv
  54. //
  55. //-----------------------------------------------------------------------------
  56. class CDefaultResourceConversionContext : public CResourceConversionContext
  57. {
  58. public:
  59. BOOL fConvertBuffer(
  60. IN BOOL fASCII,
  61. IN PBYTE pbInputBuffer,
  62. IN DWORD cbInputBuffer,
  63. IN PBYTE pbOutputBuffer,
  64. IN DWORD cbOutputBuffer,
  65. OUT DWORD *pcbWritten,
  66. OUT DWORD *pcbRead);
  67. };
  68. //---[ CDefaultResourceConversionContext::fConvertBuffer ]----------------------
  69. //
  70. //
  71. // Description:
  72. // Default Resource conversion for DSNs
  73. // Parameters:
  74. // IN fASCII TRUE if buffer is ASCII
  75. // (*must* be TRUE for default)
  76. // IN pbInputBuffer Pointer to UNICODE string buffer
  77. // IN cbInputBuffer Size (in bytes) of string buffer
  78. // IN pbOutputBuffer Buffer to write data to
  79. // IN cbOutputBuffer Size of buffer to write data to
  80. // OUT pcbWritten # of bytes written to output bufferbuffer
  81. // OUT pcbRead # of bytes read from Input buffer
  82. // Returns:
  83. // TRUE if done converting
  84. // FALSE if needs more output buffer
  85. // History:
  86. // 10/21/98 - MikeSwa Created
  87. //
  88. //-----------------------------------------------------------------------------
  89. inline BOOL CDefaultResourceConversionContext::fConvertBuffer(
  90. IN BOOL fASCII,
  91. IN PBYTE pbInputBuffer,
  92. IN DWORD cbInputBuffer,
  93. IN PBYTE pbOutputBuffer,
  94. IN DWORD cbOutputBuffer,
  95. OUT DWORD *pcbWritten,
  96. OUT DWORD *pcbRead)
  97. {
  98. _ASSERT(pcbWritten);
  99. _ASSERT(pcbRead);
  100. _ASSERT(fASCII);
  101. if (cbInputBuffer <= cbOutputBuffer)
  102. {
  103. //everything can fit in current buffer
  104. memcpy(pbOutputBuffer, pbInputBuffer, cbInputBuffer);
  105. *pcbRead = cbInputBuffer;
  106. *pcbWritten = cbInputBuffer;
  107. return TRUE;
  108. }
  109. else
  110. {
  111. //we need to write in chunks
  112. memcpy(pbOutputBuffer, pbInputBuffer, cbOutputBuffer);
  113. *pcbRead = cbOutputBuffer;
  114. *pcbWritten = cbOutputBuffer;
  115. return FALSE;
  116. }
  117. }
  118. #endif //__DSNCONV_H__