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.

181 lines
4.7 KiB

  1. //
  2. // rdpfstore.h
  3. //
  4. // Definition of CRdpFileStore, implements ISettingsStore
  5. //
  6. // CRdpFileStore implements a persistent settings store for
  7. // ts client settings.
  8. //
  9. // Copyright(C) Microsoft Corporation 2000
  10. // Author: Nadim Abdo (nadima)
  11. //
  12. #ifndef _rdpfstore_h_
  13. #define _rdpfstore_h_
  14. #include "setstore.h"
  15. #include "fstream.h"
  16. //
  17. // rdpfile record
  18. //
  19. typedef UINT RDPF_RECTYPE;
  20. #define RDPF_RECTYPE_UINT 0
  21. #define RDPF_RECTYPE_SZ 1
  22. #define RDPF_RECTYPE_BINARY 2
  23. #define RDPF_RECTYPE_UNPARSED 3
  24. #define RDPF_NAME_LEN 32
  25. #define IS_VALID_RDPF_TYPECODE(x) \
  26. (x == RDPF_RECTYPE_UINT || \
  27. x == RDPF_RECTYPE_SZ || \
  28. x == RDPF_RECTYPE_BINARY || \
  29. x == RDPF_RECTYPE_UNPARSED)
  30. typedef struct tagRDPF_RECORD
  31. {
  32. tagRDPF_RECORD* pNext;
  33. tagRDPF_RECORD* pPrev;
  34. TCHAR szName[RDPF_NAME_LEN];
  35. //
  36. // works like a variant
  37. //
  38. RDPF_RECTYPE recType;
  39. union {
  40. UINT iVal; // RDPF_RECTYPE_UINT
  41. LPTSTR szVal; // RDPF_RECTYPE_SZ
  42. PBYTE pBinVal; // RDPF_RECTYPE_BINARY
  43. LPTSTR szUnparsed; // RDPF_RECTYPE_UNPARSED
  44. } u;
  45. //length of RDPF_RECTYPE_BINARY
  46. DWORD dwBinValLen;
  47. DWORD flags;
  48. } RDPF_RECORD, *PRDPF_RECORD;
  49. class CRdpFileStore : public ISettingsStore
  50. {
  51. public:
  52. CRdpFileStore();
  53. virtual ~CRdpFileStore();
  54. //
  55. // IUnknown methods
  56. //
  57. STDMETHOD(QueryInterface)
  58. ( THIS_
  59. IN REFIID,
  60. OUT PVOID *
  61. );
  62. STDMETHOD_(ULONG,AddRef)
  63. ( THIS
  64. );
  65. STDMETHOD_(ULONG,Release)
  66. ( THIS
  67. );
  68. //
  69. // ISettingsStore methods
  70. //
  71. //
  72. // Open a store..Moniker is store specific info that points to the store
  73. //
  74. virtual BOOL OpenStore(LPCTSTR szStoreMoniker, BOOL bReadOnly=FALSE);
  75. //
  76. // Commit the current in-memory contents of the store
  77. //
  78. virtual BOOL CommitStore();
  79. //
  80. // Close the store
  81. //
  82. virtual BOOL CloseStore();
  83. //
  84. // State access functions
  85. //
  86. virtual BOOL IsOpenForRead();
  87. virtual BOOL IsOpenForWrite();
  88. virtual BOOL IsDirty();
  89. virtual BOOL SetDirtyFlag(BOOL bIsDirty);
  90. //
  91. // Typed read and write functions, writes are not commited until a ComitStore()
  92. // Values equal to the default are not persisted out
  93. // On read error (e.g if Name key is not found, the specified default value is returned)
  94. //
  95. virtual BOOL ReadString(LPCTSTR szName, LPTSTR szDefault, LPTSTR szOutBuf, UINT strLen);
  96. virtual BOOL WriteString(LPCTSTR szName, LPTSTR szDefault, LPTSTR szValue,
  97. BOOL fIgnoreDefault=FALSE);
  98. virtual BOOL ReadBinary(LPCTSTR szName, PBYTE pOutuf, UINT cbBufLen);
  99. virtual BOOL WriteBinary(LPCTSTR szName,PBYTE pBuf, UINT cbBufLen);
  100. virtual BOOL ReadInt(LPCTSTR szName, UINT defaultVal, PUINT pval);
  101. virtual BOOL WriteInt(LPCTSTR szName, UINT defaultVal, UINT val,
  102. BOOL fIgnoreDefault=FALSE);
  103. virtual BOOL ReadBool(LPCTSTR szName, UINT defaultVal, PBOOL pbVal);
  104. virtual BOOL WriteBool(LPCTSTR szName, UINT defaultVal, BOOL bVal,
  105. BOOL fIgnoreDefault=FALSE);
  106. virtual BOOL DeleteValueIfPresent(LPCTSTR szName);
  107. virtual BOOL IsValuePresent(LPTSTR szName);
  108. //
  109. // Initiliaze to an empty store that can be read from
  110. //
  111. virtual BOOL SetToNullStore();
  112. virtual DWORD GetDataLength(LPCTSTR szName);
  113. protected:
  114. //
  115. // Protected member functions
  116. //
  117. BOOL ParseFile();
  118. BOOL DeleteRecords();
  119. BOOL InsertRecordFromLine(LPTSTR szLine);
  120. BOOL ParseLine(LPTSTR szLine, PUINT pTypeCode, LPTSTR szNameField, LPTSTR szValueField);
  121. inline BOOL SetNodeValue(PRDPF_RECORD pNode, RDPF_RECTYPE TypeCode, LPCTSTR szValue);
  122. BOOL RecordToString(PRDPF_RECORD pNode, LPTSTR szBuf, UINT strLen);
  123. //
  124. // Record list fns
  125. //
  126. BOOL InsertRecord(LPCTSTR szName, UINT TypeCode, LPCTSTR szValue);
  127. BOOL InsertIntRecord(LPCTSTR szName, UINT value);
  128. BOOL InsertBinaryRecord(LPCTSTR szName, PBYTE pBuf, DWORD dwLen);
  129. inline PRDPF_RECORD FindRecord(LPCTSTR szName);
  130. inline PRDPF_RECORD NewRecord(LPCTSTR szName, UINT TypeCode);
  131. inline BOOL AppendRecord(PRDPF_RECORD node);
  132. inline BOOL DeleteRecord(PRDPF_RECORD node);
  133. private:
  134. //
  135. // Private data members
  136. //
  137. LONG _cRef;
  138. BOOL _fReadOnly;
  139. BOOL _fOpenForRead;
  140. BOOL _fOpenForWrite;
  141. BOOL _fIsDirty;
  142. PRDPF_RECORD _pRecordListHead;
  143. PRDPF_RECORD _pRecordListTail;
  144. TCHAR _szFileName[MAX_PATH];
  145. //file stream
  146. CTscFileStream _fs;
  147. };
  148. #endif //_rdpfstore_h_