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.

207 lines
4.6 KiB

  1. #include "inspch.h"
  2. #include "inseng.h"
  3. #include "download.h"
  4. #include "site.h"
  5. #include "util2.h"
  6. CDownloadSite::CDownloadSite(DOWNLOADSITE *p)
  7. {
  8. m_cRef = 0;
  9. m_pdls = p;
  10. DllAddRef();
  11. }
  12. CDownloadSite::~CDownloadSite()
  13. {
  14. if(m_pdls)
  15. FreeDownloadSite(m_pdls);
  16. DllRelease();
  17. }
  18. //************ IUnknown implementation ***************
  19. //=--------------------------------------------------------------------------=
  20. // Function name here
  21. //=--------------------------------------------------------------------------=
  22. // Function description
  23. //
  24. // Parameters:
  25. //
  26. // Returns:
  27. //
  28. // Notes:
  29. //
  30. STDMETHODIMP_(ULONG) CDownloadSite::AddRef()
  31. {
  32. return(m_cRef++);
  33. }
  34. //=--------------------------------------------------------------------------=
  35. // Function name here
  36. //=--------------------------------------------------------------------------=
  37. // Function description
  38. //
  39. // Parameters:
  40. //
  41. // Returns:
  42. //
  43. // Notes:
  44. //
  45. STDMETHODIMP_(ULONG) CDownloadSite::Release()
  46. {
  47. ULONG temp = --m_cRef;
  48. if(temp == 0)
  49. delete this;
  50. return temp;
  51. }
  52. //=--------------------------------------------------------------------------=
  53. // Function name here
  54. //=--------------------------------------------------------------------------=
  55. // Function description
  56. //
  57. // Parameters:
  58. //
  59. // Returns:
  60. //
  61. // Notes:
  62. //
  63. STDMETHODIMP CDownloadSite::QueryInterface(REFIID riid, void **ppv)
  64. {
  65. *ppv = NULL;
  66. if((riid == IID_IUnknown) || (riid == IID_IDownloadSite))
  67. *ppv = (IDownloadSite *)this;
  68. if(*ppv == NULL)
  69. return E_NOINTERFACE;
  70. AddRef();
  71. return NOERROR;
  72. }
  73. //=--------------------------------------------------------------------------=
  74. // Function name here
  75. //=--------------------------------------------------------------------------=
  76. // Function description
  77. //
  78. // Parameters:
  79. //
  80. // Returns:
  81. //
  82. // Notes:
  83. //
  84. STDMETHODIMP CDownloadSite::GetData(DOWNLOADSITE **ppdls)
  85. {
  86. if(ppdls)
  87. *ppdls = m_pdls;
  88. else
  89. return E_POINTER;
  90. return NOERROR;
  91. }
  92. // BUGBUG: I have two versions - one allocating using new (HeapAlloc)
  93. // for internal use, one using CoTaskMem... that I give away.
  94. // I am using new internally because I suspect it may be faster/less
  95. // expensive. but this makes code more complex. Good choice?
  96. // BUGBUG: Allow null url or friendly name?
  97. IDownloadSite *CopyDownloadSite(DOWNLOADSITE *pdls)
  98. {
  99. DOWNLOADSITE *p;
  100. IDownloadSite *psite = NULL;
  101. p = (DOWNLOADSITE *) CoTaskMemAlloc(sizeof(DOWNLOADSITE));
  102. if(p)
  103. {
  104. p->cbSize = sizeof(DOWNLOADSITE);
  105. p->pszUrl = COPYANSISTR(pdls->pszUrl);
  106. p->pszFriendlyName = COPYANSISTR(pdls->pszFriendlyName);
  107. p->pszLang = COPYANSISTR(pdls->pszLang);
  108. p->pszRegion = COPYANSISTR(pdls->pszRegion);
  109. if(!p->pszUrl || !p->pszFriendlyName || !p->pszLang || !p->pszRegion)
  110. {
  111. FreeDownloadSite(p);
  112. p = NULL;
  113. }
  114. }
  115. if(p)
  116. {
  117. //allocate the interface wrapper
  118. CDownloadSite *site = new CDownloadSite(p);
  119. if(site)
  120. {
  121. psite = (IDownloadSite *)site;
  122. psite->AddRef();
  123. }
  124. }
  125. return psite;
  126. }
  127. DOWNLOADSITE *AllocateDownloadSite(LPCSTR pszUrl, LPCSTR pszName, LPCSTR pszLang, LPCSTR pszRegion)
  128. {
  129. DOWNLOADSITE *p = new DOWNLOADSITE;
  130. if(p)
  131. {
  132. p->cbSize = sizeof(DOWNLOADSITE);
  133. p->pszUrl = CopyAnsiStr(pszUrl);
  134. p->pszFriendlyName = CopyAnsiStr(pszName);
  135. p->pszLang = CopyAnsiStr(pszLang);
  136. p->pszRegion = CopyAnsiStr(pszRegion);
  137. if(!p->pszUrl || !p->pszFriendlyName || !p->pszLang || !p->pszRegion)
  138. {
  139. DeleteDownloadSite(p);
  140. p = NULL;
  141. }
  142. }
  143. return p;
  144. }
  145. // this version deletes a DOWNLOADSITE allocated from the heap
  146. void DeleteDownloadSite(DOWNLOADSITE *pdls)
  147. {
  148. if(pdls)
  149. {
  150. if(pdls->pszUrl)
  151. delete pdls->pszUrl;
  152. if(pdls->pszFriendlyName)
  153. delete pdls->pszFriendlyName;
  154. if(pdls->pszLang)
  155. delete pdls->pszLang;
  156. if(pdls->pszRegion)
  157. delete pdls->pszRegion;
  158. delete pdls;
  159. }
  160. }
  161. // this version deletes a DOWNLOADSITE allocated thru CoTaskMemAlloc
  162. void FreeDownloadSite(DOWNLOADSITE *pdls)
  163. {
  164. if(pdls)
  165. {
  166. if(pdls->pszUrl)
  167. CoTaskMemFree(pdls->pszUrl);
  168. if(pdls->pszFriendlyName)
  169. CoTaskMemFree(pdls->pszFriendlyName);
  170. if(pdls->pszLang)
  171. CoTaskMemFree(pdls->pszLang);
  172. if(pdls->pszRegion)
  173. CoTaskMemFree(pdls->pszRegion);
  174. CoTaskMemFree(pdls);
  175. }
  176. }