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.

98 lines
3.4 KiB

  1. //-----------------------------------------------------------------------------
  2. //
  3. //
  4. // File: dsn_utf7
  5. //
  6. // Description: Implementations of UTF-7 based unicode character encoding
  7. // methods for DSN generation.
  8. //
  9. // Author: Mike Swafford (MikeSwa)
  10. //
  11. // History:
  12. // 10/20/98 - MikeSwa Created
  13. //
  14. // Copyright (C) 1998 Microsoft Corporation
  15. //
  16. //-----------------------------------------------------------------------------
  17. #ifndef __DSN_UTF7_H__
  18. #define __DSN_UTF7_H__
  19. #include <windows.h>
  20. #include <dbgtrace.h>
  21. #include "b64octet.h"
  22. #include "dsnconv.h"
  23. #define UTF7_CHARSET "unicode-1-1-utf-7"
  24. #define UTF7_CONTEXT_SIG '7FTU'
  25. #define UTF7_START_STREAM_CHAR '+'
  26. #define UTF7_STOP_STREAM_CHAR '-'
  27. #define UTF7_RFC1522_ENCODE_START "=?" UTF7_CHARSET "?Q?+"
  28. #define UTF7_RFC1522_ENCODE_STOP "?="
  29. #define UTF7_RFC1522_PHRASE_SEPARATOR " \r\n\t"
  30. #define UTF7_RFC1522_MAX_LENGTH 76
  31. class CUTF7ConversionContext : public CDefaultResourceConversionContext
  32. {
  33. protected:
  34. DWORD m_dwSignature;
  35. DWORD m_cBytesSinceCRLF;
  36. DWORD m_dwCurrentState;
  37. CHAR chNeedsEncoding(WCHAR wch);
  38. CBase64OctetStream m_Base64Stream;
  39. //State Description enum flags
  40. enum
  41. {
  42. UTF7_INITIAL_STATE = 0x00000000, //Initial state
  43. UTF7_ENCODING_RFC1522_SUBJECT = 0x80000000, //encoding RFC1522 subject
  44. UTF7_ENCODING_WORD = 0x00000001, //In process of encoding a word
  45. UTF7_WORD_CLOSING_PENDING = 0x00000002, //Needs a '-'
  46. UTF7_RFC1522_CHARSET_PENDING = 0x00000004, //=?charset?Q?+ pending
  47. UTF7_RFC1522_CLOSING_PENDING = 0x00000008, //needs '=?'
  48. UTF7_RFC1522_CURRENTLY_ENCODING = 0x00000010, //Currently encoding RFC1522 phrase
  49. UTF7_FOLD_HEADER_PENDING = 0x00000020, //Need to fold head before encoding
  50. //more
  51. UTF7_FLUSH_BUFFERS = 0x00000040, //Need to flush conversion buffers
  52. //Used to determine if subject needs to be encoded
  53. UTF7_SOME_INVALID_RFC822_CHARS = 0x40000000, //Contains some invalid RFC822 chars
  54. UFT7_ALL_VALID_RFC822_CHARS = 0x20000000, //All characters are valid RFC822 chars
  55. };
  56. void WriteChar(IN CHAR ch, IN OUT BYTE ** ppbBuffer, IN OUT DWORD *pcbWritten);
  57. BOOL fWriteString(IN LPSTR szString, IN DWORD cbString, IN DWORD cbBuffer,
  58. IN OUT BYTE ** ppbBuffer, IN OUT DWORD *pcbWritten);
  59. BOOL fSubjectNeedsEncoding(IN BYTE *pbBuffer, IN DWORD cbBuffer);
  60. BOOL fUTF7EncodeBuffer(
  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. BOOL fConvertBufferTo7BitASCII(
  68. IN PBYTE pbInputBuffer,
  69. IN DWORD cbInputBuffer,
  70. IN PBYTE pbOutputBuffer,
  71. IN DWORD cbOutputBuffer,
  72. OUT DWORD *pcbWritten,
  73. OUT DWORD *pcbRead);
  74. public:
  75. CUTF7ConversionContext(BOOL fIsRFC1522Subject = FALSE);
  76. BOOL fConvertBuffer(
  77. IN BOOL fASCII,
  78. IN PBYTE pbInputBuffer,
  79. IN DWORD cbInputBuffer,
  80. IN PBYTE pbOutputBuffer,
  81. IN DWORD cbOutputBuffer,
  82. OUT DWORD *pcbWritten,
  83. OUT DWORD *pcbRead);
  84. };
  85. #endif //__DSN_UTF7_H__