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
4.0 KiB

  1. //
  2. // tfprop.h
  3. //
  4. #ifndef TFPROP_H
  5. #define TFPROP_H
  6. #include "mem.h"
  7. typedef struct _PROXY_BLOB
  8. {
  9. ULONG cb;
  10. BYTE rgBytes[1]; // 0 or more...
  11. static struct _PROXY_BLOB *Alloc(ULONG cb)
  12. {
  13. return (struct _PROXY_BLOB *)cicMemAlloc(sizeof(ULONG)+cb);
  14. }
  15. static struct _PROXY_BLOB *Clone(struct _PROXY_BLOB *blobOrg)
  16. {
  17. struct _PROXY_BLOB *blobNew;
  18. if ((blobNew = Alloc(blobOrg->cb)) == NULL)
  19. return FALSE;
  20. blobNew->cb = blobOrg->cb;
  21. memcpy(blobNew->rgBytes, blobOrg->rgBytes, blobOrg->cb);
  22. return blobNew;
  23. }
  24. static void Free(struct _PROXY_BLOB *blob)
  25. {
  26. cicMemFree(blob);
  27. }
  28. } PROXY_BLOB;
  29. typedef enum
  30. {
  31. TF_PT_NONE = 0,
  32. TF_PT_UNKNOWN = 1,
  33. TF_PT_DWORD = 2,
  34. TF_PT_GUID = 3,
  35. TF_PT_BSTR = 4
  36. } TfPropertyType;
  37. typedef struct tagTFPROPERTY
  38. {
  39. TfPropertyType type;
  40. union
  41. {
  42. IUnknown * punk;
  43. DWORD dw;
  44. TfGuidAtom guidatom;
  45. BSTR bstr;
  46. PROXY_BLOB * blob;
  47. };
  48. } TFPROPERTY;
  49. inline BOOL IsValidCiceroVarType(VARTYPE vt)
  50. {
  51. return (vt == VT_I4 || vt == VT_UNKNOWN || vt == VT_EMPTY || vt == VT_BSTR);
  52. }
  53. typedef enum { ADDREF, NO_ADDREF } AddRefCmd;
  54. inline HRESULT VariantToTfProp(TFPROPERTY *ptfp, const VARIANT *pvar, AddRefCmd arc, BOOL fVTI4ToGuidAtom)
  55. {
  56. HRESULT hr = S_OK;
  57. switch (pvar->vt)
  58. {
  59. case VT_I4:
  60. if (fVTI4ToGuidAtom)
  61. ptfp->type = TF_PT_GUID;
  62. else
  63. ptfp->type = TF_PT_DWORD;
  64. ptfp->dw = pvar->lVal;
  65. break;
  66. case VT_UNKNOWN:
  67. ptfp->type = TF_PT_UNKNOWN;
  68. ptfp->punk = pvar->punkVal;
  69. if (arc == ADDREF)
  70. {
  71. if (ptfp->punk)
  72. ptfp->punk->AddRef();
  73. }
  74. break;
  75. case VT_BSTR:
  76. ptfp->type = TF_PT_BSTR;
  77. ptfp->bstr = SysAllocString(pvar->bstrVal);
  78. if (ptfp->bstr == NULL)
  79. {
  80. hr = E_OUTOFMEMORY;
  81. }
  82. break;
  83. default:
  84. Assert(pvar->vt == VT_EMPTY); // only valid value left
  85. ptfp->type = TF_PT_NONE;
  86. ptfp->dw = 0;
  87. break;
  88. }
  89. return hr;
  90. }
  91. inline HRESULT TfPropToVariant(VARIANT *pvar, TFPROPERTY *ptfp, AddRefCmd arc)
  92. {
  93. HRESULT hr = S_OK;
  94. QuickVariantInit(pvar);
  95. switch (ptfp->type)
  96. {
  97. case TF_PT_DWORD:
  98. case TF_PT_GUID:
  99. pvar->vt = VT_I4;
  100. pvar->lVal = ptfp->dw;
  101. break;
  102. case TF_PT_UNKNOWN:
  103. pvar->vt = VT_UNKNOWN;
  104. pvar->punkVal = ptfp->punk;
  105. if (arc == ADDREF)
  106. {
  107. if (pvar->punkVal)
  108. pvar->punkVal->AddRef();
  109. }
  110. break;
  111. case TF_PT_BSTR:
  112. pvar->vt = VT_BSTR;
  113. if (arc == ADDREF)
  114. {
  115. pvar->bstrVal = SysAllocString(ptfp->bstr);
  116. if (pvar->bstrVal == NULL)
  117. {
  118. hr = E_OUTOFMEMORY;
  119. }
  120. }
  121. else
  122. pvar->bstrVal = ptfp->bstr;
  123. break;
  124. default:
  125. Assert(ptfp->type == TF_PT_NONE);
  126. pvar->lVal = 0;
  127. break;
  128. }
  129. return hr;
  130. }
  131. inline VARTYPE TfPropTypeToVarType(TfPropertyType tftype)
  132. {
  133. switch (tftype)
  134. {
  135. case TF_PT_DWORD:
  136. case TF_PT_GUID:
  137. return VT_I4;
  138. case TF_PT_UNKNOWN:
  139. return VT_UNKNOWN;
  140. case TF_PT_BSTR:
  141. return VT_BSTR;
  142. default:
  143. Assert(tftype == TF_PT_NONE);
  144. return VT_EMPTY;
  145. }
  146. }
  147. #endif // TFPROP_H